Commit
0076dc9f8141bd864e24a4d160b58be7c0597ce7
odb: drop `alternates_db` field
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt <ps@pks.im> · 2026-08-17 11:09 UTC · committed by Junio C Hamano
2 files changed,
+9
−15
modified odb.c
| @@ -505,12 +505,14 @@ int odb_for_each_alternate(struct object_database *odb, | |||
| 505 | 505 | return r; | |
| 506 | 506 | } | |
| 507 | 507 | ||
| 508 | - | static void odb_prepare_alternates(struct object_database *odb) | |
| 508 | + | static void odb_prepare_alternates(struct object_database *odb, | |
| 509 | + | const char *alternate_db) | |
| 509 | 510 | { | |
| 510 | 511 | struct strvec sources = STRVEC_INIT; | |
| 511 | 512 | ||
| 512 | - | parse_alternates(odb->alternate_db, PATH_SEP, NULL, &sources); | |
| 513 | + | parse_alternates(alternate_db, PATH_SEP, NULL, &sources); | |
| 513 | 514 | odb_source_read_alternates(odb->sources, &sources); | |
| 515 | + | ||
| 514 | 516 | for (size_t i = 0; i < sources.nr; i++) | |
| 515 | 517 | odb_add_alternate_recursively(odb, sources.v[i], 0); | |
| 516 | 518 | ||
| @@ -1077,11 +1079,11 @@ struct object_database *odb_new(struct repository *repo, | |||
| 1077 | 1079 | ||
| 1078 | 1080 | o->sources = odb_source_new(o, primary_source, true); | |
| 1079 | 1081 | o->sources_tail = &o->sources->next; | |
| 1080 | - | o->alternate_db = secondary_sources; | |
| 1081 | 1082 | o->inmemory_objects = &odb_source_inmemory_new(o)->base; | |
| 1082 | 1083 | ||
| 1083 | - | odb_prepare_alternates(o); | |
| 1084 | + | odb_prepare_alternates(o, secondary_sources); | |
| 1084 | 1085 | ||
| 1086 | + | free(secondary_sources); | |
| 1085 | 1087 | free(primary_source); | |
| 1086 | 1088 | return o; | |
| 1087 | 1089 | } | |
| @@ -1115,8 +1117,6 @@ void odb_free(struct object_database *o) | |||
| 1115 | 1117 | if (!o) | |
| 1116 | 1118 | return; | |
| 1117 | 1119 | ||
| 1118 | - | free(o->alternate_db); | |
| 1119 | - | ||
| 1120 | 1120 | oidmap_clear(&o->replace_map, 1); | |
| 1121 | 1121 | pthread_mutex_destroy(&o->replace_mutex); | |
| 1122 | 1122 | ||
| @@ -1138,10 +1138,11 @@ void odb_prepare(struct object_database *o, enum odb_prepare_flags flags) | |||
| 1138 | 1138 | * Reprepare alt odbs, in case the alternates file was modified | |
| 1139 | 1139 | * during the course of this process. This only _adds_ odbs to | |
| 1140 | 1140 | * the linked list, so existing odbs will continue to exist for | |
| 1141 | - | * the lifetime of the process. | |
| 1141 | + | * the lifetime of the process. Consequently, we don't have to | |
| 1142 | + | * reprocess GIT_ALTERNATE_OBJECT_DIRECTORIES here. | |
| 1142 | 1143 | */ | |
| 1143 | 1144 | if (flags & ODB_PREPARE_FLUSH_CACHES) { | |
| 1144 | - | odb_prepare_alternates(o); | |
| 1145 | + | odb_prepare_alternates(o, NULL); | |
| 1145 | 1146 | o->object_count_valid = 0; | |
| 1146 | 1147 | } | |
| 1147 | 1148 | ||
modified odb.h
| @@ -69,13 +69,6 @@ struct object_database { | |||
| 69 | 69 | */ | |
| 70 | 70 | int source_paths_icase; | |
| 71 | 71 | ||
| 72 | - | /* | |
| 73 | - | * A list of alternate object directories loaded from the environment; | |
| 74 | - | * this should not generally need to be accessed directly, but will | |
| 75 | - | * populate the "sources" list when odb_prepare_alternates() is run. | |
| 76 | - | */ | |
| 77 | - | char *alternate_db; | |
| 78 | - | ||
| 79 | 72 | /* | |
| 80 | 73 | * Objects that should be substituted by other objects | |
| 81 | 74 | * (see git-replace(1)). | |