git-gui: Fix handling of relative paths in blame.
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> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Alexander Gavrilov committed
Dec 6, 2008 at 20:21 UTC
95e706b5ec4d9b6832640c717c98fb4c912b54c5
1 file changed
+16
-2
git-gui.sh
+16
-2
@@ -2630,6 +2630,20 @@ proc usage {} {
2630
exit 1
2631
}
2632
2633
+proc normalize_relpath {path} {
2634
+ set elements {}
2635
+ foreach item [file split $path] {
2636
+ if {$item eq {.}} continue
2637
+ if {$item eq {..} && [llength $elements] > 0
2638
+ && [lindex $elements end] ne {..}} {
2639
+ set elements [lrange $elements 0 end-1]
2640
+ continue
2641
+ }
2642
+ lappend elements $item
2643
+ }
2644
+ return [eval file join $elements]
2645
+}
2646
+
2647
# -- Not a normal commit type invocation? Do that instead!
2648
#
2649
switch -- $subcommand {
@@ -2648,7 +2662,7 @@ blame {
2662
foreach a $argv {
2663
if {$is_path || [file exists $_prefix$a]} {
2664
if {$path ne {}} usage
2651
- set path $_prefix$a
2665
+ set path [normalize_relpath $_prefix$a]
2666
break
2667
} elseif {$a eq {--}} {
2668
if {$path ne {}} {
@@ -2671,7 +2685,7 @@ blame {
2685
unset is_path
2686
2687
if {$head ne {} && $path eq {}} {
2674
- set path $_prefix$head
2688
+ set path [normalize_relpath $_prefix$head]
2689
set head {}
2690
}
2691