{"thread":{"id":"66978","subject":"[PATCH 00/12] revision: learn -Z for NUL termination","startedAt":"2026-12-02T22:14:08Z","lastAt":"2026-12-02T22:14:20Z","messageCount":13,"participants":["kristofferhaugsbakk@fastmail.com"],"isPatch":true,"patchVersion":1,"patchTotal":12},"messages":[{"id":"559927","messageId":"CV_diff-tree_NUL_termination.def@m5gid.xyz","threadId":"66978","inReplyTo":null,"subject":"[PATCH 00/12] revision: learn -Z for NUL termination","fromName":"","fromEmail":"kristofferhaugsbakk@fastmail.com","sentAt":"2026-12-02T22:14:08Z","receivedAt":"2026-12-02T22:14:08Z","isPatch":true,"sender":{"key":"kristofferhaugsbakk@fastmail.com","avatar":null},"body":"From: Kristoffer Haugsbakk <code@khaugsbakk.name>\n\nTopic name: kh/revision-nul-termination\n\nTopic summary: Commands in the git-rev-list(1) family support NUL\ndelimiting commits. NUL delimiting is handy when you want to process each\ncommit at a time (cf. just run through all via a pipeline). But this NUL\ndelimit support lacks in ergonomics, is fragile, and inconsistent.\nIntroduce `-Z` which NUL terminates commits and is decoupled\nfrom the NUL handling internal to diffs.\n\nThis started when I wanted to replace git-format-rev(1) with simply using\ngit-diff-tree(1) with some options that I would have never guessed. But I\nfound some problems:[1]\n\n    But 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”\n    delimiters (either newline or NUL) there is no delimiter for one single\n    record (output). That’s why it didn’t show up for me. (thanks `cat -A`)\n\n    But the separator behavior is a problem. Because when consuming input\n    piecemeal (like reading from a shell coproc) you need a terminator. But\n    the `log-tree.c` functionality very diligently keeps itself to using\n    separators:\n\n    1. You feed one commit: you get the output with no delimiter\n    2. 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\n    3. Repeat\n    4. Of course the final record will not have a delimiter at the end\n\n    I experimented with forcing terminator behavior but it seems that\n    git-diff-tree(1) is just unwilling.\n\nThis patch series adds `-Z`:\n\n• NUL delimiter\n• Termination. This is needed when you want to read each record and act on\n  it. Reading up until NUL avoids deadlock risks.[2]\n  • Cf. separator which does not add a delimiter after the final record\n  • Also, every separator is emitted “lazily”, at the start of the *next*\n    record\n  • The standard logic chooses separator if no custom format and terminator\n    for custom format. (You can also get separator with a custom format with\n    `--pretty=format:<fmt>`.) So you effectively cannot get termination\n    with the built-in formats.\n• Both the commit message as well as the commit acts as a record. Or just\n  the diff, of course (git-diff-tree(1))\n  • Things like `git log --format=%s --patch -z` terminate after the\n    commit subject, then the diff, then the commit subject, termination,\n    and repeat. This is inconsistent with plain `git log -z` (default\n    format), which delimits the commit message and diff as a\n    single unit (record) (see abd4e222 (Fix \"git log -z\" behaviour, 2007-02-07)\n• Decoupled from the `-z` diff behavior, which adds internal NUL to the\n  non-patch diff formats like `--name-only` and `--raw`\n  • But you can pass `-Z -z` and get both\n\nThis is a new `revision.c:handle_revision_opt` option, but the utility is\nfocused around git-diff-tree(1).\n\nAlso no backticks in the commit messages.[4] And less code-quoting overall.\n\n🔗 1: https://lore.kernel.org/git/238e5652-e95b-4d44-a900-e16aa6ab81f0@app.fastmail.com/\n† 2: I learned this while working on git-format-rev(1)[3]\n🔗 3: https://lore.kernel.org/git/e8bb57a2-8eff-4f72-96ca-72d8880901e0@gmail.com/\n🔗 4: https://lore.kernel.org/git/xmqq33sme4u5.fsf@gitster.g/\n\n[01/12] t4205: use correct 'setup' keyword\n[02/12] t4205: add test coverage for NUL separator and --patch\n[03/12] t4205: test blank line between commit and diff explicitly\n[04/12] t4013-diff-various.sh: test --stdin -z --patch\n[05/12] log-tree: terminate cmt+diff when -z --patch\n[06/12] t4205: test --diff-merges\n[07/12] revision: learn -Z for NUL termination\n[08/12] revision: split out termination character\n[09/12] diff-tree: flush each diff when --stdin\n[10/12] doc: diff-tree: tell about --no-commit-id in Description\n[11/12] doc: diff-tree: add Examples section and mention --stdin\n[12/12] doc: rev-list: complete diff-tree by mentioning --always\n\n Documentation/git-diff-tree.adoc    |  43 ++++++++++\n Documentation/git-rev-list.adoc     |   3 +\n Documentation/rev-list-options.adoc |  12 +++\n builtin/diff-tree.c                 |   4 +\n log-tree.c                          |  35 ++++++--\n log-tree.h                          |   5 ++\n pretty.c                            |   8 +-\n revision.c                          |   7 ++\n revision.h                          |   7 ++\n t/t4013-diff-various.sh             |  72 ++++++++++++++++\n t/t4205-log-pretty-formats.sh       | 127 +++++++++++++++++++++++++++-\n 11 files changed, 312 insertions(+), 11 deletions(-)\n\n\nbase-commit: 1891de46f79dc444a47db1c87bd0c8c76b5463f2\n-- \n2.56.1.5.g155936fbb2a\n\n\n"},{"id":"559928","messageId":"setup_keyword.df0@m5gid.xyz","threadId":"66978","inReplyTo":"CV_diff-tree_NUL_termination.def@m5gid.xyz","subject":"[PATCH 01/12] t4205: use correct 'setup' keyword","fromName":"","fromEmail":"kristofferhaugsbakk@fastmail.com","sentAt":"2026-12-02T22:14:09Z","receivedAt":"2026-12-02T22:14:09Z","isPatch":true,"sender":{"key":"kristofferhaugsbakk@fastmail.com","avatar":null},"body":"From: Kristoffer Haugsbakk <code@khaugsbakk.name>\n\nThe first test sets up the repository. But it uses 'set up' and not\nthe 'setup' keyword, which means that it won’t be run under\n'--run=setup,...'.\n\nSigned-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>\n---\n t/t4205-log-pretty-formats.sh | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh\nindex 01b97c88888..3ef184d7879 100755\n--- a/t/t4205-log-pretty-formats.sh\n+++ b/t/t4205-log-pretty-formats.sh\n@@ -31,7 +31,7 @@ commit_msg () {\n \tfi\n }\n \n-test_expect_success 'set up basic repos' '\n+test_expect_success 'setup basic repos' '\n \t>foo &&\n \t>bar &&\n \tgit add foo &&\n-- \n2.56.1.5.g155936fbb2a\n\n\n"},{"id":"559929","messageId":"NUL_sep._and_--patch.df1@m5gid.xyz","threadId":"66978","inReplyTo":"CV_diff-tree_NUL_termination.def@m5gid.xyz","subject":"[PATCH 02/12] t4205: add test coverage for NUL separator and --patch","fromName":"","fromEmail":"kristofferhaugsbakk@fastmail.com","sentAt":"2026-12-02T22:14:10Z","receivedAt":"2026-12-02T22:14:10Z","isPatch":true,"sender":{"key":"kristofferhaugsbakk@fastmail.com","avatar":null},"body":"From: Kristoffer Haugsbakk <code@khaugsbakk.name>\n\nThere is no test coverage for option -z combined with the default commit\nformat (medium) and user-defined pretty formats using separator.\n\nThis is relevant since we are about to change how -z, --patch, and\nNUL *termination* works in an upcoming commit.[1]\n\n† 1: commit “log-tree: terminate cmt+diff when -z --patch”\n\nSigned-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>\n---\n t/t4205-log-pretty-formats.sh | 16 ++++++++++++++++\n 1 file changed, 16 insertions(+)\n\ndiff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh\nindex 3ef184d7879..5048c3b4c39 100755\n--- a/t/t4205-log-pretty-formats.sh\n+++ b/t/t4205-log-pretty-formats.sh\n@@ -138,6 +138,22 @@ test_expect_success 'NUL separation with --stat' '\n \ttest_cmp expected actual\n '\n \n+test_expect_success 'NUL separation with --patch' '\n+\tdiff0_part=$(git diff HEAD^ HEAD) &&\n+\tdiff1_part=$(git diff-tree --no-commit-id --patch --root HEAD^) &&\n+\tprintf \"add bar\\n${diff0_part}\\n\\0$(commit_msg)\\n${diff1_part}\\n\" >expected &&\n+\tgit log -z --patch --pretty=\"format:%s\" >actual &&\n+\ttest_cmp_bin expected actual\n+'\n+\n+test_expect_success 'NUL separation with --format=medium --patch' '\n+\tgit show HEAD >expected &&\n+\tprintf \"\\0\" >>expected &&\n+\tgit show HEAD^ >>expected &&\n+\tgit log -z --patch >actual &&\n+\ttest_cmp_bin expected actual\n+'\n+\n test_expect_failure 'NUL termination with --stat' '\n \tstat0_part=$(git diff --stat HEAD^ HEAD) &&\n \tstat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) &&\n-- \n2.56.1.5.g155936fbb2a\n\n\n"},{"id":"559930","messageId":"blank_line.df2@m5gid.xyz","threadId":"66978","inReplyTo":"CV_diff-tree_NUL_termination.def@m5gid.xyz","subject":"[PATCH 03/12] t4205: test blank line between commit and diff explicitly","fromName":"","fromEmail":"kristofferhaugsbakk@fastmail.com","sentAt":"2026-12-02T22:14:11Z","receivedAt":"2026-12-02T22:14:11Z","isPatch":true,"sender":{"key":"kristofferhaugsbakk@fastmail.com","avatar":null},"body":"From: Kristoffer Haugsbakk <code@khaugsbakk.name>\n\nThis comment and code in log-tree.c:\n\n    When showing a verbose header (i.e. log message), [...] we would\n    want an extra newline between the end of log and the diff/diffstat\n    output for readability.\n\nis not directly tested by this file. There are two cases:\n\n1. Terminators\n2. Separator (--pretty=format:<fmt>)\n\nCase (1) is tested by 'NUL separation with --stat'. Let’s add an explicit\ntest for that which doesn’t use special flags like -z.\n\nCase (2) does not adhere to the comment above, though. There is no\nblank line between the commit message and the diff:\n\n    $ git log --patch --pretty=format:<fmt>\n    <subject>\n    <diff>\n\nThe reason is that terminators are added after show_log(...), i.e.\nafter the log message, while separators are added at the beginning\nof show_log(...). This is how newlines work for terminators:\n\n1. Custom format is printed; missing newline\n2. The code below this comment terminates the commit log\n3. The terminator newline adds a blank line\n4. The diff is printed\n\nWhile the separator case is missing step (3).\n\nThat might be a bug judging by this code comment. But changing it\nwould break several *other* tests. Let’s just add a regression test\nat this point.\n\nSigned-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>\n---\n t/t4205-log-pretty-formats.sh | 15 +++++++++++++++\n 1 file changed, 15 insertions(+)\n\ndiff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh\nindex 5048c3b4c39..b03dd647ee4 100755\n--- a/t/t4205-log-pretty-formats.sh\n+++ b/t/t4205-log-pretty-formats.sh\n@@ -118,6 +118,21 @@ test_expect_success 'alias loop' '\n \ttest_must_fail git log --pretty=test-foo\n '\n \n+test_expect_success 'log --format=%s --patch blank line between commit and diff' '\n+\tgit log --format=%s -1 >expect &&\n+\techo >>expect &&\n+\tgit diff HEAD^ HEAD >>expect &&\n+\tgit log --format=%s --patch -1 >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'log --pretty=format:%s --patch no blank line between commit and diff' '\n+\tgit log --format=%s -1 >expect &&\n+\tgit diff HEAD^ HEAD >>expect &&\n+\tgit log --pretty=format:%s --patch -1 >actual &&\n+\ttest_cmp expect actual\n+'\n+\n test_expect_success 'NUL separation' '\n \tprintf \"add bar\\0$(commit_msg)\" >expected &&\n \tgit log -z --pretty=\"format:%s\" >actual &&\n-- \n2.56.1.5.g155936fbb2a\n\n\n"},{"id":"559931","messageId":"test_--stdin_-z_--patch.df3@m5gid.xyz","threadId":"66978","inReplyTo":"CV_diff-tree_NUL_termination.def@m5gid.xyz","subject":"[PATCH 04/12] t4013-diff-various.sh: test --stdin -z --patch","fromName":"","fromEmail":"kristofferhaugsbakk@fastmail.com","sentAt":"2026-12-02T22:14:12Z","receivedAt":"2026-12-02T22:14:12Z","isPatch":true,"sender":{"key":"kristofferhaugsbakk@fastmail.com","avatar":null},"body":"From: Kristoffer Haugsbakk <code@khaugsbakk.name>\n\nThere aren’t any explicit tests for 'git diff-tree --stdin -z\n--patch'. Let’s add a couple of regression tests now since we are about\nto change the log-tree.c code path.[1]\n\n† 1: Upcoming commit “log-tree: terminate cmt+diff when -z --patch”\n\nSigned-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>\n---\n t/t4013-diff-various.sh | 36 ++++++++++++++++++++++++++++++++++++\n 1 file changed, 36 insertions(+)\n\ndiff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh\nindex 21c9ad7c5d0..928a07a91bd 100755\n--- a/t/t4013-diff-various.sh\n+++ b/t/t4013-diff-various.sh\n@@ -590,6 +590,42 @@ test_expect_success 'diff-tree --stdin with pathspec' '\n \ttest_cmp expect actual\n '\n \n+test_expect_success 'setup: diff-tree --stdin -z etc.' '\n+\tprintf \"%s\" $(git rev-parse main~1) >oid1 &&\n+\tprintf \"%s\" $(git rev-parse main~2) >oid2 &&\n+\tcat oid1 >commits &&\n+\techo >>commits &&\n+\tcat oid2 >>commits &&\n+\techo >>commits &&\n+\ttest_line_count = 2 commits &&\n+\tgit rev-parse main >commits2 &&\n+\tgit rev-parse main~1 >>commits2 &&\n+\ttest_line_count = 2 commits2 &&\n+\tgit diff main~2 main~1 >diff1 &&\n+\tgit diff main~3 main~2 >diff2\n+'\n+\n+test_expect_success 'diff-tree --stdin --patch -z' '\n+\tcat oid1 >expect &&\n+\tprintf \"\\0\" >>expect &&\n+\tcat diff1 >>expect &&\n+\tcat oid2 >>expect &&\n+\tprintf \"\\0\" >>expect &&\n+\tcat diff2 >>expect &&\n+\tgit diff-tree --stdin --patch -z <commits >actual &&\n+\ttest_cmp_bin expect actual\n+'\n+\n+test_expect_success 'diff-tree --stdin --patch -z --always with one empty diff' '\n+\tprintf \"%s\" $(git rev-parse main) >expect &&\n+\tprintf \"\\0\" >>expect &&\n+\tprintf \"%s\" $(git rev-parse main~1) >>expect &&\n+\tprintf \"\\0\" >>expect &&\n+\tcat diff1 >>expect &&\n+\tgit diff-tree --stdin --patch -z --always <commits2 >actual &&\n+\ttest_cmp_bin expect actual\n+'\n+\n test_expect_success 'show A B ... -- <pathspec>' '\n \t# side touches dir/sub, file0, and file3\n \t# main^ touches dir/sub, and file1\n-- \n2.56.1.5.g155936fbb2a\n\n\n"},{"id":"559932","messageId":"terminate_cmt~pldiff_etc..df4@m5gid.xyz","threadId":"66978","inReplyTo":"CV_diff-tree_NUL_termination.def@m5gid.xyz","subject":"[PATCH 05/12] log-tree: terminate cmt+diff when -z --patch","fromName":"","fromEmail":"kristofferhaugsbakk@fastmail.com","sentAt":"2026-12-02T22:14:13Z","receivedAt":"2026-12-02T22:14:13Z","isPatch":true,"sender":{"key":"kristofferhaugsbakk@fastmail.com","avatar":null},"body":"From: Kristoffer Haugsbakk <code@khaugsbakk.name>\n\nTerminate the whole log record, i.e. the commit and the diff,\nwith NUL when e.g. 'git log -z --patch' or 'git log -z --stat' is used\nand records use terminators. This is in line with how these commands\nwork with separators. This fixes test case 'NUL termination with --stat'\nin t4205.\n\nThis behavior is useful because a program can read one record at a time\nby looking for NUL. And, unlike the separator case, it can be read\npiecemeal; in the separator case, you feed one commit to log-tree.c\nand get a record without any delimiter. You have to feed the *next*\ncommit to get the delimiter and then the next record.\n\nThe separator case was fixed in abd4e222 (Fix \"git log -z\" behaviour,\n2007-02-07). It tells us this:\n\n   For commit messages, we should really put the \"line_termination\" when we\n   output the character in between different commits, *not* between the\n   commit and the diff. The diff goes hand-in-hand with the commit, it\n   shouldn't be separated from it with the termination character.\n\n   So this:\n    - uses the termination character for true inter-commit spacing\n    - uses a regular newline between the commit log and the diff\n\n   [...]\n\nThis is the problem that the terminator case has right now.\n\nThe reason is that show_log(...) handles record termination at the\nend of the function. At that point we have only printed the commit\nmessage.\n\nLet’s put off the NUL termination case to the end of\nlog_tree_commit. That covers all cases: no diff, regular diff,\nand diff on merge commits.\n\nNow, as to the the commit ID and diff case:[1]\n\n    git diff-tree -z --patch --stdin\n\nIt would be nice to uniformly have NUL termination for the whole record\nby using a newline between the commit ID and the diff. But it might seem\nthat backwards compatibility could be a problem here. Fortunately it\nisn’t, since there isn’t a way to get both NUL delimiting and record\ntermination; record termination is turned on by using custom pretty\nformats, and custom pretty formats turn off the plain commit ID\ndisplay. So we are free to define this behavior.\n\n† 1: log-tree.c:767\n\nSigned-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>\n---\n builtin/diff-tree.c           |  1 +\n log-tree.c                    | 28 ++++++++++++++++++++++++++--\n log-tree.h                    |  5 +++++\n t/t4205-log-pretty-formats.sh | 10 +++++++++-\n 4 files changed, 41 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/diff-tree.c b/builtin/diff-tree.c\nindex 8b8f8b54e40..c7734f7be63 100644\n--- a/builtin/diff-tree.c\n+++ b/builtin/diff-tree.c\n@@ -59,6 +59,7 @@ static int stdin_diff_trees(struct tree *tree1, const char *p)\n \tdiff_tree_oid(&tree1->object.oid, &tree2->object.oid,\n \t\t      \"\", &log_tree_opt.diffopt);\n \tlog_tree_diff_flush(&log_tree_opt);\n+\tlog_tree_nul_terminate(&log_tree_opt);\n \treturn 0;\n }\n \ndiff --git a/log-tree.c b/log-tree.c\nindex 361dfadbb36..5dcee870be0 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -764,7 +764,18 @@ void show_log(struct rev_info *opt)\n \t\t\tputc('\\n', opt->diffopt.file);\n \t\t\tgraph_show_remainder(opt->graph);\n \t\t}\n-\t\tputc(opt->diffopt.line_termination, opt->diffopt.file);\n+\t\tif (opt->use_terminator &&\n+\t\t    opt->diffopt.line_termination == '\\0') {\n+\t\t\t/*\n+\t\t\t * NUL termination means that we postpone the terminator.\n+\t\t\t * But we do want a newline between the commit ID and\n+\t\t\t * the diff.\n+\t\t\t */\n+\t\t\tif (opt->diffopt.output_format & ~DIFF_FORMAT_NO_OUTPUT)\n+\t\t\t\tputc('\\n', opt->diffopt.file);\n+\t\t} else {\n+\t\t\tputc(opt->diffopt.line_termination, opt->diffopt.file);\n+\t\t}\n \t\treturn;\n \t}\n \n@@ -916,7 +927,12 @@ void show_log(struct rev_info *opt)\n \tif (opt->use_terminator && !commit_format_is_empty(opt->commit_format)) {\n \t\tif (!opt->missing_newline)\n \t\t\tgraph_show_padding(opt->graph);\n-\t\tputc(opt->diffopt.line_termination, opt->diffopt.file);\n+\t\t/*\n+\t\t * Termination is postponed for NUL in case there is\n+\t\t * diff output after the log message.\n+\t\t */\n+\t\tif (opt->diffopt.line_termination != '\\0')\n+\t\t\tputc(opt->diffopt.line_termination, opt->diffopt.file);\n \t}\n \n \tstrbuf_release(&msgbuf);\n@@ -973,6 +989,12 @@ int log_tree_diff_flush(struct rev_info *opt)\n \treturn 1;\n }\n \n+void log_tree_nul_terminate(struct rev_info *opt) {\n+\tif (opt->use_terminator &&\n+\t    opt->diffopt.line_termination == '\\0')\n+\t\tputc(opt->diffopt.line_termination, opt->diffopt.file);\n+}\n+\n static int do_diff_combined(struct rev_info *opt, struct commit *commit)\n {\n \tdiff_tree_combined_merge(commit, opt);\n@@ -1312,6 +1334,8 @@ int log_tree_commit(struct rev_info *opt, struct commit *commit)\n \t\t}\n \t}\n \n+\tlog_tree_nul_terminate(opt);\n+\n \topt->loginfo = NULL;\n \tmaybe_flush_or_die(opt->diffopt.file, \"stdout\");\n \topt->diffopt.no_free = no_free;\ndiff --git a/log-tree.h b/log-tree.h\nindex e8679b6c4aa..c5eec0459d8 100644\n--- a/log-tree.h\n+++ b/log-tree.h\n@@ -26,6 +26,11 @@ struct decoration_options {\n int parse_decorate_color_config(const char *var, const char *slot_name, const char *value);\n int log_tree_diff_flush(struct rev_info *);\n int log_tree_commit(struct rev_info *, struct commit *);\n+/*\n+ * Terminates the record if 'opt->use_terminator' and if\n+ * 'opt->line_termination' is NUL.\n+ */\n+void log_tree_nul_terminate(struct rev_info *opt);\n void release_follow_pathspec_slab(struct rev_info *);\n void show_log(struct rev_info *opt);\n void format_decorations(struct strbuf *sb, const struct commit *commit,\ndiff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh\nindex b03dd647ee4..a9a470606cf 100755\n--- a/t/t4205-log-pretty-formats.sh\n+++ b/t/t4205-log-pretty-formats.sh\n@@ -169,7 +169,7 @@ test_expect_success 'NUL separation with --format=medium --patch' '\n \ttest_cmp_bin expected actual\n '\n \n-test_expect_failure 'NUL termination with --stat' '\n+test_expect_success 'NUL termination with --stat' '\n \tstat0_part=$(git diff --stat HEAD^ HEAD) &&\n \tstat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) &&\n \tprintf \"add bar\\n$stat0_part\\n\\0$(commit_msg)\\n$stat1_part\\n\\0\" >expected &&\n@@ -177,6 +177,14 @@ test_expect_failure 'NUL termination with --stat' '\n \ttest_cmp expected actual\n '\n \n+test_expect_success 'NUL termination with --patch' '\n+\tdiff0_part=$(git diff HEAD^ HEAD) &&\n+\tdiff1_part=$(git diff-tree --no-commit-id --patch --root HEAD^) &&\n+\tprintf \"add bar\\n${diff0_part}\\n\\0$(commit_msg)\\n${diff1_part}\\n\\0\" >expected &&\n+\tgit log -z --patch --pretty=\"tformat:%s\" >actual &&\n+\ttest_cmp_bin expected actual\n+'\n+\n for p in short medium full fuller email raw\n do\n \ttest_expect_success \"NUL termination with --reflog --pretty=$p\" '\n-- \n2.56.1.5.g155936fbb2a\n\n\n"},{"id":"559933","messageId":"test_--diff-merges.df5@m5gid.xyz","threadId":"66978","inReplyTo":"CV_diff-tree_NUL_termination.def@m5gid.xyz","subject":"[PATCH 06/12] t4205: test --diff-merges","fromName":"","fromEmail":"kristofferhaugsbakk@fastmail.com","sentAt":"2026-12-02T22:14:14Z","receivedAt":"2026-12-02T22:14:14Z","isPatch":true,"sender":{"key":"kristofferhaugsbakk@fastmail.com","avatar":null},"body":"From: Kristoffer Haugsbakk <code@khaugsbakk.name>\n\nThere are no test cases for diff output on merge commits. Let’s add a\nfew. In particular, we need the 'log --diff-merges NUL terminated' to\ntest this code path according to the previous commit.\n\nSigned-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>\n---\n t/t4205-log-pretty-formats.sh | 57 +++++++++++++++++++++++++++++++++++\n 1 file changed, 57 insertions(+)\n\ndiff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh\nindex a9a470606cf..ece4def4cfd 100755\n--- a/t/t4205-log-pretty-formats.sh\n+++ b/t/t4205-log-pretty-formats.sh\n@@ -215,6 +215,63 @@ test_expect_success 'NUL termination with --reflog --pretty=oneline' '\n \ttest_cmp expect actual\n '\n \n+test_expect_success 'setup merge' '\n+\toriginal=$(git branch --show-current) &&\n+\tgit checkout -b merge-branch &&\n+\tgit checkout -b f &&\n+\techo on-a-branch >feature.txt &&\n+\tgit add feature.txt &&\n+\ttest_commit --no-tag on-another-branch feature.txt &&\n+\tgit checkout merge-branch &&\n+\tgit merge --no-ff f &&\n+\ttest_merge merge-commit --no-ff f &&\n+\tgit checkout -b f1 &&\n+\techo on-f1 >f1.txt &&\n+\tgit add f1.txt &&\n+\ttest_commit --no-tag f1 f1.txt &&\n+\tgit checkout merge-branch &&\n+\tgit checkout -b f2 &&\n+\techo on-f2 >f2.txt &&\n+\tgit add f2.txt &&\n+\ttest_commit --no-tag f2 f2.txt &&\n+\tgit checkout merge-branch &&\n+\ttest_merge octopus-merge --no-ff f1 f2 &&\n+\tgit branch -D f f1 f2 &&\n+\tgit checkout \"$original\"\n+'\n+\n+test_expect_success 'log --diff-merges' '\n+\tgit log -1 merge-commit >expect &&\n+\techo >>expect &&\n+\tgit diff merge-commit^1 merge-commit >>expect &&\n+\tgit log -1 --diff-merges=first-parent \\\n+\t\tmerge-commit >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'log --diff-merges NUL terminated' '\n+\tgit log -1 --format=%s merge-commit >expect &&\n+\tgit diff merge-commit^1 merge-commit >>expect &&\n+\tprintf \"\\0\" >>expect &&\n+\tgit log -1 -z --format=%s --diff-merges=first-parent \\\n+\t\tmerge-commit >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'log --remerge-diff octopus merge' '\n+\tgit log -1 octopus-merge >expect &&\n+\techo \"diff: warning: Skipping remerge-diff for octopus merges.\" \\\n+\t\t>>expect &&\n+\tgit log -1 --remerge-diff octopus-merge >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+# Later tests depend on what tags you have\n+test_expect_success 'setup: clean up --diff-merges' '\n+\tgit tag -d merge-commit &&\n+\tgit tag -d octopus-merge\n+'\n+\n test_expect_success 'setup more commits' '\n \ttest_commit \"message one\" one one message-one &&\n \ttest_commit \"message two\" two two message-two &&\n-- \n2.56.1.5.g155936fbb2a\n\n\n"},{"id":"559934","messageId":"learn_-Z.df6@m5gid.xyz","threadId":"66978","inReplyTo":"CV_diff-tree_NUL_termination.def@m5gid.xyz","subject":"[PATCH 07/12] revision: learn -Z for NUL termination","fromName":"","fromEmail":"kristofferhaugsbakk@fastmail.com","sentAt":"2026-12-02T22:14:15Z","receivedAt":"2026-12-02T22:14:15Z","isPatch":true,"sender":{"key":"kristofferhaugsbakk@fastmail.com","avatar":null},"body":"From: Kristoffer Haugsbakk <code@khaugsbakk.name>\n\nAdd a new option -Z which turns on NUL terminators for commit records.\n\nSeparator delimiting is the default, while terminators are turned on for\nuser-defined pretty formats. But that means that you cannot get\nterminator behavior for built-in pretty formats. This options fills in\nthat gap.\n\nCombining NUL delimiting with termination behavior means that the user\ncan read and act on each record immediately without risking deadlocks.\n\nHowever, the picture is not as simple as just splitting on NUL.\nThe terminator/delimiter character is taken from struct diff_options,\nso you have to take the diff behavior with the git-log(1) behavior.\nBut we will split these up in the next comit so that you use -Z\nwithout getting NUL in any diff format.\n\nSigned-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>\n---\n Documentation/rev-list-options.adoc | 12 ++++++++++++\n pretty.c                            |  8 +++++---\n revision.c                          |  4 ++++\n revision.h                          |  5 +++++\n t/t4013-diff-various.sh             | 23 +++++++++++++++++++++++\n t/t4205-log-pretty-formats.sh       | 27 +++++++++++++++++++++++++++\n 6 files changed, 76 insertions(+), 3 deletions(-)\n\ndiff --git a/Documentation/rev-list-options.adoc b/Documentation/rev-list-options.adoc\nindex c234e865cb1..a4bf96e7d0a 100644\n--- a/Documentation/rev-list-options.adoc\n+++ b/Documentation/rev-list-options.adoc\n@@ -396,6 +396,18 @@ This mode is only compatible with the `--objects`, `--boundary`, and\n `--missing` output options.\n endif::git-rev-list[]\n \n+`-Z`::\n+\tUse NUL terminator to delimit records. The _record_ is the\n+\tcommit and whatever extra information about it, like for example\n+\t`--patch` or `--stat`.\n++\n+Note that separator/terminator behavior is usually set when using\n+`--pretty` or `--format`. These have no effect when this option is\n+given.\n++\n+This implies `-z`, so diff output formats like `--raw` and `--numstat`\n+will also contain _NUL_ internally.\n+\n History Simplification\n ~~~~~~~~~~~~~~~~~~~~~~\n \ndiff --git a/pretty.c b/pretty.c\nindex d8a9f370f6c..019e1f88511 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -54,7 +54,7 @@ static void save_user_format(struct rev_info *rev, const char *cp, int is_tforma\n {\n \tfree(user_format);\n \tuser_format = xstrdup(cp);\n-\tif (is_tformat)\n+\tif (!rev->want_terminator && is_tformat)\n \t\trev->use_terminator = 1;\n \trev->commit_format = CMIT_FMT_USERFORMAT;\n }\n@@ -191,7 +191,8 @@ void get_commit_format(const char *arg, struct rev_info *rev)\n {\n \tstruct cmt_fmt_map *commit_format;\n \n-\trev->use_terminator = 0;\n+\tif (!rev->want_terminator)\n+\t\trev->use_terminator = 0;\n \tif (!arg) {\n \t\trev->commit_format = CMIT_FMT_DEFAULT;\n \t\treturn;\n@@ -211,7 +212,8 @@ void get_commit_format(const char *arg, struct rev_info *rev)\n \t\tdie(\"invalid --pretty format: %s\", arg);\n \n \trev->commit_format = commit_format->format;\n-\trev->use_terminator = commit_format->is_tformat;\n+\tif (!rev->want_terminator)\n+\t\trev->use_terminator = commit_format->is_tformat;\n \trev->expand_tabs_in_log_default = commit_format->expand_tabs_in_log;\n \tif (!rev->date_mode_explicit && commit_format->default_date_mode_type)\n \t\trev->date_mode.type = commit_format->default_date_mode_type;\ndiff --git a/revision.c b/revision.c\nindex a83e499047b..1d2a10267ca 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -2755,6 +2755,10 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg\n \t\tif (revs->repo->fetch_if_missing)\n \t\t\tBUG(\"exclude_promisor_objects can only be used when fetch_if_missing is 0\");\n \t\trevs->exclude_promisor_objects = 1;\n+\t} else if (!strcmp(arg, \"-Z\")) {\n+\t\trevs->want_terminator = 1;\n+\t\trevs->use_terminator = 1;\n+\t\trevs->diffopt.line_termination = '\\0';\n \t} else {\n \t\tint opts = diff_opt_parse(&revs->diffopt, argv, argc, revs->prefix);\n \t\tif (!opts)\ndiff --git a/revision.h b/revision.h\nindex e5dabd18ce1..c6598ba6f22 100644\n--- a/revision.h\n+++ b/revision.h\n@@ -272,6 +272,11 @@ struct rev_info {\n \t\t\tabbrev_commit:1,\n \t\t\tabbrev_commit_given:1,\n \t\t\tzero_commit:1,\n+\t\t\t/*\n+\t\t\t * pretty.c should not set 'use_terminator' if\n+\t\t\t * this is true.\n+\t\t\t */\n+\t\t\twant_terminator:1,\n \t\t\tuse_terminator:1,\n \t\t\tmissing_newline:1,\n \t\t\tdate_mode_explicit:1,\ndiff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh\nindex 928a07a91bd..207bd2df423 100755\n--- a/t/t4013-diff-various.sh\n+++ b/t/t4013-diff-various.sh\n@@ -626,6 +626,29 @@ test_expect_success 'diff-tree --stdin --patch -z --always with one empty diff'\n \ttest_cmp_bin expect actual\n '\n \n+test_expect_success 'diff-tree --stdin --patch -Z' '\n+\tcat oid1 >expect &&\n+\techo >>expect &&\n+\tcat diff1 >>expect &&\n+\tprintf \"\\0\" >>expect &&\n+\tcat oid2 >>expect &&\n+\techo >>expect &&\n+\tcat diff2 >>expect &&\n+\tprintf \"\\0\" >>expect &&\n+\tgit diff-tree --stdin --patch -Z <commits >actual &&\n+\ttest_cmp_bin expect actual\n+'\n+\n+test_expect_success 'diff-tree --stdin --patch -Z --always with one empty diff' '\n+\tgit rev-parse main >expect &&\n+\tprintf \"\\0\" >>expect &&\n+\tgit rev-parse main~1 >>expect &&\n+\tcat diff1 >>expect &&\n+\tprintf \"\\0\" >>expect &&\n+\tgit diff-tree --stdin --patch -Z --always <commits2 >actual &&\n+\ttest_cmp_bin expect actual\n+'\n+\n test_expect_success 'show A B ... -- <pathspec>' '\n \t# side touches dir/sub, file0, and file3\n \t# main^ touches dir/sub, and file1\ndiff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh\nindex ece4def4cfd..2d6cca46fff 100755\n--- a/t/t4205-log-pretty-formats.sh\n+++ b/t/t4205-log-pretty-formats.sh\n@@ -169,6 +169,33 @@ test_expect_success 'NUL separation with --format=medium --patch' '\n \ttest_cmp_bin expected actual\n '\n \n+test_expect_success 'NUL with -Z and --format=medium --patch' '\n+\tgit show HEAD >expected &&\n+\tprintf \"\\0\" >>expected &&\n+\tgit show HEAD^ >>expected &&\n+\tprintf \"\\0\" >>expected &&\n+\tgit log -Z --patch >actual &&\n+\ttest_cmp_bin expected actual\n+'\n+\n+test_expect_success 'NUL and terminator behavior with -Z' '\n+\tgit show HEAD >expected &&\n+\tprintf \"\\0\" >>expected &&\n+\tgit show HEAD^ >>expected &&\n+\tprintf \"\\0\" >>expected &&\n+\tgit log -Z --patch >actual &&\n+\ttest_cmp_bin expected actual\n+'\n+\n+test_expect_success '-Z --format=medium still uses terminator' '\n+\tgit show HEAD >expected &&\n+\tprintf \"\\0\" >>expected &&\n+\tgit show HEAD^ >>expected &&\n+\tprintf \"\\0\" >>expected &&\n+\tgit log -Z --format=medium --patch >actual &&\n+\ttest_cmp_bin expected actual\n+'\n+\n test_expect_success 'NUL termination with --stat' '\n \tstat0_part=$(git diff --stat HEAD^ HEAD) &&\n \tstat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) &&\n-- \n2.56.1.5.g155936fbb2a\n\n\n"},{"id":"559935","messageId":"split_out_termination.df7@m5gid.xyz","threadId":"66978","inReplyTo":"CV_diff-tree_NUL_termination.def@m5gid.xyz","subject":"[PATCH 08/12] revision: split out termination character","fromName":"","fromEmail":"kristofferhaugsbakk@fastmail.com","sentAt":"2026-12-02T22:14:16Z","receivedAt":"2026-12-02T22:14:16Z","isPatch":true,"sender":{"key":"kristofferhaugsbakk@fastmail.com","avatar":null},"body":"From: Kristoffer Haugsbakk <code@khaugsbakk.name>\n\nlog-tree.c uses struct diff_options.line_termination for the commit\nrecord termination. That means that options -z and -Z give you both NUL\ncommit record delimiting as well as NUL in non-patch diff formats.\n\nThe -z behavior has to stay that way for backwards compatibility.\nBut with the new -Z option we have an opportunity to split out this\nbehavior so that -Z only means delimiting commit records and does not\naffect diffs; if you want to NUL-terminate diffs as well you can use\nboth -Z and -z.\n\nLet’s store 'delimiter' in struct rev_info and use that in\nlog-tree.c. Let’s also add -z to handle_revision_opt(...) that acts\nlike -z in diff.c for struct diffopt and also sets 'delimiter'\nappropriately.\n\nSigned-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>\n---\n Documentation/rev-list-options.adoc |  4 ++--\n log-tree.c                          | 21 ++++++++++-----------\n revision.c                          |  5 ++++-\n revision.h                          |  2 ++\n t/t4013-diff-various.sh             | 13 +++++++++++++\n 5 files changed, 31 insertions(+), 14 deletions(-)\n\ndiff --git a/Documentation/rev-list-options.adoc b/Documentation/rev-list-options.adoc\nindex a4bf96e7d0a..4ba410c5e06 100644\n--- a/Documentation/rev-list-options.adoc\n+++ b/Documentation/rev-list-options.adoc\n@@ -405,8 +405,8 @@ Note that separator/terminator behavior is usually set when using\n `--pretty` or `--format`. These have no effect when this option is\n given.\n +\n-This implies `-z`, so diff output formats like `--raw` and `--numstat`\n-will also contain _NUL_ internally.\n+This does not imply `-z`, but `-z` can be passed as well in order to use\n+_NUL_ internally for diff formats like `--raw` and `--numstat`.\n \n History Simplification\n ~~~~~~~~~~~~~~~~~~~~~~\ndiff --git a/log-tree.c b/log-tree.c\nindex 5dcee870be0..e9ea5620e9b 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -764,8 +764,7 @@ void show_log(struct rev_info *opt)\n \t\t\tputc('\\n', opt->diffopt.file);\n \t\t\tgraph_show_remainder(opt->graph);\n \t\t}\n-\t\tif (opt->use_terminator &&\n-\t\t    opt->diffopt.line_termination == '\\0') {\n+\t\tif (opt->use_terminator && opt->delimiter == '\\0') {\n \t\t\t/*\n \t\t\t * NUL termination means that we postpone the terminator.\n \t\t\t * But we do want a newline between the commit ID and\n@@ -774,7 +773,7 @@ void show_log(struct rev_info *opt)\n \t\t\tif (opt->diffopt.output_format & ~DIFF_FORMAT_NO_OUTPUT)\n \t\t\t\tputc('\\n', opt->diffopt.file);\n \t\t} else {\n-\t\t\tputc(opt->diffopt.line_termination, opt->diffopt.file);\n+\t\t\tputc(opt->delimiter, opt->diffopt.file);\n \t\t}\n \t\treturn;\n \t}\n@@ -782,8 +781,8 @@ void show_log(struct rev_info *opt)\n \t/*\n \t * If use_terminator is set, we already handled any record termination\n \t * at the end of the last record.\n-\t * Otherwise, add a diffopt.line_termination character before all\n-\t * entries but the first.  (IOW, as a separator between entries)\n+\t * Otherwise, add a ''delimiter' character before all entries\n+\t * but the first.  (IOW, as a separator between entries)\n \t */\n \tif (opt->shown_one && !opt->use_terminator) {\n \t\t/*\n@@ -798,10 +797,10 @@ void show_log(struct rev_info *opt)\n \t\t * never want the extra graph output before the entry\n \t\t * separator.\n \t\t */\n-\t\tif (opt->diffopt.line_termination == '\\n' &&\n+\t\tif (opt->delimiter == '\\n' &&\n \t\t    !opt->missing_newline)\n \t\t\tgraph_show_padding(opt->graph);\n-\t\tputc(opt->diffopt.line_termination, opt->diffopt.file);\n+\t\tputc(opt->delimiter, opt->diffopt.file);\n \t}\n \topt->shown_one = 1;\n \n@@ -931,8 +930,8 @@ void show_log(struct rev_info *opt)\n \t\t * Termination is postponed for NUL in case there is\n \t\t * diff output after the log message.\n \t\t */\n-\t\tif (opt->diffopt.line_termination != '\\0')\n-\t\t\tputc(opt->diffopt.line_termination, opt->diffopt.file);\n+\t\tif (opt->delimiter != '\\0')\n+\t\t\tputc(opt->delimiter, opt->diffopt.file);\n \t}\n \n \tstrbuf_release(&msgbuf);\n@@ -991,8 +990,8 @@ int log_tree_diff_flush(struct rev_info *opt)\n \n void log_tree_nul_terminate(struct rev_info *opt) {\n \tif (opt->use_terminator &&\n-\t    opt->diffopt.line_termination == '\\0')\n-\t\tputc(opt->diffopt.line_termination, opt->diffopt.file);\n+\t    opt->delimiter == '\\0')\n+\t\tputc(opt->delimiter, opt->diffopt.file);\n }\n \n static int do_diff_combined(struct rev_info *opt, struct commit *commit)\ndiff --git a/revision.c b/revision.c\nindex 1d2a10267ca..e9c10c354e0 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -2755,10 +2755,13 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg\n \t\tif (revs->repo->fetch_if_missing)\n \t\t\tBUG(\"exclude_promisor_objects can only be used when fetch_if_missing is 0\");\n \t\trevs->exclude_promisor_objects = 1;\n+\t} else if (!strcmp(arg, \"-z\")) {\n+\t\trevs->delimiter = '\\0';\n+\t\trevs->diffopt.line_termination = '\\0';\n \t} else if (!strcmp(arg, \"-Z\")) {\n \t\trevs->want_terminator = 1;\n \t\trevs->use_terminator = 1;\n-\t\trevs->diffopt.line_termination = '\\0';\n+\t\trevs->delimiter = '\\0';\n \t} else {\n \t\tint opts = diff_opt_parse(&revs->diffopt, argv, argc, revs->prefix);\n \t\tif (!opts)\ndiff --git a/revision.h b/revision.h\nindex c6598ba6f22..337ba08e553 100644\n--- a/revision.h\n+++ b/revision.h\n@@ -284,6 +284,7 @@ struct rev_info {\n \t\t\tforce_in_body_from:1,\n \t\t\tencode_email_headers:1,\n \t\t\tinclude_header:1;\n+\tchar\t\tdelimiter;\n \tunsigned int\tdisable_stdin:1;\n \t/* --show-linear-break */\n \tunsigned int\ttrack_linear:1,\n@@ -444,6 +445,7 @@ struct rev_info {\n \t.max_parents = -1, \\\n \t.expand_tabs_in_log = -1, \\\n \t.commit_format = CMIT_FMT_DEFAULT, \\\n+\t.delimiter = '\\n', \\\n \t.expand_tabs_in_log_default = 8, \\\n \t.rdiff_log_arg = STRVEC_INIT, \\\n \t.argv_to_free = STRVEC_INIT, \\\ndiff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh\nindex 207bd2df423..b6974b9b64d 100755\n--- a/t/t4013-diff-various.sh\n+++ b/t/t4013-diff-various.sh\n@@ -649,6 +649,19 @@ test_expect_success 'diff-tree --stdin --patch -Z --always with one empty diff'\n \ttest_cmp_bin expect actual\n '\n \n+test_expect_success 'diff-tree --stdin -Z' '\n+\tcat oid1 >expect &&\n+\techo >>expect &&\n+\tgit diff-tree main~2 main~1 >>expect &&\n+\tprintf \"\\0\" >>expect &&\n+\tcat oid2 >>expect &&\n+\techo >>expect &&\n+\tgit diff-tree main~3 main~2 >>expect &&\n+\tprintf \"\\0\" >>expect &&\n+\tgit diff-tree --stdin -Z <commits >actual &&\n+\ttest_cmp_bin expect actual\n+'\n+\n test_expect_success 'show A B ... -- <pathspec>' '\n \t# side touches dir/sub, file0, and file3\n \t# main^ touches dir/sub, and file1\n-- \n2.56.1.5.g155936fbb2a\n\n\n"},{"id":"559936","messageId":"flush_diff_--stdin.df8@m5gid.xyz","threadId":"66978","inReplyTo":"CV_diff-tree_NUL_termination.def@m5gid.xyz","subject":"[PATCH 09/12] diff-tree: flush each diff when --stdin","fromName":"","fromEmail":"kristofferhaugsbakk@fastmail.com","sentAt":"2026-12-02T22:14:17Z","receivedAt":"2026-12-02T22:14:17Z","isPatch":true,"sender":{"key":"kristofferhaugsbakk@fastmail.com","avatar":null},"body":"From: Kristoffer Haugsbakk <code@khaugsbakk.name>\n\n'git diff-tree --stdin' handles both commits and diffs. The commit case\nis handled by log-tree.c:log_tree_commit. That method calls\nmaybe_flush_or_die(...). That means that with e.g.:\n\n    git diff-tree --stdin --patch -Z\n\nWe can feed a commit to the commit and read it back in a loop without\nriskig deadlocks.\n\nThe diff case, on the other hand, calls log-tree.c:\nlog_tree_diff_flush(...). That function does not call the\nIO flush function.[1]\n\nLet’s call the IO flush function so that we are guaranteed to read back\na diff after each input immediately, just like with commits.\n\n† 1: The “flush” in the name is because it calls diff.c:diff_flush\n\nSigned-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>\n---\n builtin/diff-tree.c | 3 +++\n 1 file changed, 3 insertions(+)\n\ndiff --git a/builtin/diff-tree.c b/builtin/diff-tree.c\nindex c7734f7be63..d516c496521 100644\n--- a/builtin/diff-tree.c\n+++ b/builtin/diff-tree.c\n@@ -11,6 +11,7 @@\n #include \"revision.h\"\n #include \"tmp-objdir.h\"\n #include \"tree.h\"\n+#include \"write-or-die.h\"\n \n static struct rev_info log_tree_opt;\n \n@@ -60,6 +61,8 @@ static int stdin_diff_trees(struct tree *tree1, const char *p)\n \t\t      \"\", &log_tree_opt.diffopt);\n \tlog_tree_diff_flush(&log_tree_opt);\n \tlog_tree_nul_terminate(&log_tree_opt);\n+\tmaybe_flush_or_die(log_tree_opt.diffopt.file, \"stdout\");\n+\n \treturn 0;\n }\n \n-- \n2.56.1.5.g155936fbb2a\n\n\n"},{"id":"559937","messageId":"--no-commit-id.df9@m5gid.xyz","threadId":"66978","inReplyTo":"CV_diff-tree_NUL_termination.def@m5gid.xyz","subject":"[PATCH 10/12] doc: diff-tree: tell about --no-commit-id in Description","fromName":"","fromEmail":"kristofferhaugsbakk@fastmail.com","sentAt":"2026-12-02T22:14:18Z","receivedAt":"2026-12-02T22:14:18Z","isPatch":true,"sender":{"key":"kristofferhaugsbakk@fastmail.com","avatar":null},"body":"From: Kristoffer Haugsbakk <code@khaugsbakk.name>\n\nThis doc has many options. 'git help --man diff-tree' tells us that\nit is 1346 lines long. In turn the dedicated options are not skimmable.\nThis options is important if you for example just want regular diff\noutput. So let’s mention it in the Description section as well.\n\nSigned-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>\n---\n Documentation/git-diff-tree.adoc | 3 +++\n 1 file changed, 3 insertions(+)\n\ndiff --git a/Documentation/git-diff-tree.adoc b/Documentation/git-diff-tree.adoc\nindex f1e3134bdef..084be99e7cf 100644\n--- a/Documentation/git-diff-tree.adoc\n+++ b/Documentation/git-diff-tree.adoc\n@@ -20,6 +20,9 @@ Compare the content and mode of blobs found via two tree objects.\n If there is only one <tree-ish> given, the commit is compared with its parents\n (see --stdin below).\n \n+This command outputs a line with the commit ID when applicable. Use\n+`--no-commit-id` to suppress this behavior.\n+\n Note that 'git diff-tree' can use the tree encapsulated in a commit object.\n \n OPTIONS\n-- \n2.56.1.5.g155936fbb2a\n\n\n"},{"id":"559938","messageId":"Examples_--stdin.dfa@m5gid.xyz","threadId":"66978","inReplyTo":"CV_diff-tree_NUL_termination.def@m5gid.xyz","subject":"[PATCH 11/12] doc: diff-tree: add Examples section and mention --stdin","fromName":"","fromEmail":"kristofferhaugsbakk@fastmail.com","sentAt":"2026-12-02T22:14:19Z","receivedAt":"2026-12-02T22:14:19Z","isPatch":true,"sender":{"key":"kristofferhaugsbakk@fastmail.com","avatar":null},"body":"From: Kristoffer Haugsbakk <code@khaugsbakk.name>\n\nWe added option -Z a few commits ago.[1] This option can be used by\nany command that uses revision.c:handle_revision_opt(...), but I had in\nmind git-diff-tree(1) in particular. That is because 'git diff-tree\n--stdin' outputs each record (commit or diff or both) immediately after\nit is processed. That is unlike git-rev-list(1)/git-show(1)/git-log(1)\nwhich wait until stdin is closed to and then outputs everything.\n\n† 1: commit “revision: learn -Z (NUL termination)”\n\nAnd this behavior is useful for feeding commit IDs, getting back some\noutput, acting on it, and then feeding the next commit ID. This is\nfacilitated by using -z so that you know a record is done after you\nread it. However, this does not work well for the default separator\ncase; the delimiter is added *between* records, an in turn you have to\ngive the Nth commit in order to get the NUL delimiter for the N-1\ncommit. Also, the last commit is not terminated.\n\nHowever, with the new -Z option you can pretty-print\ncommits on demand just like 'git format-rev --stdin-mode=revs':\n\n    git cat-file --batch-command='%(objectname)' |\n    git diff-tree --no-patch --format=<fmt> --always -Z --stdin\n\nAnd you also get log-tree.c formatted output (e.g. 'Notes:' in\n--format=medium) just like commands like git-log(1). And you can do\nthe same for diffs, or combine commits and diffs with --format=<fmt>\n--patch.\n\nSigned-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>\n---\n Documentation/git-diff-tree.adoc | 40 ++++++++++++++++++++++++++++++++\n 1 file changed, 40 insertions(+)\n\ndiff --git a/Documentation/git-diff-tree.adoc b/Documentation/git-diff-tree.adoc\nindex 084be99e7cf..b73cf4d268d 100644\n--- a/Documentation/git-diff-tree.adoc\n+++ b/Documentation/git-diff-tree.adoc\n@@ -25,6 +25,8 @@ This command outputs a line with the commit ID when applicable. Use\n \n Note that 'git diff-tree' can use the tree encapsulated in a commit object.\n \n+See the \"EXAMPLES\" section at the end for a few examples.\n+\n OPTIONS\n -------\n include::diff-options.adoc[]\n@@ -129,6 +131,44 @@ include::pretty-formats.adoc[]\n \n include::diff-format.adoc[]\n \n+EXAMPLES\n+--------\n+\n+The default behavior is to show the commit ID and then the raw diff (see\n+`--raw`):\n+\n+----\n+$ git diff-tree HEAD\n+00645eb9f4e515533cdf67376d481ffb4a796bcc\n+:040000 040000 ac1844364599b5671e9e4da68eab0817cab2ac2d b39de8e87a84787fb7bc2b38e015540e6d336eae M\tDocumentation\n+----\n+\n+But you can use this command to show normal diffs (`--patch`) and commit\n+messages as well. You can for example get the same output as `git log`\n+with:\n+\n+----\n+$ git rev-list HEAD |\n+git diff-tree --no-patch --stdin --always --format=medium\n+----\n+\n+The above is of course longer to type and uses two processes instead\n+of two. But this longer form with `--stdin` is more flexible than `git\n+log --stdin`. That is because the linkgit:git-log[1] form only outputs\n+anything after you close standard in (stdin). Meanwhile, `git diff-tree\n+--stdin ...` outputs each commit or diff (or both) immediately. This\n+means that you can use `-Z` to feed the commit, handle the output, and\n+then continue with the next commit. The above can be tweaked to for\n+example show the diff as well with `--patch`.\n+\n+----\n+$ git diff-tree --no-patch --stdin --always --format=<fmt> -Z\n+     [rev-list options]\n+----\n+\n+The command `git diff-tree --stdin --patch` can be used together with\n+linkgit:git-patch-id[1] to create a map from commit IDs to pach IDs.\n+\n GIT\n ---\n Part of the linkgit:git[1] suite\n-- \n2.56.1.5.g155936fbb2a\n\n\n"},{"id":"559939","messageId":"diff-tree_ex._--always.dfb@m5gid.xyz","threadId":"66978","inReplyTo":"CV_diff-tree_NUL_termination.def@m5gid.xyz","subject":"[PATCH 12/12] doc: rev-list: complete diff-tree by mentioning --always","fromName":"","fromEmail":"kristofferhaugsbakk@fastmail.com","sentAt":"2026-12-02T22:14:20Z","receivedAt":"2026-12-02T22:14:20Z","isPatch":true,"sender":{"key":"kristofferhaugsbakk@fastmail.com","avatar":null},"body":"From: Kristoffer Haugsbakk <code@khaugsbakk.name>\n\nThis example implies that it acts a lot like some git-log(1)\ninvocation. The immediate thought is 'git log --patch', but that would\nbe wrong; the git-diff-tree(1) command does not output commits which do\nnot have a diff, like a merge commit. The example doesn’t say that, but\nit is useful for the reader to know that they need to make this\nadjustment if they want git-log(1) output. So let’s mention it after the\ncode example.\n\nOf course, this is not complete; you would need to pass '--notes' or\n'--show-notes-by-default' to git-diff-tree(1) in order to mimic the\ngit-log(1) notes behavior. And maybe other things. But those are small\ndetails compared to not getting a commit at all.\n\nSigned-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>\n---\n Documentation/git-rev-list.adoc | 3 +++\n 1 file changed, 3 insertions(+)\n\ndiff --git a/Documentation/git-rev-list.adoc b/Documentation/git-rev-list.adoc\nindex f582491dd43..0dd6269d662 100644\n--- a/Documentation/git-rev-list.adoc\n+++ b/Documentation/git-rev-list.adoc\n@@ -61,6 +61,9 @@ git rev-list --format=medium HEAD\n git rev-list HEAD |\n git diff-tree --stdin --format=medium -p\n ----------\n++\n+This will not print commits without diffs, like merge commits. Use\n+`--always` to also print those commits.\n \n * Print the list of commits on the current branch that touched any\n   file in the `Documentation` directory.\n-- \n2.56.1.5.g155936fbb2a\n\n\n"}]}