{"thread":{"id":"61869","subject":"[PATCH] grep: -W: skip trailing empty lines at EOF, too","startedAt":"2024-07-30T14:18:56Z","lastAt":"2024-07-30T16:58:52Z","messageCount":2,"participants":["René Scharfe","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"499609","messageId":"8b90e0ec-251f-46b3-8777-96efd58e227b@web.de","threadId":"61869","inReplyTo":null,"subject":"[PATCH] grep: -W: skip trailing empty lines at EOF, too","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2024-07-30T14:18:54Z","receivedAt":"2024-07-30T14:18:56Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"4aa2c4753d (grep: -W: don't extend context to trailing empty lines,\n2016-05-28) stopped showing empty lines at the end of function context\nwhen using -W.  Do the same for trailing empty lines at the end of\nfiles, for consistency -- it doesn't matter whether a function section\nis ended by the next function or the end of the file.\n\nTest it by adding a trailing empty line to the file used by the test\n\"grep -W\" and leave its expected output the same.\n\nSigned-off-by: René Scharfe <l.s.r@web.de>\n---\n grep.c          | 3 ++-\n t/t7810-grep.sh | 1 +\n 2 files changed, 3 insertions(+), 1 deletion(-)\n\ndiff --git a/grep.c b/grep.c\nindex ac34bfeafb..2f8b9553df 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -1735,7 +1735,8 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle\n \t\t\t\tpeek_eol = end_of_line(peek_bol, &peek_left);\n \t\t\t}\n\n-\t\t\tif (match_funcname(opt, gs, peek_bol, peek_eol))\n+\t\t\tif (peek_bol >= gs->buf + gs->size ||\n+\t\t\t    match_funcname(opt, gs, peek_bol, peek_eol))\n \t\t\t\tshow_function = 0;\n \t\t}\n \t\tif (show_function ||\ndiff --git a/t/t7810-grep.sh b/t/t7810-grep.sh\nindex 875dcfd98f..af2cf2f78a 100755\n--- a/t/t7810-grep.sh\n+++ b/t/t7810-grep.sh\n@@ -31,6 +31,7 @@ int main(int argc, const char **argv)\n \treturn 0;\n \t/* char ?? */\n }\n+\n EOF\n\n test_expect_success setup '\n--\n2.46.0\n"},{"id":"499628","messageId":"xmqqle1ierzq.fsf@gitster.g","threadId":"61869","inReplyTo":"8b90e0ec-251f-46b3-8777-96efd58e227b@web.de","subject":"Re: [PATCH] grep: -W: skip trailing empty lines at EOF, too","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-07-30T16:58:49Z","receivedAt":"2024-07-30T16:58:52Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"René Scharfe <l.s.r@web.de> writes:\n\n> 4aa2c4753d (grep: -W: don't extend context to trailing empty lines,\n> 2016-05-28) stopped showing empty lines at the end of function context\n> when using -W.  Do the same for trailing empty lines at the end of\n> files, for consistency -- it doesn't matter whether a function section\n> is ended by the next function or the end of the file.\n\nNice, and the implementation reflects the above logic.\n\n> Test it by adding a trailing empty line to the file used by the test\n> \"grep -W\" and leave its expected output the same.\n>\n> Signed-off-by: René Scharfe <l.s.r@web.de>\n> ---\n>  grep.c          | 3 ++-\n>  t/t7810-grep.sh | 1 +\n>  2 files changed, 3 insertions(+), 1 deletion(-)\n>\n> diff --git a/grep.c b/grep.c\n> index ac34bfeafb..2f8b9553df 100644\n> --- a/grep.c\n> +++ b/grep.c\n> @@ -1735,7 +1735,8 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle\n>  \t\t\t\tpeek_eol = end_of_line(peek_bol, &peek_left);\n>  \t\t\t}\n>\n> -\t\t\tif (match_funcname(opt, gs, peek_bol, peek_eol))\n> +\t\t\tif (peek_bol >= gs->buf + gs->size ||\n> +\t\t\t    match_funcname(opt, gs, peek_bol, peek_eol))\n>  \t\t\t\tshow_function = 0;\n>  \t\t}\n>  \t\tif (show_function ||\n> diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh\n> index 875dcfd98f..af2cf2f78a 100755\n> --- a/t/t7810-grep.sh\n> +++ b/t/t7810-grep.sh\n> @@ -31,6 +31,7 @@ int main(int argc, const char **argv)\n>  \treturn 0;\n>  \t/* char ?? */\n>  }\n> +\n>  EOF\n>\n>  test_expect_success setup '\n> --\n> 2.46.0\n"}]}