]> git.ipfire.org Git - thirdparty/git.git/commitdiff
diff: drop useless "status" parameter from diff_result_code()
authorJeff King <peff@peff.net>
Mon, 21 Aug 2023 20:20:46 +0000 (16:20 -0400)
committerJunio C Hamano <gitster@pobox.com>
Mon, 21 Aug 2023 22:33:24 +0000 (15:33 -0700)
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 <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 files changed:
builtin/describe.c
builtin/diff-files.c
builtin/diff-index.c
builtin/diff-tree.c
builtin/diff.c
builtin/log.c
builtin/stash.c
builtin/submodule--helper.c
diff-no-index.c
diff.c
diff.h
wt-status.c

index 8cdc25b7485f3eee6dc0498475639192447fc3b1..a9e375882bf2545736b2d38e65bc744c7d7b3497 100644 (file)
@@ -687,7 +687,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
                                BUG("malformed internal diff-index command line");
                        run_diff_index(&revs, 0);
 
-                       if (!diff_result_code(&revs.diffopt, 0))
+                       if (!diff_result_code(&revs.diffopt))
                                suffix = NULL;
                        else
                                suffix = dirty;
index 04070607b15dd0dbae9fd1d51482645b59527dfb..f38912cd407bf4e5098d84a928affd849f4123d8 100644 (file)
@@ -83,7 +83,7 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix)
        if (repo_read_index_preload(the_repository, &rev.diffopt.pathspec, 0) < 0)
                die_errno("repo_read_index_preload");
        run_diff_files(&rev, options);
-       result = diff_result_code(&rev.diffopt, 0);
+       result = diff_result_code(&rev.diffopt);
        release_revisions(&rev);
        return result;
 }
index 2c6a17983229dda811c1e63a205983d0bd88e4c9..220f341ffa2a138f70d6aa0d343594e6e60d2ebb 100644 (file)
@@ -73,7 +73,7 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix)
                return -1;
        }
        run_diff_index(&rev, option);
-       result = diff_result_code(&rev.diffopt, 0);
+       result = diff_result_code(&rev.diffopt);
        release_revisions(&rev);
        return result;
 }
index c9ba35f143814f2b016fccfb57ab99f86bee4c85..86be6342861be40da9edbf2f1a2002fa4abc0cda 100644 (file)
@@ -232,5 +232,5 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
                diff_free(&opt->diffopt);
        }
 
-       return diff_result_code(&opt->diffopt, 0);
+       return diff_result_code(&opt->diffopt);
 }
index 3eba691b8260a0ed2ae317ad35e242d2a28daca0..0b313549c764b7dc0d001b0b793fc160b04059ac 100644 (file)
@@ -608,7 +608,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
                builtin_diff_combined(&rev, argc, argv,
                                      ent.objects, ent.nr,
                                      first_non_parent);
-       result = diff_result_code(&rev.diffopt, 0);
+       result = diff_result_code(&rev.diffopt);
        if (1 < rev.diffopt.skip_stat_unmatch)
                refresh_index_quietly();
        release_revisions(&rev);
index db3a88bfe96058679dff1059a6f4769599ee1801..5d808c92f441523f729e5edcdc3370d09f8bafdc 100644 (file)
@@ -549,7 +549,7 @@ static int cmd_log_walk_no_free(struct rev_info *rev)
            rev->diffopt.flags.check_failed) {
                return 02;
        }
-       return diff_result_code(&rev->diffopt, 0);
+       return diff_result_code(&rev->diffopt);
 }
 
 static int cmd_log_walk(struct rev_info *rev)
index e799b660f07e1305d898bba72186d85d752ff7b5..53e8868ba1cfd7eb9ee27c1505c61b883a9901d9 100644 (file)
@@ -973,7 +973,7 @@ static int show_stash(int argc, const char **argv, const char *prefix)
        }
        log_tree_diff_flush(&rev);
 
-       ret = diff_result_code(&rev.diffopt, 0);
+       ret = diff_result_code(&rev.diffopt);
 cleanup:
        strvec_clear(&stash_args);
        free_stash_info(&info);
@@ -1111,13 +1111,13 @@ static int check_changes_tracked_files(const struct pathspec *ps)
        diff_setup_done(&rev.diffopt);
 
        run_diff_index(&rev, DIFF_INDEX_CACHED);
-       if (diff_result_code(&rev.diffopt, 0)) {
+       if (diff_result_code(&rev.diffopt)) {
                ret = 1;
                goto done;
        }
 
        run_diff_files(&rev, 0);
-       if (diff_result_code(&rev.diffopt, 0)) {
+       if (diff_result_code(&rev.diffopt)) {
                ret = 1;
                goto done;
        }
index 3764ed1f9cb4886b7bbebda281aaa490a6640941..6f3bf33e615b3162c9109c1884113497ef130809 100644 (file)
@@ -670,7 +670,7 @@ static void status_submodule(const char *path, const struct object_id *ce_oid,
        setup_revisions(diff_files_args.nr, diff_files_args.v, &rev, &opt);
        run_diff_files(&rev, 0);
 
-       if (!diff_result_code(&rev.diffopt, 0)) {
+       if (!diff_result_code(&rev.diffopt)) {
                print_status(flags, ' ', path, ce_oid,
                             displaypath);
        } else if (!(flags & OPT_CACHED)) {
index 4771cf02aa8588b9e7cb162c38e109e42332cf46..8aead3e332cf13ec11de87296edc82d6013a6b93 100644 (file)
@@ -364,7 +364,7 @@ int diff_no_index(struct rev_info *revs,
         * The return code for --no-index imitates diff(1):
         * 0 = no changes, 1 = changes, else error
         */
-       ret = diff_result_code(&revs->diffopt, 0);
+       ret = diff_result_code(&revs->diffopt);
 
 out:
        for (i = 0; i < ARRAY_SIZE(to_free); i++)
diff --git a/diff.c b/diff.c
index ee3eb629e3dc5e3010342ed988678d9f0cedd0bd..2de5d3d09881369367725594bdcf9fa0c91cffd4 100644 (file)
--- 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;
diff --git a/diff.h b/diff.h
index 528f00d5e1003a8c4c1781f84d74cd41cbcac6aa..caf1528bf077cda0be89882b5ef856fe34dd3999 100644 (file)
--- a/diff.h
+++ b/diff.h
@@ -647,7 +647,7 @@ int do_diff_cache(const struct object_id *, struct diff_options *);
 int diff_flush_patch_id(struct diff_options *, struct object_id *, int);
 void flush_one_hunk(struct object_id *result, git_hash_ctx *ctx);
 
-int diff_result_code(struct diff_options *, int);
+int diff_result_code(struct diff_options *);
 
 int diff_no_index(struct rev_info *,
                  int implicit_no_index, int, const char **);
index 545cea948f2c2a61a8e09932db7b4a63447adea4..981adb09f36a963e67c73ceb5b88e5a9fa1bb8ad 100644 (file)
@@ -2581,7 +2581,7 @@ int has_unstaged_changes(struct repository *r, int ignore_submodules)
        rev_info.diffopt.flags.quick = 1;
        diff_setup_done(&rev_info.diffopt);
        run_diff_files(&rev_info, 0);
-       result = diff_result_code(&rev_info.diffopt, 0);
+       result = diff_result_code(&rev_info.diffopt);
        release_revisions(&rev_info);
        return result;
 }
@@ -2615,7 +2615,7 @@ int has_uncommitted_changes(struct repository *r,
 
        diff_setup_done(&rev_info.diffopt);
        run_diff_index(&rev_info, DIFF_INDEX_CACHED);
-       result = diff_result_code(&rev_info.diffopt, 0);
+       result = diff_result_code(&rev_info.diffopt);
        release_revisions(&rev_info);
        return result;
 }