aboutsummaryrefslogtreecommitdiffstats
path: root/odb.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2025-07-01 14:22:22 +0200
committerJunio C Hamano <gitster@pobox.com>2025-07-01 14:46:36 -0700
commit7eafd4472d7c273e10a408da6662ca9d4b9800fd (patch)
treebbfa21372fcbef1e66f7cb6a5c08f2c83b7ecf95 /odb.c
parent798c661ce39f7d5297fa7ea8928ae464b6d5dd95 (diff)
downloadgit-7eafd4472d7c273e10a408da6662ca9d4b9800fd.tar.gz
odb: get rid of `the_repository` when handling the primary source
The functions `set_temporary_primary_odb()` and `restore_primary_odb()` are responsible for managing a temporary primary source for the database. Both of these functions 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@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'odb.c')
-rw-r--r--odb.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/odb.c b/odb.c
index 03fb68605c..4f03be7f77 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_source *set_temporary_primary_odb(const char *dir, int will_destroy)
+struct odb_source *odb_set_temporary_primary_source(struct object_database *odb,
+ const char *dir, int will_destroy)
{
struct odb_source *source;
@@ -337,14 +338,14 @@ struct odb_source *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
*/
source = xcalloc(1, sizeof(*source));
- source->odb = the_repository->objects;
+ source->odb = odb;
source->path = xstrdup(dir);
/*
@@ -353,8 +354,8 @@ struct odb_source *set_temporary_primary_odb(const char *dir, int will_destroy)
*/
source->disable_ref_updates = 1;
source->will_destroy = will_destroy;
- source->next = the_repository->objects->sources;
- the_repository->objects->sources = source;
+ source->next = odb->sources;
+ odb->sources = source;
return source->next;
}
@@ -366,19 +367,21 @@ static void free_object_directory(struct odb_source *source)
free(source);
}
-void restore_primary_odb(struct odb_source *restore_alt, const char *old_path)
+void odb_restore_primary_source(struct object_database *odb,
+ struct odb_source *restore_source,
+ const char *old_path)
{
- struct odb_source *cur_alt = the_repository->objects->sources;
+ struct odb_source *cur_source = odb->sources;
- if (strcmp(old_path, cur_alt->path))
+ if (strcmp(old_path, cur_source->path))
BUG("expected %s as primary object store; found %s",
- old_path, cur_alt->path);
+ old_path, cur_source->path);
- if (cur_alt->next != restore_alt)
+ if (cur_source->next != restore_source)
BUG("we expect the old primary object store to be the first alternate");
- the_repository->objects->sources = restore_alt;
- free_object_directory(cur_alt);
+ odb->sources = restore_source;
+ free_object_directory(cur_source);
}
char *compute_alternate_path(const char *path, struct strbuf *err)