From: Rasmus Villemoes <ravi@prevas.dk>
To: Jeff King <peff@peff.net>
Cc: Josh Poimboeuf <jpoimboe@kernel.org>,
Masahiro Yamada <masahiroy@kernel.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] setlocalversion: work around "git describe" performance
Date: Thu, 07 Nov 2024 11:52:07 +0100 [thread overview]
Message-ID: <87jzdfgvu0.fsf@prevas.dk> (raw)
In-Reply-To: <20241106212337.GA956489@coredump.intra.peff.net> (Jeff King's message of "Wed, 6 Nov 2024 16:23:37 -0500")
On Wed, Nov 06 2024, Jeff King <peff@peff.net> wrote:
> On Wed, Nov 06, 2024 at 02:28:38AM +0100, Rasmus Villemoes wrote:
>
>> This has been acknowledged as a performance bug in git [1]. However,
>> no solution is yet in git.git, and even when one lands, it will take
>> quite a while before it finds its way to a release and for
>> $random_kernel_developer to pick that up.
>
> I just posted patches in:
>
> https://lore.kernel.org/git/20241106192236.GC880133@coredump.intra.peff.net/
>
> but I agree it is worth dealing with in the interim. And also, I really
> suspect that this new code may end up faster than git-describe in some
> cases anyway.
>
>> +try_tag() {
>> + tag="$1"
>> +
>> + # Is $tag an annotated tag?
>> + [ "$(git cat-file -t "$tag" 2> /dev/null)" = "tag" ] || return 1
>> +
>> + # Is it an ancestor of HEAD, and if so, how many commits are in $tag..HEAD?
>> + read left right <<EOF || return 1
>> +$(git rev-list --count --left-right "$tag"...HEAD 2> /dev/null)
>> +EOF
>> +
>> + # $left is 0 if and only if $tag is an ancestor of HEAD
>> + [ "$left" -eq 0 ] || return 1
>> +
>> + # $right is the number of commits in the range $tag..HEAD, possibly 0.
>> + count="$right"
>> +
>> + return 0
>> +}
>
> The git parts all look good to me here (and not knowing much about the
> kernel's scripts I'll refrain from even looking closely at the other
> parts).
>
> The use of the here-doc is a little funny, but I guess you can't just
> pipe to read since that would put it in a subshell.
Exactly. I try to avoid string manipulation using "$(echo ... | cut
...)" etc. when I can get away with doing it in the shell itself, which
sometimes leads to some awkward constructions.
> But I do note that your "|| return 1" won't catch a failure from
> "rev-list", if that was the intent.
Well, not a failure from rev-list itself, but I thought that when the
command ended up producing nothing on stdout for read to consume, read
would fail. But you are right, that doesn't work as I expected.
$ printf '' | read left right ; echo "$?"
1
$ printf '\n' | read left right ; echo "$?"
0
I'd need for the inner $() to not strip a newline, and for the heredoc
to not implicitly add one, for read to actually fail.
>I think you'd have to use a real tempfile to catch it, or
> play horrid tricks with echoing $? into the "read" stream. I guess the
> explicit check for "$left -eq 0" will catch most failures anyway.
Yes, except that I should probably then use string comparison = instead
of -eq, since $left will be empty when rev-list hasn't produced any
output.
Maybe
set -- $(git rev-list ... 2> /dev/null)
left="$1"
right="$2"
is simpler. There's also
left_right="$(git rev-list ...)"
left="${left_right% *}"
right="${left_right#* }"
where the whitespace are actually tab characters, but that's probably
too subtle.
> If you use "<<-" you can get rid of the awkward indentation.
Ack, thanks for the reminder. I seemed to remember that as a bash
extension, but it's not.
Rasmus
prev parent reply other threads:[~2024-11-07 10:52 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-06 1:28 [PATCH] setlocalversion: work around "git describe" performance Rasmus Villemoes
2024-11-06 21:23 ` Jeff King
2024-11-07 10:52 ` Rasmus Villemoes [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=87jzdfgvu0.fsf@prevas.dk \
--to=ravi@prevas.dk \
--cc=jpoimboe@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=masahiroy@kernel.org \
--cc=peff@peff.net \
/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