diff: move the fallback "--exit-code" code down

When "--exit-code" is asked and the code cannot just answer by comparing the object names on both sides but needs to inspect and compare the contents, there are two ways that the result is found out. Some output modes, like "--stat" and "--patch", inherently have to inspect the contents in order to show the differences in the way they do. The codepaths for these modes set the .found_changes bit as they compute what to show. However, other output modes do not need to inspect the contents to show the differences in the way they do. The most notable example is "--quiet", which does not need to compute any output to show. When they are asked to report "--exit-code", they run the codepaths for the "--patch" output with their output redirected to "/dev/null", only to set the .found_changes bit. Currently, this fallback invocation of "--patch" output is done after the "--stat" output format and its friends and before the "--patch" and internal callback logic. Move it to the end of the sequence to clarify the fallback status of this code block. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Aug 18, 2023 at 16:59 UTC 5f107caed755dae950382fdafc76a33b31528caa
1 file changed +15 -15
diff.c
+15 -15
@@ -6551,6 +6551,21 @@ void diff_flush(struct diff_options *options)
6551 separator++;
6552 }
6553
6554 + if (output_format & DIFF_FORMAT_PATCH) {
6555 + if (separator) {
6556 + emit_diff_symbol(options, DIFF_SYMBOL_SEPARATOR, NULL, 0, 0);
6557 + if (options->stat_sep)
6558 + /* attach patch instead of inline */
6559 + emit_diff_symbol(options, DIFF_SYMBOL_STAT_SEP,
6560 + NULL, 0, 0);
6561 + }
6562 +
6563 + diff_flush_patch_all_file_pairs(options);
6564 + }
6565 +
6566 + if (output_format & DIFF_FORMAT_CALLBACK)
6567 + options->format_callback(q, options, options->format_callback_data);
6568 +
6569 if (output_format & DIFF_FORMAT_NO_OUTPUT &&
6570 options->flags.exit_with_status &&
6571 options->flags.diff_from_contents) {
@@ -6572,21 +6587,6 @@ void diff_flush(struct diff_options *options)
6587 }
6588 }
6589
6575 - if (output_format & DIFF_FORMAT_PATCH) {
6576 - if (separator) {
6577 - emit_diff_symbol(options, DIFF_SYMBOL_SEPARATOR, NULL, 0, 0);
6578 - if (options->stat_sep)
6579 - /* attach patch instead of inline */
6580 - emit_diff_symbol(options, DIFF_SYMBOL_STAT_SEP,
6581 - NULL, 0, 0);
6582 - }
6583 -
6584 - diff_flush_patch_all_file_pairs(options);
6585 - }
6586 -
6587 - if (output_format & DIFF_FORMAT_CALLBACK)
6588 - options->format_callback(q, options, options->format_callback_data);
6589 -
6590 for (i = 0; i < q->nr; i++)
6591 diff_free_filepair(q->queue[i]);
6592 free_queue: