[PATCH 3/6] xdiff: show non-empty lines before functions with -W

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
Signed-off-by: Rene Scharfe <l.s.r@xxxxxx>
---
 t/t4051-diff-function-context.sh | 2 +-
 xdiff/xemit.c                    | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/t/t4051-diff-function-context.sh b/t/t4051-diff-function-context.sh
index 30fc5bf2b3..2d76a971c4 100755
--- a/t/t4051-diff-function-context.sh
+++ b/t/t4051-diff-function-context.sh
@@ -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
 '
 
diff --git a/xdiff/xemit.c b/xdiff/xemit.c
index c2d5bd004c..7778dc2b19 100644
--- a/xdiff/xemit.c
+++ b/xdiff/xemit.c
@@ -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) {
-- 
2.15.0



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux