git-gui: Allow the user to control the number of context lines in a diff.
When displaying a diff the Git default of 3 line of context may not be enough for a user to see what has actually changed. Consequently we set our own program default to 5 lines of context and then allow the user to adjust this on a per-repository and global level through our options dialog. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce committed
Nov 12, 2006 at 19:20 UTC
358d8de8f3b9d09c9c4d7d43c03d33a4f60ba1da
1 file changed
+55
-11
git-gui
+55
-11
@@ -517,6 +517,9 @@ proc show_diff {path {w {}} {lno {}}} {
517
518
set cmd [list | git diff-index]
519
lappend cmd --no-color
520
+ if {$repo_config(gui.diffcontext) > 0} {
521
+ lappend cmd "-U$repo_config(gui.diffcontext)"
522
+ }
523
lappend cmd -p
524
525
switch $m {
@@ -1765,12 +1768,18 @@ proc do_options {} {
1768
global repo_config global_config
1769
global repo_config_new global_config_new
1770
1768
- load_config 1
1771
array unset repo_config_new
1772
array unset global_config_new
1773
foreach name [array names repo_config] {
1774
set repo_config_new($name) $repo_config($name)
1775
}
1776
+ load_config 1
1777
+ foreach name [array names repo_config] {
1778
+ switch -- $name {
1779
+ gui.diffcontext {continue}
1780
+ }
1781
+ set repo_config_new($name) $repo_config($name)
1782
+ }
1783
foreach name [array names global_config] {
1784
set global_config_new($name) $global_config($name)
1785
}
@@ -1811,18 +1820,36 @@ proc do_options {} {
1820
pack $w.global -side right -fill both -expand 1 -pady 5 -padx 5
1821
1822
foreach option {
1814
- {pullsummary {Show Pull Summary}}
1815
- {trustmtime {Trust File Modification Timestamps}}
1823
+ {b pullsummary {Show Pull Summary}}
1824
+ {b trustmtime {Trust File Modification Timestamps}}
1825
+ {i diffcontext {Number of Diff Context Lines}}
1826
} {
1817
- set name [lindex $option 0]
1818
- set text [lindex $option 1]
1827
+ set type [lindex $option 0]
1828
+ set name [lindex $option 1]
1829
+ set text [lindex $option 2]
1830
foreach f {repo global} {
1820
- checkbutton $w.$f.$name -text $text \
1821
- -variable ${f}_config_new(gui.$name) \
1822
- -onvalue true \
1823
- -offvalue false \
1824
- -font font_ui
1825
- pack $w.$f.$name -side top -anchor w
1831
+ switch $type {
1832
+ b {
1833
+ checkbutton $w.$f.$name -text $text \
1834
+ -variable ${f}_config_new(gui.$name) \
1835
+ -onvalue true \
1836
+ -offvalue false \
1837
+ -font font_ui
1838
+ pack $w.$f.$name -side top -anchor w
1839
+ }
1840
+ i {
1841
+ frame $w.$f.$name
1842
+ label $w.$f.$name.l -text "$text:" -font font_ui
1843
+ pack $w.$f.$name.l -side left -anchor w -fill x
1844
+ spinbox $w.$f.$name.v \
1845
+ -textvariable ${f}_config_new(gui.$name) \
1846
+ -from 1 -to 99 -increment 1 \
1847
+ -width 3 \
1848
+ -font font_ui
1849
+ pack $w.$f.$name.v -side right -anchor e
1850
+ pack $w.$f.$name -side top -anchor w -fill x
1851
+ }
1852
+ }
1853
}
1854
}
1855
@@ -1888,6 +1915,7 @@ proc do_save_config {w} {
1915
if {[catch {save_config} err]} {
1916
error_popup "Failed to completely save options:\n\n$err"
1917
}
1918
+ reshow_diff
1919
destroy $w
1920
}
1921
@@ -1969,6 +1997,7 @@ proc apply_config {} {
1997
1998
set default_config(gui.trustmtime) false
1999
set default_config(gui.pullsummary) true
2000
+set default_config(gui.diffcontext) 5
2001
set default_config(gui.fontui) [font configure font_ui]
2002
set default_config(gui.fontdiff) [font configure font_diff]
2003
set font_descs {
@@ -2318,6 +2347,21 @@ $ui_diff.ctxm add command -label "Decrease Font Size" \
2347
$ui_diff.ctxm add command -label "Increase Font Size" \
2348
-font font_ui \
2349
-command {incr_font_size font_diff 1}
2350
+$ui_diff.ctxm add separator
2351
+$ui_diff.ctxm add command -label "Show Less Context" \
2352
+ -font font_ui \
2353
+ -command {if {$ui_fname_value ne {}
2354
+ && $repo_config(gui.diffcontext) >= 2} {
2355
+ incr repo_config(gui.diffcontext) -1
2356
+ reshow_diff
2357
+ }}
2358
+$ui_diff.ctxm add command -label "Show More Context" \
2359
+ -font font_ui \
2360
+ -command {if {$ui_fname_value ne {}} {
2361
+ incr repo_config(gui.diffcontext)
2362
+ reshow_diff
2363
+ }}
2364
+$ui_diff.ctxm add separator
2365
$ui_diff.ctxm add command -label {Options...} \
2366
-font font_ui \
2367
-command do_options