git-format-rev(1) is an experimental command from Git 2.55.0. It was introduced because no command was found for the use case of pretty formatting one revision at a time from standard in (stdin). See [Discussion] on the doc.
🔗 Discussion: https://git-scm.com/docs/git-format-rev#_discussion
But yesterday someone was reading through all of git-rev-list(1). And this is one of the examples:
git rev-list HEAD |
git diff-tree --stdin --format=medium -pAnd if one turns on merge display and off patch display.
git rev-list HEAD |
git diff-tree --stdin --format=medium --no-patch -mYou have “on-demand pretty formatting”
And it’s even *better*. Because it supports `--notes` like git-log(1) does. And probably everything else that the rev-list machinery supports. git-format-rev(1) does not. The `--notes` display is not part of pretty formatting itself.
(There are also some minor extra things you get from the pretty formats (the built-in ones) used with git-log(1) and co. that you don’t get with git-format-rev(1). Because git-format-rev(1) just uses `pretty.h` while I think git-log(1) and co. use `log-tree.h`.)
But you do have the issue that you have to pass object names. With git-format-rev(1) you can pass revision expressions. But you can just stick a revs-to-OID pipe in front of it:
... | git cat-file --batch-command='%(objectname)' | ...
And then that’s taken care of.[2]
That’s for `git format-rev --stdin-mode=revs`. But there is a concillation price in that `git format-rev --stdin-mode=text` can format object names (full hex) in running text (by just tweaking the function that `git name-rev --annotate-stdin` calls). But that was a nice bonus and not why the command was made.
† 1: git-format-rev(1) also supports NUL-terminated input in order to
deal with multiline revision expressions.[3] And `-Z` for
git-cat-file(1) does that too (both input and output), so the pair
git-cat-file(1)/git-diff-tree(1) is equally expressive.🔗 3: https://lore.kernel.org/git/e8bb57a2-8eff-4f72-96ca-72d8880901e0@gmail.com/