Re: [PATCH v7 05/10] pkt-line: add packet_write_gently()
larsxschnei...@gmail.com writes: > +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; > +} The same comment as 4/10 applies here.
Re: [PATCH v7 05/10] pkt-line: add packet_write_gently()
> On 08 Sep 2016, at 23:24, Stefan Bellerwrote: > > On Thu, Sep 8, 2016 at 11:21 AM, wrote: > >> >> 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. I agree that this is too verbose as this function follows the standard Git return value conventions (AFAIK). I'll remove this from all commit messages. >> 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 ? I'll add this note to all commit messages that introduce new functions which are used later. Thanks, Lars
Re: [PATCH v7 05/10] pkt-line: add packet_write_gently()
On Thu, Sep 8, 2016 at 11:21 AM,wrote: > From: Lars Schneider > > 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 ? > > Signed-off-by: Lars Schneider > --- > 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 >
[PATCH v7 05/10] pkt-line: add packet_write_gently()
From: Lars Schneiderpacket_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. Add packet_write_gently() which writes arbitrary data and returns `0` for success and `-1` for an error. This function is used by other pkt-line functions in a subsequent patch. Signed-off-by: Lars Schneider --- 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