From: Patrick Steinhardt <ps@pks.im>
To: git@vger.kernel.org
Subject: Re: [RFC PATCH v2] builtin/shortlog: explicitly set hash algo when there is no repo
Date: Wed, 16 Oct 2024 10:57:13 +0200 [thread overview]
Message-ID: <Zw9_46fbvbGhjmYw@pks.im> (raw)
In-Reply-To: <gtdjnvonjodr435wuv2pofnww2pdcd33s22xxz5ypwkpvdythc@vrajz5ttkjbz>
On Wed, Oct 16, 2024 at 10:47:03AM +0200, Wolfgang Müller wrote:
> On 2024-10-16 07:32, Patrick Steinhardt wrote:
> > On Tue, Oct 15, 2024 at 01:48:26PM +0200, Wolfgang Müller wrote:
> > > diff --git a/t/t4201-shortlog.sh b/t/t4201-shortlog.sh
> > > index c20c885724..ed39c67ba1 100755
> > > --- a/t/t4201-shortlog.sh
> > > +++ b/t/t4201-shortlog.sh
> > > @@ -143,6 +143,11 @@ fuzz()
> > > test_grep "too many arguments" out
> > > '
> > >
> > > +test_expect_success 'shortlog --author from non-git directory does not segfault' '
> > > + git log --no-expand-tabs HEAD >log &&
> > > + env GIT_DIR=non-existing git shortlog --author=author <log 2>out
> > > +'
> > > +
> >
> > I'd like to see another testcase added that exercises behaviour when
> > git-shortlog(1) is passed SHA256 output outside of a repo, as I'm
> > curious how it'll behave in that scenario.
>
> I had a look at this in builtin/shortlog.c's read_from_stdin() and am
> pretty sure that git-shortlog(1), when reading from stdin, simply
> ignores anything but either the "Author:" or "Commit:" lines, depending
> on the value given by --group. The --group=format: option is not
> supported when reading from stdin. Neither is --format handled at all.
>
> So I don't think there is actually a way to make git-shortlog(1)
> encounter and handle a commit hash when reading from stdin; the hash
> algorithm seems completely meaningless for its user-facing behaviour. As
> far as I have seen the closest it comes to getting into contact with a
> hash (or more specifically, hexsz) is when cmd_shortlog() sets:
>
> log.abbrev = rev.abbrev;
>
> This relies on the parsing machinery in parse_revision_opt() - the one
> this patch is for. Technically --abbrev is honored by git-shortlog(1)
> when reading from stdin, but its value goes unused because of the
> difference in code paths when reading from stdin. Do take this with a
> grain of salt, however, this is my first look at the inner workings of
> git-shortlog(1).
Okay, thanks for the explanation.
Given that we do set `log.abbrev` I think we should be hitting code
paths in git-shortlog(1) that use it. `git shortlog --format=%h` for
example would use `log.abbrev`, wouldn't it? It would be nice to figure
out whether this can be made to misbehave based on which object hash we
have in the input.
> As for the test, I'd be happy to provide one if this is still deemed
> necessary after considering the above. There's two questions I have:
>
> 1) Is this already covered by GIT_TEST_DEFAULT_HASH=sha256? Running the
> t4201-shortlog testsuite with that passes.
I think it doesn't hurt to have an explicit test for this scenario, even
if it just demonstrates that things don't crash or behave in weird ways.
> 2) I've already experimented with setting up a test for this and am
> unsure how to cleanly set up a sha256 repository. Ordinarily it should
> be a simple init/add (perhaps with test_commit), but t4201-shortlog is
> already running within a git repository if I understand the setup step
> correctly. Is there a clean way to escape from there, or would it simply
> be fine creating another repository within that one?
You can take e.g. b2dbf97f47 (builtin/index-pack: fix segfaults when
running outside of a repo, 2024-09-04) as inspiration for how to achieve
this.
Patrick
next prev parent reply other threads:[~2024-10-16 8:57 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-11 18:34 [RFC PATCH] builtin/shortlog: explicitly set hash algo when there is no repo Wolfgang Müller
2024-10-15 9:33 ` Wolfgang Müller
2024-10-15 9:47 ` Kristoffer Haugsbakk
2024-10-15 19:54 ` Taylor Blau
2024-10-15 23:28 ` Taylor Blau
2024-10-16 8:15 ` Wolfgang Müller
2024-10-16 18:28 ` Taylor Blau
2024-10-15 11:48 ` [RFC PATCH v2] " Wolfgang Müller
2024-10-15 17:20 ` Eric Sunshine
2024-10-15 17:51 ` Wolfgang Müller
2024-10-16 5:32 ` Patrick Steinhardt
2024-10-16 8:47 ` Wolfgang Müller
2024-10-16 8:57 ` Patrick Steinhardt [this message]
2024-10-16 9:07 ` Wolfgang Müller
2024-10-16 18:52 ` Taylor Blau
2024-10-16 19:01 ` Wolfgang Müller
2024-10-17 5:04 ` Patrick Steinhardt
2024-10-16 9:48 ` Wolfgang Müller
2024-10-16 19:01 ` Taylor Blau
2024-10-16 19:14 ` Wolfgang Müller
2024-10-16 18:21 ` [PATCH v3 0/2] " Wolfgang Müller
2024-10-16 18:21 ` [PATCH v3 1/2] " Wolfgang Müller
2024-10-16 19:22 ` Taylor Blau
2024-10-16 19:37 ` Wolfgang Müller
2024-10-17 11:58 ` Patrick Steinhardt
2024-10-17 12:09 ` Wolfgang Müller
2024-10-17 12:11 ` Patrick Steinhardt
2024-10-16 18:21 ` [PATCH v3 2/2] shortlog: Test reading a log from a SHA256 repo in a non-git directory Wolfgang Müller
2024-10-16 19:25 ` Taylor Blau
2024-10-16 19:35 ` Wolfgang Müller
2024-10-16 19:45 ` Taylor Blau
2024-10-16 19:32 ` [PATCH v3 0/2] builtin/shortlog: explicitly set hash algo when there is no repo Taylor Blau
2024-10-16 19:38 ` Wolfgang Müller
2024-10-17 9:35 ` [PATCH v4] " Wolfgang Müller
2024-10-17 20:10 ` Taylor Blau
2024-10-17 22:02 ` Wolfgang Müller
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=Zw9_46fbvbGhjmYw@pks.im \
--to=ps@pks.im \
--cc=git@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.