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>
This commit is contained in:
Patrick Steinhardt
2026-06-01 10:20:34 +02:00
committed by Junio C Hamano
parent 2ade08ac29
commit 86f7ab5a1f
3 changed files with 12 additions and 20 deletions

View File

@@ -1750,9 +1750,11 @@ static int want_object_in_pack_mtime(const struct object_id *oid,
* skip the local object source.
*/
struct odb_source *source = the_repository->objects->sources->next;
for (; source; source = source->next)
if (odb_source_loose_has_object(source, oid))
for (; source; source = source->next) {
struct odb_source_files *files = odb_source_files_downcast(source);
if (!odb_source_read_object_info(&files->loose->base, oid, NULL, 0))
return 0;
}
}
/*
@@ -4135,9 +4137,11 @@ static void add_cruft_object_entry(const struct object_id *oid, enum object_type
struct odb_source *source = the_repository->objects->sources;
int found = 0;
for (; !found && source; source = source->next)
if (odb_source_loose_has_object(source, oid))
for (; !found && source; source = source->next) {
struct odb_source_files *files = odb_source_files_downcast(source);
if (!odb_source_read_object_info(&files->loose->base, oid, NULL, 0))
found = 1;
}
/*
* If a traversed tree has a missing blob then we want

View File

@@ -96,12 +96,6 @@ static int check_and_freshen_source(struct odb_source *source,
return check_and_freshen_file(path.buf, freshen);
}
int odb_source_loose_has_object(struct odb_source *source,
const struct object_id *oid)
{
return check_and_freshen_source(source, oid, 0);
}
int format_object_header(char *str, size_t size, enum object_type type,
size_t objsize)
{
@@ -1000,9 +994,11 @@ int force_object_loose(struct odb_source *source,
int hdrlen;
int ret;
for (struct odb_source *s = source->odb->sources; s; s = s->next)
if (odb_source_loose_has_object(s, oid))
for (struct odb_source *s = source->odb->sources; s; s = s->next) {
struct odb_source_files *files = odb_source_files_downcast(s);
if (!odb_source_read_object_info(&files->loose->base, oid, NULL, 0))
return 0;
}
oi.typep = &type;
oi.sizep = &len;

View File

@@ -23,14 +23,6 @@ int index_path(struct index_state *istate, struct object_id *oid, const char *pa
struct object_info;
struct odb_source;
/*
* Return true iff an object database source has a loose object
* with the specified name. This function does not respect replace
* references.
*/
int odb_source_loose_has_object(struct odb_source *source,
const struct object_id *oid);
int odb_source_loose_freshen_object(struct odb_source *source,
const struct object_id *oid);