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

[PATCH (GIT-GUI FIX)] git-gui: Fix handling of relative paths in blame.

From
Alexander Gavrilov <angavrilov@gmail.com>
Date
Dec 6, 2008, 17:21 UTC
Message-ID
<200812062021.55061.angavrilov@gmail.com>

Currently using '..' or '.' in the file path for gui blame causes it to break, because the path is passed inside the SHA:PATH spec to cat-file, which apparently does not understand such items. As a result, cat-file returns nothing, and the viewer crashes because of an "index out of range" error.

This commit adds a simple function that normalizes such paths. I choose not to use [file normalize], because it uses some data from the file system, e.g. dereferences symlinks, and creates an absolute path, while blame may be used to inspect historical information that bears no relation to the current filesystem state.

Signed-off-by: Alexander Gavrilov <angavrilov@gmail.com>
---
	On Saturday 06 December 2008 13:56:45 Paul Mackerras wrote:
	> I have checked in a fix into my gitk.git repository at
	> git://git.kernel.org/pub/scm/gitk/gitk.git.  However, there seems to
	> be a bug in git gui blame; it gives a "list index out of range" error
	> sometimes.
	> 
	> Shawn, to see an example of the error, get a current kernel tree and
	> do:
	> 
	> $ cd arch/powerpc
	> $ git gui blame --line=1183 2c5e76158fcea6e3b9536a74efa7b5e2e846d374 \
	>   ../../net/sunrpc/svcsock.c
 git-gui.sh |   18 ++++++++++++++++--
 1 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/git-gui.sh b/git-gui.sh
index 8a4b42d..65dacf9 100755
--- a/git-gui.sh
+++ b/git-gui.sh
@@ -2630,6 +2630,20 @@ proc usage {} {
 	exit 1
 }
 
+proc normalize_relpath {path} {
+	set elements {}
+	foreach item [file split $path] {
+		if {$item eq {.}} continue
+		if {$item eq {..} && [llength $elements] > 0
+		    && [lindex $elements end] ne {..}} {
+			set elements [lrange $elements 0 end-1]
+			continue
+		}
+		lappend elements $item
+	}
+	return [eval file join $elements]
+}
+
 # -- Not a normal commit type invocation?  Do that instead!
 #
 switch -- $subcommand {
@@ -2648,7 +2662,7 @@ blame {
 	foreach a $argv {
 		if {$is_path || [file exists $_prefix$a]} {
 			if {$path ne {}} usage
-			set path $_prefix$a
+			set path [normalize_relpath $_prefix$a]
 			break
 		} elseif {$a eq {--}} {
 			if {$path ne {}} {
@@ -2671,7 +2685,7 @@ blame {
 	unset is_path
 
 	if {$head ne {} && $path eq {}} {
-		set path $_prefix$head
+		set path [normalize_relpath $_prefix$head]
 		set head {}
 	}
 
-- 
1.6.0.4.30.gf4240
Message 1 of 1 in “git-gui: Fix handling of relative paths in blame.”
  1. git-gui: Fix handling of relative paths in blame.Alexander Gavrilov, Dec 6, 2008

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.