Skip to content

Commit 2ecb885

Browse files
peffgitster
authored andcommitted
diff: simplify run_external_diff() quiet logic
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 3ed5d8b (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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 1ad2760 commit 2ecb885

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

diff.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4423,7 +4423,6 @@ static void run_external_diff(const struct external_diff *pgm,
44234423
{
44244424
struct child_process cmd = CHILD_PROCESS_INIT;
44254425
struct diff_queue_struct *q = &diff_queued_diff;
4426-
int quiet = !(o->output_format & DIFF_FORMAT_PATCH) || !o->file;
44274426
int rc;
44284427

44294428
/*
@@ -4432,7 +4431,7 @@ static void run_external_diff(const struct external_diff *pgm,
44324431
* external diff program lacks the ability to tell us whether
44334432
* it's empty then we consider it non-empty without even asking.
44344433
*/
4435-
if (!pgm->trust_exit_code && quiet) {
4434+
if (!pgm->trust_exit_code && !o->file) {
44364435
o->found_changes = 1;
44374436
return;
44384437
}
@@ -4457,7 +4456,7 @@ static void run_external_diff(const struct external_diff *pgm,
44574456
diff_free_filespec_data(one);
44584457
diff_free_filespec_data(two);
44594458
cmd.use_shell = 1;
4460-
if (quiet)
4459+
if (!o->file)
44614460
cmd.no_stdout = 1;
44624461
else if (o->file != stdout)
44634462
cmd.out = xdup(fileno(o->file));

0 commit comments

Comments
 (0)