All of lore.kernel.org
 help / color / mirror / Atom feed
From: kristofferhaugsbakk@fastmail.com
To: git@vger.kernel.org
Cc: Kristoffer Haugsbakk <code@khaugsbakk.name>
Subject: [PATCH 00/12] revision: learn -Z for NUL termination
Date: Wed,  2 Dec 2026 23:14:08 +0100	[thread overview]
Message-ID: <CV_diff-tree_NUL_termination.def@m5gid.xyz> (raw)

From: Kristoffer Haugsbakk <code@khaugsbakk.name>

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:<fmt>`.) 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


             reply	other threads:[~2026-12-02 22:14 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 22:14 kristofferhaugsbakk [this message]
2026-12-02 22:14 ` [PATCH 01/12] t4205: use correct 'setup' keyword kristofferhaugsbakk
2026-12-02 22:14 ` [PATCH 02/12] t4205: add test coverage for NUL separator and --patch kristofferhaugsbakk
2026-12-02 22:14 ` [PATCH 03/12] t4205: test blank line between commit and diff explicitly kristofferhaugsbakk
2026-12-02 22:14 ` [PATCH 04/12] t4013-diff-various.sh: test --stdin -z --patch kristofferhaugsbakk
2026-12-02 22:14 ` [PATCH 05/12] log-tree: terminate cmt+diff when " kristofferhaugsbakk
2026-12-02 22:14 ` [PATCH 06/12] t4205: test --diff-merges kristofferhaugsbakk
2026-12-02 22:14 ` [PATCH 07/12] revision: learn -Z for NUL termination kristofferhaugsbakk
2026-12-02 22:14 ` [PATCH 08/12] revision: split out termination character kristofferhaugsbakk
2026-12-02 22:14 ` [PATCH 09/12] diff-tree: flush each diff when --stdin kristofferhaugsbakk
2026-12-02 22:14 ` [PATCH 10/12] doc: diff-tree: tell about --no-commit-id in Description kristofferhaugsbakk
2026-12-02 22:14 ` [PATCH 11/12] doc: diff-tree: add Examples section and mention --stdin kristofferhaugsbakk
2026-12-02 22:14 ` [PATCH 12/12] doc: rev-list: complete diff-tree by mentioning --always kristofferhaugsbakk

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=CV_diff-tree_NUL_termination.def@m5gid.xyz \
    --to=kristofferhaugsbakk@fastmail.com \
    --cc=code@khaugsbakk.name \
    --cc=git@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.