]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t: move 'hex2oct' into test-lib-functions.sh
authorTaylor Blau <me@ttaylorr.com>
Fri, 5 Apr 2019 03:37:42 +0000 (20:37 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 5 Apr 2019 06:06:04 +0000 (15:06 +0900)
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>
t/t1007-hash-object.sh
t/t1450-fsck.sh
t/t5601-clone.sh
t/test-lib-functions.sh

index a37753047e084c9be40251e7c4286084bff6870a..7099d33508a0571cd8f960fcd80c46e4364f1766 100755 (executable)
@@ -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) &&
index c61f97214137f5fcf5a9d6b7dd98ea8162e9916d..0b4d874de67eb88b30fd822c2b052ddebce2819b 100755 (executable)
@@ -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" &&
index d6948cbdab03cf827d86511ade26366e89fda149..3f4994301060fa2c0147b7ca1b879e23b6484851 100755 (executable)
@@ -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 &&
        (
index 80402a428f7735a031658a904d4f623f38e43464..349eabe851722306bb3c38669c33f09c2f2b74df 100644 (file)
@@ -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"