]> git.ipfire.org Git - thirdparty/git.git/commitdiff
odb/source-loose: wire up `read_object_info()` callback
authorPatrick Steinhardt <ps@pks.im>
Thu, 21 May 2026 08:22:26 +0000 (10:22 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 21 May 2026 13:35:19 +0000 (22:35 +0900)
Move `odb_source_loose_read_object_info()` from "object-file.c" into
"odb/source-loose.c" and wire it up as the `read_object_info()` callback
of the loose source. Callers that previously invoked it directly now go
through the generic `odb_source_read_object_info()` interface instead.

The function `read_object_info_from_path()` cannot be moved along with
it because it is still called by `for_each_object_wrapper_cb()`. It is
therefore kept in place, but adjusted to take a loose source to clarify
that it's always operating on this structure.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
object-file.c
object-file.h
odb/source-files.c
odb/source-loose.c

index 0f4f1e7bdc0733c48bb2b14024a8de0073c0a603..fa174512a43c75994b9364347b8bace64ae69bb3 100644 (file)
@@ -396,13 +396,12 @@ static int parse_loose_header(const char *hdr, struct object_info *oi)
        return 0;
 }
 
-static int read_object_info_from_path(struct odb_source *source,
-                                     const char *path,
-                                     const struct object_id *oid,
-                                     struct object_info *oi,
-                                     enum object_info_flags flags)
+int read_object_info_from_path(struct odb_source_loose *loose,
+                              const char *path,
+                              const struct object_id *oid,
+                              struct object_info *oi,
+                              enum object_info_flags flags)
 {
-       struct odb_source_files *files = odb_source_files_downcast(source);
        int ret;
        int fd;
        unsigned long mapsize;
@@ -425,7 +424,7 @@ static int read_object_info_from_path(struct odb_source *source,
                struct stat st;
 
                if ((!oi || (!oi->disk_sizep && !oi->mtimep)) && (flags & OBJECT_INFO_QUICK)) {
-                       ret = quick_has_loose(files->loose, oid) ? 0 : -1;
+                       ret = quick_has_loose(loose, oid) ? 0 : -1;
                        goto out;
                }
 
@@ -532,7 +531,7 @@ out:
                if (oi->typep == &type_scratch)
                        oi->typep = NULL;
                if (oi->delta_base_oid)
-                       oidclr(oi->delta_base_oid, source->odb->repo->hash_algo);
+                       oidclr(oi->delta_base_oid, loose->base.odb->repo->hash_algo);
                if (!ret)
                        oi->whence = OI_LOOSE;
        }
@@ -540,26 +539,6 @@ out:
        return ret;
 }
 
-int odb_source_loose_read_object_info(struct odb_source *source,
-                                     const struct object_id *oid,
-                                     struct object_info *oi,
-                                     enum object_info_flags flags)
-{
-       static struct strbuf buf = STRBUF_INIT;
-
-       /*
-        * The second read shouldn't cause new loose objects to show up, unless
-        * there was a race condition with a secondary process. We don't care
-        * about this case though, so we simply skip reading loose objects a
-        * second time.
-        */
-       if (flags & OBJECT_INFO_SECOND_READ)
-               return -1;
-
-       odb_loose_path(source, &buf, oid);
-       return read_object_info_from_path(source, buf.buf, oid, oi, flags);
-}
-
 static void hash_object_body(const struct git_hash_algo *algo, struct git_hash_ctx *c,
                             const void *buf, unsigned long len,
                             struct object_id *oid,
@@ -1833,7 +1812,7 @@ int for_each_loose_file_in_source(struct odb_source *source,
 }
 
 struct for_each_object_wrapper_data {
-       struct odb_source *source;
+       struct odb_source_loose *loose;
        const struct object_info *request;
        odb_for_each_object_cb cb;
        void *cb_data;
@@ -1848,7 +1827,7 @@ static int for_each_object_wrapper_cb(const struct object_id *oid,
        if (data->request) {
                struct object_info oi = *data->request;
 
-               if (read_object_info_from_path(data->source, path, oid, &oi, 0) < 0)
+               if (read_object_info_from_path(data->loose, path, oid, &oi, 0) < 0)
                        return -1;
 
                return data->cb(oid, &oi, data->cb_data);
@@ -1865,8 +1844,8 @@ static int for_each_prefixed_object_wrapper_cb(const struct object_id *oid,
        if (data->request) {
                struct object_info oi = *data->request;
 
-               if (odb_source_loose_read_object_info(data->source,
-                                                     oid, &oi, 0) < 0)
+               if (odb_source_read_object_info(&data->loose->base,
+                                               oid, &oi, 0) < 0)
                        return -1;
 
                return data->cb(oid, &oi, data->cb_data);
@@ -1881,8 +1860,9 @@ int odb_source_loose_for_each_object(struct odb_source *source,
                                     void *cb_data,
                                     const struct odb_for_each_object_options *opts)
 {
+       struct odb_source_files *files = odb_source_files_downcast(source);
        struct for_each_object_wrapper_data data = {
-               .source = source,
+               .loose = files->loose,
                .request = request,
                .cb = cb,
                .cb_data = cb_data,
index 420a0fff2e7d7eb25029a686d2cbbbf99eeac3a3..8ac2832dac34395a0fc6aa7014cd019bb7b17233 100644 (file)
@@ -21,11 +21,6 @@ struct object_info;
 struct odb_read_stream;
 struct odb_source;
 
-int odb_source_loose_read_object_info(struct odb_source *source,
-                                     const struct object_id *oid,
-                                     struct object_info *oi,
-                                     enum object_info_flags flags);
-
 int odb_source_loose_read_object_stream(struct odb_read_stream **out,
                                        struct odb_source *source,
                                        const struct object_id *oid);
@@ -198,6 +193,12 @@ int read_loose_object(struct repository *repo,
                      void **contents,
                      struct object_info *oi);
 
+int read_object_info_from_path(struct odb_source_loose *loose,
+                              const char *path,
+                              const struct object_id *oid,
+                              struct object_info *oi,
+                              enum object_info_flags flags);
+
 struct odb_transaction;
 
 /*
index 59e3a70d80d3554624437bf93955c5dec3d6268a..8d6924755ffb70dee49213c9a223f4331c10cecf 100644 (file)
@@ -55,7 +55,7 @@ static int odb_source_files_read_object_info(struct odb_source *source,
        struct odb_source_files *files = odb_source_files_downcast(source);
 
        if (!packfile_store_read_object_info(files->packed, oid, oi, flags) ||
-           !odb_source_loose_read_object_info(source, oid, oi, flags))
+           !odb_source_read_object_info(&files->loose->base, oid, oi, flags))
                return 0;
 
        return -1;
index 65c1076659b8fd95341ca6b3203724eb1716c76e..50f387ecf31e385f8ad2e65e1743fd5d809e8ba1 100644 (file)
@@ -2,10 +2,33 @@
 #include "abspath.h"
 #include "chdir-notify.h"
 #include "loose.h"
+#include "object-file.h"
 #include "odb.h"
 #include "odb/source-files.h"
 #include "odb/source-loose.h"
 #include "oidtree.h"
+#include "strbuf.h"
+
+static int odb_source_loose_read_object_info(struct odb_source *source,
+                                            const struct object_id *oid,
+                                            struct object_info *oi,
+                                            enum object_info_flags flags)
+{
+       struct odb_source_loose *loose = odb_source_loose_downcast(source);
+       static struct strbuf buf = STRBUF_INIT;
+
+       /*
+        * The second read shouldn't cause new loose objects to show up, unless
+        * there was a race condition with a secondary process. We don't care
+        * about this case though, so we simply skip reading loose objects a
+        * second time.
+        */
+       if (flags & OBJECT_INFO_SECOND_READ)
+               return -1;
+
+       odb_loose_path(source, &buf, oid);
+       return read_object_info_from_path(loose, buf.buf, oid, oi, flags);
+}
 
 static void odb_source_loose_clear_cache(struct odb_source_loose *loose)
 {
@@ -60,6 +83,7 @@ struct odb_source_loose *odb_source_loose_new(struct odb_source_files *files)
        loose->base.free = odb_source_loose_free;
        loose->base.close = odb_source_loose_close;
        loose->base.reprepare = odb_source_loose_reprepare;
+       loose->base.read_object_info = odb_source_loose_read_object_info;
 
        if (!is_absolute_path(loose->base.path))
                chdir_notify_register(NULL, odb_source_loose_reparent, loose);