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 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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Oct 24, 2025 at 13:09 UTC 1ad2760020bf426edd01ccec467da14c0f92cf2e
1 file changed +3 -28
diff.c
+3 -28
@@ -6835,35 +6835,18 @@ void diff_flush(struct diff_options *options)
6835 DIFF_FORMAT_NAME |
6836 DIFF_FORMAT_NAME_STATUS |
6837 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 - }
6838 for (i = 0; i < q->nr; i++) {
6839 struct diff_filepair *p = q->queue[i];
6840
6841 if (!check_pair_status(p))
6842 continue;
6843
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;
6847
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 - }
6848 flush_one_pair(p, options);
6849 }
6864 - if (options->flags.diff_from_contents) {
6865 - fclose(dev_null);
6866 - }
6850 separator++;
6851 }
6852
@@ -6914,14 +6897,6 @@ void diff_flush(struct diff_options *options)
6897 if (output_format & DIFF_FORMAT_NO_OUTPUT &&
6898 options->flags.exit_with_status &&
6899 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;
6900 for (i = 0; i < q->nr; i++) {
6901 struct diff_filepair *p = q->queue[i];
6902 if (check_pair_status(p))