[PATCH] gitk: Let user easily specify lines of context in diff view
More lines of context sometimes help to better understand a diff. This patch introduces a text field above the box displaying the blobdiffs. You can type in the number of lines of context that you wish to view. The number of lines of context is saved to ~/.gitk. Signed-off-by: Steffen Prohaska <prohaska@zib.de> Signed-off-by: Paul Mackerras <paulus@samba.org>
Steffen Prohaska committed
Aug 12, 2007 at 12:05 UTC
890fae7041bb0607f386ac1a996a49530f1cd86f
1 file changed
+32
-2
gitk
+32
-2
@@ -519,6 +519,7 @@ proc makewindow {} {
519
global textfont mainfont uifont tabstop
520
global findtype findtypemenu findloc findstring fstring geometry
521
global entries sha1entry sha1string sha1but
522
+ global diffcontextstring diffcontext
523
global maincursor textcursor curtextcursor
524
global rowctxmenu fakerowmenu mergemax wrapcomment
525
global highlight_files gdttype
@@ -733,7 +734,17 @@ proc makewindow {} {
734
-command changediffdisp -variable diffelide -value {0 1}
735
radiobutton .bleft.mid.new -text "New version" \
736
-command changediffdisp -variable diffelide -value {1 0}
737
+ label .bleft.mid.labeldiffcontext -text " Lines of context: " \
738
+ -font $uifont
739
pack .bleft.mid.diff .bleft.mid.old .bleft.mid.new -side left
740
+ spinbox .bleft.mid.diffcontext -width 5 -font $textfont \
741
+ -from 1 -increment 1 -to 10000000 \
742
+ -validate all -validatecommand "diffcontextvalidate %P" \
743
+ -textvariable diffcontextstring
744
+ .bleft.mid.diffcontext set $diffcontext
745
+ trace add variable diffcontextstring write diffcontextchange
746
+ lappend entries .bleft.mid.diffcontext
747
+ pack .bleft.mid.labeldiffcontext .bleft.mid.diffcontext -side left
748
set ctext .bleft.ctext
749
text $ctext -background $bgcolor -foreground $fgcolor \
750
-tabs "[expr {$tabstop * $charspc}]" \
@@ -1002,7 +1013,7 @@ proc savestuff {w} {
1013
global maxwidth showneartags showlocalchanges
1014
global viewname viewfiles viewargs viewperm nextviewnum
1015
global cmitmode wrapcomment
1005
- global colors bgcolor fgcolor diffcolors selectbgcolor
1016
+ global colors bgcolor fgcolor diffcolors diffcontext selectbgcolor
1017
1018
if {$stuffsaved} return
1019
if {![winfo viewable .]} return
@@ -1023,6 +1034,7 @@ proc savestuff {w} {
1034
puts $f [list set fgcolor $fgcolor]
1035
puts $f [list set colors $colors]
1036
puts $f [list set diffcolors $diffcolors]
1037
+ puts $f [list set diffcontext $diffcontext]
1038
puts $f [list set selectbgcolor $selectbgcolor]
1039
1040
puts $f "set geometry(main) [wm geometry .]"
@@ -5052,12 +5064,29 @@ proc gettreediffline {gdtf ids} {
5064
return 0
5065
}
5066
5067
+# empty string or positive integer
5068
+proc diffcontextvalidate {v} {
5069
+ return [regexp {^(|[1-9][0-9]*)$} $v]
5070
+}
5071
+
5072
+proc diffcontextchange {n1 n2 op} {
5073
+ global diffcontextstring diffcontext
5074
+
5075
+ if {[string is integer -strict $diffcontextstring]} {
5076
+ if {$diffcontextstring > 0} {
5077
+ set diffcontext $diffcontextstring
5078
+ reselectline
5079
+ }
5080
+ }
5081
+}
5082
+
5083
proc getblobdiffs {ids} {
5084
global diffopts blobdifffd diffids env
5085
global diffinhdr treediffs
5086
+ global diffcontext
5087
5088
set env(GIT_DIFF_OPTS) $diffopts
5060
- if {[catch {set bdf [open [diffcmd $ids {-p -C --no-commit-id}] r]} err]} {
5089
+ if {[catch {set bdf [open [diffcmd $ids "-p -C --no-commit-id -U$diffcontext"] r]} err]} {
5090
puts "error getting diffs: $err"
5091
return
5092
}
@@ -7631,6 +7660,7 @@ set colors {green red blue magenta darkgrey brown orange}
7660
set bgcolor white
7661
set fgcolor black
7662
set diffcolors {red "#00a000" blue}
7663
+set diffcontext 3
7664
set selectbgcolor gray85
7665
7666
catch {source ~/.gitk}