git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Cc: Elijah Newren <newren@gmail.com>, blanet <bupt_xingxin@163.com>,
	Xing Xin  <xingxin.xx@bytedance.com>
Subject: [PATCH 1/2] remerge-diff: lazily prpare temporary objdir on demand
Date: Fri, 09 Aug 2024 15:30:51 -0700	[thread overview]
Message-ID: <xmqqv8099vms.fsf@gitster.g> (raw)

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>
---

 * So here are two patches to illustate how the code to do the lazy
   set-up and centralized tear down looks like.  The first part is
   the lazy set-up.

 builtin/diff-tree.c |  7 -------
 builtin/log.c       |  7 -------
 log-tree.c          | 16 ++++++++++++----
 3 files changed, 12 insertions(+), 18 deletions(-)

diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c
index 12012ea093..af51cd29c6 100644
--- a/builtin/diff-tree.c
+++ b/builtin/diff-tree.c
@@ -168,13 +168,6 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
 
 	opt->diffopt.rotate_to_strict = 1;
 
-	if (opt->remerge_diff) {
-		opt->remerge_objdir = tmp_objdir_create("remerge-diff");
-		if (!opt->remerge_objdir)
-			die(_("unable to create temporary object directory"));
-		tmp_objdir_replace_primary_odb(opt->remerge_objdir, 1);
-	}
-
 	/*
 	 * NOTE!  We expect "a..b" to expand to "^a b" but it is
 	 * perfectly valid for revision range parser to yield "b ^a",
diff --git a/builtin/log.c b/builtin/log.c
index af6403cb71..227823a16e 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -494,13 +494,6 @@ static int cmd_log_walk_no_free(struct rev_info *rev)
 	int saved_nrl = 0;
 	int saved_dcctc = 0;
 
-	if (rev->remerge_diff) {
-		rev->remerge_objdir = tmp_objdir_create("remerge-diff");
-		if (!rev->remerge_objdir)
-			die(_("unable to create temporary object directory"));
-		tmp_objdir_replace_primary_odb(rev->remerge_objdir, 1);
-	}
-
 	if (rev->early_output)
 		setup_early_output();
 
diff --git a/log-tree.c b/log-tree.c
index 337b9334cd..83e648b7cd 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -1019,6 +1019,17 @@ static int do_remerge_diff(struct rev_info *opt,
 	struct strbuf parent1_desc = STRBUF_INIT;
 	struct strbuf parent2_desc = STRBUF_INIT;
 
+	/*
+	 * Lazily prepare a temporary object directory and rotate it
+	 * into the alternative object store list as the primary.
+	 */
+	if (opt->remerge_diff && !opt->remerge_objdir) {
+		opt->remerge_objdir = tmp_objdir_create("remerge-diff");
+		if (!opt->remerge_objdir)
+			return error(_("unable to create temporary object directory"));
+		tmp_objdir_replace_primary_odb(opt->remerge_objdir, 1);
+	}
+
 	/* Setup merge options */
 	init_merge_options(&o, the_repository);
 	o.show_rename_progress = 0;
@@ -1053,10 +1064,7 @@ static int do_remerge_diff(struct rev_info *opt,
 	merge_finalize(&o, &res);
 
 	/* Clean up the contents of the temporary object directory */
-	if (opt->remerge_objdir)
-		tmp_objdir_discard_objects(opt->remerge_objdir);
-	else
-		BUG("did a remerge diff without remerge_objdir?!?");
+	tmp_objdir_discard_objects(opt->remerge_objdir);
 
 	return !opt->loginfo;
 }
-- 
2.46.0-326-g1e046905fc


             reply	other threads:[~2024-08-09 22:30 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-09 22:30 Junio C Hamano [this message]
2024-08-09 22:31 ` [PATCH 2/2] remerge-diff: clean up temporary objdir at a central place Junio C Hamano
2024-08-12  5:17   ` Junio C Hamano
2024-08-16  6:19     ` Elijah Newren
2024-09-08 21:16       ` Junio C Hamano
2024-08-09 22:37 ` [PATCH 1/2] remerge-diff: lazily prpare temporary objdir on demand Eric Sunshine

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqv8099vms.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=bupt_xingxin@163.com \
    --cc=git@vger.kernel.org \
    --cc=newren@gmail.com \
    --cc=xingxin.xx@bytedance.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).