aboutsummaryrefslogtreecommitdiff
path: root/tmp-objdir.c
diff options
context:
space:
mode:
Diffstat (limited to 'tmp-objdir.c')
-rw-r--r--tmp-objdir.c43
1 files changed, 20 insertions, 23 deletions
diff --git a/tmp-objdir.c b/tmp-objdir.c
index 9f5a1788cd..d199d39e7c 100644
--- a/tmp-objdir.c
+++ b/tmp-objdir.c
@@ -11,6 +11,7 @@
#include "strvec.h"
#include "quote.h"
#include "odb.h"
+#include "odb/source.h"
#include "repository.h"
struct tmp_objdir {
@@ -36,6 +37,21 @@ static void tmp_objdir_free(struct tmp_objdir *t)
free(t);
}
+static void tmp_objdir_reparent(const char *name UNUSED,
+ const char *old_cwd,
+ const char *new_cwd,
+ void *cb_data)
+{
+ struct tmp_objdir *t = cb_data;
+ char *path;
+
+ path = reparent_relative_path(old_cwd, new_cwd,
+ t->path.buf);
+ strbuf_reset(&t->path);
+ strbuf_addstr(&t->path, path);
+ free(path);
+}
+
int tmp_objdir_destroy(struct tmp_objdir *t)
{
int err;
@@ -51,6 +67,7 @@ int tmp_objdir_destroy(struct tmp_objdir *t)
err = remove_dir_recursively(&t->path, 0);
+ chdir_notify_unregister(NULL, tmp_objdir_reparent, t);
tmp_objdir_free(t);
return err;
@@ -137,6 +154,9 @@ struct tmp_objdir *tmp_objdir_create(struct repository *r,
strbuf_addf(&t->path, "%s/tmp_objdir-%s-XXXXXX",
repo_get_object_directory(r), prefix);
+ if (!is_absolute_path(t->path.buf))
+ chdir_notify_register(NULL, tmp_objdir_reparent, t);
+
if (!mkdtemp(t->path.buf)) {
/* free, not destroy, as we never touched the filesystem */
tmp_objdir_free(t);
@@ -315,26 +335,3 @@ void tmp_objdir_replace_primary_odb(struct tmp_objdir *t, int will_destroy)
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_source)
- return NULL;
-
- odb_restore_primary_source(the_tmp_objdir->repo->objects,
- the_tmp_objdir->prev_source, the_tmp_objdir->path.buf);
- the_tmp_objdir->prev_source = 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);
-}