@matheusbsbs / matheus-bagliano / commits / ed1902ef5c
Fork 0

cope with multiple line breaks within sideband progress messages

A single sideband packet may sometimes contain multiple lines of progress messages, but we prepend "remote: " only to the whole buffer which creates a messed up display in that case. Make sure that the "remote: " prefix is applied to every remote lines. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Nicolas Pitre committed Oct 16, 2007 at 21:55 UTC ed1902ef5c6a30942def50809b52e41fbdcdf13f
1 file changed +17 -2
sideband.c
+17 -2
@@ -17,7 +17,7 @@ int recv_sideband(const char *me, int in_stream, int out, int err)
17 strcpy(buf, "remote:");
18 while (1) {
19 int band, len;
20 - len = packet_read_line(in_stream, buf+7, LARGE_PACKET_MAX);
20 + len = packet_read_line(in_stream, buf+7, LARGE_PACKET_MAX);
21 if (len == 0)
22 break;
23 if (len < 1) {
@@ -35,7 +35,22 @@ int recv_sideband(const char *me, int in_stream, int out, int err)
35 return SIDEBAND_REMOTE_ERROR;
36 case 2:
37 buf[7] = ' ';
38 - safe_write(err, buf, 8+len);
38 + len += 8;
39 + while (1) {
40 + int brk = 8;
41 + while (brk < len) {
42 + brk++;
43 + if (buf[brk-1] == '\n' ||
44 + buf[brk-1] == '\r')
45 + break;
46 + }
47 + safe_write(err, buf, brk);
48 + if (brk < len) {
49 + memmove(buf + 8, buf + brk, len - brk);
50 + len = len - brk + 8;
51 + } else
52 + break;
53 + }
54 continue;
55 case 1:
56 safe_write(out, buf+8, len);