Re: [PATCH 08/13] t/helper: add zlib test-tool
- From
Jeff King <peff@peff.net>
- Date
- May 19, 2025, 17:03 UTC
- Message-ID
- <20250519170335.GB772062@coredump.intra.peff.net>
- In-Reply-To
- <xmqqo6voprrk.fsf@gitster.g>
On Mon, May 19, 2025 at 08:03:11AM -0700, Junio C Hamano wrote:
Show 29 quoted lines
> > +static void do_zlib(struct git_zstream *stream,
> > + int (*zlib_func)(git_zstream *, int),
> > + int fd_in, int fd_out)
> > +{
> > + struct strbuf buf_in = STRBUF_INIT;
> > + int status = Z_OK;
> > +
> > + if (strbuf_read(&buf_in, fd_in, 0) < 0)
> > + die_errno("read error");
> > +
> > + stream->next_in = (unsigned char *)buf_in.buf;
> > + stream->avail_in = buf_in.len;
> > +
> > + while (status == Z_OK ||
> > + (status == Z_BUF_ERROR && !stream->avail_out)) {
> > + unsigned char buf_out[4096];
> > +
> > + stream->next_out = buf_out;
> > + stream->avail_out = sizeof(buf_out);
> > +
> > + status = zlib_func(stream, Z_FINISH);
> > + if (write_in_full(fd_out, buf_out,
> > + sizeof(buf_out) - stream->avail_out) < 0)
> > + die_errno("write error");
> > + }
>
> Even though I may have written this as do {} while() loop, I do not
> mind a while () loop that depends on status being initialized to
> Z_OK.Hmm, yeah. I agree that is slightly nicer, but probably not worth caring about too much.
I thought at first there might be an opportunity to also simplify some of the assignments, similar to 03e7c454e9 (unpack_loose_header(): simplify next_out assignment, 2025-02-25), but I don't think so (in that commit the complication was that we inflated a little before hitting the loop).
-Peff