]> git.ipfire.org Git - thirdparty/git.git/commit - builtin/merge-file.c
xdiff: implement a zealous diff3, or "zdiff3"
authorPhillip Wood <phillip.wood@dunelm.org.uk>
Wed, 1 Dec 2021 00:05:06 +0000 (00:05 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 1 Dec 2021 22:45:58 +0000 (14:45 -0800)
commit4496526f80b3e4952036550b279eff8d1babd60a
tree7f53e991d16c9db04d87eff111788eb92c897d4d
parentabe6bb3905392d5eb6b01fa6e54d7e784e0522aa
xdiff: implement a zealous diff3, or "zdiff3"

"zdiff3" is identical to ordinary diff3 except that it allows compaction
of common lines on the two sides of history at the beginning or end of
the conflict hunk.  For example, the following diff3 conflict:

    1
    2
    3
    4
    <<<<<<
    A
    B
    C
    D
    E
    ||||||
    5
    6
    ======
    A
    X
    C
    Y
    E
    >>>>>>
    7
    8
    9

has common lines 'A', 'C', and 'E' on the two sides.  With zdiff3, one
would instead get the following conflict:

    1
    2
    3
    4
    A
    <<<<<<
    B
    C
    D
    ||||||
    5
    6
    ======
    X
    C
    Y
    >>>>>>
    E
    7
    8
    9

Note that the common lines, 'A', and 'E' were moved outside the
conflict.  Unlike with the two-way conflicts from the 'merge'
conflictStyle, the zdiff3 conflict is NOT split into multiple conflict
regions to allow the common 'C' lines to be shown outside a conflict,
because zdiff3 shows the base version too and the base version cannot be
reasonably split.

Note also that the removing of lines common to the two sides might make
the remaining text inside the conflict region match the base text inside
the conflict region (for example, if the diff3 conflict had '5 6 E' on
the right side of the conflict, then the common line 'E' would be moved
outside and both the base and right side's remaining conflict text would
be the lines '5' and '6').  This has the potential to surprise users and
make them think there should not have been a conflict, but there
definitely was a conflict and it should remain.

Based-on-patch-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Co-authored-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Phillip Wood <phillip.wood123@gmail.com>
Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/merge-file.c
contrib/completion/git-completion.bash
t/t6427-diff3-conflict-markers.sh
xdiff-interface.c
xdiff/xdiff.h
xdiff/xmerge.c