Skip to content

Commit b436825

Browse files
bertwesargprati0100
authored andcommitted
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 <[email protected]> Signed-off-by: Pratyush Yadav <[email protected]>
1 parent c3b57dc commit b436825

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

git-gui.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3581,6 +3581,9 @@ $ui_diff tag conf d_s- \
35813581
$ui_diff tag conf d< \
35823582
-foreground orange \
35833583
-font font_diffbold
3584+
$ui_diff tag conf d| \
3585+
-foreground orange \
3586+
-font font_diffbold
35843587
$ui_diff tag conf d= \
35853588
-foreground orange \
35863589
-font font_diffbold

lib/diff.tcl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,10 @@ proc start_show_diff {cont_info {add_opts {}}} {
347347
}
348348

349349
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
350354
fconfigure $fd \
351355
-blocking 0 \
352356
-encoding [get_path_encoding $path] \
@@ -449,11 +453,23 @@ proc read_diff {fd conflict_size cont_info} {
449453
{--} {set tags d_--}
450454
{++} {
451455
set regexp [string map [list %conflict_size $conflict_size]\
452-
{^\+\+([<>=]){%conflict_size}(?: |$)}]
456+
{^\+\+([<>=|]){%conflict_size}(?: |$)}]
453457
if {[regexp $regexp $line _g op]} {
454458
set is_conflict_diff 1
455459
set line [string replace $line 0 1 { }]
456460
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_--
457473
} else {
458474
set tags d_++
459475
}

0 commit comments

Comments
 (0)