git-gui: Support passing blame to a parent commit.
Add a context menu item that switches the view to the parent of the commit under cursor. It is useful to see how the file looked before the change, and find older changes in the same lines. Signed-off-by: Alexander Gavrilov <angavrilov@gmail.com> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Alexander Gavrilov committed
Aug 23, 2008 at 12:30 UTC
80fd76bd58070fe9615baf365abf2ff82276e50c
1 file changed
+38
-10
lib/blame.tcl
+38
-10
@@ -262,6 +262,9 @@ constructor new {i_commit i_path} {
262
$w.ctxm add command \
263
-label [mc "Show History Context"] \
264
-command [cb _gitkcommit]
265
+ $w.ctxm add command \
266
+ -label [mc "Blame Parent Commit"] \
267
+ -command [cb _blameparent]
268
269
foreach i $w_columns {
270
for {set g 0} {$g < [llength $group_colors]} {incr g} {
@@ -790,19 +793,27 @@ method _load_commit {cur_w cur_d pos} {
793
set lno [lindex [split [$cur_w index $pos] .] 0]
794
set dat [lindex $line_data $lno]
795
if {$dat ne {}} {
793
- lappend history [list \
794
- $commit $path \
795
- $highlight_column \
796
- $highlight_line \
797
- [lindex [$w_file xview] 0] \
798
- [lindex [$w_file yview] 0] \
799
- ]
800
- set commit [lindex $dat 0]
801
- set path [lindex $dat 1]
802
- _load $this [list [lindex $dat 2]]
796
+ _load_new_commit $this \
797
+ [lindex $dat 0] \
798
+ [lindex $dat 1] \
799
+ [list [lindex $dat 2]]
800
}
801
}
802
803
+method _load_new_commit {new_commit new_path jump} {
804
+ lappend history [list \
805
+ $commit $path \
806
+ $highlight_column \
807
+ $highlight_line \
808
+ [lindex [$w_file xview] 0] \
809
+ [lindex [$w_file yview] 0] \
810
+ ]
811
+
812
+ set commit $new_commit
813
+ set path $new_path
814
+ _load $this $jump
815
+}
816
+
817
method _showcommit {cur_w lno} {
818
global repo_config
819
variable active_color
@@ -969,6 +980,23 @@ method _gitkcommit {} {
980
}
981
}
982
983
+method _blameparent {} {
984
+ set dat [_get_click_amov_info $this]
985
+ if {$dat ne {}} {
986
+ set cmit [lindex $dat 0]
987
+
988
+ if {[catch {set cparent [git rev-parse --verify "$cmit^"]}]} {
989
+ error_popup [strcat [mc "Cannot find parent commit:"] "\n\n$err"]
990
+ return;
991
+ }
992
+
993
+ _load_new_commit $this \
994
+ $cparent \
995
+ [lindex $dat 1] \
996
+ [list [lindex $dat 2]]
997
+ }
998
+}
999
+
1000
method _show_tooltip {cur_w pos} {
1001
if {$tooltip_wm ne {}} {
1002
_open_tooltip $this $cur_w