Skip to content

Commit 34df8ab

Browse files
j6tgitster
authored andcommitted
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 <[email protected]> Acked-by: Nicolas Pitre <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c4994ce commit 34df8ab

File tree

4 files changed

+11
-14
lines changed

4 files changed

+11
-14
lines changed

builtin-archive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static int run_remote_archiver(int argc, const char **argv,
5252
die("git archive: expected a flush");
5353

5454
/* 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);
5656
close(fd[0]);
5757
close(fd[1]);
5858
rv |= finish_connect(conn);

builtin-fetch-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ static int sideband_demux(int fd, void *data)
482482
{
483483
int *xd = data;
484484

485-
return recv_sideband("fetch-pack", xd[0], fd, 2);
485+
return recv_sideband("fetch-pack", xd[0], fd);
486486
}
487487

488488
static int get_pack(int xd[2], char **pack_lockfile)

sideband.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
#define FIX_SIZE 10 /* large enough for any of the above */
2121

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)
2323
{
2424
unsigned pf = strlen(PREFIX);
2525
unsigned sf;
@@ -41,17 +41,16 @@ int recv_sideband(const char *me, int in_stream, int out, int err)
4141
if (len == 0)
4242
break;
4343
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);
4645
return SIDEBAND_PROTOCOL_ERROR;
4746
}
4847
band = buf[pf] & 0xff;
4948
len--;
5049
switch (band) {
5150
case 3:
5251
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);
5554
return SIDEBAND_REMOTE_ERROR;
5655
case 2:
5756
buf[pf] = ' ';
@@ -95,12 +94,12 @@ int recv_sideband(const char *me, int in_stream, int out, int err)
9594
memcpy(save, b + brk, sf);
9695
b[brk + sf - 1] = b[brk - 1];
9796
memcpy(b + brk - 1, suffix, sf);
98-
safe_write(err, b, brk + sf);
97+
fprintf(stderr, "%.*s", brk + sf, b);
9998
memcpy(b + brk, save, sf);
10099
len -= brk;
101100
} else {
102101
int l = brk ? brk : len;
103-
safe_write(err, b, l);
102+
fprintf(stderr, "%.*s", l, b);
104103
len -= l;
105104
}
106105

@@ -112,10 +111,8 @@ int recv_sideband(const char *me, int in_stream, int out, int err)
112111
safe_write(out, buf + pf+1, len);
113112
continue;
114113
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);
119116
return SIDEBAND_PROTOCOL_ERROR;
120117
}
121118
}

sideband.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#define DEFAULT_PACKET_MAX 1000
88
#define LARGE_PACKET_MAX 65520
99

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);
1111
ssize_t send_sideband(int fd, int band, const char *data, ssize_t sz, int packet_max);
1212

1313
#endif

0 commit comments

Comments
 (0)