Skip to content

Commit c0c70f7

Browse files
benpeartgitster
authored andcommitted
convert: move packet_write_line() into pkt-line as packet_writel()
Add packet_writel() which writes multiple lines in a single call and then calls packet_flush_gently(). Update convert.c to use the new packet_writel() function from pkt-line. Signed-off-by: Ben Peart <benpeart@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 825b922 commit c0c70f7

3 files changed

Lines changed: 22 additions & 21 deletions

File tree

convert.c

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -521,25 +521,6 @@ static struct cmd2process *find_multi_file_filter_entry(struct hashmap *hashmap,
521521
return hashmap_get(hashmap, &key, NULL);
522522
}
523523

524-
static int packet_write_list(int fd, const char *line, ...)
525-
{
526-
va_list args;
527-
int err;
528-
va_start(args, line);
529-
for (;;) {
530-
if (!line)
531-
break;
532-
if (strlen(line) > LARGE_PACKET_DATA_MAX)
533-
return -1;
534-
err = packet_write_fmt_gently(fd, "%s\n", line);
535-
if (err)
536-
return err;
537-
line = va_arg(args, const char*);
538-
}
539-
va_end(args);
540-
return packet_flush_gently(fd);
541-
}
542-
543524
static void read_multi_file_filter_status(int fd, struct strbuf *status)
544525
{
545526
struct strbuf **pair;
@@ -616,7 +597,7 @@ static struct cmd2process *start_multi_file_filter(struct hashmap *hashmap, cons
616597

617598
sigchain_push(SIGPIPE, SIG_IGN);
618599

619-
err = packet_write_list(process->in, "git-filter-client", "version=2", NULL);
600+
err = packet_writel(process->in, "git-filter-client", "version=2", NULL);
620601
if (err)
621602
goto done;
622603

@@ -632,7 +613,7 @@ static struct cmd2process *start_multi_file_filter(struct hashmap *hashmap, cons
632613
if (err)
633614
goto done;
634615

635-
err = packet_write_list(process->in, "capability=clean", "capability=smudge", NULL);
616+
err = packet_writel(process->in, "capability=clean", "capability=smudge", NULL);
636617

637618
for (;;) {
638619
cap_buf = packet_read_line(process->out, NULL);

pkt-line.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,25 @@ int packet_write_fmt_gently(int fd, const char *fmt, ...)
171171
return status;
172172
}
173173

174+
int packet_writel(int fd, const char *line, ...)
175+
{
176+
va_list args;
177+
int err;
178+
va_start(args, line);
179+
for (;;) {
180+
if (!line)
181+
break;
182+
if (strlen(line) > LARGE_PACKET_DATA_MAX)
183+
return -1;
184+
err = packet_write_fmt_gently(fd, "%s\n", line);
185+
if (err)
186+
return err;
187+
line = va_arg(args, const char*);
188+
}
189+
va_end(args);
190+
return packet_flush_gently(fd);
191+
}
192+
174193
static int packet_write_gently(const int fd_out, const char *buf, size_t size)
175194
{
176195
static char packet_write_buffer[LARGE_PACKET_MAX];

pkt-line.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ void packet_buf_flush(struct strbuf *buf);
2525
void packet_buf_write(struct strbuf *buf, const char *fmt, ...) __attribute__((format (printf, 2, 3)));
2626
int packet_flush_gently(int fd);
2727
int packet_write_fmt_gently(int fd, const char *fmt, ...) __attribute__((format (printf, 2, 3)));
28+
int packet_writel(int fd, const char *line, ...);
2829
int write_packetized_from_fd(int fd_in, int fd_out);
2930
int write_packetized_from_buf(const char *src_in, size_t len, int fd_out);
3031

0 commit comments

Comments
 (0)