]> git.ipfire.org Git - thirdparty/git.git/commitdiff
diff: make sure the other caller of diff_flush_patch_quietly() is silent
authorJunio C Hamano <gitster@pobox.com>
Wed, 22 Oct 2025 17:39:12 +0000 (10:39 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 23 Oct 2025 16:05:28 +0000 (09:05 -0700)
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>
diff.c

diff --git a/diff.c b/diff.c
index 9b8d658b9ebb8e92f4e4b4c8c177529f47a22c92..7b5601de2f3c80a4e58f0f131f02584f3c36edaf 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -6814,18 +6814,38 @@ 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;
+               int saved_color_moved = options->color_moved;
+
+               if (options->flags.diff_from_contents) {
+                       dev_null = xfopen("/dev/null", "w");
+                       options->color_moved = 0;
+               }
                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 &&
-                           !diff_flush_patch_quietly(p, options))
-                               continue;
+                       if (options->flags.diff_from_contents) {
+                               FILE *saved_file = options->file;
+                               int found_changes;
 
+                               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);
+                       options->color_moved = saved_color_moved;
+               }
                separator++;
        }