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

[PATCH] xdl_merge(): fix and simplify conflict handling

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Dec 5, 2006, 21:15 UTC
Message-ID
<Pine.LNX.4.63.0612052209030.28348@wbgn013.biozentrum.uni-wuerzburg.de>
In-Reply-To
<7vac22glzz.fsf@assigned-by-dhcp.cox.net>

Suppose you have changes in new1 to the original lines 10-20, and changes in new2 to the original lines 15-25, then the changes to 10-25 conflict. But it is possible that the next changes in new1 still overlap with this change to new2.

So, in the next iteration we have to look at the same change to new2 again.

The old code tried to be a bit too clever. The new code is shorter and more to the point: do not fiddle with the ranges at all.

Also, xdl_append_merge() tries harder to combine conflicts. This is necessary, because with the above simplification, some conflicts would not be recognized as conflicts otherwise:

In the above scenario, it is possible that there is no other change to new1. Absent the combine logic, the change in new2 would be recorded _again_, but as a non-conflict.

Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
---
	On Tue, 5 Dec 2006, Junio C Hamano wrote:
	> However, the conflict 'next' leaves seems a bit suspicious.
	> Trying to reproduce
	> 
	> 	56f9686c4d1e1d586b731b815bd98d70f84ecda4
	> 
	> gives an interesting illustration.
	This is fixed now.
 xdiff/xmerge.c |   21 +++++----------------
 1 files changed, 5 insertions(+), 16 deletions(-)
diff --git a/xdiff/xmerge.c b/xdiff/xmerge.c
index 1fe7a1b..352207e 100644
--- a/xdiff/xmerge.c
+++ b/xdiff/xmerge.c
@@ -38,8 +38,9 @@ static int xdl_append_merge(xdmerge_t **merge, int mode,
 		long i1, long chg1, long i2, long chg2)
 {
 	xdmerge_t *m = *merge;
-	if (m && mode == m->mode &&
-			(i1 == m->i1 + m->chg1 || i2 == m->i2 + m->chg2)) {
+	if (m && (i1 <= m->i1 + m->chg1 || i2 <= m->i2 + m->chg2)) {
+		if (mode != m->mode)
+			m->mode = 0;
 		m->chg1 = i1 + chg1 - m->i1;
 		m->chg2 = i2 + chg2 - m->i2;
 	} else {
@@ -313,22 +314,10 @@ static int xdl_do_merge(xdfenv_t *xe1, xdchange_t *xscr1, const char *name1,
 		i1 = xscr1->i1 + xscr1->chg1;
 		i2 = xscr2->i1 + xscr2->chg1;
 
-		if (i1 > i2) {
-			xscr1->chg1 -= i1 - i2;
-			xscr1->i1 = i2;
-			xscr1->i2 += xscr1->chg2;
-			xscr1->chg2 = 0;
+		if (i1 >= i2)
 			xscr2 = xscr2->next;
-		} else if (i2 > i1) {
-			xscr2->chg1 -= i2 - i1;
-			xscr2->i1 = i1;
-			xscr2->i2 += xscr2->chg2;
-			xscr2->chg2 = 0;
-			xscr1 = xscr1->next;
-		} else {
+		if (i2 >= i1)
 			xscr1 = xscr1->next;
-			xscr2 = xscr2->next;
-		}
 	}
 	while (xscr1) {
 		if (!changes)
-- 
1.4.4.1.g394ac-dirty
Previous: Junio C HamanoNext: Junio C Hamano
Message 21 of 32 in “Resolving conflicts”
  1. Wink SavilleDec 1, 2006
  2. Alan ChandlerDec 1, 2006
  3. Wink SavilleDec 1, 2006
  4. Alan ChandlerDec 1, 2006
  5. Linus TorvaldsDec 1, 2006
  6. Wink SavilleDec 1, 2006
  7. Linus TorvaldsDec 1, 2006
  8. Linus TorvaldsDec 1, 2006
  9. Alan ChandlerDec 1, 2006
  10. Wink SavilleDec 1, 2006
  11. Alan ChandlerDec 1, 2006
  12. Wink SavilleDec 2, 2006
  13. Linus TorvaldsDec 2, 2006
  14. Junio C HamanoDec 2, 2006
  15. using xdl_merge(), was Re: Resolving conflictsJohannes Schindelin, Dec 2, 2006
  16. Ramsay JonesDec 5, 2006
  17. Linus TorvaldsDec 5, 2006
  18. Junio C HamanoDec 5, 2006
  19. Johannes SchindelinDec 5, 2006
  20. Junio C HamanoDec 5, 2006
  21. xdl_merge(): fix and simplify conflict handlingJohannes Schindelin, Dec 5, 2006
  22. Junio C HamanoDec 5, 2006
  23. Johannes SchindelinDec 5, 2006
  24. Junio C HamanoDec 5, 2006
  25. Jakub NarebskiDec 5, 2006
  26. Johannes SchindelinDec 5, 2006
  27. Junio C HamanoDec 6, 2006
  28. Johannes SchindelinDec 6, 2006
  29. Junio C HamanoDec 6, 2006
  30. Johannes SchindelinDec 6, 2006
  31. Johannes SchindelinDec 5, 2006
  32. Linus TorvaldsDec 1, 2006

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.