xdiff: show non-empty lines before functions with -W
Non-empty lines before a function definition are most likely comments for that function and thus relevant. Include them in function context. Such a non-empty line might also belong to the preceeding function if there is no separating blank line. Stop extending the context upwards also at the next function line to make sure only one extra function body is shown at most. Original-patch-by: Vegard Nossum <vegard.nossum@oracle.com> Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Nov 18, 2017 at 19:05 UTC
5c3ed90f3f56757f2af9cc327313e9df2e38cdd5
2 files changed
+4
-1
t/t4051-diff-function-context.sh
+1
-1
@@ -85,7 +85,7 @@ test_expect_success 'setup' '
85
86
check_diff changed_hello 'changed function'
87
88
-test_expect_failure ' context includes comment' '
88
+test_expect_success ' context includes comment' '
89
grep "^ .*Hello comment" changed_hello.diff
90
'
91
xdiff/xemit.c
+3
@@ -204,6 +204,9 @@ int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
204
}
205
206
fs1 = get_func_line(xe, xecfg, NULL, i1, -1);
207
+ while (fs1 > 0 && !is_empty_rec(&xe->xdf1, fs1 - 1) &&
208
+ !is_func_rec(&xe->xdf1, xecfg, fs1 - 1))
209
+ fs1--;
210
if (fs1 < 0)
211
fs1 = 0;
212
if (fs1 < s1) {