[PATCH v3 5/5] odb: drop `alternates_db` field
Patrick Steinhardt <[email protected]>
| Newsgroups | org.kernel.vger.git |
|---|---|
| Message-ID | <20260817-pks-odb-eagerly-prepare-alternates-v3-5-1115a7e02467@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 <[email protected]> --- odb.c | 17 +++++++++-------- odb.h | 7 ------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/odb.c b/odb.c index ada42f864b..115957e983 100644 --- a/odb.c +++ b/odb.c @@ -505,12 +505,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); @@ -1077,11 +1079,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; } @@ -1115,8 +1117,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); @@ -1138,10 +1138,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.822.g20453c30eb.dirty