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

[PATCH 5/4] diff: simplify run_external_diff() quiet logic

From
Jeff King <peff@peff.net>
Date
Oct 24, 2025, 17:25 UTC
Message-ID
<20251024172507.GA3081793@coredump.intra.peff.net>
In-Reply-To
<20251024170522.GA2344972@coredump.intra.peff.net>

We'd sometimes end up in run_external_diff() to do a dry-run diff (e.g., to find content-level changes for --quiet). We recognize this quiet mode by seeing the lack of DIFF_FORMAT_PATCH in the output format.

But since introducing an explicit dry-run check via 3ed5d8bd73 (diff: stop output garbled message in dry run mode, 2025-10-20), this logic can never trigger. We can only get to this function by calling diff_flush_patch(), and that comes from only two places:

  1. A dry-run flush comes from diff_flush_patch_quietly(), which is
     always in dry-run mode (so the other half of our "||" is true
     anyway).
  2. A regular flush comes from diff_flush_patch_all_file_pairs(),
     which is only called when output_format has DIFF_FORMAT_PATCH in
     it.

So we can simplify our "quiet" condition to just checking dry-run mode (which used to be a specific flag, but recently became just a NULL "file" pointer). And since it's so simple, we can just do that inline. This makes the logic about o->file more obvious, since we handle the NULL and non-stdout cases next to each other.

Signed-off-by: Jeff King <peff@peff.net>
---
Here's one more that I forgot to poke at before sending out the others.
 diff.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/diff.c b/diff.c
index 9169ccfaa9..a1961526c0 100644
--- a/diff.c
+++ b/diff.c
@@ -4423,7 +4423,6 @@ static void run_external_diff(const struct external_diff *pgm,
 {
 	struct child_process cmd = CHILD_PROCESS_INIT;
 	struct diff_queue_struct *q = &diff_queued_diff;
-	int quiet = !(o->output_format & DIFF_FORMAT_PATCH) || !o->file;
 	int rc;
 
 	/*
@@ -4432,7 +4431,7 @@ static void run_external_diff(const struct external_diff *pgm,
 	 * external diff program lacks the ability to tell us whether
 	 * it's empty then we consider it non-empty without even asking.
 	 */
-	if (!pgm->trust_exit_code && quiet) {
+	if (!pgm->trust_exit_code && !o->file) {
 		o->found_changes = 1;
 		return;
 	}
@@ -4457,7 +4456,7 @@ static void run_external_diff(const struct external_diff *pgm,
 	diff_free_filespec_data(one);
 	diff_free_filespec_data(two);
 	cmd.use_shell = 1;
-	if (quiet)
+	if (!o->file)
 		cmd.no_stdout = 1;
 	else if (o->file != stdout)
 		cmd.out = xdup(fileno(o->file));
-- 
2.51.1.797.g1148beab57
Previous: Jeff King
Message 7 of 7 in “diff dry-run cleanups”
  1. 0/4 diff dry-run cleanupsJeff King, Oct 24, 2025
  2. 1/4 diff: send external diff output to diff_options.fileJeff King, Oct 24, 2025
  3. 2/4 diff: drop save/restore of color_moved in dry-run modeJeff King, Oct 24, 2025
  4. 3/4 diff: replace diff_options.dry_run flag with NULL fileJeff King, Oct 24, 2025
  5. Junio C HamanoOct 24, 2025
  6. 4/4 diff: drop dry-run redirection to /dev/nullJeff King, Oct 24, 2025
  7. 5/4 diff: simplify run_external_diff() quiet logicJeff King, Oct 24, 2025

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.