@matheusbsbs / matheus-bagliano / commits / 34df8abaf3
Fork 0

recv_sideband: Bands #2 and #3 always go to stderr

This removes the last parameter of recv_sideband, by which the callers told which channel bands #2 and #3 should be written to. Sayeth Shawn Pearce: The definition of the streams in the current sideband protocol are rather well defined for the one protocol that uses it, fetch-pack/receive-pack: stream #1: pack data stream #2: stderr messages, progress, meant for tty stream #3: abort message, remote is dead, goodbye! Since both callers of the function passed 2 for the parameter, we hereby remove it and send bands #2 and #3 to stderr explicitly using fprintf. This has the nice side-effect that these two streams pass through our ANSI emulation layer on Windows. Signed-off-by: Johannes Sixt <j6t@kdbg.org> Acked-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Sixt committed Mar 10, 2009 at 22:54 UTC 34df8abaf358c83cc1447d0a81bda7848685a1c9
4 files changed +11 -14
builtin-archive.c
+1 -1
@@ -52,7 +52,7 @@ static int run_remote_archiver(int argc, const char **argv,
52 die("git archive: expected a flush");
53
54 /* Now, start reading from fd[0] and spit it out to stdout */
55 - rv = recv_sideband("archive", fd[0], 1, 2);
55 + rv = recv_sideband("archive", fd[0], 1);
56 close(fd[0]);
57 close(fd[1]);
58 rv |= finish_connect(conn);
builtin-fetch-pack.c
+1 -1
@@ -482,7 +482,7 @@ static int sideband_demux(int fd, void *data)
482 {
483 int *xd = data;
484
485 - return recv_sideband("fetch-pack", xd[0], fd, 2);
485 + return recv_sideband("fetch-pack", xd[0], fd);
486 }
487
488 static int get_pack(int xd[2], char **pack_lockfile)
sideband.c
+8 -11
@@ -19,7 +19,7 @@
19
20 #define FIX_SIZE 10 /* large enough for any of the above */
21
22 -int recv_sideband(const char *me, int in_stream, int out, int err)
22 +int recv_sideband(const char *me, int in_stream, int out)
23 {
24 unsigned pf = strlen(PREFIX);
25 unsigned sf;
@@ -41,8 +41,7 @@ int recv_sideband(const char *me, int in_stream, int out, int err)
41 if (len == 0)
42 break;
43 if (len < 1) {
44 - len = sprintf(buf, "%s: protocol error: no band designator\n", me);
45 - safe_write(err, buf, len);
44 + fprintf(stderr, "%s: protocol error: no band designator\n", me);
45 return SIDEBAND_PROTOCOL_ERROR;
46 }
47 band = buf[pf] & 0xff;
@@ -50,8 +49,8 @@ int recv_sideband(const char *me, int in_stream, int out, int err)
49 switch (band) {
50 case 3:
51 buf[pf] = ' ';
53 - buf[pf+1+len] = '\n';
54 - safe_write(err, buf, pf+1+len+1);
52 + buf[pf+1+len] = '\0';
53 + fprintf(stderr, "%s\n", buf);
54 return SIDEBAND_REMOTE_ERROR;
55 case 2:
56 buf[pf] = ' ';
@@ -95,12 +94,12 @@ int recv_sideband(const char *me, int in_stream, int out, int err)
94 memcpy(save, b + brk, sf);
95 b[brk + sf - 1] = b[brk - 1];
96 memcpy(b + brk - 1, suffix, sf);
98 - safe_write(err, b, brk + sf);
97 + fprintf(stderr, "%.*s", brk + sf, b);
98 memcpy(b + brk, save, sf);
99 len -= brk;
100 } else {
101 int l = brk ? brk : len;
103 - safe_write(err, b, l);
102 + fprintf(stderr, "%.*s", l, b);
103 len -= l;
104 }
105
@@ -112,10 +111,8 @@ int recv_sideband(const char *me, int in_stream, int out, int err)
111 safe_write(out, buf + pf+1, len);
112 continue;
113 default:
115 - len = sprintf(buf,
116 - "%s: protocol error: bad band #%d\n",
117 - me, band);
118 - safe_write(err, buf, len);
114 + fprintf(stderr, "%s: protocol error: bad band #%d\n",
115 + me, band);
116 return SIDEBAND_PROTOCOL_ERROR;
117 }
118 }
sideband.h
+1 -1
@@ -7,7 +7,7 @@
7 #define DEFAULT_PACKET_MAX 1000
8 #define LARGE_PACKET_MAX 65520
9
10 -int recv_sideband(const char *me, int in_stream, int out, int err);
10 +int recv_sideband(const char *me, int in_stream, int out);
11 ssize_t send_sideband(int fd, int band, const char *data, ssize_t sz, int packet_max);
12
13 #endif