Skip to content

Commit 1ad2760

Browse files
peffgitster
authored andcommitted
diff: drop dry-run redirection to /dev/null
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 623f7af (diff: restore redirection to /dev/null for diff_from_contents, 2025-10-17) and 3da4413 (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 623f7af. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent b2b5ad5 commit 1ad2760

File tree

1 file changed

+3
-28
lines changed

1 file changed

+3
-28
lines changed

diff.c

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6835,35 +6835,18 @@ void diff_flush(struct diff_options *options)
68356835
DIFF_FORMAT_NAME |
68366836
DIFF_FORMAT_NAME_STATUS |
68376837
DIFF_FORMAT_CHECKDIFF)) {
6838-
/*
6839-
* make sure diff_Flush_patch_quietly() to be silent.
6840-
*/
6841-
FILE *dev_null = NULL;
6842-
6843-
if (options->flags.diff_from_contents) {
6844-
dev_null = xfopen("/dev/null", "w");
6845-
}
68466838
for (i = 0; i < q->nr; i++) {
68476839
struct diff_filepair *p = q->queue[i];
68486840

68496841
if (!check_pair_status(p))
68506842
continue;
68516843

6852-
if (options->flags.diff_from_contents) {
6853-
FILE *saved_file = options->file;
6854-
int found_changes;
6844+
if (options->flags.diff_from_contents &&
6845+
!diff_flush_patch_quietly(p, options))
6846+
continue;
68556847

6856-
options->file = dev_null;
6857-
found_changes = diff_flush_patch_quietly(p, options);
6858-
options->file = saved_file;
6859-
if (!found_changes)
6860-
continue;
6861-
}
68626848
flush_one_pair(p, options);
68636849
}
6864-
if (options->flags.diff_from_contents) {
6865-
fclose(dev_null);
6866-
}
68676850
separator++;
68686851
}
68696852

@@ -6914,14 +6897,6 @@ void diff_flush(struct diff_options *options)
69146897
if (output_format & DIFF_FORMAT_NO_OUTPUT &&
69156898
options->flags.exit_with_status &&
69166899
options->flags.diff_from_contents) {
6917-
/*
6918-
* run diff_flush_patch for the exit status. setting
6919-
* options->file to /dev/null should be safe, because we
6920-
* aren't supposed to produce any output anyway.
6921-
*/
6922-
diff_free_file(options);
6923-
options->file = xfopen("/dev/null", "w");
6924-
options->close_file = 1;
69256900
for (i = 0; i < q->nr; i++) {
69266901
struct diff_filepair *p = q->queue[i];
69276902
if (check_pair_status(p))

0 commit comments

Comments
 (0)