From 5cc6b2d70bc55ab75913ee93d9ac96ad875fbb29 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Mon, 21 Aug 2023 16:20:46 -0400 Subject: diff: drop useless "status" parameter from diff_result_code() Many programs use diff_result_code() to get a user-visible program exit code from a diff result (e.g., checking opts.found_changes if --exit-code was requested). This function also takes a "status" parameter, which seems at first glance that it could be used to propagate an error encountered when computing the diff. But it doesn't work that way: - negative values are passed through as-is, but are not appropriate as program exit codes - when --exit-code or --check is in effect, we _ignore_ the passed-in status completely. So a failed diff which did not have a chance to set opts.found_changes would erroneously report "success, no changes" instead of propagating the error. After recent cleanups, neither of these bugs is possible to trigger, as every caller just passes in "0". So rather than fixing them, we can simply drop the useless parameter instead. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- diff.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'diff.c') diff --git a/diff.c b/diff.c index ee3eb629e3..2de5d3d098 100644 --- a/diff.c +++ b/diff.c @@ -6973,16 +6973,14 @@ void diffcore_std(struct diff_options *options) options->found_follow = 0; } -int diff_result_code(struct diff_options *opt, int status) +int diff_result_code(struct diff_options *opt) { int result = 0; diff_warn_rename_limit("diff.renameLimit", opt->needed_rename_limit, opt->degraded_cc_to_c); - if (!opt->flags.exit_with_status && - !(opt->output_format & DIFF_FORMAT_CHECKDIFF)) - return status; + if (opt->flags.exit_with_status && opt->flags.has_changes) result |= 01; -- cgit v1.2.3