[PATCH v2 10/17] odb: get rid of `the_repository` when handling the primary alternate

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The functions `set_temporary_primary_odb()` and `restore_primary_odb()`
are responsible for managing a temporary primary alternate 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@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 feca14d9683..100dd39cbe8 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_alternate *set_temporary_primary_odb(const char *dir, int will_destroy)
+struct odb_alternate *odb_set_temporary_primary_alternate(struct object_database *odb,
+							  const char *dir, int will_destroy)
 {
 	struct odb_alternate *alternate;
 
@@ -337,14 +338,14 @@ struct odb_alternate *set_temporary_primary_odb(const char *dir, int will_destro
 	 * 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
 	 */
 	alternate = xcalloc(1, sizeof(*alternate));
-	alternate->odb = the_repository->objects;
+	alternate->odb = odb;
 	alternate->path = xstrdup(dir);
 
 	/*
@@ -353,8 +354,8 @@ struct odb_alternate *set_temporary_primary_odb(const char *dir, int will_destro
 	 */
 	alternate->disable_ref_updates = 1;
 	alternate->will_destroy = will_destroy;
-	alternate->next = the_repository->objects->alternates;
-	the_repository->objects->alternates = alternate;
+	alternate->next = odb->alternates;
+	odb->alternates = alternate;
 	return alternate->next;
 }
 
@@ -366,9 +367,11 @@ static void free_object_directory(struct odb_alternate *alternate)
 	free(alternate);
 }
 
-void restore_primary_odb(struct odb_alternate *restore_alt, const char *old_path)
+void odb_restore_primary_alternate(struct object_database *odb,
+				   struct odb_alternate *restore_alt,
+				   const char *old_path)
 {
-	struct odb_alternate *cur_alt = the_repository->objects->alternates;
+	struct odb_alternate *cur_alt = odb->alternates;
 
 	if (strcmp(old_path, cur_alt->path))
 		BUG("expected %s as primary object store; found %s",
@@ -377,7 +380,7 @@ void restore_primary_odb(struct odb_alternate *restore_alt, const char *old_path
 	if (cur_alt->next != restore_alt)
 		BUG("we expect the old primary object store to be the first alternate");
 
-	the_repository->objects->alternates = restore_alt;
+	odb->alternates = restore_alt;
 	free_object_directory(cur_alt);
 }
 
diff --git a/odb.h b/odb.h
index 03ac369bca9..f61b391764f 100644
--- a/odb.h
+++ b/odb.h
@@ -63,17 +63,6 @@ struct odb_alternate {
 	char *path;
 };
 
-/*
- * Replace the current writable object directory with the specified temporary
- * object directory; returns the former primary object directory.
- */
-struct odb_alternate *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_alternate *restore_alternate, const char *old_path);
-
 struct packed_git;
 struct multi_pack_index;
 struct cached_object_entry;
@@ -177,6 +166,20 @@ void odb_clear(struct object_database *o);
  */
 struct odb_alternate *odb_find_alternate(struct object_database *odb, const char *obj_dir);
 
+/*
+ * Replace the current writable object directory with the specified temporary
+ * object directory; returns the former primary alternate.
+ */
+struct odb_alternate *odb_set_temporary_primary_alternate(struct object_database *odb,
+							  const char *dir, int will_destroy);
+
+/*
+ * Restore a previous bakcend replaced by `odb_set_temporary_primary_alternate()`.
+ */
+void odb_restore_primary_alternate(struct object_database *odb,
+				   struct odb_alternate *restore_alt,
+				   const char *old_path);
+
 /*
  * Iterate through all alternates 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 cbb50438d16..c2e58c4be5c 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_alt)
-		restore_primary_odb(t->prev_alt, t->path.buf);
+		odb_restore_primary_alternate(t->repo->objects, t->prev_alt, 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_alt) {
 		if (t->repo->objects->alternates->will_destroy)
 			BUG("migrating an ODB that was marked for destruction");
-		restore_primary_odb(t->prev_alt, t->path.buf);
+		odb_restore_primary_alternate(t->repo->objects, t->prev_alt, t->path.buf);
 		t->prev_alt = NULL;
 	}
 
@@ -311,7 +311,8 @@ void tmp_objdir_replace_primary_odb(struct tmp_objdir *t, int will_destroy)
 {
 	if (t->prev_alt)
 		BUG("the primary object database is already replaced");
-	t->prev_alt = set_temporary_primary_odb(t->path.buf, will_destroy);
+	t->prev_alt = odb_set_temporary_primary_alternate(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_alt)
 		return NULL;
 
-	restore_primary_odb(the_tmp_objdir->prev_alt, the_tmp_objdir->path.buf);
+	odb_restore_primary_alternate(the_tmp_objdir->repo->objects,
+				      the_tmp_objdir->prev_alt, the_tmp_objdir->path.buf);
 	the_tmp_objdir->prev_alt = NULL;
 	return the_tmp_objdir;
 }

-- 
2.49.0.1077.gc0e912fd4c.dirty





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux