--- a/mercurial/bdiff.c Thu Jun 02 16:18:44 2016 -0700
+++ b/mercurial/bdiff.c Thu Jun 02 17:09:06 2016 -0500
@@ -166,10 +166,17 @@
/* loop through all lines match a[i] in b */
for (; j >= b1; j = b[j].n) {
/* does this extend an earlier match? */
- if (i > a1 && j > b1 && pos[j - 1].pos == i - 1)
- k = pos[j - 1].len + 1;
- else
- k = 1;
+ for (k = 1; j - k >= b1 && i - k >= a1; k++) {
+ /* reached an earlier match? */
+ if (pos[j - k].pos == i - k) {
+ k += pos[j - k].len;
+ break;
+ }
+ /* previous line mismatch? */
+ if (a[i - k].e != b[j - k].e)
+ break;
+ }
+
pos[j].pos = i;
pos[j].len = k;