git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [RFC PATCH v2] builtin/shortlog: explicitly set hash algo when there is no repo

From
Taylor Blau <me@ttaylorr.com>
Date
Oct 16, 2024, 19:01 UTC
Message-ID
<ZxANnCw/yVzLl0yn@nand.local>
In-Reply-To
<w6vzuumbd5vrdluvnheescdgw36teuj6k5anlyiphvpr6slcgc@2gkwe2ye26a6>
On Wed, Oct 16, 2024 at 11:48:24AM +0200, Wolfgang Müller wrote:
Show 16 quoted lines
> 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.
Show 7 quoted lines
> 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.
Previous: Wolfgang MüllerNext: Wolfgang Müller
Message 19 of 36 in “builtin/shortlog: explicitly set hash algo when there is no repo”
  1. builtin/shortlog: explicitly set hash algo when there is no repoWolfgang Müller, Oct 11, 2024
  2. Wolfgang MüllerOct 15, 2024
  3. Kristoffer HaugsbakkOct 15, 2024
  4. Taylor BlauOct 15, 2024
  5. Taylor BlauOct 15, 2024
  6. Wolfgang MüllerOct 16, 2024
  7. Taylor BlauOct 16, 2024
  8. builtin/shortlog: explicitly set hash algo when there is no repoWolfgang Müller, Oct 15, 2024
  9. Eric SunshineOct 15, 2024
  10. Wolfgang MüllerOct 15, 2024
  11. Patrick SteinhardtOct 16, 2024
  12. Wolfgang MüllerOct 16, 2024
  13. Patrick SteinhardtOct 16, 2024
  14. Wolfgang MüllerOct 16, 2024
  15. Taylor BlauOct 16, 2024
  16. Wolfgang MüllerOct 16, 2024
  17. Patrick SteinhardtOct 17, 2024
  18. Wolfgang MüllerOct 16, 2024
  19. Taylor BlauOct 16, 2024
  20. Wolfgang MüllerOct 16, 2024
  21. 0/2 builtin/shortlog: explicitly set hash algo when there is no repoWolfgang Müller, Oct 16, 2024
  22. 1/2 builtin/shortlog: explicitly set hash algo when there is no repoWolfgang Müller, Oct 16, 2024
  23. Taylor BlauOct 16, 2024
  24. Wolfgang MüllerOct 16, 2024
  25. Patrick SteinhardtOct 17, 2024
  26. Wolfgang MüllerOct 17, 2024
  27. Patrick SteinhardtOct 17, 2024
  28. 2/2 shortlog: Test reading a log from a SHA256 repo in a non-git directoryWolfgang Müller, Oct 16, 2024
  29. Taylor BlauOct 16, 2024
  30. Wolfgang MüllerOct 16, 2024
  31. Taylor BlauOct 16, 2024
  32. Taylor BlauOct 16, 2024
  33. Wolfgang MüllerOct 16, 2024
  34. builtin/shortlog: explicitly set hash algo when there is no repoWolfgang Müller, Oct 17, 2024
  35. Taylor BlauOct 17, 2024
  36. Wolfgang MüllerOct 17, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.