odb/source-loose: drop `odb_source_loose_has_object()`

The function `odb_source_loose_has_object()` checks whether a specific object exists as a loose object on disk by using lstat(3p). This interface is somewhat redundant, as we typically check for object existence in a generic way via `odb_source_read_object_info()`. In fact, these two calls are redundant in case the latter is called in a specific way: when called without an object info request and without the `OBJECT_INFO_QUICK` flag, then we will end up doing the same call to lstat(3p) in `read_object_info_from_path()`. Drop the function and adapt callers to instead use the generic interface so that its calling conventions align with that of other sources. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Jun 1, 2026 at 10:20 UTC 86f7ab5a1f12ecfdf51b6df0b9b014e2329944be
3 files changed +12 -20
builtin/pack-objects.c
+8 -4
@@ -1750,9 +1750,11 @@ static int want_object_in_pack_mtime(const struct object_id *oid,
1750 * skip the local object source.
1751 */
1752 struct odb_source *source = the_repository->objects->sources->next;
1753 - for (; source; source = source->next)
1754 - if (odb_source_loose_has_object(source, oid))
1753 + for (; source; source = source->next) {
1754 + struct odb_source_files *files = odb_source_files_downcast(source);
1755 + if (!odb_source_read_object_info(&files->loose->base, oid, NULL, 0))
1756 return 0;
1757 + }
1758 }
1759
1760 /*
@@ -4135,9 +4137,11 @@ static void add_cruft_object_entry(const struct object_id *oid, enum object_type
4137 struct odb_source *source = the_repository->objects->sources;
4138 int found = 0;
4139
4138 - for (; !found && source; source = source->next)
4139 - if (odb_source_loose_has_object(source, oid))
4140 + for (; !found && source; source = source->next) {
4141 + struct odb_source_files *files = odb_source_files_downcast(source);
4142 + if (!odb_source_read_object_info(&files->loose->base, oid, NULL, 0))
4143 found = 1;
4144 + }
4145
4146 /*
4147 * If a traversed tree has a missing blob then we want
object-file.c
+4 -8
@@ -96,12 +96,6 @@ static int check_and_freshen_source(struct odb_source *source,
96 return check_and_freshen_file(path.buf, freshen);
97 }
98
99 -int odb_source_loose_has_object(struct odb_source *source,
100 - const struct object_id *oid)
101 -{
102 - return check_and_freshen_source(source, oid, 0);
103 -}
104 -
99 int format_object_header(char *str, size_t size, enum object_type type,
100 size_t objsize)
101 {
@@ -1000,9 +994,11 @@ int force_object_loose(struct odb_source *source,
994 int hdrlen;
995 int ret;
996
1003 - for (struct odb_source *s = source->odb->sources; s; s = s->next)
1004 - if (odb_source_loose_has_object(s, oid))
997 + for (struct odb_source *s = source->odb->sources; s; s = s->next) {
998 + struct odb_source_files *files = odb_source_files_downcast(s);
999 + if (!odb_source_read_object_info(&files->loose->base, oid, NULL, 0))
1000 return 0;
1001 + }
1002
1003 oi.typep = &type;
1004 oi.sizep = &len;
object-file.h
-8
@@ -23,14 +23,6 @@ int index_path(struct index_state *istate, struct object_id *oid, const char *pa
23 struct object_info;
24 struct odb_source;
25
26 -/*
27 - * Return true iff an object database source has a loose object
28 - * with the specified name. This function does not respect replace
29 - * references.
30 - */
31 -int odb_source_loose_has_object(struct odb_source *source,
32 - const struct object_id *oid);
33 -
26 int odb_source_loose_freshen_object(struct odb_source *source,
27 const struct object_id *oid);
28