Skip to content

Commit 08a757b

Browse files
neerajsi-msftdscho
authored andcommitted
fixup! tmp-objdir: new API for creating temporary writable databases
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 <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent b83c4e4 commit 08a757b

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

environment.c

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "commit.h"
1818
#include "strvec.h"
1919
#include "object-store.h"
20+
#include "tmp-objdir.h"
2021
#include "chdir-notify.h"
2122
#include "shallow.h"
2223

@@ -343,10 +344,14 @@ static void update_relative_gitdir(const char *name,
343344
void *data)
344345
{
345346
char *path = reparent_relative_path(old_cwd, new_cwd, get_git_dir());
347+
struct tmp_objdir *tmp_objdir = tmp_objdir_unapply_primary_odb();
346348
trace_printf_key(&trace_setup_key,
347349
"setup: move $GIT_DIR to '%s'",
348350
path);
351+
349352
set_git_dir_1(path);
353+
if (tmp_objdir)
354+
tmp_objdir_reapply_primary_odb(tmp_objdir, old_cwd, new_cwd);
350355
free(path);
351356
}
352357

tmp-objdir.c

+25
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "cache.h"
22
#include "tmp-objdir.h"
3+
#include "chdir-notify.h"
34
#include "dir.h"
45
#include "sigchain.h"
56
#include "string-list.h"
@@ -12,6 +13,7 @@ struct tmp_objdir {
1213
struct strbuf path;
1314
struct strvec env;
1415
struct object_directory *prev_odb;
16+
int will_destroy;
1517
};
1618

1719
/*
@@ -315,4 +317,27 @@ void tmp_objdir_replace_primary_odb(struct tmp_objdir *t, int will_destroy)
315317
if (t->prev_odb)
316318
BUG("the primary object database is already replaced");
317319
t->prev_odb = set_temporary_primary_odb(t->path.buf, will_destroy);
320+
t->will_destroy = will_destroy;
321+
}
322+
323+
struct tmp_objdir *tmp_objdir_unapply_primary_odb(void)
324+
{
325+
if (!the_tmp_objdir || !the_tmp_objdir->prev_odb)
326+
return NULL;
327+
328+
restore_primary_odb(the_tmp_objdir->prev_odb, the_tmp_objdir->path.buf);
329+
the_tmp_objdir->prev_odb = NULL;
330+
return the_tmp_objdir;
331+
}
332+
333+
void tmp_objdir_reapply_primary_odb(struct tmp_objdir *t, const char *old_cwd,
334+
const char *new_cwd)
335+
{
336+
char *path;
337+
338+
path = reparent_relative_path(old_cwd, new_cwd, t->path.buf);
339+
strbuf_reset(&t->path);
340+
strbuf_addstr(&t->path, path);
341+
free(path);
342+
tmp_objdir_replace_primary_odb(t, t->will_destroy);
318343
}

tmp-objdir.h

+15
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,19 @@ void tmp_objdir_add_as_alternate(const struct tmp_objdir *);
5959
*/
6060
void tmp_objdir_replace_primary_odb(struct tmp_objdir *, int will_destroy);
6161

62+
/*
63+
* If the primary object database was replaced by a temporary object directory,
64+
* restore it to its original value while keeping the directory contents around.
65+
* Returns NULL if the primary object database was not replaced.
66+
*/
67+
struct tmp_objdir *tmp_objdir_unapply_primary_odb(void);
68+
69+
/*
70+
* Reapplies the former primary temporary object database, after protentially
71+
* changing its relative path.
72+
*/
73+
void tmp_objdir_reapply_primary_odb(struct tmp_objdir *, const char *old_cwd,
74+
const char *new_cwd);
75+
76+
6277
#endif /* TMP_OBJDIR_H */

0 commit comments

Comments
 (0)