t: move 'hex2oct' into test-lib-functions.sh

The helper 'hex2oct' is used to convert base-16 encoded data into a base-8 binary form, and is useful for preparing data for commands that accept input in a binary format, such as 'git hash-object', via 'printf'. This helper is defined identically in three separate places throughout 't'. Move the definition to test-lib-function.sh, so that it can be used in new test suites, and its definition is not redundant. This will likewise make our job easier in the subsequent commit, which also uses 'hex2oct'. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed Apr 4, 2019 at 20:37 UTC 5c07647d987d7f74f11ffadd39343c2f1540176c
4 files changed +6 -12
t/t1007-hash-object.sh
-4
@@ -199,10 +199,6 @@ test_expect_success 'too-short tree' '
199 test_i18ngrep "too-short tree object" err
200 '
201
202 -hex2oct() {
203 - perl -ne 'printf "\\%03o", hex for /../g'
204 -}
205 -
202 test_expect_success 'malformed mode in tree' '
203 hex_sha1=$(echo foo | git hash-object --stdin -w) &&
204 bin_sha1=$(echo $hex_sha1 | hex2oct) &&
t/t1450-fsck.sh
-4
@@ -256,10 +256,6 @@ test_expect_success 'unparseable tree object' '
256 test_i18ngrep ! "fatal: empty filename in tree entry" out
257 '
258
259 -hex2oct() {
260 - perl -ne 'printf "\\%03o", hex for /../g'
261 -}
262 -
259 test_expect_success 'tree entry with type mismatch' '
260 test_when_finished "remove_object \$blob" &&
261 test_when_finished "remove_object \$tree" &&
t/t5601-clone.sh
-4
@@ -611,10 +611,6 @@ test_expect_success 'GIT_TRACE_PACKFILE produces a usable pack' '
611 git -C replay.git index-pack -v --stdin <tmp.pack
612 '
613
614 -hex2oct () {
615 - perl -ne 'printf "\\%03o", hex for /../g'
616 -}
617 -
614 test_expect_success 'clone on case-insensitive fs' '
615 git init icasefs &&
616 (
t/test-lib-functions.sh
+6
@@ -1202,6 +1202,12 @@ depacketize () {
1202 '
1203 }
1204
1205 +# Converts base-16 data into base-8. The output is given as a sequence of
1206 +# escaped octals, suitable for consumption by 'printf'.
1207 +hex2oct () {
1208 + perl -ne 'printf "\\%03o", hex for /../g'
1209 +}
1210 +
1211 # Set the hash algorithm in use to $1. Only useful when testing the testsuite.
1212 test_set_hash () {
1213 test_hash_algo="$1"