{"thread":{"id":"66543","subject":"git-diff-tree(1) can already do the important parts of git-format-rev(1)","startedAt":"2026-10-15T10:35:36Z","lastAt":"2026-10-17T16:34:13Z","messageCount":3,"participants":["Kristoffer Haugsbakk"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"555130","messageId":"ce69d94e-7329-449d-b3c3-47d4f3aa608c@app.fastmail.com","threadId":"66543","inReplyTo":null,"subject":"git-diff-tree(1) can already do the important parts of git-format-rev(1)","fromName":"Kristoffer Haugsbakk","fromEmail":"kristofferhaugsbakk@fastmail.com","sentAt":"2026-10-15T10:35:36Z","receivedAt":"2026-10-15T10:35:36Z","isPatch":false,"sender":{"key":"kristofferhaugsbakk@fastmail.com","avatar":null},"body":"git-format-rev(1) is an experimental command from Git 2.55.0. It was\nintroduced because no command was found for the use case of pretty\nformatting one revision at a time from standard in (stdin). See\n[Discussion] on the doc.\n\n🔗 Discussion: https://git-scm.com/docs/git-format-rev#_discussion\n\nBut yesterday someone was reading through all of git-rev-list(1). And\nthis is one of the examples:\n\n    git rev-list HEAD |\n    git diff-tree --stdin --format=medium -p\n\nAnd if one turns on merge display and off patch display.\n\n    git rev-list HEAD |\n    git diff-tree --stdin --format=medium --no-patch -m\n\nYou have “on-demand pretty formatting”\n\nAnd it’s even *better*. Because it supports `--notes` like git-log(1)\ndoes. And probably everything else that the rev-list machinery\nsupports. git-format-rev(1) does not. The `--notes` display is not part\nof pretty formatting itself.\n\n(There are also some minor extra things you get from the pretty formats\n(the built-in ones) used with git-log(1) and co. that you don’t get with\ngit-format-rev(1). Because git-format-rev(1) just uses `pretty.h` while\nI think git-log(1) and co. use `log-tree.h`.)\n\nBut you do have the issue that you have to pass object names. With\ngit-format-rev(1) you can pass revision expressions. But you can just\nstick a revs-to-OID pipe in front of it:\n\n    ... | git cat-file --batch-command='%(objectname)' | ...\n\nAnd then that’s taken care of.[2]\n\nThat’s for `git format-rev --stdin-mode=revs`. But there is a\nconcillation price in that `git format-rev --stdin-mode=text` can format\nobject names (full hex) in running text (by just tweaking the function\nthat `git name-rev --annotate-stdin` calls). But that was a nice bonus\nand not why the command was made.\n\n† 1: git-format-rev(1) also supports NUL-terminated input in order to\n     deal with multiline revision expressions.[3] And `-Z` for\n     git-cat-file(1) does that too (both input and output), so the pair\n     git-cat-file(1)/git-diff-tree(1) is equally expressive.\n\n     🔗 3: https://lore.kernel.org/git/e8bb57a2-8eff-4f72-96ca-72d8880901e0@gmail.com/\n\n"},{"id":"555182","messageId":"2c1656e2-a054-43c2-94cc-31625f8c69e9@app.fastmail.com","threadId":"66543","inReplyTo":"ce69d94e-7329-449d-b3c3-47d4f3aa608c@app.fastmail.com","subject":"Re: git-diff-tree(1) can already do the important parts of git-format-rev(1)","fromName":"Kristoffer Haugsbakk","fromEmail":"kristofferhaugsbakk@fastmail.com","sentAt":"2026-10-15T18:42:36Z","receivedAt":"2026-10-15T18:42:36Z","isPatch":false,"sender":{"key":"kristofferhaugsbakk@fastmail.com","avatar":null},"body":"On Thu, Oct 15, 2026, at 12:35, Kristoffer Haugsbakk wrote:\n> git-format-rev(1) is an experimental command from Git 2.55.0. It was\n> introduced because no command was found for the use case of pretty\n> formatting one revision at a time from standard in (stdin). See\n> [Discussion] on the doc.\n>\n> 🔗 Discussion: https://git-scm.com/docs/git-format-rev#_discussion\n>\n> But yesterday someone was reading through all of git-rev-list(1). And\n> this is one of the examples:\n>\n>     git rev-list HEAD |\n>     git diff-tree --stdin --format=medium -p\n>\n> And if one turns on merge display and off patch display.\n>\n>     git rev-list HEAD |\n>     git diff-tree --stdin --format=medium --no-patch -m\n>\n> You have “on-demand pretty formatting”\n\nBut for multiline pretties you need NUL termination. And this is what\n`-z` says:\n\n    When --raw, --numstat, --name-only or --name-status has been given,\n    do not munge pathnames and use NULs as output field terminators.\n\n    Without this option, pathnames with \"unusual\" characters are quoted\n    as explained for the configuration variable core.quotePath (see\n    git-config(1)).\n\nSo `-z` only applies to some primitive and name-centric diff\nformats. And that’s why my later footnote is wrong:\n\n>[snip]\n>\n> † 1: git-format-rev(1) also supports NUL-terminated input in order to\n>      deal with multiline revision expressions.[3] And `-Z` for\n>      git-cat-file(1) does that too (both input and output), so the pair\n>      git-cat-file(1)/git-diff-tree(1) is equally expressive.\n>\n>      🔗 3: https://lore.kernel.org/git/e8bb57a2-8eff-4f72-96ca-72d8880901e0@gmail.com/\n\n"},{"id":"555330","messageId":"238e5652-e95b-4d44-a900-e16aa6ab81f0@app.fastmail.com","threadId":"66543","inReplyTo":"2c1656e2-a054-43c2-94cc-31625f8c69e9@app.fastmail.com","subject":"Re: git-diff-tree(1) can already do the important parts of git-format-rev(1)","fromName":"Kristoffer Haugsbakk","fromEmail":"kristofferhaugsbakk@fastmail.com","sentAt":"2026-10-17T16:34:13Z","receivedAt":"2026-10-17T16:34:13Z","isPatch":false,"sender":{"key":"kristofferhaugsbakk@fastmail.com","avatar":null},"body":"On Thu, Oct 15, 2026, at 20:42, Kristoffer Haugsbakk wrote:\n> On Thu, Oct 15, 2026, at 12:35, Kristoffer Haugsbakk wrote:\n>>[snip]\n>>\n>>     git rev-list HEAD |\n>>     git diff-tree --stdin --format=medium --no-patch -m\n>>\n>> You have “on-demand pretty formatting”\n>\n> But for multiline pretties you need NUL termination. And this is what\n> `-z` says:\n>\n>     When --raw, --numstat, --name-only or --name-status has been given,\n>     do not munge pathnames and use NULs as output field terminators.\n>\n>     Without this option, pathnames with \"unusual\" characters are quoted\n>     as explained for the configuration variable core.quotePath (see\n>     git-config(1)).\n>\n> So `-z` only applies to some primitive and name-centric diff\n> formats. And that’s why my later footnote is wrong:\n>\n>>[snip]\n>>\n>> † 1: git-format-rev(1) also supports NUL-terminated input in order to\n>>      deal with multiline revision expressions.[3] And `-Z` for\n>>      git-cat-file(1) does that too (both input and output), so the pair\n>>      git-cat-file(1)/git-diff-tree(1) is equally expressive.\n>>\n>>      🔗 3: https://lore.kernel.org/git/e8bb57a2-8eff-4f72-96ca-72d8880901e0@gmail.com/\n\nBut I was wrong again. git-diff-tree(1) supports NUL for pretty printing\n(`-v`). I was only looking at one single output. But with “separator”\ndelimiters (either newline or NUL) there is no delimiter for one single\nrecord (output). That’s why it didn’t show up for me. (thanks `cat -A`)\n\nBut the separator behavior is a problem. Because when consuming input\npiecemeal (like reading from a shell coproc) you need a terminator. But\nthe `log-tree.c` functionality very diligently keeps itself to using\nseparators:\n\n1. You feed one commit: you get the output with no delimiter\n2. You feed another one: now there are two output records so a delimiter\n   is needed. *Then* a separator is printed right before the record\n3. Repeat\n4. Of course the final record will not have a delimiter at the end\n\nI experimented with forcing terminator behavior but it seems that\ngit-diff-tree(1) is just unwilling.\n\nBut it seems that one can just add a `--use-terminator` option\ncommands that use `tree-log.c` (I think by adding it to `revision.c:\nhandle_revision_opt`). Then I can use a git-diff-tree(1) that acts like\ngit-format-rev(1) with `--stdin-mode=revs`... and in fact a bit better\n(see previous).\n\nAll of this for pretty-printing (`-z`). For `--patch` (cf. raw diff)\nthere is no NUL delimiter support.\n\n  THE CONTEXT\n\nI am working on a shell script that needs to construct a git-log(1)/\ngit-format-patch(1)-like output. Each commit message describes a range\nof commits. And the optional patch/diff output is the interdiff between\neach range if they happen to share the same base. This is like\ngit-format-patch(1) with `--interdiff`. So what I need for each\nrecord/entry in the log:\n\n1. A commit message\n2. An interdiff if wanted and if it can be produced\n\nWhat I have done, respectively:\n\n1. A coproc for `git format-rev --stdin-mode=revs`\n2. Individual calls to git-diff-tree(1) (not `--stdin`)\n\nSomewhat incidental to this, I figured out that git-diff-tree(1) can\nalmost replace `git format-rev --stdin`.\n\nBut when I turned to git-diff-tree(1) and tried to transform (2) into a\ncoproc. But that seems to not be feasible, since it seems that\nNUL-termination is not supported for diffs that a person would want\nto look at.\n\n"}]}