From: Jeff King <peff@peff•net>
To: git@vger•kernel.org
Cc: Lidong Yan <yldhome2d2@gmail•com>, Junio C Hamano <gitster@pobox•com>
Subject: [PATCH 4/4] diff: drop dry-run redirection to /dev/null
Date: Fri, 24 Oct 2025 13:09:25 -0400 [thread overview]
Message-ID: <20251024170925.GD2345184@coredump.intra.peff.net> (raw)
In-Reply-To: <20251024170522.GA2344972@coredump.intra.peff.net>
As an added protection against dry-run diffs accidentally producing
output, we redirect diff_options.file to /dev/null. But as of the
previous patch, this now does nothing, since dry-run diffs are
implemented by setting "file" to NULL.
So we can drop this extra code with no change in behavior. This is
effectively a revert of 623f7af284 (diff: restore redirection to
/dev/null for diff_from_contents, 2025-10-17) and 3da4413dbc (diff: make
sure the other caller of diff_flush_patch_quietly() is silent,
2025-10-22), but:
1. We get a conflict because we already dropped the color_moved
handling in an earlier patch. But we just resolve the conflicts to
"theirs" (removing all of the code).
2. We retain the test from 623f7af284.
Signed-off-by: Jeff King <peff@peff•net>
---
diff.c | 31 +++----------------------------
1 file changed, 3 insertions(+), 28 deletions(-)
diff --git a/diff.c b/diff.c
index a8d50fb1fc..9169ccfaa9 100644
--- a/diff.c
+++ b/diff.c
@@ -6835,35 +6835,18 @@ void diff_flush(struct diff_options *options)
DIFF_FORMAT_NAME |
DIFF_FORMAT_NAME_STATUS |
DIFF_FORMAT_CHECKDIFF)) {
- /*
- * make sure diff_Flush_patch_quietly() to be silent.
- */
- FILE *dev_null = NULL;
-
- if (options->flags.diff_from_contents) {
- dev_null = xfopen("/dev/null", "w");
- }
for (i = 0; i < q->nr; i++) {
struct diff_filepair *p = q->queue[i];
if (!check_pair_status(p))
continue;
- if (options->flags.diff_from_contents) {
- FILE *saved_file = options->file;
- int found_changes;
+ if (options->flags.diff_from_contents &&
+ !diff_flush_patch_quietly(p, options))
+ continue;
- options->file = dev_null;
- found_changes = diff_flush_patch_quietly(p, options);
- options->file = saved_file;
- if (!found_changes)
- continue;
- }
flush_one_pair(p, options);
}
- if (options->flags.diff_from_contents) {
- fclose(dev_null);
- }
separator++;
}
@@ -6914,14 +6897,6 @@ void diff_flush(struct diff_options *options)
if (output_format & DIFF_FORMAT_NO_OUTPUT &&
options->flags.exit_with_status &&
options->flags.diff_from_contents) {
- /*
- * run diff_flush_patch for the exit status. setting
- * options->file to /dev/null should be safe, because we
- * aren't supposed to produce any output anyway.
- */
- diff_free_file(options);
- options->file = xfopen("/dev/null", "w");
- options->close_file = 1;
for (i = 0; i < q->nr; i++) {
struct diff_filepair *p = q->queue[i];
if (check_pair_status(p))
--
2.51.1.797.g1148beab57
next prev parent reply other threads:[~2025-10-24 17:09 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-24 17:05 [PATCH 0/4] diff dry-run cleanups Jeff King
2025-10-24 17:06 ` [PATCH 1/4] diff: send external diff output to diff_options.file Jeff King
2025-10-24 17:07 ` [PATCH 2/4] diff: drop save/restore of color_moved in dry-run mode Jeff King
2025-10-24 17:08 ` [PATCH 3/4] diff: replace diff_options.dry_run flag with NULL file Jeff King
2025-10-24 17:22 ` Junio C Hamano
2025-10-24 17:09 ` Jeff King [this message]
2025-10-24 17:25 ` [PATCH 5/4] diff: simplify run_external_diff() quiet logic Jeff King
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=20251024170925.GD2345184@coredump.intra.peff.net \
--to=peff@peff$(echo .)net \
--cc=git@vger$(echo .)kernel.org \
--cc=gitster@pobox$(echo .)com \
--cc=yldhome2d2@gmail$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox