Skip to content

Commit 19f7a9c

Browse files
rctaygitster
authored andcommitted
xdiff/xhistogram: rework handling of recursed results
Previously we were over-complicating matters by trying to combine the recursed results. Now, terminate immediately if a recursive call failed and return its result. Signed-off-by: Tay Ray Chuan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 739864b commit 19f7a9c

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

xdiff/xhistogram.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -339,21 +339,24 @@ static int histogram_diff(xpparam_t const *xpp, xdfenv_t *env,
339339
if (find_lcs(&index, &lcs, line1, count1, line2, count2))
340340
result = fall_back_to_classic_diff(&index, line1, count1, line2, count2);
341341
else {
342-
result = 0;
343342
if (lcs.begin1 == 0 && lcs.begin2 == 0) {
344343
int ptr;
345344
for (ptr = 0; ptr < count1; ptr++)
346345
env->xdf1.rchg[line1 + ptr - 1] = 1;
347346
for (ptr = 0; ptr < count2; ptr++)
348347
env->xdf2.rchg[line2 + ptr - 1] = 1;
348+
result = 0;
349349
} else {
350350
result = histogram_diff(xpp, env,
351-
line1, lcs.begin1 - line1,
352-
line2, lcs.begin2 - line2);
351+
line1, lcs.begin1 - line1,
352+
line2, lcs.begin2 - line2);
353+
if (result)
354+
goto cleanup;
353355
result = histogram_diff(xpp, env,
354-
lcs.end1 + 1, LINE_END(1) - lcs.end1,
355-
lcs.end2 + 1, LINE_END(2) - lcs.end2);
356-
result *= -1;
356+
lcs.end1 + 1, LINE_END(1) - lcs.end1,
357+
lcs.end2 + 1, LINE_END(2) - lcs.end2);
358+
if (result)
359+
goto cleanup;
357360
}
358361
}
359362

0 commit comments

Comments
 (0)