git-gui: Support starting gitk from Gui Blame
Add a context menu command to load commits that are within a certain time range from the selected commit into gitk. It can be useful for understanding of the code, especially if the repository is imported from a VCS that does not support atomic commits. 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
a9c80b83d4bb40e0ff696520de3ef2b0f74ff8c6
3 files changed
+55
-2
git-gui.sh
+1
@@ -668,6 +668,7 @@ set default_config(gui.pruneduringfetch) false
668
set default_config(gui.trustmtime) false
669
set default_config(gui.fastcopyblame) false
670
set default_config(gui.copyblamethreshold) 40
671
+set default_config(gui.blamehistoryctx) 7
672
set default_config(gui.diffcontext) 5
673
set default_config(gui.commitmsgwidth) 75
674
set default_config(gui.newbranchtemplate) {}
lib/blame.tcl
+53
-2
@@ -259,6 +259,9 @@ constructor new {i_commit i_path} {
259
$w.ctxm add command \
260
-label [mc "Do Full Copy Detection"] \
261
-command [cb _fullcopyblame]
262
+ $w.ctxm add command \
263
+ -label [mc "Show History Context"] \
264
+ -command [cb _gitkcommit]
265
266
foreach i $w_columns {
267
for {set g 0} {$g < [llength $group_colors]} {incr g} {
@@ -905,10 +908,14 @@ method _showcommit {cur_w lno} {
908
}
909
}
910
908
-method _copycommit {} {
911
+method _get_click_amov_info {} {
912
set pos @$::cursorX,$::cursorY
913
set lno [lindex [split [$::cursorW index $pos] .] 0]
911
- set dat [lindex $amov_data $lno]
914
+ return [lindex $amov_data $lno]
915
+}
916
+
917
+method _copycommit {} {
918
+ set dat [_get_click_amov_info $this]
919
if {$dat ne {}} {
920
clipboard clear
921
clipboard append \
@@ -918,6 +925,50 @@ method _copycommit {} {
925
}
926
}
927
928
+method _format_offset_date {base offset} {
929
+ set exval [expr {$base + $offset*24*60*60}]
930
+ return [clock format $exval -format {%Y-%m-%d}]
931
+}
932
+
933
+method _gitkcommit {} {
934
+ set dat [_get_click_amov_info $this]
935
+ if {$dat ne {}} {
936
+ set cmit [lindex $dat 0]
937
+ set radius [get_config gui.blamehistoryctx]
938
+ set cmdline [list --select-commit=$cmit]
939
+
940
+ if {$radius > 0} {
941
+ set author_time {}
942
+ set committer_time {}
943
+
944
+ catch {set author_time $header($cmit,author-time)}
945
+ catch {set committer_time $header($cmit,committer-time)}
946
+
947
+ if {$committer_time eq {}} {
948
+ set committer_time $author_time
949
+ }
950
+
951
+ set after_time [_format_offset_date $this $committer_time [expr {-$radius}]]
952
+ set before_time [_format_offset_date $this $committer_time $radius]
953
+
954
+ lappend cmdline --after=$after_time --before=$before_time
955
+ }
956
+
957
+ lappend cmdline $cmit
958
+
959
+ set base_rev "HEAD"
960
+ if {$commit ne {}} {
961
+ set base_rev $commit
962
+ }
963
+
964
+ if {$base_rev ne $cmit} {
965
+ lappend cmdline $base_rev
966
+ }
967
+
968
+ do_gitk $cmdline
969
+ }
970
+}
971
+
972
method _show_tooltip {cur_w pos} {
973
if {$tooltip_wm ne {}} {
974
_open_tooltip $this $cur_w
lib/option.tcl
+1
@@ -125,6 +125,7 @@ proc do_options {} {
125
{b gui.matchtrackingbranch {mc "Match Tracking Branches"}}
126
{b gui.fastcopyblame {mc "Blame Copy Only On Changed Files"}}
127
{i-20..200 gui.copyblamethreshold {mc "Minimum Letters To Blame Copy On"}}
128
+ {i-0..300 gui.blamehistoryctx {mc "Blame History Context Radius (days)"}}
129
{i-0..99 gui.diffcontext {mc "Number of Diff Context Lines"}}
130
{i-0..99 gui.commitmsgwidth {mc "Commit Message Text Width"}}
131
{t gui.newbranchtemplate {mc "New Branch Name Template"}}