git-gui: support for diff3 conflict style
This adds highlight support for the diff3 conflict style. The common pre-image will be reversed to --, because it has been removed and replaced with ours or theirs side respectively. Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com> Signed-off-by: Pratyush Yadav <me@yadavpratyush.com>
Bert Wesarg committed
Oct 2, 2019 at 09:36 UTC
b436825b9bf3c606bb684e41f426fa3d0c088328
2 files changed
+20
-1
git-gui.sh
+3
@@ -3581,6 +3581,9 @@ $ui_diff tag conf d_s- \
3581
$ui_diff tag conf d< \
3582
-foreground orange \
3583
-font font_diffbold
3584
+$ui_diff tag conf d| \
3585
+ -foreground orange \
3586
+ -font font_diffbold
3587
$ui_diff tag conf d= \
3588
-foreground orange \
3589
-font font_diffbold
lib/diff.tcl
+17
-1
@@ -347,6 +347,10 @@ proc start_show_diff {cont_info {add_opts {}}} {
347
}
348
349
set ::current_diff_inheader 1
350
+ # Detect pre-image lines of the diff3 conflict-style. They are just
351
+ # '++' lines which is not bijective. Thus, we need to maintain a state
352
+ # across lines.
353
+ set ::conflict_in_pre_image 0
354
fconfigure $fd \
355
-blocking 0 \
356
-encoding [get_path_encoding $path] \
@@ -449,11 +453,23 @@ proc read_diff {fd conflict_size cont_info} {
453
{--} {set tags d_--}
454
{++} {
455
set regexp [string map [list %conflict_size $conflict_size]\
452
- {^\+\+([<>=]){%conflict_size}(?: |$)}]
456
+ {^\+\+([<>=|]){%conflict_size}(?: |$)}]
457
if {[regexp $regexp $line _g op]} {
458
set is_conflict_diff 1
459
set line [string replace $line 0 1 { }]
460
set tags d$op
461
+
462
+ # The ||| conflict-marker marks the start of the pre-image.
463
+ # All those lines are also prefixed with '++'. Thus we need
464
+ # to maintain this state.
465
+ set ::conflict_in_pre_image [expr {$op eq {|}}]
466
+ } elseif {$::conflict_in_pre_image} {
467
+ # This is a pre-image line. It is the one which both sides
468
+ # are based on. As it has also the '++' line start, it is
469
+ # normally shown as 'added'. Invert this to '--' to make
470
+ # it a 'removed' line.
471
+ set line [string replace $line 0 1 {--}]
472
+ set tags d_--
473
} else {
474
set tags d_++
475
}