Skip to content

Commit 98e6da8

Browse files
dschoJunio C Hamano
authored andcommitted
xdl_merge(): fix and simplify conflict handling
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>
1 parent 710daa8 commit 98e6da8

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

xdiff/xmerge.c

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ static int xdl_append_merge(xdmerge_t **merge, int mode,
3838
long i1, long chg1, long i2, long chg2)
3939
{
4040
xdmerge_t *m = *merge;
41-
if (m && mode == m->mode &&
42-
(i1 == m->i1 + m->chg1 || i2 == m->i2 + m->chg2)) {
41+
if (m && (i1 <= m->i1 + m->chg1 || i2 <= m->i2 + m->chg2)) {
42+
if (mode != m->mode)
43+
m->mode = 0;
4344
m->chg1 = i1 + chg1 - m->i1;
4445
m->chg2 = i2 + chg2 - m->i2;
4546
} else {
@@ -313,22 +314,10 @@ static int xdl_do_merge(xdfenv_t *xe1, xdchange_t *xscr1, const char *name1,
313314
i1 = xscr1->i1 + xscr1->chg1;
314315
i2 = xscr2->i1 + xscr2->chg1;
315316

316-
if (i1 > i2) {
317-
xscr1->chg1 -= i1 - i2;
318-
xscr1->i1 = i2;
319-
xscr1->i2 += xscr1->chg2;
320-
xscr1->chg2 = 0;
317+
if (i1 >= i2)
321318
xscr2 = xscr2->next;
322-
} else if (i2 > i1) {
323-
xscr2->chg1 -= i2 - i1;
324-
xscr2->i1 = i1;
325-
xscr2->i2 += xscr2->chg2;
326-
xscr2->chg2 = 0;
327-
xscr1 = xscr1->next;
328-
} else {
319+
if (i2 >= i1)
329320
xscr1 = xscr1->next;
330-
xscr2 = xscr2->next;
331-
}
332321
}
333322
while (xscr1) {
334323
if (!changes)

0 commit comments

Comments
 (0)