grep: -W: skip trailing empty lines at EOF, too
4aa2c4753d (grep: -W: don't extend context to trailing empty lines, 2016-05-28) stopped showing empty lines at the end of function context when using -W. Do the same for trailing empty lines at the end of files, for consistency -- it doesn't matter whether a function section is ended by the next function or the end of the file. Test it by adding a trailing empty line to the file used by the test "grep -W" and leave its expected output the same. Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Jul 30, 2024 at 16:18 UTC
8e5dd94e68e37d2d4b67e34db00b9e9790a2325b
2 files changed
+3
-1
grep.c
+2
-1
@@ -1735,7 +1735,8 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle
1735
peek_eol = end_of_line(peek_bol, &peek_left);
1736
}
1737
1738
- if (match_funcname(opt, gs, peek_bol, peek_eol))
1738
+ if (peek_bol >= gs->buf + gs->size ||
1739
+ match_funcname(opt, gs, peek_bol, peek_eol))
1740
show_function = 0;
1741
}
1742
if (show_function ||
t/t7810-grep.sh
+1
@@ -31,6 +31,7 @@ int main(int argc, const char **argv)
31
return 0;
32
/* char ?? */
33
}
34
+
35
EOF
36
37
test_expect_success setup '