xdiff -W: relax end-of-file function detection

When adding a new function to the end of a file, it's enough to know that 1) the addition is at the end of the file; and 2) there is a function _somewhere_ in there. If we had simply been changing the end of an existing function, then we would also be deleting something from the old version. This fixes the case where we add e.g. // Begin of dummy static int dummy(void) { } to the end of the file. Signed-off-by: Vegard Nossum <vegard.nossum@oracle.com> Acked-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Vegard Nossum committed Jan 13, 2017 at 17:15 UTC 540d3eb0ebad425f0902cbca0549288fe627f058
1 file changed +6 -8
xdiff/xemit.c
+6 -8
@@ -183,16 +183,14 @@ int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
183
184 /*
185 * We don't need additional context if
186 - * a whole function was added, possibly
187 - * starting with empty lines.
186 + * a whole function was added.
187 */
189 - while (i2 < xe->xdf2.nrec &&
190 - is_empty_rec(&xe->xdf2, i2))
188 + while (i2 < xe->xdf2.nrec) {
189 + if (match_func_rec(&xe->xdf2, xecfg, i2,
190 + dummy, sizeof(dummy)) >= 0)
191 + goto post_context_calculation;
192 i2++;
192 - if (i2 < xe->xdf2.nrec &&
193 - match_func_rec(&xe->xdf2, xecfg, i2,
194 - dummy, sizeof(dummy)) >= 0)
195 - goto post_context_calculation;
193 + }
194
195 /*
196 * Otherwise get more context from the