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>
Alexander Gavrilov committed
Sep 8, 2008 at 11:18 UTC
a9786bb42ff4fa4b8031ab69215a66cf329d8324
2 files changed
+29
-3
git-gui.sh
+3
@@ -1025,6 +1025,9 @@ set current_diff_path {}
1025
set is_3way_diff 0
1026
set selected_commit_type new
1027
1028
+set nullid "0000000000000000000000000000000000000000"
1029
+set nullid2 "0000000000000000000000000000000000000001"
1030
+
1031
######################################################################
1032
##
1033
## task management
lib/blame.tcl
+26
-3
@@ -942,9 +942,20 @@ method _format_offset_date {base offset} {
942
}
943
944
method _gitkcommit {} {
945
+ global nullid
946
+
947
set dat [_get_click_amov_info $this]
948
if {$dat ne {}} {
949
set cmit [lindex $dat 0]
950
+
951
+ # If the line belongs to the working copy, use HEAD instead
952
+ if {$cmit eq $nullid} {
953
+ if {[catch {set cmit [git rev-parse --verify HEAD]} err]} {
954
+ error_popup [strcat [mc "Cannot find HEAD commit:"] "\n\n$err"]
955
+ return;
956
+ }
957
+ }
958
+
959
set radius [get_config gui.blamehistoryctx]
960
set cmdline [list --select-commit=$cmit]
961
@@ -981,12 +992,20 @@ method _gitkcommit {} {
992
}
993
994
method _blameparent {} {
995
+ global nullid
996
+
997
set dat [_get_click_amov_info $this]
998
if {$dat ne {}} {
999
set cmit [lindex $dat 0]
1000
set new_path [lindex $dat 1]
1001
989
- if {[catch {set cparent [git rev-parse --verify "$cmit^"]}]} {
1002
+ # Allow using Blame Parent on lines modified in the working copy
1003
+ if {$cmit eq $nullid} {
1004
+ set parent_ref "HEAD"
1005
+ } else {
1006
+ set parent_ref "$cmit^"
1007
+ }
1008
+ if {[catch {set cparent [git rev-parse --verify $parent_ref]} err]} {
1009
error_popup [strcat [mc "Cannot find parent commit:"] "\n\n$err"]
1010
return;
1011
}
@@ -996,8 +1015,12 @@ method _blameparent {} {
1015
# Generate a diff between the commit and its parent,
1016
# and use the hunks to update the line number.
1017
# Request zero context to simplify calculations.
999
- if {[catch {set fd [eval git_read diff-tree \
1000
- --unified=0 $cparent $cmit $new_path]} err]} {
1018
+ if {$cmit eq $nullid} {
1019
+ set diffcmd [list diff-index --unified=0 $cparent -- $new_path]
1020
+ } else {
1021
+ set diffcmd [list diff-tree --unified=0 $cparent $cmit -- $new_path]
1022
+ }
1023
+ if {[catch {set fd [eval git_read $diffcmd]} err]} {
1024
$status stop [mc "Unable to display parent"]
1025
error_popup [strcat [mc "Error loading diff:"] "\n\n$err"]
1026
return