Skip to content

Commit 4bcd37d

Browse files
bmwillgitster
authored andcommitted
test-pkt-line: add unpack-sideband subcommand
Add an 'unpack-sideband' subcommand to the test-pkt-line helper to enable unpacking packet line data sent multiplexed using a sideband. Signed-off-by: Brandon Williams <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 53f9a3e commit 4bcd37d

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

t/helper/test-pkt-line.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "cache.h"
12
#include "pkt-line.h"
23

34
static void pack_line(const char *line)
@@ -48,6 +49,36 @@ static void unpack(void)
4849
}
4950
}
5051

52+
static void unpack_sideband(void)
53+
{
54+
struct packet_reader reader;
55+
packet_reader_init(&reader, 0, NULL, 0,
56+
PACKET_READ_GENTLE_ON_EOF |
57+
PACKET_READ_CHOMP_NEWLINE);
58+
59+
while (packet_reader_read(&reader) != PACKET_READ_EOF) {
60+
int band;
61+
int fd;
62+
63+
switch (reader.status) {
64+
case PACKET_READ_EOF:
65+
break;
66+
case PACKET_READ_NORMAL:
67+
band = reader.line[0] & 0xff;
68+
if (band < 1 || band > 2)
69+
die("unexpected side band %d", band);
70+
fd = band;
71+
72+
write_or_die(fd, reader.line + 1, reader.pktlen - 1);
73+
break;
74+
case PACKET_READ_FLUSH:
75+
return;
76+
case PACKET_READ_DELIM:
77+
break;
78+
}
79+
}
80+
}
81+
5182
int cmd_main(int argc, const char **argv)
5283
{
5384
if (argc < 2)
@@ -57,6 +88,8 @@ int cmd_main(int argc, const char **argv)
5788
pack(argc - 2, argv + 2);
5889
else if (!strcmp(argv[1], "unpack"))
5990
unpack();
91+
else if (!strcmp(argv[1], "unpack-sideband"))
92+
unpack_sideband();
6093
else
6194
die("invalid argument '%s'", argv[1]);
6295

0 commit comments

Comments
 (0)