git-gui: Fix Blame Parent & Context for working copy lines.
Make Blame Parent Commit and Show History Context work properly for lines blamed on the working copy. Signed-off-by: Alexander Gavrilov <angavrilov@gmail.com> Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
parent
95b6a2db25
commit
a9786bb42f
@ -1025,6 +1025,9 @@ set current_diff_path {}
|
|||||||
set is_3way_diff 0
|
set is_3way_diff 0
|
||||||
set selected_commit_type new
|
set selected_commit_type new
|
||||||
|
|
||||||
|
set nullid "0000000000000000000000000000000000000000"
|
||||||
|
set nullid2 "0000000000000000000000000000000000000001"
|
||||||
|
|
||||||
######################################################################
|
######################################################################
|
||||||
##
|
##
|
||||||
## task management
|
## task management
|
||||||
|
@ -942,9 +942,20 @@ method _format_offset_date {base offset} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
method _gitkcommit {} {
|
method _gitkcommit {} {
|
||||||
|
global nullid
|
||||||
|
|
||||||
set dat [_get_click_amov_info $this]
|
set dat [_get_click_amov_info $this]
|
||||||
if {$dat ne {}} {
|
if {$dat ne {}} {
|
||||||
set cmit [lindex $dat 0]
|
set cmit [lindex $dat 0]
|
||||||
|
|
||||||
|
# If the line belongs to the working copy, use HEAD instead
|
||||||
|
if {$cmit eq $nullid} {
|
||||||
|
if {[catch {set cmit [git rev-parse --verify HEAD]} err]} {
|
||||||
|
error_popup [strcat [mc "Cannot find HEAD commit:"] "\n\n$err"]
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
set radius [get_config gui.blamehistoryctx]
|
set radius [get_config gui.blamehistoryctx]
|
||||||
set cmdline [list --select-commit=$cmit]
|
set cmdline [list --select-commit=$cmit]
|
||||||
|
|
||||||
@ -981,12 +992,20 @@ method _gitkcommit {} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
method _blameparent {} {
|
method _blameparent {} {
|
||||||
|
global nullid
|
||||||
|
|
||||||
set dat [_get_click_amov_info $this]
|
set dat [_get_click_amov_info $this]
|
||||||
if {$dat ne {}} {
|
if {$dat ne {}} {
|
||||||
set cmit [lindex $dat 0]
|
set cmit [lindex $dat 0]
|
||||||
set new_path [lindex $dat 1]
|
set new_path [lindex $dat 1]
|
||||||
|
|
||||||
if {[catch {set cparent [git rev-parse --verify "$cmit^"]}]} {
|
# Allow using Blame Parent on lines modified in the working copy
|
||||||
|
if {$cmit eq $nullid} {
|
||||||
|
set parent_ref "HEAD"
|
||||||
|
} else {
|
||||||
|
set parent_ref "$cmit^"
|
||||||
|
}
|
||||||
|
if {[catch {set cparent [git rev-parse --verify $parent_ref]} err]} {
|
||||||
error_popup [strcat [mc "Cannot find parent commit:"] "\n\n$err"]
|
error_popup [strcat [mc "Cannot find parent commit:"] "\n\n$err"]
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -996,8 +1015,12 @@ method _blameparent {} {
|
|||||||
# Generate a diff between the commit and its parent,
|
# Generate a diff between the commit and its parent,
|
||||||
# and use the hunks to update the line number.
|
# and use the hunks to update the line number.
|
||||||
# Request zero context to simplify calculations.
|
# Request zero context to simplify calculations.
|
||||||
if {[catch {set fd [eval git_read diff-tree \
|
if {$cmit eq $nullid} {
|
||||||
--unified=0 $cparent $cmit $new_path]} err]} {
|
set diffcmd [list diff-index --unified=0 $cparent -- $new_path]
|
||||||
|
} else {
|
||||||
|
set diffcmd [list diff-tree --unified=0 $cparent $cmit -- $new_path]
|
||||||
|
}
|
||||||
|
if {[catch {set fd [eval git_read $diffcmd]} err]} {
|
||||||
$status stop [mc "Unable to display parent"]
|
$status stop [mc "Unable to display parent"]
|
||||||
error_popup [strcat [mc "Error loading diff:"] "\n\n$err"]
|
error_popup [strcat [mc "Error loading diff:"] "\n\n$err"]
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user