The functions `set_temporary_primary_odb()` and `restore_primary_odb()` are responsible for managing a temporary primary backend for the database. Both of these fucntions implicitly rely on `the_repository`. Refactor them to instead take an explicit object database parameter as argument and adjust callers. Rename the functions accordingly. Signed-off-by: Patrick Steinhardt <ps@xxxxxx> --- odb.c | 19 +++++++++++-------- odb.h | 25 ++++++++++++++----------- tmp-objdir.c | 10 ++++++---- 3 files changed, 31 insertions(+), 23 deletions(-) diff --git a/odb.c b/odb.c index 66cad14f538..8be5d4fb2d6 100644 --- a/odb.c +++ b/odb.c @@ -329,7 +329,8 @@ void odb_add_to_alternates_memory(struct object_database *odb, '\n', NULL, 0); } -struct odb_backend *set_temporary_primary_odb(const char *dir, int will_destroy) +struct odb_backend *odb_set_temporary_primary_backend(struct object_database *odb, + const char *dir, int will_destroy) { struct odb_backend *backend; @@ -337,14 +338,14 @@ struct odb_backend *set_temporary_primary_odb(const char *dir, int will_destroy) * Make sure alternates are initialized, or else our entry may be * overwritten when they are. */ - odb_prepare_alternates(the_repository->objects); + odb_prepare_alternates(odb); /* * Make a new primary odb and link the old primary ODB in as an * alternate */ backend = xcalloc(1, sizeof(*backend)); - backend->odb = the_repository->objects; + backend->odb = odb; backend->path = xstrdup(dir); /* @@ -353,8 +354,8 @@ struct odb_backend *set_temporary_primary_odb(const char *dir, int will_destroy) */ backend->disable_ref_updates = 1; backend->will_destroy = will_destroy; - backend->next = the_repository->objects->backends; - the_repository->objects->backends = backend; + backend->next = odb->backends; + odb->backends = backend; return backend->next; } @@ -366,9 +367,11 @@ static void free_object_directory(struct odb_backend *odb) free(odb); } -void restore_primary_odb(struct odb_backend *restore_odb, const char *old_path) +void odb_restore_primary_backend(struct object_database *odb, + struct odb_backend *restore_odb, + const char *old_path) { - struct odb_backend *cur_odb = the_repository->objects->backends; + struct odb_backend *cur_odb = odb->backends; if (strcmp(old_path, cur_odb->path)) BUG("expected %s as primary object store; found %s", @@ -377,7 +380,7 @@ void restore_primary_odb(struct odb_backend *restore_odb, const char *old_path) if (cur_odb->next != restore_odb) BUG("we expect the old primary object store to be the first alternate"); - the_repository->objects->backends = restore_odb; + odb->backends = restore_odb; free_object_directory(cur_odb); } diff --git a/odb.h b/odb.h index 2165396a165..e80ee5efec6 100644 --- a/odb.h +++ b/odb.h @@ -61,17 +61,6 @@ struct odb_backend { char *path; }; -/* - * Replace the current writable object directory with the specified temporary - * object directory; returns the former primary object directory. - */ -struct odb_backend *set_temporary_primary_odb(const char *dir, int will_destroy); - -/* - * Restore a previous ODB replaced by set_temporary_main_odb. - */ -void restore_primary_odb(struct odb_backend *restore_odb, const char *old_path); - struct packed_git; struct multi_pack_index; struct cached_object_entry; @@ -175,6 +164,20 @@ void odb_clear(struct object_database *o); */ struct odb_backend *odb_find_backend(struct object_database *odb, const char *obj_dir); +/* + * Replace the current writable object directory with the specified temporary + * object directory; returns the former primary backend. + */ +struct odb_backend *odb_set_temporary_primary_backend(struct object_database *odb, + const char *dir, int will_destroy); + +/* + * Restore a previous bakcend replaced by `odb_set_temporary_primary_backend()`. + */ +void odb_restore_primary_backend(struct object_database *odb, + struct odb_backend *restore_odb, + const char *old_path); + /* * Iterate through all backends of the database and execute the provided * callback function for each of them. Stop iterating once the callback diff --git a/tmp-objdir.c b/tmp-objdir.c index 2982c646569..e6221879395 100644 --- a/tmp-objdir.c +++ b/tmp-objdir.c @@ -47,7 +47,7 @@ int tmp_objdir_destroy(struct tmp_objdir *t) the_tmp_objdir = NULL; if (t->prev_odb) - restore_primary_odb(t->prev_odb, t->path.buf); + odb_restore_primary_backend(t->repo->objects, t->prev_odb, t->path.buf); err = remove_dir_recursively(&t->path, 0); @@ -279,7 +279,7 @@ int tmp_objdir_migrate(struct tmp_objdir *t) if (t->prev_odb) { if (t->repo->objects->backends->will_destroy) BUG("migrating an ODB that was marked for destruction"); - restore_primary_odb(t->prev_odb, t->path.buf); + odb_restore_primary_backend(t->repo->objects, t->prev_odb, t->path.buf); t->prev_odb = NULL; } @@ -311,7 +311,8 @@ 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->prev_odb = odb_set_temporary_primary_backend(t->repo->objects, + t->path.buf, will_destroy); t->will_destroy = will_destroy; } @@ -320,7 +321,8 @@ 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); + odb_restore_primary_backend(the_tmp_objdir->repo->objects, + the_tmp_objdir->prev_odb, the_tmp_objdir->path.buf); the_tmp_objdir->prev_odb = NULL; return the_tmp_objdir; } -- 2.49.0.1045.g170613ef41.dirty