object-file: read objects via the loose object source

When reading an object via `loose_object_info()` or `map_loose_object()`
we hand in the whole repository. We then iterate through each of the
object sources to figure out whether that source has the object in
question.

This logic is reversing responsibility though: a specific backend should
only care about one specific source, where the object sources themselves
are then managed by the object database.

Refactor the code accordingly by passing an object source to both of
these functions instead. The different sources are then handled by
either `do_oid_object_info_extended()`, which sits on the object
database level, and by `open_istream_loose()`. The latter function
arguably is still at the wrong level, but this will be cleaned up at a
later point in time.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Patrick Steinhardt
2025-11-03 08:42:04 +01:00
committed by Junio C Hamano
parent 376016ec71
commit ff7ad5cb39
4 changed files with 50 additions and 53 deletions

9
odb.c
View File

@@ -697,13 +697,18 @@ static int do_oid_object_info_extended(struct object_database *odb,
return 0;
}
odb_prepare_alternates(odb);
while (1) {
struct odb_source *source;
if (find_pack_entry(odb->repo, real, &e))
break;
/* Most likely it's a loose object. */
if (!loose_object_info(odb->repo, real, oi, flags))
return 0;
for (source = odb->sources; source; source = source->next)
if (!odb_source_loose_read_object_info(source, real, oi, flags))
return 0;
/* Not a loose object; someone else may have just packed it. */
if (!(flags & OBJECT_INFO_QUICK)) {