]> git.ipfire.org Git - thirdparty/git.git/commitdiff
odb/source-loose: drop `odb_source_loose_has_object()`
authorPatrick Steinhardt <ps@pks.im>
Thu, 21 May 2026 08:22:31 +0000 (10:22 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 21 May 2026 13:35:19 +0000 (22:35 +0900)
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>
builtin/pack-objects.c
object-file.c
object-file.h

index 480cc0bd8c8d227caa875e9a2293c9df73f6f547..a6be3d659f8e36498e5d6aee7625c11057467172 100644 (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
index 9b2044de3784e61c15a663f5934c7f3550073f55..c83136cf70024c5a3e3d186e02d9626486a025dd 100644 (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;
index bc72d89f54891553ac618b2b8fb34868028ff7db..506ca6be40b7499e0a1d6d1d5bf7d06eb8fd3e1f 100644 (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);