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

[PATCH 14/17] odb/source: make `write_object_stream()` function pluggable

From: Patrick Steinhardt <hidden>
Date: 2026-02-23 16:18:48
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.c              |  2 +-
 odb/source-files.c |  9 +++++++++
 odb/source.h       | 28 ++++++++++++++++++++++++++++
 3 files changed, 38 insertions(+), 1 deletion(-)
diff --git a/odb.c b/odb.c
index 5eb60063dc..f439de9db2 100644
--- a/odb.c
+++ b/odb.c
@@ -1013,7 +1013,7 @@ int odb_write_object_stream(struct object_database *odb,
 			    struct odb_write_stream *stream, size_t len,
 			    struct object_id *oid)
 {
-	return odb_source_loose_write_stream(odb->sources, stream, len, oid);
+	return odb_source_write_object_stream(odb->sources, stream, len, oid);
 }
 
 struct object_database *odb_new(struct repository *repo,
diff --git a/odb/source-files.c b/odb/source-files.c
index 67c2aff659..b8844f11b7 100644
--- a/odb/source-files.c
+++ b/odb/source-files.c
@@ -109,6 +109,14 @@ static int odb_source_files_write_object(struct odb_source *source,
 					     oid, compat_oid, flags);
 }
 
+static int odb_source_files_write_object_stream(struct odb_source *source,
+						struct odb_write_stream *stream,
+						size_t len,
+						struct object_id *oid)
+{
+	return odb_source_loose_write_stream(source, stream, len, oid);
+}
+
 struct odb_source_files *odb_source_files_new(struct object_database *odb,
 					      const char *path,
 					      bool local)
@@ -128,6 +136,7 @@ struct odb_source_files *odb_source_files_new(struct object_database *odb,
 	files->base.for_each_object = odb_source_files_for_each_object;
 	files->base.freshen_object = odb_source_files_freshen_object;
 	files->base.write_object = odb_source_files_write_object;
+	files->base.write_object_stream = odb_source_files_write_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 a6ef7f782c..ddce43eb20 100644
--- a/odb/source.h
+++ b/odb/source.h
@@ -54,6 +54,7 @@ enum object_info_flags {
 struct object_id;
 struct object_info;
 struct odb_read_stream;
+struct odb_write_stream;
 
 /*
  * A callback function that can be used to iterate through objects. If given,
@@ -216,6 +217,18 @@ struct odb_source {
 			    struct object_id *oid,
 			    struct object_id *compat_oid,
 			    unsigned flags);
+
+	/*
+	 * This callback is expected to persist the given object stream into
+	 * the object source.
+	 *
+	 * The resulting object ID shall be written into the out pointer. The
+	 * callback is expected to return 0 on success, a negative error code
+	 * otherwise.
+	 */
+	int (*write_object_stream)(struct odb_source *source,
+				   struct odb_write_stream *stream, size_t len,
+				   struct object_id *oid);
 };
 
 /*
@@ -351,4 +364,19 @@ static inline int odb_source_write_object(struct odb_source *source,
 				    compat_oid, flags);
 }
 
+/*
+ * Write an object into the object database source via a stream. The overall
+ * length of the object must be known in advance.
+ *
+ * Return 0 on success, a negative error code otherwise. Populates the given
+ * out pointer for the object ID.
+ */
+static inline int odb_source_write_object_stream(struct odb_source *source,
+						 struct odb_write_stream *stream,
+						 size_t len,
+						 struct object_id *oid)
+{
+	return source->write_object_stream(source, stream, len, oid);
+}
+
 #endif
-- 
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