git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 0/2] RFC: implement new zdiff3 conflict style

From
Elijah Newren via GitGitGadget <gitgitgadget@gmail.com>
Date
Sep 18, 2021, 23:02 UTC
Message-ID
<pull.1036.v3.git.git.1632006164.gitgitgadget@gmail.com>
In-Reply-To
<pull.1036.v2.git.git.1631379829.gitgitgadget@gmail.com>

Implement a zealous diff3, or "zdiff3". This new mode is identical to ordinary diff3 except that it allows compaction of common lines between the two sides of history, if those common lines occur at the beginning or end of a conflict hunk.

This is still just RFC, because a testcase provided by Phillip fails. I think we should get it working first.

Changes since v2:
 * Included more fixes from Phillip, and a new testcase
Changes since v1:
 * Included fixes from Phillip (thanks!)
 * Added some testcases
Elijah Newren (2):
  xdiff: implement a zealous diff3, or "zdiff3"
  update documentation for new zdiff3 conflictStyle
 Documentation/config/merge.txt         |  9 ++-
 Documentation/git-checkout.txt         |  3 +-
 Documentation/git-merge-file.txt       |  3 +
 Documentation/git-merge.txt            | 32 +++++++--
 Documentation/git-rebase.txt           |  6 +-
 Documentation/git-restore.txt          |  3 +-
 Documentation/git-switch.txt           |  3 +-
 Documentation/technical/rerere.txt     | 10 +--
 builtin/checkout.c                     |  2 +-
 builtin/merge-file.c                   |  2 +
 contrib/completion/git-completion.bash |  6 +-
 t/t6427-diff3-conflict-markers.sh      | 90 ++++++++++++++++++++++++++
 xdiff-interface.c                      |  2 +
 xdiff/xdiff.h                          |  1 +
 xdiff/xmerge.c                         | 68 +++++++++++++++++--
 15 files changed, 210 insertions(+), 30 deletions(-)
base-commit: 4c719308ce59dc70e606f910f40801f2c6051b24
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1036%2Fnewren%2Fzdiff3-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1036/newren/zdiff3-v3
Pull-Request: https://github.com/git/git/pull/1036
Range-diff vs v2:
 1:  06e04c88dea ! 1:  798aefbb40a xdiff: implement a zealous diff3, or "zdiff3"
     @@ Commit message
          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>
     -    Helped-by: Phillip Wood <phillip.wood123@gmail.com>
     +    Co-authored-by: Phillip Wood <phillip.wood123@gmail.com>
          Signed-off-by: Elijah Newren <newren@gmail.com>
      
       ## builtin/merge-file.c ##
     @@ t/t6427-diff3-conflict-markers.sh: test_expect_success 'rebase --apply describes
      +		test_write_lines 1 2 3 4 5 6 7 8 9 >basic &&
      +		test_write_lines 1 2 3 AA 4 5 BB 6 7 8 >middle-common &&
      +		test_write_lines 1 2 3 4 5 6 7 8 9 >interesting &&
     ++		test_write_lines 1 2 3 4 5 6 7 8 9 >evil &&
      +
     -+		git add basic middle-common &&
     ++		git add basic middle-common interesting evil &&
      +		git commit -m base &&
      +
      +		git branch left &&
     @@ t/t6427-diff3-conflict-markers.sh: test_expect_success 'rebase --apply describes
      +		test_write_lines 1 2 3 4 A B C D E 7 8 9 >basic &&
      +		test_write_lines 1 2 3 CC 4 5 DD 6 7 8 >middle-common &&
      +		test_write_lines 1 2 3 4 A B C D E F G H I J 7 8 9 >interesting &&
     ++		test_write_lines 1 2 3 4 X A B C 7 8 9 >evil &&
      +		git add -u &&
      +		git commit -m letters &&
      +
     @@ t/t6427-diff3-conflict-markers.sh: test_expect_success 'rebase --apply describes
      +		test_write_lines 1 2 3 4 A X C Y E 7 8 9 >basic &&
      +		test_write_lines 1 2 3 EE 4 5 FF 6 7 8 >middle-common &&
      +		test_write_lines 1 2 3 4 A B C 5 6 G H I J 7 8 9 >interesting &&
     ++		test_write_lines 1 2 3 4 Y A B C B C 7 8 9 >evil &&
      +		git add -u &&
      +		git commit -m permuted
      +	)
     @@ t/t6427-diff3-conflict-markers.sh: test_expect_success 'rebase --apply describes
      +
      +		git checkout left^0 &&
      +
     ++		base=$(git rev-parse --short HEAD^1) &&
      +		test_must_fail git -c merge.conflictstyle=zdiff3 merge -s recursive right^0 &&
      +
     -+		test_write_lines 1 2 3 4 A "<<<<<<< HEAD" B C D "||||||| $(git rev-parse --short HEAD^1)" 5 6 ======= X C Y ">>>>>>> right^0" E 7 8 9 >expect &&
     ++		test_write_lines 1 2 3 4 A \
     ++				 "<<<<<<< HEAD" B C D \
     ++				 "||||||| $base" 5 6 \
     ++				 ======= X C Y \
     ++				 ">>>>>>> right^0" \
     ++				 E 7 8 9 \
     ++				 >expect &&
      +		test_cmp expect basic &&
      +
     -+		test_write_lines 1 2 3 "<<<<<<< HEAD" CC "||||||| $(git rev-parse --short HEAD^1)" AA ======= EE ">>>>>>> right^0" 4 5 "<<<<<<< HEAD" DD "||||||| $(git rev-parse --short HEAD^1)" BB ======= FF ">>>>>>> right^0" 6 7 8 >expect &&
     ++		test_write_lines 1 2 3 \
     ++				 "<<<<<<< HEAD" CC \
     ++				 "||||||| $base" AA \
     ++				 ======= EE \
     ++				 ">>>>>>> right^0" \
     ++				 4 5 \
     ++				 "<<<<<<< HEAD" DD \
     ++				 "||||||| $base" BB \
     ++				 ======= FF \
     ++				 ">>>>>>> right^0" \
     ++				 6 7 8 \
     ++				 >expect &&
      +		test_cmp expect middle-common &&
      +
     -+		# Not passing this one yet.  For some reason, after extracting
     -+		# the common lines "A B C" and "G H I J", the remaining part
     -+		# is comparing "5 6" in the base to "5 6" on the left and
     -+		# "D E F" on the right.  And zdiff3 currently picks the side
     -+		# that matches the base as the merge result.  Weird.
     -+		test_write_lines 1 2 3 4 A B C D E F G H I J 7 8 9 >expect &&
     -+		test_cmp expect interesting
     ++		test_write_lines 1 2 3 4 A B C \
     ++				 "<<<<<<< HEAD" D E F \
     ++				 "||||||| $base" 5 6 \
     ++				 ======= 5 6 \
     ++				 ">>>>>>> right^0" \
     ++				 G H I J 7 8 9 \
     ++				 >expect &&
     ++		test_cmp expect interesting &&
     ++
     ++		# Not passing this one yet; the common "B C" lines is still
     ++		# being left in the conflict blocks on the left and right
     ++		# sides.
     ++		test_write_lines 1 2 3 4 \
     ++				 "<<<<<<< HEAD" X A \
     ++				 "||||||| $base" 5 6 \
     ++				 ======= Y A B C \
     ++				 ">>>>>>> right^0" \
     ++				 B C 7 8 9 \
     ++				 >expect &&
     ++		test_cmp expect evil
      +	)
      +'
      +
 2:  9ce7246c0e9 = 2:  90aee68e14a update documentation for new zdiff3 conflictStyle
-- 
gitgitgadget
Previous: Elijah Newren via GitGitGadgetNext: Elijah Newren via GitGitGadget
Message 29 of 39 in “RFC: implement new zdiff3 conflict style”
  1. 0/2 RFC: implement new zdiff3 conflict styleElijah Newren via GitGitGadget, Jun 15, 2021
  2. 1/2 xdiff: implement a zealous diff3, or "zdiff3"Elijah Newren via GitGitGadget, Jun 15, 2021
  3. Junio C HamanoJun 15, 2021
  4. Felipe ContrerasJun 15, 2021
  5. Elijah NewrenJun 15, 2021
  6. Sergey OrganovJun 15, 2021
  7. 2/2 update documentation for new zdiff3 conflictStyleElijah Newren via GitGitGadget, Jun 15, 2021
  8. Junio C HamanoJun 15, 2021
  9. Jeff KingJun 15, 2021
  10. Elijah NewrenJun 15, 2021
  11. Phillip WoodJun 16, 2021
  12. Jeff KingJun 16, 2021
  13. Phillip WoodJun 23, 2021
  14. Jeff KingJun 23, 2021
  15. Elijah NewrenJun 17, 2021
  16. Johannes SixtJun 15, 2021
  17. Elijah NewrenJun 15, 2021
  18. Johannes SixtJun 16, 2021
  19. Elijah NewrenJun 16, 2021
  20. 0/2 RFC: implement new zdiff3 conflict styleElijah Newren via GitGitGadget, Sep 11, 2021
  21. 1/2 xdiff: implement a zealous diff3, or "zdiff3"Elijah Newren via GitGitGadget, Sep 11, 2021
  22. Phillip WoodSep 15, 2021
  23. Phillip WoodSep 15, 2021
  24. Elijah NewrenSep 18, 2021
  25. Phillip WoodSep 24, 2021
  26. Elijah NewrenSep 18, 2021
  27. Phillip WoodSep 24, 2021
  28. 2/2 update documentation for new zdiff3 conflictStyleElijah Newren via GitGitGadget, Sep 11, 2021
  29. 0/2 RFC: implement new zdiff3 conflict styleElijah Newren via GitGitGadget, Sep 18, 2021
  30. 1/2 xdiff: implement a zealous diff3, or "zdiff3"Elijah Newren via GitGitGadget, Sep 18, 2021
  31. 2/2 update documentation for new zdiff3 conflictStyleElijah Newren via GitGitGadget, Sep 18, 2021
  32. 0/2 Implement new zdiff3 conflict styleElijah Newren via GitGitGadget, Nov 16, 2021
  33. 1/2 xdiff: implement a zealous diff3, or "zdiff3"Phillip Wood via GitGitGadget, Nov 16, 2021
  34. 2/2 update documentation for new zdiff3 conflictStyleElijah Newren via GitGitGadget, Nov 16, 2021
  35. 0/2 Implement new zdiff3 conflict styleElijah Newren via GitGitGadget, Dec 1, 2021
  36. 1/2 xdiff: implement a zealous diff3, or "zdiff3"Phillip Wood via GitGitGadget, Dec 1, 2021
  37. 2/2 update documentation for new zdiff3 conflictStyleElijah Newren via GitGitGadget, Dec 1, 2021
  38. Bagas SanjayaDec 2, 2021
  39. Eric SunshineDec 2, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.