]> Kevux Git Server - rit/commitdiff
odb/source: make `read_object_stream()` function pluggable
authorPatrick Steinhardt <ps@pks.im>
Thu, 5 Mar 2026 14:19:50 +0000 (15:19 +0100)
committerJunio C Hamano <gitster@pobox.com>
Thu, 5 Mar 2026 19:45:16 +0000 (11:45 -0800)
Introduce a new callback function in `struct odb_source` to make the
function pluggable.

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

index f2969a1214c8f726db671bf262cd3c7a515ece4e..b50a1f54926f1d82702a36462992232d5fb49e18 100644 (file)
@@ -55,6 +55,17 @@ static int odb_source_files_read_object_info(struct odb_source *source,
        return -1;
 }
 
+static int odb_source_files_read_object_stream(struct odb_read_stream **out,
+                                              struct odb_source *source,
+                                              const struct object_id *oid)
+{
+       struct odb_source_files *files = odb_source_files_downcast(source);
+       if (!packfile_store_read_object_stream(out, files->packed, oid) ||
+           !odb_source_loose_read_object_stream(out, source, oid))
+               return 0;
+       return -1;
+}
+
 struct odb_source_files *odb_source_files_new(struct object_database *odb,
                                              const char *path,
                                              bool local)
@@ -70,6 +81,7 @@ struct odb_source_files *odb_source_files_new(struct object_database *odb,
        files->base.close = odb_source_files_close;
        files->base.reprepare = odb_source_files_reprepare;
        files->base.read_object_info = odb_source_files_read_object_info;
+       files->base.read_object_stream = odb_source_files_read_object_stream;
 
        /*
         * Ideally, we would only ever store absolute paths in the source. This
index 150becafe6ce379b79d514988accc7b098e32908..4397cada27861a4fadae1a7692022a2042f55883 100644 (file)
@@ -50,6 +50,7 @@ enum object_info_flags {
 
 struct object_id;
 struct object_info;
+struct odb_read_stream;
 
 /*
  * The source is the part of the object database that stores the actual
@@ -138,6 +139,17 @@ struct odb_source {
                                const struct object_id *oid,
                                struct object_info *oi,
                                enum object_info_flags flags);
+
+       /*
+        * This callback is expected to create a new read stream that can be
+        * used to stream the object identified by the given ID.
+        *
+        * The callback is expected to return a negative error code in case
+        * creating the object stream has failed, 0 otherwise.
+        */
+       int (*read_object_stream)(struct odb_read_stream **out,
+                                 struct odb_source *source,
+                                 const struct object_id *oid);
 };
 
 /*
@@ -209,4 +221,15 @@ static inline int odb_source_read_object_info(struct odb_source *source,
        return source->read_object_info(source, oid, oi, flags);
 }
 
+/*
+ * Create a new read stream for the given object ID. Returns 0 on success, a
+ * negative error code otherwise.
+ */
+static inline int odb_source_read_object_stream(struct odb_read_stream **out,
+                                               struct odb_source *source,
+                                               const struct object_id *oid)
+{
+       return source->read_object_stream(out, source, oid);
+}
+
 #endif
index 19cda9407d1ce3d3a915065df32eda3176f3af6d..a4355cd2458c3856d847da3b46be291fcffb8b61 100644 (file)
@@ -6,11 +6,9 @@
 #include "convert.h"
 #include "environment.h"
 #include "repository.h"
-#include "object-file.h"
 #include "odb.h"
 #include "odb/streaming.h"
 #include "replace-object.h"
-#include "packfile.h"
 
 #define FILTER_BUFFER (1024*16)
 
@@ -186,12 +184,9 @@ static int istream_source(struct odb_read_stream **out,
        struct odb_source *source;
 
        odb_prepare_alternates(odb);
-       for (source = odb->sources; source; source = source->next) {
-               struct odb_source_files *files = odb_source_files_downcast(source);
-               if (!packfile_store_read_object_stream(out, files->packed, oid) ||
-                   !odb_source_loose_read_object_stream(out, source, oid))
+       for (source = odb->sources; source; source = source->next)
+               if (!odb_source_read_object_stream(out, source, oid))
                        return 0;
-       }
 
        return open_istream_incore(out, odb, oid);
 }