Skip to content

Commit 5c07647

Browse files
ttaylorrgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent aeb582a commit 5c07647

File tree

4 files changed

+6
-12
lines changed

4 files changed

+6
-12
lines changed

t/t1007-hash-object.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,6 @@ test_expect_success 'too-short tree' '
199199
test_i18ngrep "too-short tree object" err
200200
'
201201

202-
hex2oct() {
203-
perl -ne 'printf "\\%03o", hex for /../g'
204-
}
205-
206202
test_expect_success 'malformed mode in tree' '
207203
hex_sha1=$(echo foo | git hash-object --stdin -w) &&
208204
bin_sha1=$(echo $hex_sha1 | hex2oct) &&

t/t1450-fsck.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,6 @@ test_expect_success 'unparseable tree object' '
256256
test_i18ngrep ! "fatal: empty filename in tree entry" out
257257
'
258258

259-
hex2oct() {
260-
perl -ne 'printf "\\%03o", hex for /../g'
261-
}
262-
263259
test_expect_success 'tree entry with type mismatch' '
264260
test_when_finished "remove_object \$blob" &&
265261
test_when_finished "remove_object \$tree" &&

t/t5601-clone.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -611,10 +611,6 @@ test_expect_success 'GIT_TRACE_PACKFILE produces a usable pack' '
611611
git -C replay.git index-pack -v --stdin <tmp.pack
612612
'
613613

614-
hex2oct () {
615-
perl -ne 'printf "\\%03o", hex for /../g'
616-
}
617-
618614
test_expect_success 'clone on case-insensitive fs' '
619615
git init icasefs &&
620616
(

t/test-lib-functions.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,6 +1202,12 @@ depacketize () {
12021202
'
12031203
}
12041204

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+
12051211
# Set the hash algorithm in use to $1. Only useful when testing the testsuite.
12061212
test_set_hash () {
12071213
test_hash_algo="$1"

0 commit comments

Comments
 (0)