提交 385d1bfd 编写于 作者: J Jonathan Tan 提交者: Junio C Hamano

t5616: refactor packfile replacement

A subsequent patch will perform the same packfile replacement that is
already done twice, so refactor it into its own function. Also, the same
subsequent patch will use, in another way, part of the packfile
replacement functionality, so extract those out too.
Signed-off-by: NJonathan Tan <jonathantanmy@google.com>
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 ab15ad1a
......@@ -244,11 +244,25 @@ test_expect_success 'fetch what is specified on CLI even if already promised' '
. "$TEST_DIRECTORY"/lib-httpd.sh
start_httpd
# Converts bytes into a form suitable for inclusion in a sed command. For
# example, "printf 'ab\r\n' | hex_unpack" results in '\x61\x62\x0d\x0a'.
sed_escape () {
perl -e '$/ = undef; $input = <>; print unpack("H2" x length($input), $input)' |
sed 's/\(..\)/\\x\1/g'
# Converts bytes into their hexadecimal representation. For example,
# "printf 'ab\r\n' | hex_unpack" results in '61620d0a'.
hex_unpack () {
perl -e '$/ = undef; $input = <>; print unpack("H2" x length($input), $input)'
}
# Inserts $1 at the start of the string and every 2 characters thereafter.
intersperse () {
sed 's/\(..\)/'$1'\1/g'
}
# Create a one-time-sed command to replace the existing packfile with $1.
replace_packfile () {
# The protocol requires that the packfile be sent in sideband 1, hence
# the extra \x01 byte at the beginning.
printf "1,/packfile/!c %04x\\\\x01%s0000" \
"$(($(wc -c <$1) + 5))" \
"$(hex_unpack <$1 | intersperse '\\x')" \
>"$HTTPD_ROOT_PATH/one-time-sed"
}
test_expect_success 'upon cloning, check that all refs point to objects' '
......@@ -270,10 +284,7 @@ test_expect_success 'upon cloning, check that all refs point to objects' '
# Replace the existing packfile with the crafted one. The protocol
# requires that the packfile be sent in sideband 1, hence the extra
# \x01 byte at the beginning.
printf "1,/packfile/!c %04x\\\\x01%s0000" \
"$(($(wc -c <incomplete.pack) + 5))" \
"$(sed_escape <incomplete.pack)" \
>"$HTTPD_ROOT_PATH/one-time-sed" &&
replace_packfile incomplete.pack &&
# Use protocol v2 because the sed command looks for the "packfile"
# section header.
......@@ -313,10 +324,7 @@ test_expect_success 'when partial cloning, tolerate server not sending target of
# Replace the existing packfile with the crafted one. The protocol
# requires that the packfile be sent in sideband 1, hence the extra
# \x01 byte at the beginning.
printf "1,/packfile/!c %04x\\\\x01%s0000" \
"$(($(wc -c <incomplete.pack) + 5))" \
"$(sed_escape <incomplete.pack)" \
>"$HTTPD_ROOT_PATH/one-time-sed" &&
replace_packfile incomplete.pack &&
# Use protocol v2 because the sed command looks for the "packfile"
# section header.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册