From: kristofferhaugsbakk@fastmail.com Date: Wed, 02 Dec 2026 22:14:08 GMT Subject: [PATCH 00/12] revision: learn -Z for NUL termination Message-ID: From: Kristoffer Haugsbakk Topic name: kh/revision-nul-termination Topic summary: Commands in the git-rev-list(1) family support NUL delimiting commits. NUL delimiting is handy when you want to process each commit at a time (cf. just run through all via a pipeline). But this NUL delimit support lacks in ergonomics, is fragile, and inconsistent. Introduce `-Z` which NUL terminates commits and is decoupled from the NUL handling internal to diffs. This started when I wanted to replace git-format-rev(1) with simply using git-diff-tree(1) with some options that I would have never guessed. But I found some problems:[1] But I was wrong again. git-diff-tree(1) supports NUL for pretty printing (`-v`). I was only looking at one single output. But with “separator” delimiters (either newline or NUL) there is no delimiter for one single record (output). That’s why it didn’t show up for me. (thanks `cat -A`) But the separator behavior is a problem. Because when consuming input piecemeal (like reading from a shell coproc) you need a terminator. But the `log-tree.c` functionality very diligently keeps itself to using separators: 1. You feed one commit: you get the output with no delimiter 2. You feed another one: now there are two output records so a delimiter is needed. *Then* a separator is printed right before the record 3. Repeat 4. Of course the final record will not have a delimiter at the end I experimented with forcing terminator behavior but it seems that git-diff-tree(1) is just unwilling. This patch series adds `-Z`: • NUL delimiter • Termination. This is needed when you want to read each record and act on it. Reading up until NUL avoids deadlock risks.[2] • Cf. separator which does not add a delimiter after the final record • Also, every separator is emitted “lazily”, at the start of the *next* record • The standard logic chooses separator if no custom format and terminator for custom format. (You can also get separator with a custom format with `--pretty=format:`.) So you effectively cannot get termination with the built-in formats. • Both the commit message as well as the commit acts as a record. Or just the diff, of course (git-diff-tree(1)) • Things like `git log --format=%s --patch -z` terminate after the commit subject, then the diff, then the commit subject, termination, and repeat. This is inconsistent with plain `git log -z` (default format), which delimits the commit message and diff as a single unit (record) (see abd4e222 (Fix "git log -z" behaviour, 2007-02-07) • Decoupled from the `-z` diff behavior, which adds internal NUL to the non-patch diff formats like `--name-only` and `--raw` • But you can pass `-Z -z` and get both This is a new `revision.c:handle_revision_opt` option, but the utility is focused around git-diff-tree(1). Also no backticks in the commit messages.[4] And less code-quoting overall. 🔗 1: https://lore.kernel.org/git/238e5652-e95b-4d44-a900-e16aa6ab81f0@app.fastmail.com/ † 2: I learned this while working on git-format-rev(1)[3] 🔗 3: https://lore.kernel.org/git/e8bb57a2-8eff-4f72-96ca-72d8880901e0@gmail.com/ 🔗 4: https://lore.kernel.org/git/xmqq33sme4u5.fsf@gitster.g/ [01/12] t4205: use correct 'setup' keyword [02/12] t4205: add test coverage for NUL separator and --patch [03/12] t4205: test blank line between commit and diff explicitly [04/12] t4013-diff-various.sh: test --stdin -z --patch [05/12] log-tree: terminate cmt+diff when -z --patch [06/12] t4205: test --diff-merges [07/12] revision: learn -Z for NUL termination [08/12] revision: split out termination character [09/12] diff-tree: flush each diff when --stdin [10/12] doc: diff-tree: tell about --no-commit-id in Description [11/12] doc: diff-tree: add Examples section and mention --stdin [12/12] doc: rev-list: complete diff-tree by mentioning --always Documentation/git-diff-tree.adoc | 43 ++++++++++ Documentation/git-rev-list.adoc | 3 + Documentation/rev-list-options.adoc | 12 +++ builtin/diff-tree.c | 4 + log-tree.c | 35 ++++++-- log-tree.h | 5 ++ pretty.c | 8 +- revision.c | 7 ++ revision.h | 7 ++ t/t4013-diff-various.sh | 72 ++++++++++++++++ t/t4205-log-pretty-formats.sh | 127 +++++++++++++++++++++++++++- 11 files changed, 312 insertions(+), 11 deletions(-) base-commit: 1891de46f79dc444a47db1c87bd0c8c76b5463f2 -- 2.56.1.5.g155936fbb2a