Thread (73 messages) 73 messages, 3 authors, 2026-03-05
STALE104d

[PATCH 10/17] odb/source: make `read_object_stream()` function pluggable

From: Patrick Steinhardt <hidden>
Date: 2026-02-23 16:18:35
Subsystem: the rest · Maintainer: Linus Torvalds

Introduce a new callback function in `struct odb_source` to make the
function pluggable.

Signed-off-by: Patrick Steinhardt <redacted>
---
 odb/source-files.c | 12 ++++++++++++
 odb/source.h       | 23 +++++++++++++++++++++++
 odb/streaming.c    |  9 ++-------
 3 files changed, 37 insertions(+), 7 deletions(-)
diff --git a/odb/source-files.c b/odb/source-files.c
index f2969a1214..b50a1f5492 100644
--- a/odb/source-files.c
+++ b/odb/source-files.c
@@ -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
diff --git a/odb/source.h b/odb/source.h
index 45563de61e..edb425fdef 100644
--- a/odb/source.h
+++ b/odb/source.h
@@ -51,6 +51,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
@@ -139,6 +140,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);
 };
 
 /*
@@ -210,4 +222,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
diff --git a/odb/streaming.c b/odb/streaming.c
index 19cda9407d..a4355cd245 100644
--- a/odb/streaming.c
+++ b/odb/streaming.c
@@ -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);
 }
-- 
2.53.0.536.g309c995771.dirty
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help