Skip to content

Commit 69fdb92

Browse files
committed
Merge branch 'bw/diff3-conflict-style'
git-gui now highlights diff3 style conflicts properly. As an auxiliary change, querying a path's attribute is done via the existing interface instead of hand-rolling the code. * bw/diff3-conflict-style: git-gui: support for diff3 conflict style git-gui: use existing interface to query a path's attribute
2 parents 45ab460 + b436825 commit 69fdb92

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

git-gui.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3589,6 +3589,9 @@ $ui_diff tag conf d_s- \
35893589
$ui_diff tag conf d< \
35903590
-foreground orange \
35913591
-font font_diffbold
3592+
$ui_diff tag conf d| \
3593+
-foreground orange \
3594+
-font font_diffbold
35923595
$ui_diff tag conf d= \
35933596
-foreground orange \
35943597
-font font_diffbold

lib/diff.tcl

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -270,19 +270,6 @@ proc show_other_diff {path w m cont_info} {
270270
}
271271
}
272272

273-
proc get_conflict_marker_size {path} {
274-
set size 7
275-
catch {
276-
set fd_rc [eval [list git_read check-attr "conflict-marker-size" -- $path]]
277-
set ret [gets $fd_rc line]
278-
close $fd_rc
279-
if {$ret > 0} {
280-
regexp {.*: conflict-marker-size: (\d+)$} $line line size
281-
}
282-
}
283-
return $size
284-
}
285-
286273
proc start_show_diff {cont_info {add_opts {}}} {
287274
global file_states file_lists
288275
global is_3way_diff is_submodule_diff diff_active repo_config
@@ -298,7 +285,7 @@ proc start_show_diff {cont_info {add_opts {}}} {
298285
set is_submodule_diff 0
299286
set diff_active 1
300287
set current_diff_header {}
301-
set conflict_size [get_conflict_marker_size $path]
288+
set conflict_size [gitattr $path conflict-marker-size 7]
302289

303290
set cmd [list]
304291
if {$w eq $ui_index} {
@@ -360,6 +347,10 @@ proc start_show_diff {cont_info {add_opts {}}} {
360347
}
361348

362349
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
363354
fconfigure $fd \
364355
-blocking 0 \
365356
-encoding [get_path_encoding $path] \
@@ -462,11 +453,23 @@ proc read_diff {fd conflict_size cont_info} {
462453
{--} {set tags d_--}
463454
{++} {
464455
set regexp [string map [list %conflict_size $conflict_size]\
465-
{^\+\+([<>=]){%conflict_size}(?: |$)}]
456+
{^\+\+([<>=|]){%conflict_size}(?: |$)}]
466457
if {[regexp $regexp $line _g op]} {
467458
set is_conflict_diff 1
468459
set line [string replace $line 0 1 { }]
469460
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_--
470473
} else {
471474
set tags d_++
472475
}

0 commit comments

Comments
 (0)