{"thread":{"id":"19887","subject":"[PATCH] gitk: Fix \"git gui blame\" invocation when called from topdir","startedAt":"2009-06-21T17:34:11Z","lastAt":"2009-06-21T17:34:11Z","messageCount":1,"participants":["Markus Heidelberg"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"116717","messageId":"1245605651-27001-1-git-send-email-markus.heidelberg@web.de","threadId":"19887","inReplyTo":null,"subject":"[PATCH] gitk: Fix \"git gui blame\" invocation when called from topdir","fromName":"Markus Heidelberg","fromEmail":"markus.heidelberg@web.de","sentAt":"2009-06-21T17:34:11Z","receivedAt":"2009-06-21T17:34:11Z","isPatch":true,"sender":{"key":"markus.heidelberg@web.de","avatar":"https://avatars.githubusercontent.com/u/6334512?v=4"},"body":"In this case \"git rev-parse --git-dir\" doesn't return an absolute path,\nbut merely \".git\", so the selected file has a relative path.\nThe function make_relative then tries to make the already relative path\nrelative, which results in a path like \"../../../../Makefile\" with as\nmuch \"..\" as the number of parts [pwd] consists of.\n\nThis regression was introduced by commit 9712b81 (gitk: Fix bugs in\nblaming code, 2008-12-06), which fixed \"git gui blame\" when called from\nsubdirs.\n\nThis also fixes it for bare repositories.\n\nSigned-off-by: Markus Heidelberg <markus.heidelberg@web.de>\n---\n\n    For convencience the output of diff -w:\n\n    @@ -3366,6 +3366,7 @@ proc index_sha1 {fname} {\n    \n     # Turn an absolute path into one relative to the current directory\n     proc make_relative {f} {\n    +    if {[file pathtype $f] ne \"relative\"} {\n         set elts [file split $f]\n         set here [file split [pwd]]\n         set ei 0\n    @@ -3381,6 +3382,9 @@ proc make_relative {f} {\n         }\n         set elts [concat $res [lrange $elts $ei end]]\n         return [eval file join $elts]\n    +    } else {\n    +       return $f\n    +    }\n     }\n    \n     proc external_blame {parent_idx {line {}}} {\n\n\n    While fixing this I also noticed that the tree view treats pwd as the\n    topdir, so it shows directly .gitignore instead of po/.gitignore for\n    example.\n\n gitk |   30 +++++++++++++++++-------------\n 1 files changed, 17 insertions(+), 13 deletions(-)\n\ndiff --git a/gitk b/gitk\nindex 4604c83..46d7782 100755\n--- a/gitk\n+++ b/gitk\n@@ -3366,21 +3366,25 @@ proc index_sha1 {fname} {\n \n # Turn an absolute path into one relative to the current directory\n proc make_relative {f} {\n-    set elts [file split $f]\n-    set here [file split [pwd]]\n-    set ei 0\n-    set hi 0\n-    set res {}\n-    foreach d $here {\n-\tif {$ei < $hi || $ei >= [llength $elts] || [lindex $elts $ei] ne $d} {\n-\t    lappend res \"..\"\n-\t} else {\n-\t    incr ei\n+    if {[file pathtype $f] ne \"relative\"} {\n+\tset elts [file split $f]\n+\tset here [file split [pwd]]\n+\tset ei 0\n+\tset hi 0\n+\tset res {}\n+\tforeach d $here {\n+\t    if {$ei < $hi || $ei >= [llength $elts] || [lindex $elts $ei] ne $d} {\n+\t\tlappend res \"..\"\n+\t    } else {\n+\t\tincr ei\n+\t    }\n+\t    incr hi\n \t}\n-\tincr hi\n+\tset elts [concat $res [lrange $elts $ei end]]\n+\treturn [eval file join $elts]\n+    } else {\n+\treturn $f\n     }\n-    set elts [concat $res [lrange $elts $ei end]]\n-    return [eval file join $elts]\n }\n \n proc external_blame {parent_idx {line {}}} {\n-- \n1.6.3.2.369.gdf06\n"}]}