Skip to content

Commit 540d3eb

Browse files
vegardgitster
authored andcommitted
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 <[email protected]> Acked-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d7dffce commit 540d3eb

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

xdiff/xemit.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,16 +183,14 @@ int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
183183

184184
/*
185185
* 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.
188187
*/
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;
191192
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+
}
196194

197195
/*
198196
* Otherwise get more context from the

0 commit comments

Comments
 (0)