Skip to content

Commit cdf4fb8

Browse files
peffgitster
authored andcommitted
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>
1 parent e148542 commit cdf4fb8

File tree

10 files changed

+19
-35
lines changed

10 files changed

+19
-35
lines changed

builtin/receive-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ static void report(struct command *commands, const char *unpack_status)
932932
if (use_sideband)
933933
send_sideband(1, 1, buf.buf, buf.len, use_sideband);
934934
else
935-
safe_write(1, buf.buf, buf.len);
935+
write_or_die(1, buf.buf, buf.len);
936936
strbuf_release(&buf);
937937
}
938938

builtin/send-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ static void print_helper_status(struct ref *ref)
7979
}
8080
strbuf_addch(&buf, '\n');
8181

82-
safe_write(1, buf.buf, buf.len);
82+
write_or_die(1, buf.buf, buf.len);
8383
}
8484
strbuf_release(&buf);
8585
}

fetch-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ static void send_request(struct fetch_pack_args *args,
247247
send_sideband(fd, -1, buf->buf, buf->len, LARGE_PACKET_MAX);
248248
packet_flush(fd);
249249
} else
250-
safe_write(fd, buf->buf, buf->len);
250+
write_or_die(fd, buf->buf, buf->len);
251251
}
252252

253253
static void insert_one_alternate_ref(const struct ref *ref, void *unused)

http-backend.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static void format_write(int fd, const char *fmt, ...)
7070
if (n >= sizeof(buffer))
7171
die("protocol error: impossibly long line");
7272

73-
safe_write(fd, buffer, n);
73+
write_or_die(fd, buffer, n);
7474
}
7575

7676
static void http_status(unsigned code, const char *msg)
@@ -111,7 +111,7 @@ static void hdr_cache_forever(void)
111111

112112
static void end_headers(void)
113113
{
114-
safe_write(1, "\r\n", 2);
114+
write_or_die(1, "\r\n", 2);
115115
}
116116

117117
__attribute__((format (printf, 1, 2)))
@@ -157,7 +157,7 @@ static void send_strbuf(const char *type, struct strbuf *buf)
157157
hdr_int(content_length, buf->len);
158158
hdr_str(content_type, type);
159159
end_headers();
160-
safe_write(1, buf->buf, buf->len);
160+
write_or_die(1, buf->buf, buf->len);
161161
}
162162

163163
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)
185185
die_errno("Cannot read '%s'", p);
186186
if (!n)
187187
break;
188-
safe_write(1, buf, n);
188+
write_or_die(1, buf, n);
189189
}
190190
close(fd);
191191
free(buf);

pkt-line.c

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,31 +46,14 @@ static void packet_trace(const char *buf, unsigned int len, int write)
4646
strbuf_release(&out);
4747
}
4848

49-
ssize_t safe_write(int fd, const void *buf, ssize_t n)
50-
{
51-
ssize_t nn = n;
52-
while (n) {
53-
int ret = xwrite(fd, buf, n);
54-
if (ret > 0) {
55-
buf = (char *) buf + ret;
56-
n -= ret;
57-
continue;
58-
}
59-
if (!ret)
60-
die("write error (disk full?)");
61-
die_errno("write error");
62-
}
63-
return nn;
64-
}
65-
6649
/*
6750
* If we buffered things up above (we don't, but we should),
6851
* we'd flush it here
6952
*/
7053
void packet_flush(int fd)
7154
{
7255
packet_trace("0000", 4, 1);
73-
safe_write(fd, "0000", 4);
56+
write_or_die(fd, "0000", 4);
7457
}
7558

7659
void packet_buf_flush(struct strbuf *buf)
@@ -106,7 +89,7 @@ void packet_write(int fd, const char *fmt, ...)
10689
va_start(args, fmt);
10790
n = format_packet(fmt, args);
10891
va_end(args);
109-
safe_write(fd, buffer, n);
92+
write_or_die(fd, buffer, n);
11093
}
11194

11295
void packet_buf_write(struct strbuf *buf, const char *fmt, ...)

pkt-line.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,5 @@ void packet_buf_write(struct strbuf *buf, const char *fmt, ...) __attribute__((f
2727
int packet_read_line(int fd, char *buffer, unsigned size);
2828
int packet_read(int fd, char *buffer, unsigned size);
2929
int packet_get_line(struct strbuf *out, char **src_buf, size_t *src_len);
30-
ssize_t safe_write(int, const void *, ssize_t);
3130

3231
#endif

remote-curl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ static int fetch_git(struct discovery *heads,
685685

686686
err = rpc_service(&rpc, heads);
687687
if (rpc.result.len)
688-
safe_write(1, rpc.result.buf, rpc.result.len);
688+
write_or_die(1, rpc.result.buf, rpc.result.len);
689689
strbuf_release(&rpc.result);
690690
strbuf_release(&preamble);
691691
free(depth_arg);
@@ -805,7 +805,7 @@ static int push_git(struct discovery *heads, int nr_spec, char **specs)
805805

806806
err = rpc_service(&rpc, heads);
807807
if (rpc.result.len)
808-
safe_write(1, rpc.result.buf, rpc.result.len);
808+
write_or_die(1, rpc.result.buf, rpc.result.len);
809809
strbuf_release(&rpc.result);
810810
free(argv);
811811
return err;

send-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ int send_pack(struct send_pack_args *args,
280280
send_sideband(out, -1, req_buf.buf, req_buf.len, LARGE_PACKET_MAX);
281281
}
282282
} else {
283-
safe_write(out, req_buf.buf, req_buf.len);
283+
write_or_die(out, req_buf.buf, req_buf.len);
284284
packet_flush(out);
285285
}
286286
strbuf_release(&req_buf);

sideband.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "cache.h"
12
#include "pkt-line.h"
23
#include "sideband.h"
34

@@ -108,7 +109,7 @@ int recv_sideband(const char *me, int in_stream, int out)
108109
} while (len);
109110
continue;
110111
case 1:
111-
safe_write(out, buf + pf+1, len);
112+
write_or_die(out, buf + pf+1, len);
112113
continue;
113114
default:
114115
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
138139
if (0 <= band) {
139140
sprintf(hdr, "%04x", n + 5);
140141
hdr[4] = band;
141-
safe_write(fd, hdr, 5);
142+
write_or_die(fd, hdr, 5);
142143
} else {
143144
sprintf(hdr, "%04x", n + 4);
144-
safe_write(fd, hdr, 4);
145+
write_or_die(fd, hdr, 4);
145146
}
146-
safe_write(fd, p, n);
147+
write_or_die(fd, p, n);
147148
p += n;
148149
sz -= n;
149150
}

upload-pack.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ static ssize_t send_client_data(int fd, const char *data, ssize_t sz)
6969
xwrite(fd, data, sz);
7070
return sz;
7171
}
72-
return safe_write(fd, data, sz);
72+
write_or_die(fd, data, sz);
73+
return sz;
7374
}
7475

7576
static FILE *pack_pipe = NULL;

0 commit comments

Comments
 (0)