Skip to content

Commit 06355d7

Browse files
committed
Merge branch 'ab/pkt-line-cleanup'
Code clean-up. * ab/pkt-line-cleanup: pkt-line.[ch]: remove unused packet_read_line_buf() pkt-line.[ch]: remove unused packet_buf_write_len()
2 parents d54fd59 + ec9a37d commit 06355d7

File tree

6 files changed

+13
-53
lines changed

6 files changed

+13
-53
lines changed

builtin/checkout--worker.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ static void worker_loop(struct checkout *state)
8282
size_t i, nr = 0, alloc = 0;
8383

8484
while (1) {
85-
int len = packet_read(0, NULL, NULL, packet_buffer,
86-
sizeof(packet_buffer), 0);
85+
int len = packet_read(0, packet_buffer, sizeof(packet_buffer),
86+
0);
8787

8888
if (len < 0)
8989
BUG("packet_read() returned negative value");

daemon.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ static int execute(void)
765765

766766
set_keep_alive(0);
767767
alarm(init_timeout ? init_timeout : timeout);
768-
pktlen = packet_read(0, NULL, NULL, packet_buffer, sizeof(packet_buffer), 0);
768+
pktlen = packet_read(0, packet_buffer, sizeof(packet_buffer), 0);
769769
alarm(0);
770770

771771
len = strlen(line);

parallel-checkout.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,8 +603,7 @@ static void gather_results_from_workers(struct pc_worker *workers,
603603
continue;
604604

605605
if (pfd->revents & POLLIN) {
606-
int len = packet_read(pfd->fd, NULL, NULL,
607-
packet_buffer,
606+
int len = packet_read(pfd->fd, packet_buffer,
608607
sizeof(packet_buffer), 0);
609608

610609
if (len < 0) {

pkt-line.c

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -289,22 +289,6 @@ void packet_buf_write(struct strbuf *buf, const char *fmt, ...)
289289
va_end(args);
290290
}
291291

292-
void packet_buf_write_len(struct strbuf *buf, const char *data, size_t len)
293-
{
294-
size_t orig_len, n;
295-
296-
orig_len = buf->len;
297-
strbuf_addstr(buf, "0000");
298-
strbuf_add(buf, data, len);
299-
n = buf->len - orig_len;
300-
301-
if (n > LARGE_PACKET_MAX)
302-
die(_("protocol error: impossibly long line"));
303-
304-
set_packet_header(&buf->buf[orig_len], n);
305-
packet_trace(data, len, 1);
306-
}
307-
308292
int write_packetized_from_fd_no_flush(int fd_in, int fd_out)
309293
{
310294
char *buf = xmalloc(LARGE_PACKET_DATA_MAX);
@@ -453,38 +437,28 @@ enum packet_read_status packet_read_with_status(int fd, char **src_buffer,
453437
return PACKET_READ_NORMAL;
454438
}
455439

456-
int packet_read(int fd, char **src_buffer, size_t *src_len,
457-
char *buffer, unsigned size, int options)
440+
int packet_read(int fd, char *buffer, unsigned size, int options)
458441
{
459442
int pktlen = -1;
460443

461-
packet_read_with_status(fd, src_buffer, src_len, buffer, size,
462-
&pktlen, options);
444+
packet_read_with_status(fd, NULL, NULL, buffer, size, &pktlen,
445+
options);
463446

464447
return pktlen;
465448
}
466449

467-
static char *packet_read_line_generic(int fd,
468-
char **src, size_t *src_len,
469-
int *dst_len)
450+
char *packet_read_line(int fd, int *dst_len)
470451
{
471-
int len = packet_read(fd, src, src_len,
472-
packet_buffer, sizeof(packet_buffer),
452+
int len = packet_read(fd, packet_buffer, sizeof(packet_buffer),
473453
PACKET_READ_CHOMP_NEWLINE);
474454
if (dst_len)
475455
*dst_len = len;
476456
return (len > 0) ? packet_buffer : NULL;
477457
}
478458

479-
char *packet_read_line(int fd, int *len_p)
480-
{
481-
return packet_read_line_generic(fd, NULL, NULL, len_p);
482-
}
483-
484459
int packet_read_line_gently(int fd, int *dst_len, char **dst_line)
485460
{
486-
int len = packet_read(fd, NULL, NULL,
487-
packet_buffer, sizeof(packet_buffer),
461+
int len = packet_read(fd, packet_buffer, sizeof(packet_buffer),
488462
PACKET_READ_CHOMP_NEWLINE|PACKET_READ_GENTLE_ON_EOF);
489463
if (dst_len)
490464
*dst_len = len;
@@ -493,11 +467,6 @@ int packet_read_line_gently(int fd, int *dst_len, char **dst_line)
493467
return len;
494468
}
495469

496-
char *packet_read_line_buf(char **src, size_t *src_len, int *dst_len)
497-
{
498-
return packet_read_line_generic(-1, src, src_len, dst_len);
499-
}
500-
501470
ssize_t read_packetized_to_strbuf(int fd_in, struct strbuf *sb_out, int options)
502471
{
503472
int packet_len;
@@ -507,7 +476,7 @@ ssize_t read_packetized_to_strbuf(int fd_in, struct strbuf *sb_out, int options)
507476

508477
for (;;) {
509478
strbuf_grow(sb_out, LARGE_PACKET_DATA_MAX);
510-
packet_len = packet_read(fd_in, NULL, NULL,
479+
packet_len = packet_read(fd_in,
511480
/* strbuf_grow() above always allocates one extra byte to
512481
* store a '\0' at the end of the string. packet_read()
513482
* writes a '\0' extra byte at the end, too. Let it know

pkt-line.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ void packet_buf_delim(struct strbuf *buf);
2929
void set_packet_header(char *buf, int size);
3030
void packet_write(int fd_out, const char *buf, size_t size);
3131
void packet_buf_write(struct strbuf *buf, const char *fmt, ...) __attribute__((format (printf, 2, 3)));
32-
void packet_buf_write_len(struct strbuf *buf, const char *data, size_t len);
3332
int packet_flush_gently(int fd);
3433
int packet_write_fmt_gently(int fd, const char *fmt, ...) __attribute__((format (printf, 2, 3)));
3534
int write_packetized_from_fd_no_flush(int fd_in, int fd_out);
@@ -88,8 +87,7 @@ void packet_fflush(FILE *f);
8887
#define PACKET_READ_CHOMP_NEWLINE (1u<<1)
8988
#define PACKET_READ_DIE_ON_ERR_PACKET (1u<<2)
9089
#define PACKET_READ_GENTLE_ON_READ_ERROR (1u<<3)
91-
int packet_read(int fd, char **src_buffer, size_t *src_len, char
92-
*buffer, unsigned size, int options);
90+
int packet_read(int fd, char *buffer, unsigned size, int options);
9391

9492
/*
9593
* Convert a four hex digit packet line length header into its numeric
@@ -138,12 +136,6 @@ char *packet_read_line(int fd, int *size);
138136
*/
139137
int packet_read_line_gently(int fd, int *size, char **dst_line);
140138

141-
/*
142-
* Same as packet_read_line, but read from a buf rather than a descriptor;
143-
* see packet_read for details on how src_* is used.
144-
*/
145-
char *packet_read_line_buf(char **src_buf, size_t *src_len, int *size);
146-
147139
/*
148140
* Reads a stream of variable sized packets until a flush packet is detected.
149141
*/

remote-curl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,7 @@ static int rpc_service(struct rpc_state *rpc, struct discovery *heads,
10881088
rpc->protocol_header = NULL;
10891089

10901090
while (!err) {
1091-
int n = packet_read(rpc->out, NULL, NULL, rpc->buf, rpc->alloc, 0);
1091+
int n = packet_read(rpc->out, rpc->buf, rpc->alloc, 0);
10921092
if (!n)
10931093
break;
10941094
rpc->pos = 0;

0 commit comments

Comments
 (0)