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>
This commit is contained in:
parent
4845b77245
commit
cacae4329f
@ -1373,11 +1373,10 @@ packetize() {
|
|||||||
packet="$*"
|
packet="$*"
|
||||||
printf '%04x%s' "$((4 + ${#packet}))" "$packet"
|
printf '%04x%s' "$((4 + ${#packet}))" "$packet"
|
||||||
else
|
else
|
||||||
cat >packetize.tmp &&
|
perl -e '
|
||||||
len=$(wc -c <packetize.tmp) &&
|
my $packet = do { local $/; <STDIN> };
|
||||||
printf '%04x' "$(($len + 4))" &&
|
printf "%04x%s", 4 + length($packet), $packet;
|
||||||
cat packetize.tmp &&
|
'
|
||||||
rm -f packetize.tmp
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user