git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 4/4] odb: drop `alternates_db` field

From
Patrick Steinhardt <ps@pks.im>
Date
Aug 12, 2026, 09:14 UTC
Message-ID
<20260812-pks-odb-eagerly-prepare-alternates-v2-4-522b9a5bc1ea@pks.im>
In-Reply-To
<20260812-pks-odb-eagerly-prepare-alternates-v2-0-522b9a5bc1ea@pks.im>

The `struct object_database::alternates_db` field tracks the value of the "GIT_ALTERNATE_OBJECT_DIRECTORIES" environment variable and is used in `odb_prepare_alternates()`. It's not necessary to store it as a separate field anymore though, as we stopped lazy-loading alternates. Consequently, we can simply pass it to `odb_prepare_alternates()` via `odb_new()` now.

Do so and remove the field.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 odb.c | 17 +++++++++--------
 odb.h |  7 -------
 2 files changed, 9 insertions(+), 15 deletions(-)
diff --git a/odb.c b/odb.c
index 2eb37a2f44..0212eaa998 100644
--- a/odb.c
+++ b/odb.c
@@ -490,12 +490,14 @@ int odb_for_each_alternate(struct object_database *odb,
 	return r;
 }
 
-static void odb_prepare_alternates(struct object_database *odb)
+static void odb_prepare_alternates(struct object_database *odb,
+				   const char *alternate_db)
 {
 	struct strvec sources = STRVEC_INIT;
 
-	parse_alternates(odb->alternate_db, PATH_SEP, NULL, &sources);
+	parse_alternates(alternate_db, PATH_SEP, NULL, &sources);
 	odb_source_read_alternates(odb->sources, &sources);
+
 	for (size_t i = 0; i < sources.nr; i++)
 		odb_add_alternate_recursively(odb, sources.v[i], 0);
 
@@ -1062,11 +1064,11 @@ struct object_database *odb_new(struct repository *repo,
 
 	o->sources = odb_source_new(o, primary_source, true);
 	o->sources_tail = &o->sources->next;
-	o->alternate_db = secondary_sources;
 	o->inmemory_objects = &odb_source_inmemory_new(o)->base;
 
-	odb_prepare_alternates(o);
+	odb_prepare_alternates(o, secondary_sources);
 
+	free(secondary_sources);
 	free(primary_source);
 	return o;
 }
@@ -1100,8 +1102,6 @@ void odb_free(struct object_database *o)
 	if (!o)
 		return;
 
-	free(o->alternate_db);
-
 	oidmap_clear(&o->replace_map, 1);
 	pthread_mutex_destroy(&o->replace_mutex);
 
@@ -1123,10 +1123,11 @@ void odb_prepare(struct object_database *o, enum odb_prepare_flags flags)
 	 * Reprepare alt odbs, in case the alternates file was modified
 	 * during the course of this process. This only _adds_ odbs to
 	 * the linked list, so existing odbs will continue to exist for
-	 * the lifetime of the process.
+	 * the lifetime of the process. Consequently, we don't have to
+	 * reprocess GIT_ALTERNATE_OBJECT_DIRECTORIES here.
 	 */
 	if (flags & ODB_PREPARE_FLUSH_CACHES) {
-		odb_prepare_alternates(o);
+		odb_prepare_alternates(o, NULL);
 		o->object_count_valid = 0;
 	}
 
diff --git a/odb.h b/odb.h
index aefb34213f..748366a610 100644
--- a/odb.h
+++ b/odb.h
@@ -69,13 +69,6 @@ struct object_database {
 	 */
 	int source_paths_icase;
 
-	/*
-	 * A list of alternate object directories loaded from the environment;
-	 * this should not generally need to be accessed directly, but will
-	 * populate the "sources" list when odb_prepare_alternates() is run.
-	 */
-	char *alternate_db;
-
 	/*
 	 * Objects that should be substituted by other objects
 	 * (see git-replace(1)).
-- 
2.55.0.679.g6767b8d81c.dirty
Previous: Karthik NayakNext: Junio C Hamano
Message 32 of 47 in “odb: eagerly load alternates”
  1. 0/4 odb: eagerly load alternatesPatrick Steinhardt, Aug 10, 2026
  2. 1/4 odb: decouple source path comparisons from `the_repository`Patrick Steinhardt, Aug 10, 2026
  3. Justin ToblerAug 11, 2026
  4. Patrick SteinhardtAug 12, 2026
  5. 2/4 odb: eagerly initialize alternatesPatrick Steinhardt, Aug 10, 2026
  6. Justin ToblerAug 11, 2026
  7. Patrick SteinhardtAug 12, 2026
  8. 3/4 odb: drop `loaded_alternates` fieldPatrick Steinhardt, Aug 10, 2026
  9. Justin ToblerAug 11, 2026
  10. 4/4 odb: drop `alternates_db` fieldPatrick Steinhardt, Aug 10, 2026
  11. Justin ToblerAug 11, 2026
  12. Patrick SteinhardtAug 12, 2026
  13. 0/4 odb: eagerly load alternatesPatrick Steinhardt, Aug 12, 2026
  14. 1/4 odb: decouple source path comparisons from `the_repository`Patrick Steinhardt, Aug 12, 2026
  15. Karthik NayakAug 13, 2026
  16. Patrick SteinhardtAug 13, 2026
  17. Karthik NayakAug 14, 2026
  18. Jeff KingAug 14, 2026
  19. Junio C HamanoAug 14, 2026
  20. Jeff KingAug 14, 2026
  21. Patrick SteinhardtAug 17, 2026
  22. Patrick SteinhardtAug 17, 2026
  23. Jeff KingAug 17, 2026
  24. Patrick SteinhardtAug 17, 2026
  25. Jeff KingAug 17, 2026
  26. Jeff KingAug 17, 2026
  27. Jeff KingAug 14, 2026
  28. Patrick SteinhardtAug 17, 2026
  29. 2/4 odb: eagerly initialize alternatesPatrick Steinhardt, Aug 12, 2026
  30. 3/4 odb: drop `loaded_alternates` fieldPatrick Steinhardt, Aug 12, 2026
  31. Karthik NayakAug 13, 2026
  32. 4/4 odb: drop `alternates_db` fieldPatrick Steinhardt, Aug 12, 2026
  33. Junio C HamanoAug 12, 2026
  34. Patrick SteinhardtAug 13, 2026
  35. Karthik NayakAug 13, 2026
  36. Justin ToblerAug 13, 2026
  37. 0/5 odb: eagerly load alternatesPatrick Steinhardt, Aug 17, 2026
  38. 1/5 setup: create ref and object databases after config is writtenPatrick Steinhardt, Aug 17, 2026
  39. Karthik NayakAug 20, 2026
  40. 2/5 odb: decouple source path comparisons from `the_repository`Patrick Steinhardt, Aug 17, 2026
  41. Junio C HamanoAug 20, 2026
  42. Patrick SteinhardtAug 21, 2026
  43. Junio C HamanoAug 21, 2026
  44. 3/5 odb: eagerly initialize alternatesPatrick Steinhardt, Aug 17, 2026
  45. 4/5 odb: drop `loaded_alternates` fieldPatrick Steinhardt, Aug 17, 2026
  46. 5/5 odb: drop `alternates_db` fieldPatrick Steinhardt, Aug 17, 2026
  47. Karthik NayakAug 20, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.