git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Lars Schneider <larsxschneider@gmail.com>
To: Stefan Beller <sbeller@google.com>
Cc: "git@vger.kernel.org" <git@vger.kernel.org>,
	"Jeff King" <peff@peff.net>, "Junio C Hamano" <gitster@pobox.com>,
	"Johannes Schindelin" <Johannes.Schindelin@gmx.de>,
	"Jakub Narębski" <jnareb@gmail.com>,
	"Martin-Louis Bright" <mlbright@gmail.com>,
	"Torsten Bögershausen" <tboegi@web.de>,
	"Jacob Keller" <jacob.keller@gmail.com>
Subject: Re: [PATCH v7 06/10] pkt-line: add functions to read/write flush terminated packet streams
Date: Sun, 11 Sep 2016 14:33:19 +0200	[thread overview]
Message-ID: <6CCFB3A0-2C3B-4142-8E62-47C3DD6AE7A3@gmail.com> (raw)
In-Reply-To: <CAGZ79kYHX6-hhKW_6JEd1hBNi8R+sBY-RjZARfHDMnyLKFZnsQ@mail.gmail.com>


> On 08 Sep 2016, at 23:49, Stefan Beller <sbeller@google.com> wrote:
> 
> On Thu, Sep 8, 2016 at 11:21 AM,  <larsxschneider@gmail.com> wrote:
>> From: Lars Schneider <larsxschneider@gmail.com>
>> 
>> write_packetized_from_fd() and write_packetized_from_buf() write a
>> stream of packets. All content packets use the maximal packet size
>> except for the last one. After the last content packet a `flush` control
>> packet is written.
> 
> I presume we need both write_* things in a later patch; can you clarify why
> we need both of them?

Since 9035d7 Git streams from fd to required filters and from buf to
non-required filters. The Git filter protocol v2 makes use of all that,
too.

https://github.com/git/git/commit/9035d75a2be9d80d82676504d69553245017f6d4


>> +       if (paket_len < 0) {
>> +               if (oldalloc == 0)
>> +                       strbuf_release(sb_out);
> 
> So if old alloc is 0, we release it, which is documented as
> /**
> * Release a string buffer and the memory it used. You should not use the
> * string buffer after using this function, unless you initialize it again.
> */
> 
>> +               else
>> +                       strbuf_setlen(sb_out, oldlen);
> 
> Otherwise we just set the length back, such that it looks like before.
> 
> So as a caller the strbuf is in a different state in case of error
> depending whether
> the strbuf already had some data in it. I think it would be better if
> we only did
> `strbuf_setlen(sb_out, oldlen);` here, such that the caller can
> strbuf_release it
> unconditionally.

I tried to mimic the behavior of strbuf_read() [1]. The error handling
was introduced in 2fc647 [2] to ease error handling:

"This allows for easier error handling, as callers only need to call
strbuf_release() if A) the command succeeded or B) if they would have had
to do so anyway because they added something to the strbuf themselves."

Does this convince you to keep the proposed error handling? If yes, then
I would add a comment to the function to document that behavior explicitly!

[1] https://github.com/git/git/blob/cda1bbd474805e653dda8a71d4ea3790e2a66cbb/strbuf.c#L377-L383
[2] https://github.com/git/git/commit/2fc647004ac7016128372a85db8245581e493812


> Or to make things more confusing, you could use strbuf_reset in case of 0,
> as that is a strbuf_setlen internally. ;)


Thanks,
Lars

  reply	other threads:[~2016-09-11 12:33 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-08 18:21 [PATCH v7 00/10] Git filter protocol larsxschneider
2016-09-08 18:21 ` [PATCH v7 01/10] pkt-line: rename packet_write() to packet_write_fmt() larsxschneider
2016-09-08 18:21 ` [PATCH v7 02/10] pkt-line: extract set_packet_header() larsxschneider
2016-09-08 18:21 ` [PATCH v7 03/10] pkt-line: add packet_write_fmt_gently() larsxschneider
2016-09-08 21:18   ` Stefan Beller
2016-09-11 11:36     ` Lars Schneider
2016-09-11 16:01       ` Stefan Beller
2016-09-12  9:22         ` Lars Schneider
2016-09-08 18:21 ` [PATCH v7 04/10] pkt-line: add packet_flush_gently() larsxschneider
2016-09-12 23:30   ` Junio C Hamano
2016-09-13 22:12     ` Lars Schneider
2016-09-13 22:44       ` Junio C Hamano
2016-09-15 16:42         ` Lars Schneider
2016-09-15 19:44           ` Jeff King
2016-09-15 20:19             ` Lars Schneider
2016-09-15 20:33               ` Junio C Hamano
2016-09-08 18:21 ` [PATCH v7 05/10] pkt-line: add packet_write_gently() larsxschneider
2016-09-08 21:24   ` Stefan Beller
2016-09-11 11:44     ` Lars Schneider
2016-09-12 23:31   ` Junio C Hamano
2016-09-08 18:21 ` [PATCH v7 06/10] pkt-line: add functions to read/write flush terminated packet streams larsxschneider
2016-09-08 21:49   ` Stefan Beller
2016-09-11 12:33     ` Lars Schneider [this message]
2016-09-11 16:03       ` Stefan Beller
2016-09-11 21:42     ` Junio C Hamano
2016-09-08 18:21 ` [PATCH v7 07/10] convert: quote filter names in error messages larsxschneider
2016-09-08 18:21 ` [PATCH v7 08/10] convert: modernize tests larsxschneider
2016-09-08 22:05   ` Stefan Beller
2016-09-11 12:34     ` Lars Schneider
2016-09-08 18:21 ` [PATCH v7 09/10] convert: make apply_filter() adhere to standard Git error handling larsxschneider
2016-09-08 18:21 ` [PATCH v7 10/10] convert: add filter.<driver>.process option larsxschneider
2016-09-10  6:29   ` Torsten Bögershausen
2016-09-12  9:49     ` Lars Schneider
2016-09-13 14:44       ` Torsten Bögershausen
2016-09-13 16:42         ` Junio C Hamano
2016-09-15 17:23           ` Lars Schneider
2016-09-15 20:04             ` Junio C Hamano
2016-09-29  6:33               ` Torsten Bögershausen
2016-09-29  9:37                 ` Jakub Narębski
2016-09-10 16:40   ` Torsten Bögershausen
2016-09-13 22:04     ` Lars Schneider
2016-09-13 15:22   ` Junio C Hamano
2016-09-15 20:16     ` Lars Schneider
2016-09-15 20:24       ` Junio C Hamano
2016-09-13 16:00 ` [PATCH v7 00/10] Git filter protocol Junio C Hamano

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=6CCFB3A0-2C3B-4142-8E62-47C3DD6AE7A3@gmail.com \
    --to=larsxschneider@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jacob.keller@gmail.com \
    --cc=jnareb@gmail.com \
    --cc=mlbright@gmail.com \
    --cc=peff@peff.net \
    --cc=sbeller@google.com \
    --cc=tboegi@web.de \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).