remerge-diff: clean up temporary objdir at a central place

After running a diff between two things, or a series of diffs while walking the history, the diff computation is concluded by a call to diff_result_code() to extract the exit status of the diff machinery. The function can work on "struct diffopt", but all the callers historically and currently pass "struct diffopt" that is embedded in the "struct rev_info" that is used to hold the remerge_diff bit and the remerge_objdir variable that points at the temporary object directory in use. Redefine diff_result_code() to take the whole "struct rev_info" to give it an access to these members related to remerge-diff, so that it can get rid of the temporary object directory for any and all callers that used the feature. We can lose the equivalent code to do so from the code paths for individual commands, diff-tree, diff, and log. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Aug 9, 2024 at 15:31 UTC 4460e052e074490cfc083703fba285d3c2e36560
12 files changed +26 -26
builtin/describe.c
+1 -1
@@ -687,7 +687,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
687 BUG("malformed internal diff-index command line");
688 run_diff_index(&revs, 0);
689
690 - if (!diff_result_code(&revs.diffopt))
690 + if (!diff_result_code(&revs))
691 suffix = NULL;
692 else
693 suffix = dirty;
builtin/diff-files.c
+1 -1
@@ -82,7 +82,7 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix)
82 if (repo_read_index_preload(the_repository, &rev.diffopt.pathspec, 0) < 0)
83 die_errno("repo_read_index_preload");
84 run_diff_files(&rev, options);
85 - result = diff_result_code(&rev.diffopt);
85 + result = diff_result_code(&rev);
86 release_revisions(&rev);
87 return result;
88 }
builtin/diff-index.c
+1 -1
@@ -71,7 +71,7 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix)
71 return -1;
72 }
73 run_diff_index(&rev, option);
74 - result = diff_result_code(&rev.diffopt);
74 + result = diff_result_code(&rev);
75 release_revisions(&rev);
76 return result;
77 }
builtin/diff-tree.c
+1 -6
@@ -232,10 +232,5 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
232 diff_free(&opt->diffopt);
233 }
234
235 - if (opt->remerge_diff) {
236 - tmp_objdir_destroy(opt->remerge_objdir);
237 - opt->remerge_objdir = NULL;
238 - }
239 -
240 - return diff_result_code(&opt->diffopt);
235 + return diff_result_code(opt);
236 }
builtin/diff.c
+1 -1
@@ -605,7 +605,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
605 builtin_diff_combined(&rev, argc, argv,
606 ent.objects, ent.nr,
607 first_non_parent);
608 - result = diff_result_code(&rev.diffopt);
608 + result = diff_result_code(&rev);
609 if (1 < rev.diffopt.skip_stat_unmatch)
610 refresh_index_quietly();
611 release_revisions(&rev);
builtin/log.c
+4 -7
@@ -493,6 +493,7 @@ static int cmd_log_walk_no_free(struct rev_info *rev)
493 struct commit *commit;
494 int saved_nrl = 0;
495 int saved_dcctc = 0;
496 + int result;
497
498 if (rev->early_output)
499 setup_early_output();
@@ -533,16 +534,12 @@ static int cmd_log_walk_no_free(struct rev_info *rev)
534 rev->diffopt.degraded_cc_to_c = saved_dcctc;
535 rev->diffopt.needed_rename_limit = saved_nrl;
536
536 - if (rev->remerge_diff) {
537 - tmp_objdir_destroy(rev->remerge_objdir);
538 - rev->remerge_objdir = NULL;
539 - }
540 -
537 + result = diff_result_code(rev);
538 if (rev->diffopt.output_format & DIFF_FORMAT_CHECKDIFF &&
539 rev->diffopt.flags.check_failed) {
543 - return 02;
540 + result = 02;
541 }
545 - return diff_result_code(&rev->diffopt);
542 + return result;
543 }
544
545 static int cmd_log_walk(struct rev_info *rev)
builtin/stash.c
+3 -3
@@ -972,7 +972,7 @@ static int show_stash(int argc, const char **argv, const char *prefix)
972 }
973 log_tree_diff_flush(&rev);
974
975 - ret = diff_result_code(&rev.diffopt);
975 + ret = diff_result_code(&rev);
976 cleanup:
977 strvec_clear(&stash_args);
978 free_stash_info(&info);
@@ -1116,13 +1116,13 @@ static int check_changes_tracked_files(const struct pathspec *ps)
1116 diff_setup_done(&rev.diffopt);
1117
1118 run_diff_index(&rev, DIFF_INDEX_CACHED);
1119 - if (diff_result_code(&rev.diffopt)) {
1119 + if (diff_result_code(&rev)) {
1120 ret = 1;
1121 goto done;
1122 }
1123
1124 run_diff_files(&rev, 0);
1125 - if (diff_result_code(&rev.diffopt)) {
1125 + if (diff_result_code(&rev)) {
1126 ret = 1;
1127 goto done;
1128 }
builtin/submodule--helper.c
+1 -1
@@ -675,7 +675,7 @@ static void status_submodule(const char *path, const struct object_id *ce_oid,
675 setup_revisions(diff_files_args.nr, diff_files_args.v, &rev, &opt);
676 run_diff_files(&rev, 0);
677
678 - if (!diff_result_code(&rev.diffopt)) {
678 + if (!diff_result_code(&rev)) {
679 print_status(flags, ' ', path, ce_oid,
680 displaypath);
681 } else if (!(flags & OPT_CACHED)) {
diff-no-index.c
+1 -1
@@ -362,7 +362,7 @@ int diff_no_index(struct rev_info *revs,
362 * The return code for --no-index imitates diff(1):
363 * 0 = no changes, 1 = changes, else error
364 */
365 - ret = diff_result_code(&revs->diffopt);
365 + ret = diff_result_code(revs);
366
367 out:
368 for (i = 0; i < ARRAY_SIZE(to_free); i++)
diff.c
+9 -1
@@ -9,6 +9,7 @@
9 #include "environment.h"
10 #include "gettext.h"
11 #include "tempfile.h"
12 +#include "revision.h"
13 #include "quote.h"
14 #include "diff.h"
15 #include "diffcore.h"
@@ -26,6 +27,7 @@
27 #include "merge-ll.h"
28 #include "string-list.h"
29 #include "strvec.h"
30 +#include "tmp-objdir.h"
31 #include "graph.h"
32 #include "oid-array.h"
33 #include "packfile.h"
@@ -7012,10 +7014,16 @@ void diffcore_std(struct diff_options *options)
7014 options->found_follow = 0;
7015 }
7016
7015 -int diff_result_code(struct diff_options *opt)
7017 +int diff_result_code(struct rev_info *revs)
7018 {
7019 + struct diff_options *opt = &revs->diffopt;
7020 int result = 0;
7021
7022 + if (revs->remerge_diff) {
7023 + tmp_objdir_destroy(revs->remerge_objdir);
7024 + revs->remerge_objdir = NULL;
7025 + }
7026 +
7027 diff_warn_rename_limit("diff.renameLimit",
7028 opt->needed_rename_limit,
7029 opt->degraded_cc_to_c);
diff.h
+1 -1
@@ -648,7 +648,7 @@ int do_diff_cache(const struct object_id *, struct diff_options *);
648 int diff_flush_patch_id(struct diff_options *, struct object_id *, int);
649 void flush_one_hunk(struct object_id *result, git_hash_ctx *ctx);
650
651 -int diff_result_code(struct diff_options *);
651 +int diff_result_code(struct rev_info *);
652
653 int diff_no_index(struct rev_info *,
654 int implicit_no_index, int, const char **);
wt-status.c
+2 -2
@@ -2582,7 +2582,7 @@ int has_unstaged_changes(struct repository *r, int ignore_submodules)
2582 rev_info.diffopt.flags.quick = 1;
2583 diff_setup_done(&rev_info.diffopt);
2584 run_diff_files(&rev_info, 0);
2585 - result = diff_result_code(&rev_info.diffopt);
2585 + result = diff_result_code(&rev_info);
2586 release_revisions(&rev_info);
2587 return result;
2588 }
@@ -2616,7 +2616,7 @@ int has_uncommitted_changes(struct repository *r,
2616
2617 diff_setup_done(&rev_info.diffopt);
2618 run_diff_index(&rev_info, DIFF_INDEX_CACHED);
2619 - result = diff_result_code(&rev_info.diffopt);
2619 + result = diff_result_code(&rev_info);
2620 release_revisions(&rev_info);
2621 return result;
2622 }