gitk: Add the equivalent of diff --color-words
Use the newly added 'diff --word-diff=porcelain' to teach gitk a color-words mode, with two different modes analogous to the --word-diff=plain and --word-diff=color settings. These are selected by a dropdown box. As an extra twist, automatically enable this word-diff support when the user mentions a word-diff related option on the command line. These options were previously ignored because they would break diff parsing. Both of these features are only enabled if we have a version of git that supports --word-diff=porcelain, meaning at least 1.7.2. Signed-off-by: Thomas Rast <trast@student.ethz.ch> Signed-off-by: Paul Mackerras <paulus@samba.org>
Thomas Rast committed
Oct 16, 2010 at 12:15 UTC
ae4e3ff93df4489579400d8af0629cdd4e5a3e67
1 file changed
+61
-3
gitk
+61
-3
@@ -131,6 +131,7 @@ proc unmerged_files {files} {
131
132
proc parseviewargs {n arglist} {
133
global vdatemode vmergeonly vflags vdflags vrevs vfiltered vorigargs env
134
+ global worddiff git_version
135
136
set vdatemode($n) 0
137
set vmergeonly($n) 0
@@ -168,7 +169,7 @@ proc parseviewargs {n arglist} {
169
lappend diffargs $arg
170
}
171
"--raw" - "--patch-with-raw" - "--patch-with-stat" -
171
- "--name-only" - "--name-status" - "--color" - "--color-words" -
172
+ "--name-only" - "--name-status" - "--color" -
173
"--log-size" - "--pretty=*" - "--decorate" - "--abbrev-commit" -
174
"--cc" - "-z" - "--header" - "--parents" - "--boundary" -
175
"--no-color" - "-g" - "--walk-reflogs" - "--no-walk" -
@@ -177,6 +178,18 @@ proc parseviewargs {n arglist} {
178
# These cause our parsing of git log's output to fail, or else
179
# they're options we want to set ourselves, so ignore them.
180
}
181
+ "--color-words*" - "--word-diff=color" {
182
+ # These trigger a word diff in the console interface,
183
+ # so help the user by enabling our own support
184
+ if {[package vcompare $git_version "1.7.2"] >= 0} {
185
+ set worddiff [mc "Color words"]
186
+ }
187
+ }
188
+ "--word-diff*" {
189
+ if {[package vcompare $git_version "1.7.2"] >= 0} {
190
+ set worddiff [mc "Markup words"]
191
+ }
192
+ }
193
"--stat=*" - "--numstat" - "--shortstat" - "--summary" -
194
"--check" - "--exit-code" - "--quiet" - "--topo-order" -
195
"--full-history" - "--dense" - "--sparse" -
@@ -1972,6 +1985,8 @@ proc makewindow {} {
1985
global fprogitem fprogcoord lastprogupdate progupdatepending
1986
global rprogitem rprogcoord rownumsel numcommits
1987
global have_tk85 use_ttk NS
1988
+ global git_version
1989
+ global worddiff
1990
1991
# The "mc" arguments here are purely so that xgettext
1992
# sees the following string as needing to be translated
@@ -2245,6 +2260,15 @@ proc makewindow {} {
2260
${NS}::checkbutton .bleft.mid.ignspace -text [mc "Ignore space change"] \
2261
-command changeignorespace -variable ignorespace
2262
pack .bleft.mid.ignspace -side left -padx 5
2263
+
2264
+ set worddiff [mc "Line diff"]
2265
+ if {[package vcompare $git_version "1.7.2"] >= 0} {
2266
+ makedroplist .bleft.mid.worddiff worddiff [mc "Line diff"] \
2267
+ [mc "Markup words"] [mc "Color words"]
2268
+ trace add variable worddiff write changeworddiff
2269
+ pack .bleft.mid.worddiff -side left -padx 5
2270
+ }
2271
+
2272
set ctext .bleft.bottom.ctext
2273
text $ctext -background $bgcolor -foreground $fgcolor \
2274
-state disabled -font textfont \
@@ -7504,11 +7528,16 @@ proc changeignorespace {} {
7528
reselectline
7529
}
7530
7531
+proc changeworddiff {name ix op} {
7532
+ reselectline
7533
+}
7534
+
7535
proc getblobdiffs {ids} {
7536
global blobdifffd diffids env
7537
global diffinhdr treediffs
7538
global diffcontext
7539
global ignorespace
7540
+ global worddiff
7541
global limitdiffs vfilelimit curview
7542
global diffencoding targetline diffnparents
7543
global git_version currdiffsubmod
@@ -7525,6 +7554,9 @@ proc getblobdiffs {ids} {
7554
if {$ignorespace} {
7555
append cmd " -w"
7556
}
7557
+ if {$worddiff ne [mc "Line diff"]} {
7558
+ append cmd " --word-diff=porcelain"
7559
+ }
7560
if {$limitdiffs && $vfilelimit($curview) ne {}} {
7561
set cmd [concat $cmd -- $vfilelimit($curview)]
7562
}
@@ -7610,6 +7642,7 @@ proc getblobdiffline {bdf ids} {
7642
global ctext_file_names ctext_file_lines
7643
global diffinhdr treediffs mergemax diffnparents
7644
global diffencoding jump_to_here targetline diffline currdiffsubmod
7645
+ global worddiff
7646
7647
set nr 0
7648
$ctext conf -state normal
@@ -7749,15 +7782,28 @@ proc getblobdiffline {bdf ids} {
7782
# parse the prefix - one ' ', '-' or '+' for each parent
7783
set prefix [string range $line 0 [expr {$diffnparents - 1}]]
7784
set tag [expr {$diffnparents > 1? "m": "d"}]
7785
+ set dowords [expr {$worddiff ne [mc "Line diff"] && $diffnparents == 1}]
7786
+ set words_pre_markup ""
7787
+ set words_post_markup ""
7788
if {[string trim $prefix " -+"] eq {}} {
7789
# prefix only has " ", "-" and "+" in it: normal diff line
7790
set num [string first "-" $prefix]
7791
+ if {$dowords} {
7792
+ set line [string range $line 1 end]
7793
+ }
7794
if {$num >= 0} {
7795
# removed line, first parent with line is $num
7796
if {$num >= $mergemax} {
7797
set num "max"
7798
}
7760
- $ctext insert end "$line\n" $tag$num
7799
+ if {$dowords && $worddiff eq [mc "Markup words"]} {
7800
+ $ctext insert end "\[-$line-\]" $tag$num
7801
+ } else {
7802
+ $ctext insert end "$line" $tag$num
7803
+ }
7804
+ if {!$dowords} {
7805
+ $ctext insert end "\n" $tag$num
7806
+ }
7807
} else {
7808
set tags {}
7809
if {[string first "+" $prefix] >= 0} {
@@ -7772,6 +7818,8 @@ proc getblobdiffline {bdf ids} {
7818
lappend tags m$num
7819
}
7820
}
7821
+ set words_pre_markup "{+"
7822
+ set words_post_markup "+}"
7823
}
7824
if {$targetline ne {}} {
7825
if {$diffline == $targetline} {
@@ -7781,8 +7829,17 @@ proc getblobdiffline {bdf ids} {
7829
incr diffline
7830
}
7831
}
7784
- $ctext insert end "$line\n" $tags
7832
+ if {$dowords && $worddiff eq [mc "Markup words"]} {
7833
+ $ctext insert end "$words_pre_markup$line$words_post_markup" $tags
7834
+ } else {
7835
+ $ctext insert end "$line" $tags
7836
+ }
7837
+ if {!$dowords} {
7838
+ $ctext insert end "\n" $tags
7839
+ }
7840
}
7841
+ } elseif {$dowords && $prefix eq "~"} {
7842
+ $ctext insert end "\n" {}
7843
} else {
7844
# "\ No newline at end of file",
7845
# or something else we don't recognize
@@ -11393,6 +11450,7 @@ if {[tk windowingsystem] eq "win32"} {
11450
set diffcolors {red "#00a000" blue}
11451
set diffcontext 3
11452
set ignorespace 0
11453
+set worddiff ""
11454
set markbgcolor "#e0e0ff"
11455
11456
set circlecolors {white blue gray blue blue}