Skip to content

Commit

Permalink
gitk: Fix bugs in blaming code
Browse files Browse the repository at this point in the history
The "show origin of this line" function wasn't working when gitk was
run in a subdirectory, since it passed the path relative to the
top-level directory to git blame.  This fixes it by passing the
absolute path to the file instead of the relative path.

The same problem occurs when running git gui blame, except that
git gui blame appears not to be able to accept an absolute path to the
file, so we make a relative path using a new [make_relative] function.

Finally, this fixes a bug in [show_line_source] where we weren't
setting id, resulting in an error when trying to find the origin of
a line in the fake commit for local changes not checked in, when its
parent was a real commit (i.e. there were no changes checked in).

Signed-off-by: Paul Mackerras <paulus@samba.org>
  • Loading branch information
Paul Mackerras committed Dec 6, 2008
1 parent 7fb0abb commit 9712b81
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions gitk
Original file line number Diff line number Diff line change
Expand Up @@ -3318,8 +3318,27 @@ proc index_sha1 {fname} {
return {}
}

# 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
}
incr hi
}
set elts [concat $res [lrange $elts $ei end]]
return [eval file join $elts]
}

proc external_blame {parent_idx {line {}}} {
global flist_menu_file
global flist_menu_file gitdir
global nullid nullid2
global parentlist selectedline currentid

Expand All @@ -3338,7 +3357,12 @@ proc external_blame {parent_idx {line {}}} {
if {$line ne {} && $line > 1} {
lappend cmdline "--line=$line"
}
lappend cmdline $base_commit $flist_menu_file
set f [file join [file dirname $gitdir] $flist_menu_file]
# Unfortunately it seems git gui blame doesn't like
# being given an absolute path...
set f [make_relative $f]
lappend cmdline $base_commit $f
puts "cmdline={$cmdline}"
if {[catch {eval exec $cmdline &} err]} {
error_popup "[mc "git gui blame: command failed:"] $err"
}
Expand Down Expand Up @@ -3382,6 +3406,8 @@ proc show_line_source {} {
error_popup [mc "Error reading index: %s" $err]
return
}
} else {
set id $parents($curview,$currentid)
}
} else {
set id [lindex $parents($curview,$currentid) $pi]
Expand All @@ -3398,7 +3424,7 @@ proc show_line_source {} {
} else {
lappend blameargs $id
}
lappend blameargs -- $flist_menu_file
lappend blameargs -- [file join [file dirname $gitdir] $flist_menu_file]
if {[catch {
set f [open $blameargs r]
} err]} {
Expand Down

0 comments on commit 9712b81

Please sign in to comment.