threads / patch / 21445

patchgitk: Fix "git gui blame" invocation when called from topdir

Subject: [PATCH resend] gitk: Fix "git gui blame" invocation when called from topdir

## tl;dr

4 messages between Oct 31, 2009 and Nov 14, 2009. Diffs are folded; open one to read it.

replies: 3people: 2as markdown or json

Markus Heidelberg· Oct 31, 2009, 12:09 UTC · lore

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@web.de>
---
 gitk |   30 +++++++++++++++++-------------
 1 files changed, 17 insertions(+), 13 deletions(-)
Show changes to gitk +17 −13
diff --git a/gitk b/gitk
index a0214b7..07a9440 100755
--- a/gitk
+++ b/gitk
@@ -3377,21 +3377,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.5.2.155.gaa0e5
Paul Mackerras· Nov 3, 2009, 10:39 UTC · re: Markus Heidelberg · lore

Re: [PATCH resend] gitk: Fix "git gui blame" invocation when called from topdir

Markus Heidelberg writes:
Show 11 quoted lines
> 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.
Thanks for the patch, but I'd prefer to just add:
    if {[file pathtype $f] ne "relative"} {
	return $f
    }

at the start of the function. I think that's easier to read than having a big if statement. Would you like to do a new patch or will I just make that change to your patch?

Paul.
Markus Heidelberg· Nov 3, 2009, 23:21 UTC · re: Paul Mackerras · lore

[PATCH] gitk: Fix "git gui blame" invocation when called from topdir

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@web.de>
---
    Paul Mackerras, 03.11.2009:
    > Thanks for the patch, but I'd prefer to just add:
    > 
    >     if {[file pathtype $f] ne "relative"} {
    >         return $f
    >     }
    > 
    > at the start of the function.  I think that's easier to read than
    > having a big if statement.
    
    Definitely yes. But eq instead of ne.
    
 gitk |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
Show changes to gitk +3 −0
diff --git a/gitk b/gitk
index 32e4ab0..949abfe 100755
--- a/gitk
+++ b/gitk
@@ -3378,6 +3378,9 @@ proc index_sha1 {fname} {
 
 # Turn an absolute path into one relative to the current directory
 proc make_relative {f} {
+    if {[file pathtype $f] eq "relative"} {
+	return $f
+    }
     set elts [file split $f]
     set here [file split [pwd]]
     set ei 0
-- 
1.6.5.2.155.gaa0e5
Paul Mackerras· Nov 14, 2009, 11:14 UTC · re: Markus Heidelberg · lore

Re: [PATCH] gitk: Fix "git gui blame" invocation when called from topdir

Markus Heidelberg writes:
Show 13 quoted lines
> 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@web.de>
Thanks, applied.
Paul.

← back to recent threads