Skip to content

Commit 5cc6b2d

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c0049ca commit 5cc6b2d

File tree

12 files changed

+16
-18
lines changed

12 files changed

+16
-18
lines changed

builtin/describe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
687687
BUG("malformed internal diff-index command line");
688688
run_diff_index(&revs, 0);
689689

690-
if (!diff_result_code(&revs.diffopt, 0))
690+
if (!diff_result_code(&revs.diffopt))
691691
suffix = NULL;
692692
else
693693
suffix = dirty;

builtin/diff-files.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix)
8383
if (repo_read_index_preload(the_repository, &rev.diffopt.pathspec, 0) < 0)
8484
die_errno("repo_read_index_preload");
8585
run_diff_files(&rev, options);
86-
result = diff_result_code(&rev.diffopt, 0);
86+
result = diff_result_code(&rev.diffopt);
8787
release_revisions(&rev);
8888
return result;
8989
}

builtin/diff-index.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix)
7373
return -1;
7474
}
7575
run_diff_index(&rev, option);
76-
result = diff_result_code(&rev.diffopt, 0);
76+
result = diff_result_code(&rev.diffopt);
7777
release_revisions(&rev);
7878
return result;
7979
}

builtin/diff-tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,5 +232,5 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
232232
diff_free(&opt->diffopt);
233233
}
234234

235-
return diff_result_code(&opt->diffopt, 0);
235+
return diff_result_code(&opt->diffopt);
236236
}

builtin/diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
608608
builtin_diff_combined(&rev, argc, argv,
609609
ent.objects, ent.nr,
610610
first_non_parent);
611-
result = diff_result_code(&rev.diffopt, 0);
611+
result = diff_result_code(&rev.diffopt);
612612
if (1 < rev.diffopt.skip_stat_unmatch)
613613
refresh_index_quietly();
614614
release_revisions(&rev);

builtin/log.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ static int cmd_log_walk_no_free(struct rev_info *rev)
549549
rev->diffopt.flags.check_failed) {
550550
return 02;
551551
}
552-
return diff_result_code(&rev->diffopt, 0);
552+
return diff_result_code(&rev->diffopt);
553553
}
554554

555555
static int cmd_log_walk(struct rev_info *rev)

builtin/stash.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,7 @@ static int show_stash(int argc, const char **argv, const char *prefix)
973973
}
974974
log_tree_diff_flush(&rev);
975975

976-
ret = diff_result_code(&rev.diffopt, 0);
976+
ret = diff_result_code(&rev.diffopt);
977977
cleanup:
978978
strvec_clear(&stash_args);
979979
free_stash_info(&info);
@@ -1111,13 +1111,13 @@ static int check_changes_tracked_files(const struct pathspec *ps)
11111111
diff_setup_done(&rev.diffopt);
11121112

11131113
run_diff_index(&rev, DIFF_INDEX_CACHED);
1114-
if (diff_result_code(&rev.diffopt, 0)) {
1114+
if (diff_result_code(&rev.diffopt)) {
11151115
ret = 1;
11161116
goto done;
11171117
}
11181118

11191119
run_diff_files(&rev, 0);
1120-
if (diff_result_code(&rev.diffopt, 0)) {
1120+
if (diff_result_code(&rev.diffopt)) {
11211121
ret = 1;
11221122
goto done;
11231123
}

builtin/submodule--helper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ static void status_submodule(const char *path, const struct object_id *ce_oid,
670670
setup_revisions(diff_files_args.nr, diff_files_args.v, &rev, &opt);
671671
run_diff_files(&rev, 0);
672672

673-
if (!diff_result_code(&rev.diffopt, 0)) {
673+
if (!diff_result_code(&rev.diffopt)) {
674674
print_status(flags, ' ', path, ce_oid,
675675
displaypath);
676676
} else if (!(flags & OPT_CACHED)) {

diff-no-index.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ int diff_no_index(struct rev_info *revs,
364364
* The return code for --no-index imitates diff(1):
365365
* 0 = no changes, 1 = changes, else error
366366
*/
367-
ret = diff_result_code(&revs->diffopt, 0);
367+
ret = diff_result_code(&revs->diffopt);
368368

369369
out:
370370
for (i = 0; i < ARRAY_SIZE(to_free); i++)

diff.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6973,16 +6973,14 @@ void diffcore_std(struct diff_options *options)
69736973
options->found_follow = 0;
69746974
}
69756975

6976-
int diff_result_code(struct diff_options *opt, int status)
6976+
int diff_result_code(struct diff_options *opt)
69776977
{
69786978
int result = 0;
69796979

69806980
diff_warn_rename_limit("diff.renameLimit",
69816981
opt->needed_rename_limit,
69826982
opt->degraded_cc_to_c);
6983-
if (!opt->flags.exit_with_status &&
6984-
!(opt->output_format & DIFF_FORMAT_CHECKDIFF))
6985-
return status;
6983+
69866984
if (opt->flags.exit_with_status &&
69876985
opt->flags.has_changes)
69886986
result |= 01;

0 commit comments

Comments
 (0)