xdiff: show non-empty lines before functions with -W
authorRené Scharfe <l.s.r@web.de>
Sat, 18 Nov 2017 18:05:19 +0000 (19:05 +0100)
committerJunio C Hamano <gitster@pobox.com>
Tue, 21 Nov 2017 00:36:06 +0000 (09:36 +0900)
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>
t/t4051-diff-function-context.sh
xdiff/xemit.c
index 30fc5bf2b36d815d6a43f2b439f938b81a8816ca..2d76a971c43f6850a1f443eab3e91bf3762fe952 100755 (executable)
@@ -85,7 +85,7 @@ test_expect_success 'setup' '
 
 check_diff changed_hello 'changed function'
 
-test_expect_failure ' context includes comment' '
+test_expect_success ' context includes comment' '
        grep "^ .*Hello comment" changed_hello.diff
 '
 
index c2d5bd004c72fc5361ea72884fb455be2281e260..7778dc2b190f84fe2ab1e1539756a7e1f4254c3b 100644 (file)
@@ -204,6 +204,9 @@ int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
                        }
 
                        fs1 = get_func_line(xe, xecfg, NULL, i1, -1);
+                       while (fs1 > 0 && !is_empty_rec(&xe->xdf1, fs1 - 1) &&
+                              !is_func_rec(&xe->xdf1, xecfg, fs1 - 1))
+                               fs1--;
                        if (fs1 < 0)
                                fs1 = 0;
                        if (fs1 < s1) {