@@ -26,6 +26,17 @@ static void pack(int argc, const char **argv)
}
}
+static void pack_raw_stdin(void)
+{
+
+ struct strbuf sb = STRBUF_INIT;
+ strbuf_read(&sb, 0, 0);
+ if (strbuf_read(&sb, 0, 0) < 0)
+ die_errno("failed to read from stdin");
+ packet_write(1, sb.buf, sb.len);
+ strbuf_release(&sb);
+}
+
static void unpack(void)
{
struct packet_reader reader;
@@ -110,6 +121,8 @@ int cmd__pkt_line(int argc, const char **argv)
if (!strcmp(argv[1], "pack"))
pack(argc - 2, argv + 2);
+ else if (!strcmp(argv[1], "pack-raw-stdin"))
+ pack_raw_stdin();
else if (!strcmp(argv[1], "unpack"))
unpack();
else if (!strcmp(argv[1], "unpack-sideband"))
@@ -28,10 +28,10 @@ test_expect_success "proc-receive: report status v1" '
if test -z "$GIT_DEFAULT_HASH" || test "$GIT_DEFAULT_HASH" = "sha1"
then
printf "%s %s refs/heads/main\0report-status\n" \
- $A $B | packetize
+ $A $B | test-tool pkt-line pack-raw-stdin
else
printf "%s %s refs/heads/main\0report-status object-format=$GIT_DEFAULT_HASH\n" \
- $A $B | packetize
+ $A $B | test-tool pkt-line pack-raw-stdin
fi &&
printf "%s %s refs/for/main/topic1\n" \
$ZERO_OID $A | test-tool pkt-line pack &&
@@ -64,7 +64,8 @@ test_expect_success 'setup' '
hash_next=$(git commit-tree -p HEAD -m next HEAD^{tree}) &&
{
printf "%s %s refs/heads/newbranch\\0report-status object-format=%s\\n" \
- "$ZERO_OID" "$hash_next" "$(test_oid algo)" | packetize &&
+ "$ZERO_OID" "$hash_next" "$(test_oid algo)" |
+ test-tool pkt-line pack-raw-stdin &&
printf 0000 &&
echo "$hash_next" | git pack-objects --stdout
} >push_body &&
@@ -193,10 +193,12 @@ test_expect_success 'hostname cannot break out of directory' '
'
test_expect_success FAKENC 'hostname interpolation works after LF-stripping' '
- {
- printf "git-upload-pack /interp.git\n\0host=localhost" | packetize
- printf "0000"
- } >input &&
+ printf "git-upload-pack /interp.git\n\0host=localhost" >has-null &&
+ test-tool pkt-line pack-raw-stdin >input <has-null &&
+ test-tool pkt-line pack >>input <<-\EOF &&
+ 0000
+ EOF
+
fake_nc "$GIT_DAEMON_HOST_PORT" <input >output &&
test-tool pkt-line unpack <output >actual &&
Move the only remaining users of "packetize()" over to "test-tool pkt-line", for this we need a new "pack-raw-stdin" subcommand in the test-tool. The "pack" command takes input on stdin, but splits it by "\n", furthermore we'll format the output using C-strings, so the embedded "\0" being tested for here would cause the string to be truncated. So we need another mode that just calls packet_write() on the raw input we got on stdin. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- t/helper/test-pkt-line.c | 13 +++++++++++++ t/t5411/once-0010-report-status-v1.sh | 4 ++-- t/t5562-http-backend-content-length.sh | 3 ++- t/t5570-git-daemon.sh | 10 ++++++---- 4 files changed, 23 insertions(+), 7 deletions(-)