git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 8/8] odb/streaming: unify function names to create new streams

From
Patrick Steinhardt <ps@pks.im>
Date
Aug 5, 2026, 07:44 UTC
Message-ID
<20260805-pks-odb-stream-unification-v2-8-b8c369564641@pks.im>
In-Reply-To
<20260805-pks-odb-stream-unification-v2-0-b8c369564641@pks.im>

Unify the function names to create new streams from different sources so that they follow a common schema. While at it, document the ownership of the file descriptor passed to `odb_stream_from_fd()`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 archive-tar.c          |  2 +-
 archive-zip.c          |  2 +-
 builtin/index-pack.c   |  2 +-
 builtin/pack-objects.c |  4 ++--
 object-file.c          |  4 ++--
 object.c               |  2 +-
 odb/streaming.c        | 10 +++++-----
 odb/streaming.h        | 23 +++++++++++++----------
 8 files changed, 26 insertions(+), 23 deletions(-)
diff --git a/archive-tar.c b/archive-tar.c
index df2d7fb8e9..a1c66024d4 100644
--- a/archive-tar.c
+++ b/archive-tar.c
@@ -133,7 +133,7 @@ static int stream_blocked(struct repository *r, const struct object_id *oid)
 	char buf[BLOCKSIZE];
 	ssize_t readlen;
 
-	st = odb_read_stream_open(r->objects, oid, NULL);
+	st = odb_stream_from_object(r->objects, oid, NULL);
 	if (!st)
 		return error(_("cannot stream blob %s"), oid_to_hex(oid));
 	for (;;) {
diff --git a/archive-zip.c b/archive-zip.c
index 8095fd04d5..1a948c2f83 100644
--- a/archive-zip.c
+++ b/archive-zip.c
@@ -347,7 +347,7 @@ static int write_zip_entry(struct archiver_args *args,
 			method = ZIP_METHOD_DEFLATE;
 
 		if (!buffer) {
-			stream = odb_read_stream_open(args->repo->objects, oid, NULL);
+			stream = odb_stream_from_object(args->repo->objects, oid, NULL);
 			if (!stream)
 				return error(_("cannot stream blob %s"),
 					     oid_to_hex(oid));
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 7226da3e65..d1761282db 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -806,7 +806,7 @@ static int check_collison(struct object_entry *entry)
 
 	memset(&data, 0, sizeof(data));
 	data.entry = entry;
-	data.st = odb_read_stream_open(the_repository->objects, &entry->idx.oid, NULL);
+	data.st = odb_stream_from_object(the_repository->objects, &entry->idx.oid, NULL);
 	if (!data.st)
 		return -1;
 	if (data.st->size != entry->size || data.st->type != entry->type)
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 683160c6bb..10d00ca792 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -528,8 +528,8 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent
 		if (oe_type(entry) == OBJ_BLOB &&
 		    oe_size_greater_than(&to_pack, entry,
 					 repo_settings_get_big_file_threshold(the_repository)) &&
-		    (st = odb_read_stream_open(the_repository->objects, &entry->idx.oid,
-					       NULL)) != NULL) {
+		    (st = odb_stream_from_object(the_repository->objects, &entry->idx.oid,
+						 NULL)) != NULL) {
 			buf = NULL;
 			type = st->type;
 			size = st->size;
diff --git a/object-file.c b/object-file.c
index 068c6e5672..11d1af342e 100644
--- a/object-file.c
+++ b/object-file.c
@@ -952,8 +952,8 @@ int index_fd(struct index_state *istate, struct object_id *oid,
 		ret = index_core(istate, oid, fd, xsize_t(st->st_size),
 				 type, path, flags);
 	} else {
-		struct odb_stream *stream = odb_write_stream_from_fd(fd, xsize_t(st->st_size),
-								     OBJ_BLOB);
+		struct odb_stream *stream = odb_stream_from_fd(fd, xsize_t(st->st_size),
+							       OBJ_BLOB);
 
 		if (flags & INDEX_WRITE_OBJECT) {
 			struct object_database *odb = the_repository->objects;
diff --git a/object.c b/object.c
index 37e6efee47..97f7fc0e87 100644
--- a/object.c
+++ b/object.c
@@ -345,7 +345,7 @@ struct object *parse_object_with_flags(struct repository *r,
 	if ((!obj || obj->type == OBJ_NONE || obj->type == OBJ_BLOB) &&
 	    odb_read_object_info(r->objects, oid, NULL) == OBJ_BLOB) {
 		if (!skip_hash) {
-			struct odb_stream *stream = odb_read_stream_open(r->objects, oid, NULL);
+			struct odb_stream *stream = odb_stream_from_object(r->objects, oid, NULL);
 
 			if (!stream) {
 				error(_("unable to open object stream for %s"), oid_to_hex(oid));
diff --git a/odb/streaming.c b/odb/streaming.c
index c436b18d39..9c85ec54f5 100644
--- a/odb/streaming.c
+++ b/odb/streaming.c
@@ -208,9 +208,9 @@ ssize_t odb_stream_read(struct odb_stream *st, void *buf, size_t sz)
 	return st->read(st, buf, sz);
 }
 
-struct odb_stream *odb_read_stream_open(struct object_database *odb,
-					const struct object_id *oid,
-					struct stream_filter *filter)
+struct odb_stream *odb_stream_from_object(struct object_database *odb,
+					  const struct object_id *oid,
+					  struct stream_filter *filter)
 {
 	struct odb_stream *st;
 	const struct object_id *real = lookup_replace_object(odb->repo, oid);
@@ -242,7 +242,7 @@ int odb_stream_blob_to_fd(struct object_database *odb,
 	ssize_t kept = 0;
 	int result = -1;
 
-	st = odb_read_stream_open(odb, oid, filter);
+	st = odb_stream_from_object(odb, oid, filter);
 	if (!st) {
 		if (filter)
 			free_stream_filter(filter);
@@ -320,7 +320,7 @@ static int fd_stream_close(struct odb_stream *stream UNUSED)
 	return 0;
 }
 
-struct odb_stream *odb_write_stream_from_fd(int fd, size_t size, enum object_type type)
+struct odb_stream *odb_stream_from_fd(int fd, size_t size, enum object_type type)
 {
 	struct fd_stream *fds;
 
diff --git a/odb/streaming.h b/odb/streaming.h
index 60b9803190..b522ff513f 100644
--- a/odb/streaming.h
+++ b/odb/streaming.h
@@ -26,14 +26,22 @@ struct odb_stream {
 };
 
 /*
- * Create a new object stream for the given object database. An optional filter
- * can be used to transform the object's content.
+ * Create a new object stream for the given object. An optional filter can be
+ * used to transform the object's content.
  *
  * Returns the stream on success, a `NULL` pointer otherwise.
  */
-struct odb_stream *odb_read_stream_open(struct object_database *odb,
-					const struct object_id *oid,
-					struct stream_filter *filter);
+struct odb_stream *odb_stream_from_object(struct object_database *odb,
+					  const struct object_id *oid,
+					  struct stream_filter *filter);
+
+/*
+ * Create a new object stream for the given file descriptor. This can be used
+ * to, for example, stream an object into the object database. This function
+ * does _not_ take ownership of the file descriptor. It's the responsibility of
+ * the caller to close it after the stream has been closed.
+ */
+struct odb_stream *odb_stream_from_fd(int fd, size_t size, enum object_type type);
 
 /*
  * Close the given object stream and release all resources associated with it.
@@ -65,9 +73,4 @@ int odb_stream_blob_to_fd(struct object_database *odb,
 			  struct stream_filter *filter,
 			  int can_seek);
 
-/*
- * Sets up an ODB write stream that reads from an fd.
- */
-struct odb_stream *odb_write_stream_from_fd(int fd, size_t size, enum object_type type);
-
 #endif /* STREAMING_H */
-- 
2.55.0.679.g6767b8d81c.dirty
Previous: Patrick SteinhardtNext: Karthik Nayak
Message 30 of 33 in “odb: unify read and write streams”
  1. 0/7 odb: unify read and write streamsPatrick Steinhardt, Aug 4, 2026
  2. 1/7 odb/streaming: track write stream size in the structurePatrick Steinhardt, Aug 4, 2026
  3. Justin ToblerAug 4, 2026
  4. 2/7 odb/streaming: drop `is_finished` fieldPatrick Steinhardt, Aug 4, 2026
  5. Justin ToblerAug 4, 2026
  6. 3/7 odb/streaming: support streaming arbitrary object typesPatrick Steinhardt, Aug 4, 2026
  7. Justin ToblerAug 4, 2026
  8. Patrick SteinhardtAug 5, 2026
  9. Junio C HamanoAug 4, 2026
  10. Patrick SteinhardtAug 5, 2026
  11. 4/7 odb/streaming: rename `struct odb_read_stream`Patrick Steinhardt, Aug 4, 2026
  12. 5/7 odb/streaming: consolidate read and write streamsPatrick Steinhardt, Aug 4, 2026
  13. Justin ToblerAug 4, 2026
  14. Patrick SteinhardtAug 5, 2026
  15. 6/7 odb/streaming: rename `struct read_object_fd_data`Patrick Steinhardt, Aug 4, 2026
  16. Justin ToblerAug 4, 2026
  17. 7/7 odb/streaming: unify function names to create new streamsPatrick Steinhardt, Aug 4, 2026
  18. Justin ToblerAug 4, 2026
  19. 0/8 odb: unify read and write streamsPatrick Steinhardt, Aug 5, 2026
  20. 1/8 odb/streaming: track write stream size in the structurePatrick Steinhardt, Aug 5, 2026
  21. Karthik NayakAug 11, 2026
  22. 2/8 odb/streaming: drop `is_finished` fieldPatrick Steinhardt, Aug 5, 2026
  23. Karthik NayakAug 11, 2026
  24. 3/8 odb/streaming: support streaming arbitrary object typesPatrick Steinhardt, Aug 5, 2026
  25. 4/8 odb/streaming: rename `struct odb_read_stream`Patrick Steinhardt, Aug 5, 2026
  26. 5/8 odb/streaming: consolidate read and write streamsPatrick Steinhardt, Aug 5, 2026
  27. Karthik NayakAug 11, 2026
  28. 6/8 odb/streaming: rename `struct read_object_fd_data`Patrick Steinhardt, Aug 5, 2026
  29. 7/8 odb/streaming: rename `struct input_zstream_data`Patrick Steinhardt, Aug 5, 2026
  30. 8/8 odb/streaming: unify function names to create new streamsPatrick Steinhardt, Aug 5, 2026
  31. Karthik NayakAug 11, 2026
  32. Patrick SteinhardtAug 11, 2026
  33. Justin ToblerAug 11, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.