remerge-diff: lazily prepare temporary objdir on demand

It is error prone for each caller that sets revs.remerge_diff bit to be responsible for preparing a temporary object directory and rotate it into the list of alternate object stores, making it the primary object store. Instead, remove the code to set up and arrange the temporary object directory from the current callers and implement it in the code that runs remerge-diff logic. The code to undo the futzing of the list of alternate object store is still spread across the callers, but we will deal with it in future steps. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Aug 9, 2024 at 15:30 UTC 245cac5c3312b9afab5c47cb222f0e5d1845da0d
3 files changed +12 -18
builtin/diff-tree.c
-7
@@ -168,13 +168,6 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
168
169 opt->diffopt.rotate_to_strict = 1;
170
171 - if (opt->remerge_diff) {
172 - opt->remerge_objdir = tmp_objdir_create("remerge-diff");
173 - if (!opt->remerge_objdir)
174 - die(_("unable to create temporary object directory"));
175 - tmp_objdir_replace_primary_odb(opt->remerge_objdir, 1);
176 - }
177 -
171 /*
172 * NOTE! We expect "a..b" to expand to "^a b" but it is
173 * perfectly valid for revision range parser to yield "b ^a",
builtin/log.c
-7
@@ -494,13 +494,6 @@ static int cmd_log_walk_no_free(struct rev_info *rev)
494 int saved_nrl = 0;
495 int saved_dcctc = 0;
496
497 - if (rev->remerge_diff) {
498 - rev->remerge_objdir = tmp_objdir_create("remerge-diff");
499 - if (!rev->remerge_objdir)
500 - die(_("unable to create temporary object directory"));
501 - tmp_objdir_replace_primary_odb(rev->remerge_objdir, 1);
502 - }
503 -
497 if (rev->early_output)
498 setup_early_output();
499
log-tree.c
+12 -4
@@ -1019,6 +1019,17 @@ static int do_remerge_diff(struct rev_info *opt,
1019 struct strbuf parent1_desc = STRBUF_INIT;
1020 struct strbuf parent2_desc = STRBUF_INIT;
1021
1022 + /*
1023 + * Lazily prepare a temporary object directory and rotate it
1024 + * into the alternative object store list as the primary.
1025 + */
1026 + if (opt->remerge_diff && !opt->remerge_objdir) {
1027 + opt->remerge_objdir = tmp_objdir_create("remerge-diff");
1028 + if (!opt->remerge_objdir)
1029 + return error(_("unable to create temporary object directory"));
1030 + tmp_objdir_replace_primary_odb(opt->remerge_objdir, 1);
1031 + }
1032 +
1033 /* Setup merge options */
1034 init_merge_options(&o, the_repository);
1035 o.show_rename_progress = 0;
@@ -1053,10 +1064,7 @@ static int do_remerge_diff(struct rev_info *opt,
1064 merge_finalize(&o, &res);
1065
1066 /* Clean up the contents of the temporary object directory */
1056 - if (opt->remerge_objdir)
1057 - tmp_objdir_discard_objects(opt->remerge_objdir);
1058 - else
1059 - BUG("did a remerge diff without remerge_objdir?!?");
1067 + tmp_objdir_discard_objects(opt->remerge_objdir);
1068
1069 return !opt->loginfo;
1070 }