--- 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;
}