Merge branch 'mg/timestamp-t-fix'
[gitweb.git] / pkt-line.c
index d4b6bfe076341d64bb948e4932655b927a369bc0..f364944b931a756b3b4819fb49ff5e9e01daf676 100644 (file)
@@ -136,9 +136,10 @@ static void format_packet(struct strbuf *out, const char *fmt, va_list args)
 static int packet_write_fmt_1(int fd, int gently,
                              const char *fmt, va_list args)
 {
-       struct strbuf buf = STRBUF_INIT;
+       static struct strbuf buf = STRBUF_INIT;
        ssize_t count;
 
+       strbuf_reset(&buf);
        format_packet(&buf, fmt, args);
        count = write_in_full(fd, buf.buf, buf.len);
        if (count == buf.len)
@@ -315,7 +316,7 @@ static char *packet_read_line_generic(int fd,
                              PACKET_READ_CHOMP_NEWLINE);
        if (dst_len)
                *dst_len = len;
-       return len ? packet_buffer : NULL;
+       return (len > 0) ? packet_buffer : NULL;
 }
 
 char *packet_read_line(int fd, int *len_p)
@@ -323,6 +324,18 @@ char *packet_read_line(int fd, int *len_p)
        return packet_read_line_generic(fd, NULL, NULL, len_p);
 }
 
+int packet_read_line_gently(int fd, int *dst_len, char **dst_line)
+{
+       int len = packet_read(fd, NULL, NULL,
+                             packet_buffer, sizeof(packet_buffer),
+                             PACKET_READ_CHOMP_NEWLINE|PACKET_READ_GENTLE_ON_EOF);
+       if (dst_len)
+               *dst_len = len;
+       if (dst_line)
+               *dst_line = (len > 0) ? packet_buffer : NULL;
+       return len;
+}
+
 char *packet_read_line_buf(char **src, size_t *src_len, int *dst_len)
 {
        return packet_read_line_generic(-1, src, src_len, dst_len);