Re: [PATCH 1/7] odb/streaming: track write stream size in the structure

Justin Tobler <[email protected]> Tue, 4 Aug 2026 11:47:48 -0500
Newsgroups org.kernel.vger.git
Message-ID <anIWUKV8iBFkT7g9@denethor>
On 26/08/04 09:25AM, Patrick Steinhardt wrote:
> When passing around a `struct odb_write_stream` we typically also have
> to pass the number of bytes that the stream will yield. This is required
> because the object header itself contains that size, and consequently we
> cannot write the header without that information.
> 
> Move this information into the stream itself so that it becomes self-
> describing. In addition to that, this also brings the `struct
> odb_write_stream` a bit closer to the `struct odb_read_stream` so that
> we can eventually merge both stream types.

Storing the object size in the stream directly makes complete sense.

> Signed-off-by: Patrick Steinhardt <[email protected]>
> ---
>  builtin/unpack-objects.c      |  3 ++-
>  object-file.c                 | 25 +++++++++++--------------
>  odb.c                         |  4 ++--
>  odb.h                         |  2 +-
>  odb/source-files.c            |  3 +--
>  odb/source-inmemory.c         | 11 +++++------
>  odb/source-loose.c            |  7 +++----
>  odb/source-packed.c           |  1 -
>  odb/source.h                  |  5 ++---
>  odb/streaming.c               |  1 +
>  odb/streaming.h               |  1 +
>  odb/transaction.c             |  4 ++--
>  odb/transaction.h             |  4 ++--
>  t/unit-tests/u-odb-inmemory.c | 11 +++++------
>  14 files changed, 38 insertions(+), 44 deletions(-)
> 
[snip]
> diff --git a/odb/streaming.h b/odb/streaming.h
> index c023671780..4d7d31b5aa 100644
> --- a/odb/streaming.h
> +++ b/odb/streaming.h
> @@ -55,6 +55,7 @@ ssize_t odb_read_stream_read(struct odb_read_stream *stream, void *buf, size_t l
>  struct odb_write_stream {
>  	ssize_t (*read)(struct odb_write_stream *, unsigned char *, size_t);
>  	void *data;
> +	size_t size;
>  	int is_finished;
>  };

The size is now stored directly in the stream, the rest of this patch is
adjusting callers to use the embedded size information instead of
passing it. Looks good.

-Justin