Gmane
Picon
From: Markus Heidelberg <markus.heidelberg <at> web.de>
Subject: [PATCH] gitk: Fix "git gui blame" invocation when called from topdir
Newsgroups: gmane.comp.version-control.git
Date: 2009-06-21 17:34:11 GMT (37 weeks, 4 days, 2 hours and 6 minutes ago)
In this case "git rev-parse --git-dir" doesn't return an absolute path,
but merely ".git", so the selected file has a relative path.
The function make_relative then tries to make the already relative path
relative, which results in a path like "../../../../Makefile" with as
much ".." as the number of parts [pwd] consists of.

This regression was introduced by commit 9712b81 (gitk: Fix bugs in
blaming code, 2008-12-06), which fixed "git gui blame" when called from
subdirs.

This also fixes it for bare repositories.

Signed-off-by: Markus Heidelberg <markus.heidelberg <at> web.de>
---

    For convencience the output of diff -w:

    @@ -3366,6 +3366,7 @@ proc index_sha1 {fname} {

     # Turn an absolute path into one relative to the current directory
     proc make_relative {f} {
    +    if {[file pathtype $f] ne "relative"} {
         set elts [file split $f]
         set here [file split [pwd]]
         set ei 0
    @@ -3381,6 +3382,9 @@ proc make_relative {f} {
         }
         set elts [concat $res [lrange $elts $ei end]]
         return [eval file join $elts]
    +    } else {
    +       return $f
    +    }
     }

     proc external_blame {parent_idx {line {}}} {

    While fixing this I also noticed that the tree view treats pwd as the
    topdir, so it shows directly .gitignore instead of po/.gitignore for
    example.

 gitk |   30 +++++++++++++++++-------------
 1 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/gitk b/gitk
index 4604c83..46d7782 100755
--- a/gitk
+++ b/gitk
@@ -3366,21 +3366,25 @@ proc index_sha1 {fname} {

 # Turn an absolute path into one relative to the current directory
 proc make_relative {f} {
-    set elts [file split $f]
-    set here [file split [pwd]]
-    set ei 0
-    set hi 0
-    set res {}
-    foreach d $here {
-	if {$ei < $hi || $ei >= [llength $elts] || [lindex $elts $ei] ne $d} {
-	    lappend res ".."
-	} else {
-	    incr ei
+    if {[file pathtype $f] ne "relative"} {
+	set elts [file split $f]
+	set here [file split [pwd]]
+	set ei 0
+	set hi 0
+	set res {}
+	foreach d $here {
+	    if {$ei < $hi || $ei >= [llength $elts] || [lindex $elts $ei] ne $d} {
+		lappend res ".."
+	    } else {
+		incr ei
+	    }
+	    incr hi
 	}
-	incr hi
+	set elts [concat $res [lrange $elts $ei end]]
+	return [eval file join $elts]
+    } else {
+	return $f
     }
-    set elts [concat $res [lrange $elts $ei end]]
-    return [eval file join $elts]
 }

 proc external_blame {parent_idx {line {}}} {
-- 
1.6.3.2.369.gdf06