From: Vegard Nossum Date: Fri, 13 Jan 2017 16:15:10 +0000 (+0100) Subject: xdiff -W: relax end-of-file function detection X-Git-Tag: v2.13.0-rc0~157^2 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/540d3eb0ebad425f0902cbca0549288fe627f058?hp=d7dffce1cebde29a0c4b309a79e4345450bf352a 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 Acked-by: René Scharfe Signed-off-by: Junio C Hamano --- diff --git a/xdiff/xemit.c b/xdiff/xemit.c index 7389ce4102..8c88dbde38 100644 --- a/xdiff/xemit.c +++ b/xdiff/xemit.c @@ -183,16 +183,14 @@ int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb, /* * We don't need additional context if - * a whole function was added, possibly - * starting with empty lines. + * a whole function was added. */ - while (i2 < xe->xdf2.nrec && - is_empty_rec(&xe->xdf2, i2)) + while (i2 < xe->xdf2.nrec) { + if (match_func_rec(&xe->xdf2, xecfg, i2, + dummy, sizeof(dummy)) >= 0) + goto post_context_calculation; i2++; - if (i2 < xe->xdf2.nrec && - match_func_rec(&xe->xdf2, xecfg, i2, - dummy, sizeof(dummy)) >= 0) - goto post_context_calculation; + } /* * Otherwise get more context from the