git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Taylor Blau <me@ttaylorr.com>
To: Patrick Steinhardt <ps@pks.im>, 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 15:01:48 -0400	[thread overview]
Message-ID: <ZxANnCw/yVzLl0yn@nand.local> (raw)
In-Reply-To: <w6vzuumbd5vrdluvnheescdgw36teuj6k5anlyiphvpr6slcgc@2gkwe2ye26a6>

On Wed, Oct 16, 2024 at 11:48:24AM +0200, Wolfgang Müller wrote:
> On 2024-10-16 10:57, Patrick Steinhardt wrote:
> > 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.
>
> I dove into the code again and now I'm fairly sure custom formatting is
> only ever done when in a repository. shortlog_output() itself, called at
> the end of cmd_shortlog(), doesn't do any formatting, only possibly
> wrapping the lines already present in the shortlog struct.
>
> That struct is filled either by read_from_stdin() or get_from_rev(). The
> latter is only ever called when in a repository:
>
> [...]

Thanks; I agree with your analysis here.

> So whilst we parse all the relevant options like --abbrev and --format,
> we take a shortcut through read_from_stdin() and never get to apply a
> custom format. Commit hashes from stdin are discarded.
>
> I'm not sure a test case for different hash algorithms would test
> anything meaningful here, unless the plan in the future is to have
> git-shortlog(1) support formatting when reading from stdin.

I think that in general it would be difficult to support the full range
of --format specifiers when operating outside of a repository, because
we don't have all of the information necessary to assemble all of the
possible formatting options.

For instance, let's say I want to take Patrick's example to test 'git
shortlog' with '--format="%H"' outside of the repository. There's no way
to disambiguate whether, say, a SHA-256 hash is either (a) a correctly
formatted SHA-256 hash, or (b) a corrupted / too-long SHA-1 hash.

So that means that '%H', '%h', '%T', and '%t' are off the table. '%an'
and '%ae' seem reasonable to implement, but '%aN' and '%aE' less so,
because we don't have a .mailmap file to read. The same goes for the
committer variants of all of those.

I don't think there is any reasonable interpretation of '%d'/'%D', and
likewise for '%(decorate)' as well as '%(describe)'. We could probably
go on, but I am getting tired of looking through the 'PRETTY FORMATS'
section of git-log(1) and trying to figure out how they'd work (or not)
without a repository ;-).

In any event, my feeling is that while we could probably implement a
handful of these formatting options, that it would likely be kind of
awkward to do so. Not to mention the user-visible awkwardness of
supporting some '--format' specifiers but not others[^1].

So I think that the best course of action would be to document the
limitation and move on ;-).

Thanks,
Taylor

[^1]: Playing devil's advocate, though, perhaps it is OK to document
  well which formatting options do and don't work, and accept that a
  user asking for '--format="%(describe)"' (etc.) outside of a
  repository is nonsensical and warn / return nothing appropriately.

  reply	other threads:[~2024-10-16 19:01 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
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 [this message]
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=ZxANnCw/yVzLl0yn@nand.local \
    --to=me@ttaylorr.com \
    --cc=git@vger.kernel.org \
    --cc=ps@pks.im \
    /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).