{"thread":{"id":"16612","subject":"[PATCH (GIT-GUI FIX)] git-gui: Fix handling of relative paths in blame.","startedAt":"2008-12-06T17:21:54Z","lastAt":"2008-12-06T17:21:54Z","messageCount":1,"participants":["Alexander Gavrilov"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"97268","messageId":"200812062021.55061.angavrilov@gmail.com","threadId":"16612","inReplyTo":null,"subject":"[PATCH (GIT-GUI FIX)] git-gui: Fix handling of relative paths in blame.","fromName":"Alexander Gavrilov","fromEmail":"angavrilov@gmail.com","sentAt":"2008-12-06T17:21:54Z","receivedAt":"2008-12-06T17:21:54Z","isPatch":true,"sender":{"key":"angavrilov@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42666?v=4"},"body":"Currently using '..' or '.' in the file path for gui blame\ncauses it to break, because the path is passed inside the \nSHA:PATH spec to cat-file, which apparently does not understand\nsuch items. As a result, cat-file returns nothing, and the\nviewer crashes because of an \"index out of range\" error.\n\nThis commit adds a simple function that normalizes such paths.\nI choose not to use [file normalize], because it uses some data\nfrom the file system, e.g. dereferences symlinks, and creates\nan absolute path, while blame may be used to inspect historical\ninformation that bears no relation to the current filesystem state.\n\nSigned-off-by: Alexander Gavrilov <angavrilov@gmail.com>\n---\n\n\tOn Saturday 06 December 2008 13:56:45 Paul Mackerras wrote:\n\t> I have checked in a fix into my gitk.git repository at\n\t> git://git.kernel.org/pub/scm/gitk/gitk.git.  However, there seems to\n\t> be a bug in git gui blame; it gives a \"list index out of range\" error\n\t> sometimes.\n\t> \n\t> Shawn, to see an example of the error, get a current kernel tree and\n\t> do:\n\t> \n\t> $ cd arch/powerpc\n\t> $ git gui blame --line=1183 2c5e76158fcea6e3b9536a74efa7b5e2e846d374 \\\n\t>   ../../net/sunrpc/svcsock.c\n\n git-gui.sh |   18 ++++++++++++++++--\n 1 files changed, 16 insertions(+), 2 deletions(-)\n\ndiff --git a/git-gui.sh b/git-gui.sh\nindex 8a4b42d..65dacf9 100755\n--- a/git-gui.sh\n+++ b/git-gui.sh\n@@ -2630,6 +2630,20 @@ proc usage {} {\n \texit 1\n }\n \n+proc normalize_relpath {path} {\n+\tset elements {}\n+\tforeach item [file split $path] {\n+\t\tif {$item eq {.}} continue\n+\t\tif {$item eq {..} && [llength $elements] > 0\n+\t\t    && [lindex $elements end] ne {..}} {\n+\t\t\tset elements [lrange $elements 0 end-1]\n+\t\t\tcontinue\n+\t\t}\n+\t\tlappend elements $item\n+\t}\n+\treturn [eval file join $elements]\n+}\n+\n # -- Not a normal commit type invocation?  Do that instead!\n #\n switch -- $subcommand {\n@@ -2648,7 +2662,7 @@ blame {\n \tforeach a $argv {\n \t\tif {$is_path || [file exists $_prefix$a]} {\n \t\t\tif {$path ne {}} usage\n-\t\t\tset path $_prefix$a\n+\t\t\tset path [normalize_relpath $_prefix$a]\n \t\t\tbreak\n \t\t} elseif {$a eq {--}} {\n \t\t\tif {$path ne {}} {\n@@ -2671,7 +2685,7 @@ blame {\n \tunset is_path\n \n \tif {$head ne {} && $path eq {}} {\n-\t\tset path $_prefix$head\n+\t\tset path [normalize_relpath $_prefix$head]\n \t\tset head {}\n \t}\n \n-- \n1.6.0.4.30.gf4240\n"}]}