diff: make sure the other caller of diff_flush_patch_quietly() is silent

Earlier, we added is a protection for the loop that computes "git diff --quiet -w" to ensure calls to the diff_flush_patch_quietly() helper stays quiet. Do the same for another loop that deals with options like "--name-status" to make calls to the same helper. Helped-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Oct 22, 2025 at 10:39 UTC 3da4413dbcdb8df021739ca6f20fe4f0bcd1fd3c
1 file changed +23 -3
diff.c
+23 -3
@@ -6814,18 +6814,38 @@ void diff_flush(struct diff_options *options)
6814 DIFF_FORMAT_NAME |
6815 DIFF_FORMAT_NAME_STATUS |
6816 DIFF_FORMAT_CHECKDIFF)) {
6817 + /*
6818 + * make sure diff_Flush_patch_quietly() to be silent.
6819 + */
6820 + FILE *dev_null = NULL;
6821 + int saved_color_moved = options->color_moved;
6822 +
6823 + if (options->flags.diff_from_contents) {
6824 + dev_null = xfopen("/dev/null", "w");
6825 + options->color_moved = 0;
6826 + }
6827 for (i = 0; i < q->nr; i++) {
6828 struct diff_filepair *p = q->queue[i];
6829
6830 if (!check_pair_status(p))
6831 continue;
6832
6823 - if (options->flags.diff_from_contents &&
6824 - !diff_flush_patch_quietly(p, options))
6825 - continue;
6833 + if (options->flags.diff_from_contents) {
6834 + FILE *saved_file = options->file;
6835 + int found_changes;
6836
6837 + options->file = dev_null;
6838 + found_changes = diff_flush_patch_quietly(p, options);
6839 + options->file = saved_file;
6840 + if (!found_changes)
6841 + continue;
6842 + }
6843 flush_one_pair(p, options);
6844 }
6845 + if (options->flags.diff_from_contents) {
6846 + fclose(dev_null);
6847 + options->color_moved = saved_color_moved;
6848 + }
6849 separator++;
6850 }
6851