From: Junio C Hamano <gitster@pobox.com>
To: "René Scharfe" <l.s.r@web.de>
Cc: Git List <git@vger.kernel.org>
Subject: Re: [PATCH] grep: -W: skip trailing empty lines at EOF, too
Date: Tue, 30 Jul 2024 09:58:49 -0700 [thread overview]
Message-ID: <xmqqle1ierzq.fsf@gitster.g> (raw)
In-Reply-To: <8b90e0ec-251f-46b3-8777-96efd58e227b@web.de> ("René Scharfe"'s message of "Tue, 30 Jul 2024 16:18:54 +0200")
René Scharfe <l.s.r@web.de> writes:
> 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.
Nice, and the implementation reflects the above logic.
> 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>
> ---
> grep.c | 3 ++-
> t/t7810-grep.sh | 1 +
> 2 files changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/grep.c b/grep.c
> index ac34bfeafb..2f8b9553df 100644
> --- 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 ||
> diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh
> index 875dcfd98f..af2cf2f78a 100755
> --- a/t/t7810-grep.sh
> +++ b/t/t7810-grep.sh
> @@ -31,6 +31,7 @@ int main(int argc, const char **argv)
> return 0;
> /* char ?? */
> }
> +
> EOF
>
> test_expect_success setup '
> --
> 2.46.0
prev parent reply other threads:[~2024-07-30 16:58 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-30 14:18 [PATCH] grep: -W: skip trailing empty lines at EOF, too René Scharfe
2024-07-30 16:58 ` Junio C Hamano [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqle1ierzq.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=l.s.r@web.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).