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

Re: [PATCH v7 05/10] pkt-line: add packet_write_gently()

From
Stefan Beller <sbeller@google.com>
Date
Sep 8, 2016, 21:24 UTC
Message-ID
<CAGZ79kZdroDdD5SHP+-9svSTYbJfn2vsFXAwC4aen3hMVEOOPA@mail.gmail.com>
In-Reply-To
<20160908182132.50788-6-larsxschneider@gmail.com>
On Thu, Sep 8, 2016 at 11:21 AM,  <larsxschneider@gmail.com> wrote:
Show 5 quoted lines
> From: Lars Schneider <larsxschneider@gmail.com>
>
> packet_write_fmt_gently() uses format_packet() which lets the caller
> only send string data via "%s". That means it cannot be used for
> arbitrary data that may contain NULs.
Makes sense.
>
> Add packet_write_gently() which writes arbitrary data and returns `0`
> for success and `-1` for an error.

I think documenting the return code is better done in either the header file or in a commend preceding the implementation instead of the commit message?

Maybe just a generic comment for *_gently is good enough, maybe even no comment. So the commit is fine, too. I dunno.

> This function is used by other
> pkt-line functions in a subsequent patch.

That's what I figured. Do we also need to mention that in the preceding patch for packet_flush_gently ?

Show 39 quoted lines
>
> Signed-off-by: Lars Schneider <larsxschneider@gmail.com>
> ---
>  pkt-line.c | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
>
> diff --git a/pkt-line.c b/pkt-line.c
> index 37345ca..1d3d725 100644
> --- a/pkt-line.c
> +++ b/pkt-line.c
> @@ -181,6 +181,25 @@ int packet_write_fmt_gently(int fd, const char *fmt, ...)
>         return status;
>  }
>
> +int packet_write_gently(const int fd_out, const char *buf, size_t size)
> +{
> +       static char packet_write_buffer[LARGE_PACKET_MAX];
> +
> +       if (size > sizeof(packet_write_buffer) - 4) {
> +               error("packet write failed");
> +               return -1;
> +       }
> +       packet_trace(buf, size, 1);
> +       size += 4;
> +       set_packet_header(packet_write_buffer, size);
> +       memcpy(packet_write_buffer + 4, buf, size - 4);
> +       if (write_in_full(fd_out, packet_write_buffer, size) == size)
> +               return 0;
> +
> +       error("packet write failed");
> +       return -1;
> +}
> +
>  void packet_buf_write(struct strbuf *buf, const char *fmt, ...)
>  {
>         va_list args;
> --
> 2.10.0
>
Previous: larsxschneider@gmail.comNext: Lars Schneider
Message 18 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.