@@ -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);
}
@@ -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);
}
@@ -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 */