git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: Junio C Hamano <junkio@cox.net>
Cc: Linus Torvalds <torvalds@osdl.org>,
	Ramsay Jones <ramsay@ramsay1.demon.co.uk>,
	git@vger.kernel.org
Subject: [PATCH] xdl_merge(): fix and simplify conflict handling
Date: Tue, 5 Dec 2006 22:15:35 +0100 (CET)	[thread overview]
Message-ID: <Pine.LNX.4.63.0612052209030.28348@wbgn013.biozentrum.uni-wuerzburg.de> (raw)
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

  reply	other threads:[~2006-12-05 21:15 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-01  7:06 Resolving conflicts Wink Saville
2006-12-01  7:30 ` Alan Chandler
2006-12-01  7:41   ` Wink Saville
2006-12-01  8:10     ` Alan Chandler
2006-12-01  7:39 ` Linus Torvalds
2006-12-01  7:52   ` Wink Saville
2006-12-01  7:57     ` Linus Torvalds
2006-12-01  8:00       ` Linus Torvalds
2006-12-01  8:13         ` Alan Chandler
2006-12-01  8:22         ` Wink Saville
2006-12-01 23:47           ` Alan Chandler
2006-12-02  3:04             ` Wink Saville
2006-12-02  4:30     ` Linus Torvalds
2006-12-02  7:55       ` Junio C Hamano
2006-12-02 10:49         ` using xdl_merge(), was " Johannes Schindelin
2006-12-05 17:58           ` Ramsay Jones
2006-12-05 18:28             ` Linus Torvalds
2006-12-05 18:43               ` Junio C Hamano
2006-12-05 18:53               ` Johannes Schindelin
2006-12-05 19:50                 ` Junio C Hamano
2006-12-05 21:15                   ` Johannes Schindelin [this message]
2006-12-05 22:10                     ` [PATCH] xdl_merge(): fix and simplify conflict handling Junio C Hamano
2006-12-05 22:24                       ` Johannes Schindelin
2006-12-05 22:54                         ` Junio C Hamano
2006-12-05 22:27                       ` Jakub Narebski
2006-12-05 22:27                         ` Johannes Schindelin
2006-12-06  9:48                   ` using xdl_merge(), was Re: Resolving conflicts Junio C Hamano
2006-12-06 10:02                     ` Johannes Schindelin
2006-12-06 10:13                       ` Junio C Hamano
2006-12-06 10:47                         ` Johannes Schindelin
2006-12-05 18:36             ` Johannes Schindelin
2006-12-01  7:53   ` Linus Torvalds

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.63.0612052209030.28348@wbgn013.biozentrum.uni-wuerzburg.de \
    --to=johannes.schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    --cc=ramsay@ramsay1.demon.co.uk \
    --cc=torvalds@osdl.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).