Skip to content

Commit 5f107ca

Browse files
committed
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 <[email protected]>
1 parent 8397398 commit 5f107ca

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

diff.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6551,6 +6551,21 @@ void diff_flush(struct diff_options *options)
65516551
separator++;
65526552
}
65536553

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+
65546569
if (output_format & DIFF_FORMAT_NO_OUTPUT &&
65556570
options->flags.exit_with_status &&
65566571
options->flags.diff_from_contents) {
@@ -6572,21 +6587,6 @@ void diff_flush(struct diff_options *options)
65726587
}
65736588
}
65746589

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-
65906590
for (i = 0; i < q->nr; i++)
65916591
diff_free_filepair(q->queue[i]);
65926592
free_queue:

0 commit comments

Comments
 (0)