]> git.ipfire.org Git - thirdparty/git.git/commitdiff
grep: -W: skip trailing empty lines at EOF, too
authorRené Scharfe <l.s.r@web.de>
Tue, 30 Jul 2024 14:18:54 +0000 (16:18 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 30 Jul 2024 16:59:04 +0000 (09:59 -0700)
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>
grep.c
t/t7810-grep.sh

diff --git a/grep.c b/grep.c
index ac34bfeafb3c911aa6918d4f90deeca5f8da3bee..2f8b9553df99845597b7586cf3d0e084a0ee4919 100644 (file)
--- a/grep.c
+++ b/grep.c
@@ -1735,7 +1735,8 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle
                                peek_eol = end_of_line(peek_bol, &peek_left);
                        }
 
-                       if (match_funcname(opt, gs, peek_bol, peek_eol))
+                       if (peek_bol >= gs->buf + gs->size ||
+                           match_funcname(opt, gs, peek_bol, peek_eol))
                                show_function = 0;
                }
                if (show_function ||
index 875dcfd98f3a0eb5e47b7f32b15da43b27a50577..af2cf2f78ab890662c3743ae407aa6ac101b5d8d 100755 (executable)
@@ -31,6 +31,7 @@ int main(int argc, const char **argv)
        return 0;
        /* char ?? */
 }
+
 EOF
 
 test_expect_success setup '