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>
This commit is contained in:
parent
861c68e3b6
commit
95e706b5ec
18
git-gui.sh
18
git-gui.sh
@ -2630,6 +2630,20 @@ proc usage {} {
|
|||||||
exit 1
|
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!
|
# -- Not a normal commit type invocation? Do that instead!
|
||||||
#
|
#
|
||||||
switch -- $subcommand {
|
switch -- $subcommand {
|
||||||
@ -2648,7 +2662,7 @@ blame {
|
|||||||
foreach a $argv {
|
foreach a $argv {
|
||||||
if {$is_path || [file exists $_prefix$a]} {
|
if {$is_path || [file exists $_prefix$a]} {
|
||||||
if {$path ne {}} usage
|
if {$path ne {}} usage
|
||||||
set path $_prefix$a
|
set path [normalize_relpath $_prefix$a]
|
||||||
break
|
break
|
||||||
} elseif {$a eq {--}} {
|
} elseif {$a eq {--}} {
|
||||||
if {$path ne {}} {
|
if {$path ne {}} {
|
||||||
@ -2671,7 +2685,7 @@ blame {
|
|||||||
unset is_path
|
unset is_path
|
||||||
|
|
||||||
if {$head ne {} && $path eq {}} {
|
if {$head ne {} && $path eq {}} {
|
||||||
set path $_prefix$head
|
set path [normalize_relpath $_prefix$head]
|
||||||
set head {}
|
set head {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user