Skip to content

Commit 5bae927

Browse files
committed
Merge branch 'ab/pkt-line-tests'
Tests that cover protocol bits have been updated and helpers used there have been consolidated. * ab/pkt-line-tests: test-lib-functions: use test-tool for [de]packetize()
2 parents 4d4c8dd + 64f0109 commit 5bae927

File tree

5 files changed

+24
-34
lines changed

5 files changed

+24
-34
lines changed

t/helper/test-pkt-line.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ static void pack(int argc, const char **argv)
2626
}
2727
}
2828

29+
static void pack_raw_stdin(void)
30+
{
31+
struct strbuf sb = STRBUF_INIT;
32+
33+
if (strbuf_read(&sb, 0, 0) < 0)
34+
die_errno("failed to read from stdin");
35+
packet_write(1, sb.buf, sb.len);
36+
strbuf_release(&sb);
37+
}
38+
2939
static void unpack(void)
3040
{
3141
struct packet_reader reader;
@@ -110,6 +120,8 @@ int cmd__pkt_line(int argc, const char **argv)
110120

111121
if (!strcmp(argv[1], "pack"))
112122
pack(argc - 2, argv + 2);
123+
else if (!strcmp(argv[1], "pack-raw-stdin"))
124+
pack_raw_stdin();
113125
else if (!strcmp(argv[1], "unpack"))
114126
unpack();
115127
else if (!strcmp(argv[1], "unpack-sideband"))

t/t5411/once-0010-report-status-v1.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ test_expect_success "proc-receive: report status v1" '
2828
if test -z "$GIT_DEFAULT_HASH" || test "$GIT_DEFAULT_HASH" = "sha1"
2929
then
3030
printf "%s %s refs/heads/main\0report-status\n" \
31-
$A $B | packetize
31+
$A $B | packetize_raw
3232
else
3333
printf "%s %s refs/heads/main\0report-status object-format=$GIT_DEFAULT_HASH\n" \
34-
$A $B | packetize
34+
$A $B | packetize_raw
3535
fi &&
3636
printf "%s %s refs/for/main/topic1\n" \
3737
$ZERO_OID $A | packetize &&

t/t5562-http-backend-content-length.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ test_expect_success 'setup' '
6363
hash_next=$(git commit-tree -p HEAD -m next HEAD^{tree}) &&
6464
{
6565
printf "%s %s refs/heads/newbranch\\0report-status object-format=%s\\n" \
66-
"$ZERO_OID" "$hash_next" "$(test_oid algo)" | packetize &&
66+
"$ZERO_OID" "$hash_next" "$(test_oid algo)" | packetize_raw
6767
printf 0000 &&
6868
echo "$hash_next" | git pack-objects --stdout
6969
} >push_body &&

t/t5570-git-daemon.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ test_expect_success 'hostname cannot break out of directory' '
194194

195195
test_expect_success FAKENC 'hostname interpolation works after LF-stripping' '
196196
{
197-
printf "git-upload-pack /interp.git\n\0host=localhost" | packetize
197+
printf "git-upload-pack /interp.git\n\0host=localhost" | packetize_raw
198198
printf "0000"
199199
} >input &&
200200
fake_nc "$GIT_DAEMON_HOST_PORT" <input >output &&

t/test-lib-functions.sh

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,46 +1479,24 @@ nongit () {
14791479
)
14801480
} 7>&2 2>&4
14811481

1482-
# convert function arguments or stdin (if not arguments given) to pktline
1483-
# representation. If multiple arguments are given, they are separated by
1484-
# whitespace and put in a single packet. Note that data containing NULs must be
1485-
# given on stdin, and that empty input becomes an empty packet, not a flush
1486-
# packet (for that you can just print 0000 yourself).
1482+
# These functions are historical wrappers around "test-tool pkt-line"
1483+
# for older tests. Use "test-tool pkt-line" itself in new tests.
14871484
packetize () {
14881485
if test $# -gt 0
14891486
then
14901487
packet="$*"
14911488
printf '%04x%s' "$((4 + ${#packet}))" "$packet"
14921489
else
1493-
perl -e '
1494-
my $packet = do { local $/; <STDIN> };
1495-
printf "%04x%s", 4 + length($packet), $packet;
1496-
'
1490+
test-tool pkt-line pack
14971491
fi
14981492
}
14991493

1500-
# Parse the input as a series of pktlines, writing the result to stdout.
1501-
# Sideband markers are removed automatically, and the output is routed to
1502-
# stderr if appropriate.
1503-
#
1504-
# NUL bytes are converted to "\\0" for ease of parsing with text tools.
1494+
packetize_raw () {
1495+
test-tool pkt-line pack-raw-stdin
1496+
}
1497+
15051498
depacketize () {
1506-
perl -e '
1507-
while (read(STDIN, $len, 4) == 4) {
1508-
if ($len eq "0000") {
1509-
print "FLUSH\n";
1510-
} else {
1511-
read(STDIN, $buf, hex($len) - 4);
1512-
$buf =~ s/\0/\\0/g;
1513-
if ($buf =~ s/^[\x2\x3]//) {
1514-
print STDERR $buf;
1515-
} else {
1516-
$buf =~ s/^\x1//;
1517-
print $buf;
1518-
}
1519-
}
1520-
}
1521-
'
1499+
test-tool pkt-line unpack
15221500
}
15231501

15241502
# Converts base-16 data into base-8. The output is given as a sequence of

0 commit comments

Comments
 (0)