Conversation
Author
|
/cc Nikita Makarov n.makarov@yadro.com |
|
User |
spkrka
force-pushed
the
krka/line-range-trailing-blank
branch
2 times, most recently
from
September 21, 2026 10:47
7fd6178 to
40609b2
Compare
git log -L :funcname: includes trailing empty lines in the
function range. This boils down to parse_range_funcname()
extending the range forward until it either reaches end-of-file
or another function, without skipping empty lines at the
boundary. Including empty lines is inconsistent with how it
works for git grep -W.
Fix this by trimming trailing empty lines from the computed range,
with the same goal as this fix (though with a different approach):
8e5dd94 (grep: -W: skip trailing empty lines at EOF, too,
2024-07-30)
Reported-by: Nikita Makarov <n.makarov@yadro.com>
Signed-off-by: Kristofer Karlsson <krka@spotify.com>
spkrka
force-pushed
the
krka/line-range-trailing-blank
branch
from
September 21, 2026 10:51
40609b2 to
f2e217d
Compare
Author
|
/submit |
|
Submitted as pull.2234.git.1789991377413.gitgitgadget@gmail.com To fetch this version into To fetch this version to local tag |
|
Junio C Hamano wrote on the Git mailing list (how to reply to this email): "Kristofer Karlsson via GitGitGadget" <gitgitgadget@gmail.com>
writes:
> diff --git a/line-range.c b/line-range.c
> index b99f0d9895..44b52d4e34 100644
> --- a/line-range.c
> +++ b/line-range.c
> @@ -233,6 +233,11 @@ static const char *parse_range_funcname(
> (*end)++;
> }
>
> + /* exclude trailing empty lines from the function range */
> + while (*end > *begin + 1 &&
> + nth_line_cb(cb_data, *end - 1)[0] == '\n')
> + (*end)--;
> +
While the new behaviour may mean well, the implementation falls a
bit short of matching what "grep -W" did, doesn't it? Over there we
treat a line with only whitespace characters on it as an empty line
that we want to ignore, but the above code does not allow anything
before the LF. I do not know offhand if the above misbehaves on
CRLF text files, but if you treated a line with only whitespace
characters on it as an empty line, concerns on CRLF files would also
disappear ;-).
|
|
Kristofer Karlsson wrote on the Git mailing list (how to reply to this email): On Mon, 21 Sept 2026 at 19:30, Junio C Hamano <gitster@pobox.com> wrote:
>
> "Kristofer Karlsson via GitGitGadget" <gitgitgadget@gmail.com>
> writes:
>
> > diff --git a/line-range.c b/line-range.c
> > index b99f0d9895..44b52d4e34 100644
> > --- a/line-range.c
> > +++ b/line-range.c
> > @@ -233,6 +233,11 @@ static const char *parse_range_funcname(
> > (*end)++;
> > }
> >
> > + /* exclude trailing empty lines from the function range */
> > + while (*end > *begin + 1 &&
> > + nth_line_cb(cb_data, *end - 1)[0] == '\n')
> > + (*end)--;
> > +
>
> While the new behaviour may mean well, the implementation falls a
> bit short of matching what "grep -W" did, doesn't it? Over there we
> treat a line with only whitespace characters on it as an empty line
> that we want to ignore, but the above code does not allow anything
> before the LF. I do not know offhand if the above misbehaves on
> CRLF text files, but if you treated a line with only whitespace
> characters on it as an empty line, concerns on CRLF files would also
> disappear ;-).
>
Ah yes, a blank line is not the same as an empty line, good point.
I also noticed the old behavior is still in the documentation
for man git grep:
-W, --function-context
Show the surrounding text from the previous line
containing a function name up to the one before
the next function name, effectively showing the whole
function in which the match was found.
And for man git log (in the -L section):
If :<funcname> is given in place of <start> and <end>,
it is a regular expression that denotes the range from
the first funcname line that matches <funcname>, up to
the next funcname line. :<funcname> searches from the
end of the previous -L range, if any, otherwise from the
start of file.
So neither of these functions should do any blank-line trimming
according to the docs (but the docs can be changed).
So I suppose the question is what behavior we actually want,
and if these two use cases should be analogous or not.
Thanks,
Kristofer |
|
User |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
cc: René Scharfe l.s.r@web.de
cc: Nikita Makarov n.makarov@yadro.com
cc: Kristofer Karlsson krka@spotify.com