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

Re: [PATCH v7 06/10] pkt-line: add functions to read/write flush terminated packet streams

From
Lars Schneider <larsxschneider@gmail.com>
Date
Sep 11, 2016, 12:33 UTC
Message-ID
<6CCFB3A0-2C3B-4142-8E62-47C3DD6AE7A3@gmail.com>
In-Reply-To
<CAGZ79kYHX6-hhKW_6JEd1hBNi8R+sBY-RjZARfHDMnyLKFZnsQ@mail.gmail.com>
Show 12 quoted lines
> 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
Show 22 quoted lines
>> +       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

Previous: Stefan BellerNext: Stefan Beller
Message 23 of 45 in “Git filter protocol”
  1. 00/10 Git filter protocollarsxschneider@gmail.com, Sep 8, 2016
  2. 01/10 pkt-line: rename packet_write() to packet_write_fmt()larsxschneider@gmail.com, Sep 8, 2016
  3. 02/10 pkt-line: extract set_packet_header()larsxschneider@gmail.com, Sep 8, 2016
  4. 03/10 pkt-line: add packet_write_fmt_gently()larsxschneider@gmail.com, Sep 8, 2016
  5. Stefan BellerSep 8, 2016
  6. Lars SchneiderSep 11, 2016
  7. Stefan BellerSep 11, 2016
  8. Lars SchneiderSep 12, 2016
  9. 04/10 pkt-line: add packet_flush_gently()larsxschneider@gmail.com, Sep 8, 2016
  10. Junio C HamanoSep 12, 2016
  11. Lars SchneiderSep 13, 2016
  12. Junio C HamanoSep 13, 2016
  13. Lars SchneiderSep 15, 2016
  14. Jeff KingSep 15, 2016
  15. Lars SchneiderSep 15, 2016
  16. Junio C HamanoSep 15, 2016
  17. 05/10 pkt-line: add packet_write_gently()larsxschneider@gmail.com, Sep 8, 2016
  18. Stefan BellerSep 8, 2016
  19. Lars SchneiderSep 11, 2016
  20. Junio C HamanoSep 12, 2016
  21. 06/10 pkt-line: add functions to read/write flush terminated packet streamslarsxschneider@gmail.com, Sep 8, 2016
  22. Stefan BellerSep 8, 2016
  23. Lars SchneiderSep 11, 2016
  24. Stefan BellerSep 11, 2016
  25. Junio C HamanoSep 11, 2016
  26. 09/10 convert: make apply_filter() adhere to standard Git error handlinglarsxschneider@gmail.com, Sep 8, 2016
  27. 08/10 convert: modernize testslarsxschneider@gmail.com, Sep 8, 2016
  28. Stefan BellerSep 8, 2016
  29. Lars SchneiderSep 11, 2016
  30. 07/10 convert: quote filter names in error messageslarsxschneider@gmail.com, Sep 8, 2016
  31. 10/10 convert: add filter.<driver>.process optionlarsxschneider@gmail.com, Sep 8, 2016
  32. Torsten BögershausenSep 10, 2016
  33. Lars SchneiderSep 12, 2016
  34. Torsten BögershausenSep 13, 2016
  35. Junio C HamanoSep 13, 2016
  36. Lars SchneiderSep 15, 2016
  37. Junio C HamanoSep 15, 2016
  38. Torsten BögershausenSep 29, 2016
  39. Jakub NarębskiSep 29, 2016
  40. Torsten BögershausenSep 10, 2016
  41. Lars SchneiderSep 13, 2016
  42. Junio C HamanoSep 13, 2016
  43. Lars SchneiderSep 15, 2016
  44. Junio C HamanoSep 15, 2016
  45. Junio C HamanoSep 13, 2016

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.