diff options
author | Jeff King <peff@peff.net> | 2020-03-29 11:02:26 -0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2020-03-29 08:49:47 -0700 |
commit | cacae4329fa4779127f4944e7807512e7b9e8cac (patch) | |
tree | 5e536642db0238699763589ba8b17d26416bfa92 | |
parent | upload-pack: handle unexpected delim packets (diff) | |
download | tgif-cacae4329fa4779127f4944e7807512e7b9e8cac.tar.xz |
test-lib-functions: simplify packetize() stdin code
The code path in packetize() for reading stdin needs to handle NUL
bytes, so we can't rely on shell variables. However, the current code
takes a whopping 4 processes and uses a temporary file. We can do this
much more simply and efficiently by using a single perl invocation (and
we already rely on perl in the matching depacketize() function).
We'll keep the non-stdin code path as it is, since that uses zero extra
processes.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r-- | t/test-lib-functions.sh | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index 216918a58c..88b7dbd69a 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -1373,11 +1373,10 @@ packetize() { packet="$*" printf '%04x%s' "$((4 + ${#packet}))" "$packet" else - cat >packetize.tmp && - len=$(wc -c <packetize.tmp) && - printf '%04x' "$(($len + 4))" && - cat packetize.tmp && - rm -f packetize.tmp + perl -e ' + my $packet = do { local $/; <STDIN> }; + printf "%04x%s", 4 + length($packet), $packet; + ' fi } |