aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2025-10-26 19:48:18 -0700
committerJunio C Hamano <gitster@pobox.com>2025-10-26 19:48:18 -0700
commit306eb9ae56571c256ecaec8198c08aa116782531 (patch)
treee9c7b0eee487258dfa308e69e70f7aeb4deced8f
parentMerge branch 'jk/diff-from-contents-fix' into maint-2.51 (diff)
parentdiff: make sure the other caller of diff_flush_patch_quietly() is silent (diff)
downloadgit-306eb9ae56571c256ecaec8198c08aa116782531.tar.gz
git-306eb9ae56571c256ecaec8198c08aa116782531.zip
Merge branch 'jc/diff-from-contents-fix' into maint-2.51
The code to squelch output from "git diff -w --name-status" etc. for paths that "git diff -w -p" would have stayed silent leaked output from dry-run patch generation, which has been corrected. * jc/diff-from-contents-fix: diff: make sure the other caller of diff_flush_patch_quietly() is silent
-rw-r--r--diff.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/diff.c b/diff.c
index 9b8d658b9e..7b5601de2f 100644
--- 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++;
}