odb: read alternates via sources
Adapt how we read alternates so that the interface is structured around the object database source we're reading from. This will eventually allow us to abstract away this behaviour with pluggable object databases so that every format can have its own mechanism for listing alternates. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Dec 11, 2025 at 10:30 UTC
f7dbd9fb2ea9b14b4df0949411205f4b5d284b41
1 file changed
+6
-6
odb.c
+6
-6
@@ -199,19 +199,19 @@ static void parse_alternates(const char *string,
199
strbuf_release(&buf);
200
}
201
202
-static void read_info_alternates(const char *relative_base,
203
- struct strvec *out)
202
+static void odb_source_read_alternates(struct odb_source *source,
203
+ struct strvec *out)
204
{
205
struct strbuf buf = STRBUF_INIT;
206
char *path;
207
208
- path = xstrfmt("%s/info/alternates", relative_base);
208
+ path = xstrfmt("%s/info/alternates", source->path);
209
if (strbuf_read_file(&buf, path, 1024) < 0) {
210
warn_on_fopen_errors(path);
211
free(path);
212
return;
213
}
214
- parse_alternates(buf.buf, '\n', relative_base, out);
214
+ parse_alternates(buf.buf, '\n', source->path, out);
215
216
strbuf_release(&buf);
217
free(path);
@@ -257,7 +257,7 @@ static struct odb_source *odb_add_alternate_recursively(struct object_database *
257
kh_value(odb->source_by_path, pos) = alternate;
258
259
/* recursively add alternates */
260
- read_info_alternates(alternate->path, &sources);
260
+ odb_source_read_alternates(alternate, &sources);
261
if (sources.nr && depth + 1 > 5) {
262
error(_("%s: ignoring alternate object stores, nesting too deep"),
263
source);
@@ -599,7 +599,7 @@ void odb_prepare_alternates(struct object_database *odb)
599
return;
600
601
parse_alternates(odb->alternate_db, PATH_SEP, NULL, &sources);
602
- read_info_alternates(odb->sources->path, &sources);
602
+ odb_source_read_alternates(odb->sources, &sources);
603
for (size_t i = 0; i < sources.nr; i++)
604
odb_add_alternate_recursively(odb, sources.v[i], 0);
605