From: "Neeraj Singh via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Johannes.Schindelin@gmx.de,
"Neeraj K. Singh" <neerajsi@microsoft.com>,
Neeraj Singh <neerajsi@microsoft.com>
Subject: [PATCH 2/2] fixup! tmp-objdir: new API for creating temporary writable databases
Date: Tue, 26 Oct 2021 22:35:30 +0000 [thread overview]
Message-ID: <ef5a087813b7dfd232a9366eee09774d197e2307.1635287730.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1067.git.1635287730.gitgitgadget@gmail.com>
From: Neeraj Singh <neerajsi@microsoft.com>
When setup_work_tree executes, it redoes setup of the object database
path and various other aspects of the_repository. This destroys the
temporary object database state.
This commit removes the temporary object database and reapplies it
around the operations in the chdir_notify callback.
Signed-off-by: Neeraj Singh <neerajsi@microsoft.com>
---
environment.c | 5 +++++
tmp-objdir.c | 25 +++++++++++++++++++++++++
tmp-objdir.h | 15 +++++++++++++++
3 files changed, 45 insertions(+)
diff --git a/environment.c b/environment.c
index 46ec5072c05..7ba5ae06c71 100644
--- a/environment.c
+++ b/environment.c
@@ -17,6 +17,7 @@
#include "commit.h"
#include "strvec.h"
#include "object-store.h"
+#include "tmp-objdir.h"
#include "chdir-notify.h"
#include "shallow.h"
@@ -344,10 +345,14 @@ static void update_relative_gitdir(const char *name,
void *data)
{
char *path = reparent_relative_path(old_cwd, new_cwd, get_git_dir());
+ struct tmp_objdir *tmp_objdir = tmp_objdir_unapply_primary_odb();
trace_printf_key(&trace_setup_key,
"setup: move $GIT_DIR to '%s'",
path);
+
set_git_dir_1(path);
+ if (tmp_objdir)
+ tmp_objdir_reapply_primary_odb(tmp_objdir, old_cwd, new_cwd);
free(path);
}
diff --git a/tmp-objdir.c b/tmp-objdir.c
index 45d42a7bcf0..3d38eeab66b 100644
--- a/tmp-objdir.c
+++ b/tmp-objdir.c
@@ -1,5 +1,6 @@
#include "cache.h"
#include "tmp-objdir.h"
+#include "chdir-notify.h"
#include "dir.h"
#include "sigchain.h"
#include "string-list.h"
@@ -12,6 +13,7 @@ struct tmp_objdir {
struct strbuf path;
struct strvec env;
struct object_directory *prev_odb;
+ int will_destroy;
};
/*
@@ -315,4 +317,27 @@ void tmp_objdir_replace_primary_odb(struct tmp_objdir *t, int will_destroy)
if (t->prev_odb)
BUG("the primary object database is already replaced");
t->prev_odb = set_temporary_primary_odb(t->path.buf, will_destroy);
+ t->will_destroy = will_destroy;
+}
+
+struct tmp_objdir *tmp_objdir_unapply_primary_odb(void)
+{
+ if (!the_tmp_objdir || !the_tmp_objdir->prev_odb)
+ return NULL;
+
+ restore_primary_odb(the_tmp_objdir->prev_odb, the_tmp_objdir->path.buf);
+ the_tmp_objdir->prev_odb = NULL;
+ return the_tmp_objdir;
+}
+
+void tmp_objdir_reapply_primary_odb(struct tmp_objdir *t, const char *old_cwd,
+ const char *new_cwd)
+{
+ char *path;
+
+ path = reparent_relative_path(old_cwd, new_cwd, t->path.buf);
+ strbuf_reset(&t->path);
+ strbuf_addstr(&t->path, path);
+ free(path);
+ tmp_objdir_replace_primary_odb(t, t->will_destroy);
}
diff --git a/tmp-objdir.h b/tmp-objdir.h
index 75754cbfba6..a3145051f25 100644
--- a/tmp-objdir.h
+++ b/tmp-objdir.h
@@ -59,4 +59,19 @@ void tmp_objdir_add_as_alternate(const struct tmp_objdir *);
*/
void tmp_objdir_replace_primary_odb(struct tmp_objdir *, int will_destroy);
+/*
+ * If the primary object database was replaced by a temporary object directory,
+ * restore it to its original value while keeping the directory contents around.
+ * Returns NULL if the primary object database was not replaced.
+ */
+struct tmp_objdir *tmp_objdir_unapply_primary_odb(void);
+
+/*
+ * Reapplies the former primary temporary object database, after protentially
+ * changing its relative path.
+ */
+void tmp_objdir_reapply_primary_odb(struct tmp_objdir *, const char *old_cwd,
+ const char *new_cwd);
+
+
#endif /* TMP_OBJDIR_H */
--
gitgitgadget
next prev parent reply other threads:[~2021-10-26 22:35 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-26 22:35 [PATCH 0/2] tmp-objdir: fix regressions in core.fsyncobjectfiles=batch Neeraj K. Singh via GitGitGadget
2021-10-26 22:35 ` [PATCH 1/2] fixup! tmp-objdir: new API for creating temporary writable databases Neeraj Singh via GitGitGadget
2021-10-26 22:35 ` Neeraj Singh via GitGitGadget [this message]
2021-10-27 12:44 ` [PATCH 0/2] tmp-objdir: fix regressions in core.fsyncobjectfiles=batch Johannes Schindelin
2021-10-27 21:09 ` Junio C Hamano
2021-10-27 22:57 ` Neeraj Singh
2021-10-28 0:30 ` Junio C Hamano
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=ef5a087813b7dfd232a9366eee09774d197e2307.1635287730.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=neerajsi@microsoft.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.