When diffing against a patch we treat each hunk separately
and join the result.
This joining doesn't merge adjacent matches so it doesn't really
tell the full story of where the matches are and how big
they are. This can confuse other code, particularly when
examining hunk headers to create the merger.
So add detection for adjacent matches.
Signed-off-by: NeilBrown <neilb@suse.de>
struct csl *csl_join(struct csl *c1, struct csl *c2)
{
int cnt1, cnt2;
+ int offset = 0;
if (c1 == NULL)
return c2;
if (c2 == NULL)
;
for (cnt2 = 0; c2[cnt2].len; cnt2++)
;
+ if (cnt1 && cnt2 &&
+ c1[cnt1-1].a + c1[cnt1-1].len == c2[0].a &&
+ c1[cnt1-1].b + c1[cnt1-1].len == c2[0].b) {
+ /* Merge these two */
+ c1[cnt1-1].len += c2[0].len;
+ offset = 1;
+ cnt2--;
+ }
c1 = realloc(c1, (cnt1+cnt2+1)*sizeof(*c1));
while (cnt2 >= 0) {
- c1[cnt1+cnt2] = c2[cnt2];
+ c1[cnt1+cnt2] = c2[cnt2 + offset];
cnt2--;
}
free(c2);