git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 09/12] diff-tree: flush each diff when --stdin

From
Kkristofferhaugsbakk@fastmail.com <kristofferhaugsbakk@fastmail.com>
Date
Dec 2, 2026, 22:14 UTC
Message-ID
<flush_diff_--stdin.df8@m5gid.xyz>
In-Reply-To
<CV_diff-tree_NUL_termination.def@m5gid.xyz>
From: Kristoffer Haugsbakk <code@khaugsbakk.name>

'git diff-tree --stdin' handles both commits and diffs. The commit case is handled by log-tree.c:log_tree_commit. That method calls maybe_flush_or_die(...). That means that with e.g.:

    git diff-tree --stdin --patch -Z

We can feed a commit to the commit and read it back in a loop without riskig deadlocks.

The diff case, on the other hand, calls log-tree.c: log_tree_diff_flush(...). That function does not call the IO flush function.[1]

Let’s call the IO flush function so that we are guaranteed to read back a diff after each input immediately, just like with commits.

† 1: The “flush” in the name is because it calls diff.c:diff_flush
Signed-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>
---
 builtin/diff-tree.c | 3 +++
 1 file changed, 3 insertions(+)
diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c
index c7734f7be63..d516c496521 100644
--- a/builtin/diff-tree.c
+++ b/builtin/diff-tree.c
@@ -11,6 +11,7 @@
 #include "revision.h"
 #include "tmp-objdir.h"
 #include "tree.h"
+#include "write-or-die.h"
 
 static struct rev_info log_tree_opt;
 
@@ -60,6 +61,8 @@ static int stdin_diff_trees(struct tree *tree1, const char *p)
 		      "", &log_tree_opt.diffopt);
 	log_tree_diff_flush(&log_tree_opt);
 	log_tree_nul_terminate(&log_tree_opt);
+	maybe_flush_or_die(log_tree_opt.diffopt.file, "stdout");
+
 	return 0;
 }
 
-- 
2.56.1.5.g155936fbb2a
Previous: kristofferhaugsbakk@fastmail.comNext: kristofferhaugsbakk@fastmail.com
Message 10 of 13 in “revision: learn -Z for NUL termination”
  1. 00/12 revision: learn -Z for NUL terminationkristofferhaugsbakk@fastmail.com, Dec 2, 2026
  2. 01/12 t4205: use correct 'setup' keywordkristofferhaugsbakk@fastmail.com, Dec 2, 2026
  3. 02/12 t4205: add test coverage for NUL separator and --patchkristofferhaugsbakk@fastmail.com, Dec 2, 2026
  4. 03/12 t4205: test blank line between commit and diff explicitlykristofferhaugsbakk@fastmail.com, Dec 2, 2026
  5. 04/12 t4013-diff-various.sh: test --stdin -z --patchkristofferhaugsbakk@fastmail.com, Dec 2, 2026
  6. 05/12 log-tree: terminate cmt+diff when -z --patchkristofferhaugsbakk@fastmail.com, Dec 2, 2026
  7. 06/12 t4205: test --diff-mergeskristofferhaugsbakk@fastmail.com, Dec 2, 2026
  8. 07/12 revision: learn -Z for NUL terminationkristofferhaugsbakk@fastmail.com, Dec 2, 2026
  9. 08/12 revision: split out termination characterkristofferhaugsbakk@fastmail.com, Dec 2, 2026
  10. 09/12 diff-tree: flush each diff when --stdinkristofferhaugsbakk@fastmail.com, Dec 2, 2026
  11. 10/12 doc: diff-tree: tell about --no-commit-id in Descriptionkristofferhaugsbakk@fastmail.com, Dec 2, 2026
  12. 11/12 doc: diff-tree: add Examples section and mention --stdinkristofferhaugsbakk@fastmail.com, Dec 2, 2026
  13. 12/12 doc: rev-list: complete diff-tree by mentioning --alwayskristofferhaugsbakk@fastmail.com, Dec 2, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.