зеркало из https://github.com/microsoft/git.git
pkt-line: check write_in_full() errors against "< 0"
As with the previous two commits, we prefer to check write_in_full()'s return value to see if it is negative, rather than comparing it to the input length. These cases actually flip the logic to check for success, making conversion a little different than in other cases. We could of course write: if (write_in_full(...) >= 0) return 0; return error(...); But our usual method of spelling write() error checks is just "< 0". So let's flip the logic for each of these conditionals to our usual style. Signed-off-by: Jeff King <peff@peff.net> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Родитель
564bde9ae6
Коммит
4c95e3dd28
29
pkt-line.c
29
pkt-line.c
|
@ -94,9 +94,9 @@ void packet_flush(int fd)
|
|||
int packet_flush_gently(int fd)
|
||||
{
|
||||
packet_trace("0000", 4, 1);
|
||||
if (write_in_full(fd, "0000", 4) == 4)
|
||||
return 0;
|
||||
return error("flush packet write failed");
|
||||
if (write_in_full(fd, "0000", 4) < 0)
|
||||
return error("flush packet write failed");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void packet_buf_flush(struct strbuf *buf)
|
||||
|
@ -137,18 +137,17 @@ static int packet_write_fmt_1(int fd, int gently,
|
|||
const char *fmt, va_list args)
|
||||
{
|
||||
struct strbuf buf = STRBUF_INIT;
|
||||
ssize_t count;
|
||||
|
||||
format_packet(&buf, fmt, args);
|
||||
count = write_in_full(fd, buf.buf, buf.len);
|
||||
if (count == buf.len)
|
||||
return 0;
|
||||
|
||||
if (!gently) {
|
||||
check_pipe(errno);
|
||||
die_errno("packet write with format failed");
|
||||
if (write_in_full(fd, buf.buf, buf.len) < 0) {
|
||||
if (!gently) {
|
||||
check_pipe(errno);
|
||||
die_errno("packet write with format failed");
|
||||
}
|
||||
return error("packet write with format failed");
|
||||
}
|
||||
return error("packet write with format failed");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void packet_write_fmt(int fd, const char *fmt, ...)
|
||||
|
@ -183,9 +182,9 @@ static int packet_write_gently(const int fd_out, const char *buf, size_t size)
|
|||
packet_size = size + 4;
|
||||
set_packet_header(packet_write_buffer, packet_size);
|
||||
memcpy(packet_write_buffer + 4, buf, size);
|
||||
if (write_in_full(fd_out, packet_write_buffer, packet_size) == packet_size)
|
||||
return 0;
|
||||
return error("packet write failed");
|
||||
if (write_in_full(fd_out, packet_write_buffer, packet_size) < 0)
|
||||
return error("packet write failed");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void packet_buf_write(struct strbuf *buf, const char *fmt, ...)
|
||||
|
|
Загрузка…
Ссылка в новой задаче