Mercurial > public > mercurial-scm > hg
diff mercurial/bdiff.c @ 7104:9514cbb6e4f6
bdiff: normalize the diff (issue1295)
When the common part of a diff can be moved forward, move it forward.
Otherwise we don't get deterministic results (it would depends on the way we
split for the recursion).
That way we get identical hunks when doing the same change, it helps to solve
issue1295 (inconsistent diffs on different side during a merge).
author | Benoit Boissinot <benoit.boissinot@ens-lyon.org> |
---|---|
date | Tue, 14 Oct 2008 20:13:53 +0200 |
parents | bfad9865b1dc |
children | 8bbbba2a1a9c |
line wrap: on
line diff
--- a/mercurial/bdiff.c Wed Oct 15 23:27:35 2008 +0200 +++ b/mercurial/bdiff.c Tue Oct 14 20:13:53 2008 +0200 @@ -240,6 +240,7 @@ static struct hunklist diff(struct line *a, int an, struct line *b, int bn) { struct hunklist l; + struct hunk *curr; struct pos *pos; int t; @@ -259,6 +260,30 @@ } free(pos); + + for (curr = l.base; curr != l.head; curr++) { + struct hunk *next = curr+1; + int shift = 0; + + if (next == l.head) + break; + + if (curr->a2 == next->a1) + while (curr->a2+shift < an && curr->b2+shift < bn + && !cmp(a+curr->a2+shift, b+curr->b2+shift)) + shift++; + else if (curr->b2 == next->b1) + while (curr->b2+shift < bn && curr->a2+shift < an + && !cmp(b+curr->b2+shift, a+curr->a2+shift)) + shift++; + if (!shift) + continue; + curr->b2 += shift; + next->b1 += shift; + curr->a2 += shift; + next->a1 += shift; + } + return l; }