Git development
 help / color / mirror / Atom feed
From: Justin Tobler <jltobler@gmail.com>
To: Patrick Steinhardt <ps@pks.im>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 5/7] odb/streaming: consolidate read and write streams
Date: Tue, 4 Aug 2026 13:23:42 -0500	[thread overview]
Message-ID: <anIrtigj0L7PU2hl@denethor> (raw)
In-Reply-To: <20260804-pks-odb-stream-unification-v1-5-86d70e82345e@pks.im>

On 26/08/04 09:25AM, Patrick Steinhardt wrote:
> The `struct odb_read_stream` and `struct odb_write_stream` both provide
> the same functionality: they allow a caller to read object data from an
> arbitrary source. Historically, the only difference was that the read
> stream was used to read data out of the object database, whereas the
> write stream was used to write data into the object database, but the
> interfaces were mostly the same.

Ok.

> Over the preceding commits we have refactored the write stream to have
> almost exactly the same interface as the read stream. With these
> refactorings we can now easily merge those two streams into a single
> interface that's used for both use cases.

Nice.

> While most of the changes are mechanical, there are two sites that need
> special mention:
> 
>   - "builtin/unpack-objects.c" creates a write stream from compressed
>     object data.
> 
>   - "odb/streaming.c" creates a write stream from a file descriptor.
> 
> Adapting these sites to yield the new stream type requires a couple more
> changes. Most importantly, instead of embedding the pointer to the data
> in `struct odb_write_stream`, we now allocate a structure that wraps the
> new `struct odb_stream` base. Other than that though, the changes are
> rather straight forward.

Ok, creating wrapper stream types for these sounds reasonable.

> 
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
>  builtin/unpack-objects.c      | 31 ++++++++++++++++---------------
>  object-file.c                 | 25 ++++++++++++-------------
>  odb.c                         |  2 +-
>  odb.h                         |  4 ++--
>  odb/source-files.c            |  2 +-
>  odb/source-inmemory.c         |  4 ++--
>  odb/source-loose.c            |  6 +++---
>  odb/source-packed.c           |  2 +-
>  odb/source.h                  |  4 ++--
>  odb/streaming.c               | 35 ++++++++++++++++-------------------
>  odb/streaming.h               | 31 +++----------------------------
>  odb/transaction.c             |  2 +-
>  odb/transaction.h             |  4 ++--
>  t/unit-tests/u-odb-inmemory.c |  6 +++---
>  14 files changed, 65 insertions(+), 93 deletions(-)
> 
> diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
> index 7439ec53be..05a2d48011 100644
> --- a/builtin/unpack-objects.c
> +++ b/builtin/unpack-objects.c
> @@ -359,20 +359,21 @@ static void unpack_non_delta_entry(enum object_type type, unsigned long size,
>  }
>  
>  struct input_zstream_data {
> +	struct odb_stream base;
>  	git_zstream *zstream;
>  	int status;
>  };

Ok, as mentioned in the commit message, we now embed the stream instead
storing a pointer to the extra data. Should we also update the struct
name here now that `input_zstream_data` is really itself a stream?

> -static ssize_t feed_input_zstream(struct odb_write_stream *in_stream,
> -				  unsigned char *buf, size_t buf_len)
> +static ssize_t feed_input_zstream(struct odb_stream *in_stream,
> +				  char *buf, size_t buf_len)
>  {
> -	struct input_zstream_data *data = in_stream->data;
> +	struct input_zstream_data *data = container_of(in_stream, struct input_zstream_data, base);

Callback is updated to fetch data from the base stream.

>  	git_zstream *zstream = data->zstream;
>  
>  	if (data->status != Z_OK)
>  		return 0;
>  
> -	zstream->next_out = buf;
> +	zstream->next_out = (unsigned char *) buf;
>  	zstream->avail_out = buf_len;
>  
>  	while (data->status == Z_OK && zstream->avail_out == buf_len) {
> @@ -388,24 +389,24 @@ static ssize_t feed_input_zstream(struct odb_write_stream *in_stream,
>  static void stream_blob(unsigned long size, unsigned nr)
>  {
>  	git_zstream zstream = { 0 };
> -	struct input_zstream_data data = { 0 };
> -	struct odb_write_stream in_stream = {
> -		.read = feed_input_zstream,
> -		.data = &data,
> -		.size = size,
> -		.type = OBJ_BLOB,
> +	struct input_zstream_data in_stream = {
> +		.base = {
> +			.read = feed_input_zstream,
> +			.size = size,
> +			.type = OBJ_BLOB,
> +		},
> +		.zstream = &zstream,
> +		.status = Z_OK,
>  	};
>  	struct obj_info *info = &obj_list[nr];
>  
> -	data.zstream = &zstream;
> -	data.status = Z_OK;
>  	git_inflate_init(&zstream);
>  
> -	if (odb_write_object_stream(the_repository->objects, &in_stream, &info->oid))
> +	if (odb_write_object_stream(the_repository->objects, &in_stream.base, &info->oid))
>  		die(_("failed to write object in stream"));
>  
> -	if (data.status != Z_STREAM_END)
> -		die(_("inflate returned (%d)"), data.status);
> +	if (in_stream.status != Z_STREAM_END)
> +		die(_("inflate returned (%d)"), in_stream.status);
>  	git_inflate_end(&zstream);
>  
>  	if (strict) {

Stream set up is now updated to use the wrapper stream. Looks good.

[snip]
> @@ -299,14 +289,15 @@ int odb_stream_blob_to_fd(struct object_database *odb,
>  }
>  
>  struct read_object_fd_data {
> +	struct odb_stream base;
>  	int fd;
>  	size_t remaining;
>  };

`read_object_fd_data` is also now set up as a wrapper stream. Should we
also rename it accordingly?

> -static ssize_t read_object_fd(struct odb_write_stream *stream,
> -			      unsigned char *buf, size_t len)
> +static ssize_t read_object_fd(struct odb_stream *stream,
> +			      char *buf, size_t len)
>  {
> -	struct read_object_fd_data *data = stream->data;
> +	struct read_object_fd_data *data = container_of(stream, struct read_object_fd_data, base);
>  	ssize_t read_result;
>  	size_t count;
>  
> @@ -323,17 +314,23 @@ static ssize_t read_object_fd(struct odb_write_stream *stream,
>  	return read_result;
>  }
>  
> -void odb_write_stream_from_fd(struct odb_write_stream *stream, int fd,
> -			      size_t size, enum object_type type)
> +static int close_object_fd(struct odb_stream *stream UNUSED)
> +{
> +	/* The file descriptor is owned by the caller for now. */
> +	return 0;
> +}
> +
> +struct odb_stream *odb_write_stream_from_fd(int fd, size_t size, enum object_type type)

Should we also update the name of this function?

The rest of this patch is just renames and call site updates to
consolidate the two stream types. Looks good.

-Justin

  reply	other threads:[~2026-08-04 18:23 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-04  7:25 [PATCH 0/7] odb: unify read and write streams Patrick Steinhardt
2026-08-04  7:25 ` [PATCH 1/7] odb/streaming: track write stream size in the structure Patrick Steinhardt
2026-08-04 16:47   ` Justin Tobler
2026-08-04  7:25 ` [PATCH 2/7] odb/streaming: drop `is_finished` field Patrick Steinhardt
2026-08-04 17:46   ` Justin Tobler
2026-08-04  7:25 ` [PATCH 3/7] odb/streaming: support streaming arbitrary object types Patrick Steinhardt
2026-08-04 18:03   ` Justin Tobler
2026-08-05  6:06     ` Patrick Steinhardt
2026-08-04 18:54   ` Junio C Hamano
2026-08-05  6:06     ` Patrick Steinhardt
2026-08-04  7:25 ` [PATCH 4/7] odb/streaming: rename `struct odb_read_stream` Patrick Steinhardt
2026-08-04  7:25 ` [PATCH 5/7] odb/streaming: consolidate read and write streams Patrick Steinhardt
2026-08-04 18:23   ` Justin Tobler [this message]
2026-08-05  6:06     ` Patrick Steinhardt
2026-08-04  7:25 ` [PATCH 6/7] odb/streaming: rename `struct read_object_fd_data` Patrick Steinhardt
2026-08-04 18:25   ` Justin Tobler
2026-08-04  7:25 ` [PATCH 7/7] odb/streaming: unify function names to create new streams Patrick Steinhardt
2026-08-04 18:30   ` Justin Tobler
2026-08-05  7:44 ` [PATCH v2 0/8] odb: unify read and write streams Patrick Steinhardt
2026-08-05  7:44   ` [PATCH v2 1/8] odb/streaming: track write stream size in the structure Patrick Steinhardt
2026-08-05  7:44   ` [PATCH v2 2/8] odb/streaming: drop `is_finished` field Patrick Steinhardt
2026-08-05  7:44   ` [PATCH v2 3/8] odb/streaming: support streaming arbitrary object types Patrick Steinhardt
2026-08-05  7:44   ` [PATCH v2 4/8] odb/streaming: rename `struct odb_read_stream` Patrick Steinhardt
2026-08-05  7:44   ` [PATCH v2 5/8] odb/streaming: consolidate read and write streams Patrick Steinhardt
2026-08-05  7:44   ` [PATCH v2 6/8] odb/streaming: rename `struct read_object_fd_data` Patrick Steinhardt
2026-08-05  7:44   ` [PATCH v2 7/8] odb/streaming: rename `struct input_zstream_data` Patrick Steinhardt
2026-08-05  7:44   ` [PATCH v2 8/8] odb/streaming: unify function names to create new streams Patrick Steinhardt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=anIrtigj0L7PU2hl@denethor \
    --to=jltobler@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=ps@pks.im \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox