diff options
author | Taylor Blau <me@ttaylorr.com> | 2019-04-04 20:37:42 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2019-04-05 15:06:04 +0900 |
commit | 5c07647d987d7f74f11ffadd39343c2f1540176c (patch) | |
tree | 354e4bb19f8a9450c89b27e09c2b1987c58e1d98 | |
parent | mingw: allow building with an MSYS2 runtime v3.x (diff) | |
download | tgif-5c07647d987d7f74f11ffadd39343c2f1540176c.tar.xz |
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>
-rwxr-xr-x | t/t1007-hash-object.sh | 4 | ||||
-rwxr-xr-x | t/t1450-fsck.sh | 4 | ||||
-rwxr-xr-x | t/t5601-clone.sh | 4 | ||||
-rw-r--r-- | t/test-lib-functions.sh | 6 |
4 files changed, 6 insertions, 12 deletions
diff --git a/t/t1007-hash-object.sh b/t/t1007-hash-object.sh index a37753047e..7099d33508 100755 --- a/t/t1007-hash-object.sh +++ b/t/t1007-hash-object.sh @@ -199,10 +199,6 @@ test_expect_success 'too-short tree' ' test_i18ngrep "too-short tree object" err ' -hex2oct() { - perl -ne 'printf "\\%03o", hex for /../g' -} - test_expect_success 'malformed mode in tree' ' hex_sha1=$(echo foo | git hash-object --stdin -w) && bin_sha1=$(echo $hex_sha1 | hex2oct) && diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh index c61f972141..0b4d874de6 100755 --- a/t/t1450-fsck.sh +++ b/t/t1450-fsck.sh @@ -256,10 +256,6 @@ test_expect_success 'unparseable tree object' ' test_i18ngrep ! "fatal: empty filename in tree entry" out ' -hex2oct() { - perl -ne 'printf "\\%03o", hex for /../g' -} - test_expect_success 'tree entry with type mismatch' ' test_when_finished "remove_object \$blob" && test_when_finished "remove_object \$tree" && diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh index d6948cbdab..3f49943010 100755 --- a/t/t5601-clone.sh +++ b/t/t5601-clone.sh @@ -611,10 +611,6 @@ test_expect_success 'GIT_TRACE_PACKFILE produces a usable pack' ' git -C replay.git index-pack -v --stdin <tmp.pack ' -hex2oct () { - perl -ne 'printf "\\%03o", hex for /../g' -} - test_expect_success 'clone on case-insensitive fs' ' git init icasefs && ( diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index 80402a428f..349eabe851 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -1202,6 +1202,12 @@ depacketize () { ' } +# Converts base-16 data into base-8. The output is given as a sequence of +# escaped octals, suitable for consumption by 'printf'. +hex2oct () { + perl -ne 'printf "\\%03o", hex for /../g' +} + # Set the hash algorithm in use to $1. Only useful when testing the testsuite. test_set_hash () { test_hash_algo="$1" |