Re: [PATCH v5] diff: ensure consistent diff behavior with ignore options
From: Johannes Schindelin <hidden>
Date: 2025-10-16 14:55:32
Hi, On Fri, 8 Aug 2025, Lidong Yan wrote:
quoted hunk ↗ jump to hunk
@@ -6778,8 +6816,15 @@ void diff_flush(struct diff_options *options) DIFF_FORMAT_CHECKDIFF)) { for (i = 0; i < q->nr; i++) { struct diff_filepair *p = q->queue[i]; - if (check_pair_status(p)) - flush_one_pair(p, options); + + if (!check_pair_status(p)) + continue; + + if (options->flags.diff_from_contents && + !diff_flush_patch_quietly(p, options)) + continue; + + flush_one_pair(p, options); } separator++; }
I'll play Ἑρμῆς here and relay the bug report from https://github.com/git/git/commit/77f8e1002be5c736e064ed0e656ba51c82d85b5d#r168025843: fcharlie wrote: This code will cause git diff --patch --raw to produce garbled output under certain conditions (e.g., using --ignore-space-change and whitespace changes). flush_one_pair will output --raw format, but because diff_flush_patch_quietly has already output a patch, garbled output will be produced (actually, no diff_flush_patch_quietly should be called here). [...] A few exchanges later, brandb97 (AKA Lidong Yan) suggested this patch: diff --git a/diff.c b/diff.c index 87fa16b730..4baf9b535e 100644 --- a/diff.c +++ b/diff.c @@ -1351,6 +1351,9 @@ static void emit_diff_symbol_from_struct(struct diff_options *o, int len = eds->len; unsigned flags = eds->flags; + if (o->dry_run) + return; + switch (s) { case DIFF_SYMBOL_NO_LF_EOF: context = diff_get_color_opt(o, DIFF_CONTEXT); @@ -4420,7 +4423,7 @@ static void run_external_diff(const struct external_diff *pgm, { struct child_process cmd = CHILD_PROCESS_INIT; struct diff_queue_struct *q = &diff_queued_diff; - int quiet = !(o->output_format & DIFF_FORMAT_PATCH); + int quiet = !(o->output_format & DIFF_FORMAT_PATCH) || o->dry_run; int rc; /* fcharlie then responded by promising to test that patch tomorrow. I will hold off from releasing Git for Windows v2.51.1 to await the result of this test. Ciao, Johannes