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>
Ben Peart committed
May 5, 2017 at 11:27 UTC
c0c70f7ac080c3b4ecc50a3207eb66e97c10271d
3 files changed
+22
-21
convert.c
+2
-21
@@ -521,25 +521,6 @@ static struct cmd2process *find_multi_file_filter_entry(struct hashmap *hashmap,
521
return hashmap_get(hashmap, &key, NULL);
522
}
523
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
-
524
static void read_multi_file_filter_status(int fd, struct strbuf *status)
525
{
526
struct strbuf **pair;
@@ -616,7 +597,7 @@ static struct cmd2process *start_multi_file_filter(struct hashmap *hashmap, cons
597
598
sigchain_push(SIGPIPE, SIG_IGN);
599
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);
601
if (err)
602
goto done;
603
@@ -632,7 +613,7 @@ static struct cmd2process *start_multi_file_filter(struct hashmap *hashmap, cons
613
if (err)
614
goto done;
615
635
- err = packet_write_list(process->in, "capability=clean", "capability=smudge", NULL);
616
+ err = packet_writel(process->in, "capability=clean", "capability=smudge", NULL);
617
618
for (;;) {
619
cap_buf = packet_read_line(process->out, NULL);
pkt-line.c
+19
@@ -171,6 +171,25 @@ int packet_write_fmt_gently(int fd, const char *fmt, ...)
171
return status;
172
}
173
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
+
193
static int packet_write_gently(const int fd_out, const char *buf, size_t size)
194
{
195
static char packet_write_buffer[LARGE_PACKET_MAX];
pkt-line.h
+1
@@ -25,6 +25,7 @@ void packet_buf_flush(struct strbuf *buf);
25
void packet_buf_write(struct strbuf *buf, const char *fmt, ...) __attribute__((format (printf, 2, 3)));
26
int packet_flush_gently(int fd);
27
int packet_write_fmt_gently(int fd, const char *fmt, ...) __attribute__((format (printf, 2, 3)));
28
+int packet_writel(int fd, const char *line, ...);
29
int write_packetized_from_fd(int fd_in, int fd_out);
30
int write_packetized_from_buf(const char *src_in, size_t len, int fd_out);
31