зеркало из https://github.com/microsoft/git.git
pkt-line: drop safe_write function
This is just write_or_die by another name. The one distinction is that write_or_die will treat EPIPE specially by suppressing error messages. That's fine, as we die by SIGPIPE anyway (and in the off chance that it is disabled, write_or_die will simulate it). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Родитель
e148542870
Коммит
cdf4fb8e33
|
@ -932,7 +932,7 @@ static void report(struct command *commands, const char *unpack_status)
|
|||
if (use_sideband)
|
||||
send_sideband(1, 1, buf.buf, buf.len, use_sideband);
|
||||
else
|
||||
safe_write(1, buf.buf, buf.len);
|
||||
write_or_die(1, buf.buf, buf.len);
|
||||
strbuf_release(&buf);
|
||||
}
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ static void print_helper_status(struct ref *ref)
|
|||
}
|
||||
strbuf_addch(&buf, '\n');
|
||||
|
||||
safe_write(1, buf.buf, buf.len);
|
||||
write_or_die(1, buf.buf, buf.len);
|
||||
}
|
||||
strbuf_release(&buf);
|
||||
}
|
||||
|
|
|
@ -247,7 +247,7 @@ static void send_request(struct fetch_pack_args *args,
|
|||
send_sideband(fd, -1, buf->buf, buf->len, LARGE_PACKET_MAX);
|
||||
packet_flush(fd);
|
||||
} else
|
||||
safe_write(fd, buf->buf, buf->len);
|
||||
write_or_die(fd, buf->buf, buf->len);
|
||||
}
|
||||
|
||||
static void insert_one_alternate_ref(const struct ref *ref, void *unused)
|
||||
|
|
|
@ -70,7 +70,7 @@ static void format_write(int fd, const char *fmt, ...)
|
|||
if (n >= sizeof(buffer))
|
||||
die("protocol error: impossibly long line");
|
||||
|
||||
safe_write(fd, buffer, n);
|
||||
write_or_die(fd, buffer, n);
|
||||
}
|
||||
|
||||
static void http_status(unsigned code, const char *msg)
|
||||
|
@ -111,7 +111,7 @@ static void hdr_cache_forever(void)
|
|||
|
||||
static void end_headers(void)
|
||||
{
|
||||
safe_write(1, "\r\n", 2);
|
||||
write_or_die(1, "\r\n", 2);
|
||||
}
|
||||
|
||||
__attribute__((format (printf, 1, 2)))
|
||||
|
@ -157,7 +157,7 @@ static void send_strbuf(const char *type, struct strbuf *buf)
|
|||
hdr_int(content_length, buf->len);
|
||||
hdr_str(content_type, type);
|
||||
end_headers();
|
||||
safe_write(1, buf->buf, buf->len);
|
||||
write_or_die(1, buf->buf, buf->len);
|
||||
}
|
||||
|
||||
static void send_local_file(const char *the_type, const char *name)
|
||||
|
@ -185,7 +185,7 @@ static void send_local_file(const char *the_type, const char *name)
|
|||
die_errno("Cannot read '%s'", p);
|
||||
if (!n)
|
||||
break;
|
||||
safe_write(1, buf, n);
|
||||
write_or_die(1, buf, n);
|
||||
}
|
||||
close(fd);
|
||||
free(buf);
|
||||
|
|
21
pkt-line.c
21
pkt-line.c
|
@ -46,23 +46,6 @@ static void packet_trace(const char *buf, unsigned int len, int write)
|
|||
strbuf_release(&out);
|
||||
}
|
||||
|
||||
ssize_t safe_write(int fd, const void *buf, ssize_t n)
|
||||
{
|
||||
ssize_t nn = n;
|
||||
while (n) {
|
||||
int ret = xwrite(fd, buf, n);
|
||||
if (ret > 0) {
|
||||
buf = (char *) buf + ret;
|
||||
n -= ret;
|
||||
continue;
|
||||
}
|
||||
if (!ret)
|
||||
die("write error (disk full?)");
|
||||
die_errno("write error");
|
||||
}
|
||||
return nn;
|
||||
}
|
||||
|
||||
/*
|
||||
* If we buffered things up above (we don't, but we should),
|
||||
* we'd flush it here
|
||||
|
@ -70,7 +53,7 @@ ssize_t safe_write(int fd, const void *buf, ssize_t n)
|
|||
void packet_flush(int fd)
|
||||
{
|
||||
packet_trace("0000", 4, 1);
|
||||
safe_write(fd, "0000", 4);
|
||||
write_or_die(fd, "0000", 4);
|
||||
}
|
||||
|
||||
void packet_buf_flush(struct strbuf *buf)
|
||||
|
@ -106,7 +89,7 @@ void packet_write(int fd, const char *fmt, ...)
|
|||
va_start(args, fmt);
|
||||
n = format_packet(fmt, args);
|
||||
va_end(args);
|
||||
safe_write(fd, buffer, n);
|
||||
write_or_die(fd, buffer, n);
|
||||
}
|
||||
|
||||
void packet_buf_write(struct strbuf *buf, const char *fmt, ...)
|
||||
|
|
|
@ -27,6 +27,5 @@ void packet_buf_write(struct strbuf *buf, const char *fmt, ...) __attribute__((f
|
|||
int packet_read_line(int fd, char *buffer, unsigned size);
|
||||
int packet_read(int fd, char *buffer, unsigned size);
|
||||
int packet_get_line(struct strbuf *out, char **src_buf, size_t *src_len);
|
||||
ssize_t safe_write(int, const void *, ssize_t);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -685,7 +685,7 @@ static int fetch_git(struct discovery *heads,
|
|||
|
||||
err = rpc_service(&rpc, heads);
|
||||
if (rpc.result.len)
|
||||
safe_write(1, rpc.result.buf, rpc.result.len);
|
||||
write_or_die(1, rpc.result.buf, rpc.result.len);
|
||||
strbuf_release(&rpc.result);
|
||||
strbuf_release(&preamble);
|
||||
free(depth_arg);
|
||||
|
@ -805,7 +805,7 @@ static int push_git(struct discovery *heads, int nr_spec, char **specs)
|
|||
|
||||
err = rpc_service(&rpc, heads);
|
||||
if (rpc.result.len)
|
||||
safe_write(1, rpc.result.buf, rpc.result.len);
|
||||
write_or_die(1, rpc.result.buf, rpc.result.len);
|
||||
strbuf_release(&rpc.result);
|
||||
free(argv);
|
||||
return err;
|
||||
|
|
|
@ -280,7 +280,7 @@ int send_pack(struct send_pack_args *args,
|
|||
send_sideband(out, -1, req_buf.buf, req_buf.len, LARGE_PACKET_MAX);
|
||||
}
|
||||
} else {
|
||||
safe_write(out, req_buf.buf, req_buf.len);
|
||||
write_or_die(out, req_buf.buf, req_buf.len);
|
||||
packet_flush(out);
|
||||
}
|
||||
strbuf_release(&req_buf);
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#include "cache.h"
|
||||
#include "pkt-line.h"
|
||||
#include "sideband.h"
|
||||
|
||||
|
@ -108,7 +109,7 @@ int recv_sideband(const char *me, int in_stream, int out)
|
|||
} while (len);
|
||||
continue;
|
||||
case 1:
|
||||
safe_write(out, buf + pf+1, len);
|
||||
write_or_die(out, buf + pf+1, len);
|
||||
continue;
|
||||
default:
|
||||
fprintf(stderr, "%s: protocol error: bad band #%d\n",
|
||||
|
@ -138,12 +139,12 @@ ssize_t send_sideband(int fd, int band, const char *data, ssize_t sz, int packet
|
|||
if (0 <= band) {
|
||||
sprintf(hdr, "%04x", n + 5);
|
||||
hdr[4] = band;
|
||||
safe_write(fd, hdr, 5);
|
||||
write_or_die(fd, hdr, 5);
|
||||
} else {
|
||||
sprintf(hdr, "%04x", n + 4);
|
||||
safe_write(fd, hdr, 4);
|
||||
write_or_die(fd, hdr, 4);
|
||||
}
|
||||
safe_write(fd, p, n);
|
||||
write_or_die(fd, p, n);
|
||||
p += n;
|
||||
sz -= n;
|
||||
}
|
||||
|
|
|
@ -69,7 +69,8 @@ static ssize_t send_client_data(int fd, const char *data, ssize_t sz)
|
|||
xwrite(fd, data, sz);
|
||||
return sz;
|
||||
}
|
||||
return safe_write(fd, data, sz);
|
||||
write_or_die(fd, data, sz);
|
||||
return sz;
|
||||
}
|
||||
|
||||
static FILE *pack_pipe = NULL;
|
||||
|
|
Загрузка…
Ссылка в новой задаче