git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Markus Heidelberg <markus.heidelberg@web.de>
Date
Oct 31, 2009, 12:09 UTC
Message-ID
<1256990974-32671-1-git-send-email-markus.heidelberg@web.de>

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(-)
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
Next: Paul Mackerras
Message 1 of 4 in “gitk: Fix "git gui blame" invocation when called from topdir”
  1. gitk: Fix "git gui blame" invocation when called from topdirMarkus Heidelberg, Oct 31, 2009
  2. Paul MackerrasNov 3, 2009
  3. gitk: Fix "git gui blame" invocation when called from topdirMarkus Heidelberg, Nov 3, 2009
  4. Paul MackerrasNov 14, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.