Skip to content

Commit 8d7eea4

Browse files
ttaylorrgitster
authored andcommitted
t/helper/test-tool: implement sha1-unsafe helper
Add a new helper similar to 't/helper/test-tool sha1' called instead "sha1-unsafe" which uses the unsafe variant of Git's SHA-1 wrappers. While we're at it, modify the test-sha1.sh script to exercise both the sha1 and sha1-unsafe test tools to ensure that both produce the expected hash values. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 32daa6b commit 8d7eea4

File tree

4 files changed

+29
-16
lines changed

4 files changed

+29
-16
lines changed

t/helper/test-sha1.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,8 @@ int cmd__sha1_is_sha1dc(int argc UNUSED, const char **argv UNUSED)
1313
#endif
1414
return 1;
1515
}
16+
17+
int cmd__sha1_unsafe(int ac, const char **av)
18+
{
19+
return cmd_hash_impl(ac, av, GIT_HASH_SHA1, 1);
20+
}

t/helper/test-sha1.sh

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,31 @@
33
dd if=/dev/zero bs=1048576 count=100 2>/dev/null |
44
/usr/bin/time t/helper/test-tool sha1 >/dev/null
55

6+
dd if=/dev/zero bs=1048576 count=100 2>/dev/null |
7+
/usr/bin/time t/helper/test-tool sha1-unsafe >/dev/null
8+
69
while read expect cnt pfx
710
do
811
case "$expect" in '#'*) continue ;; esac
9-
actual=$(
10-
{
11-
test -z "$pfx" || echo "$pfx"
12-
dd if=/dev/zero bs=1048576 count=$cnt 2>/dev/null |
13-
perl -pe 'y/\000/g/'
14-
} | ./t/helper/test-tool sha1 $cnt
15-
)
16-
if test "$expect" = "$actual"
17-
then
18-
echo "OK: $expect $cnt $pfx"
19-
else
20-
echo >&2 "OOPS: $cnt"
21-
echo >&2 "expect: $expect"
22-
echo >&2 "actual: $actual"
23-
exit 1
24-
fi
12+
for sha1 in sha1 sha1-unsafe
13+
do
14+
actual=$(
15+
{
16+
test -z "$pfx" || echo "$pfx"
17+
dd if=/dev/zero bs=1048576 count=$cnt 2>/dev/null |
18+
perl -pe 'y/\000/g/'
19+
} | ./t/helper/test-tool $sha1 $cnt
20+
)
21+
if test "$expect" = "$actual"
22+
then
23+
echo "OK ($sha1): $expect $cnt $pfx"
24+
else
25+
echo >&2 "OOPS ($sha1): $cnt"
26+
echo >&2 "expect ($sha1): $expect"
27+
echo >&2 "actual ($sha1): $actual"
28+
exit 1
29+
fi
30+
done
2531
done <<EOF
2632
da39a3ee5e6b4b0d3255bfef95601890afd80709 0
2733
3f786850e387550fdab836ed7e6dc881de23001b 0 a

t/helper/test-tool.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ static struct test_cmd cmds[] = {
7070
{ "serve-v2", cmd__serve_v2 },
7171
{ "sha1", cmd__sha1 },
7272
{ "sha1-is-sha1dc", cmd__sha1_is_sha1dc },
73+
{ "sha1-unsafe", cmd__sha1_unsafe },
7374
{ "sha256", cmd__sha256 },
7475
{ "sigchain", cmd__sigchain },
7576
{ "simple-ipc", cmd__simple_ipc },

t/helper/test-tool.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ int cmd__scrap_cache_tree(int argc, const char **argv);
6363
int cmd__serve_v2(int argc, const char **argv);
6464
int cmd__sha1(int argc, const char **argv);
6565
int cmd__sha1_is_sha1dc(int argc, const char **argv);
66+
int cmd__sha1_unsafe(int argc, const char **argv);
6667
int cmd__sha256(int argc, const char **argv);
6768
int cmd__sigchain(int argc, const char **argv);
6869
int cmd__simple_ipc(int argc, const char **argv);

0 commit comments

Comments
 (0)