aboutsummaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2025-01-31 10:05:46 -0800
committerJunio C Hamano <gitster@pobox.com>2025-01-31 10:05:46 -0800
commit0cbcba54550b1ea108e977c24b835e07b96b1c0e (patch)
tree6cb525c7fdb38ee631d741c2f32bcaf2fffa5f07 /t
parent3b0d05c4a79d0e441283680a864529b02dca5f08 (diff)
parent04292c3796bb92664f6111326215d9c060ef71c8 (diff)
downloadgit-0cbcba54550b1ea108e977c24b835e07b96b1c0e.tar.gz
Merge branch 'tb/unsafe-hash-cleanup' into ps/hash-cleanup
* tb/unsafe-hash-cleanup: hash.h: drop unsafe_ function variants csum-file: introduce hashfile_checkpoint_init() t/helper/test-hash.c: use unsafe_hash_algo() csum-file.c: use unsafe_hash_algo() hash.h: introduce `unsafe_hash_algo()` csum-file.c: extract algop from hashfile_checksum_valid() csum-file: store the hash algorithm as a struct field t/helper/test-tool: implement sha1-unsafe helper
Diffstat (limited to 't')
-rw-r--r--t/helper/test-hash.c4
-rw-r--r--t/helper/test-sha1.c7
-rwxr-xr-xt/helper/test-sha1.sh38
-rw-r--r--t/helper/test-sha256.c2
-rw-r--r--t/helper/test-tool.c1
-rw-r--r--t/helper/test-tool.h3
6 files changed, 35 insertions, 20 deletions
diff --git a/t/helper/test-hash.c b/t/helper/test-hash.c
index 45d829c908..aa82638c62 100644
--- a/t/helper/test-hash.c
+++ b/t/helper/test-hash.c
@@ -1,7 +1,7 @@
#include "test-tool.h"
#include "hex.h"
-int cmd_hash_impl(int ac, const char **av, int algo)
+int cmd_hash_impl(int ac, const char **av, int algo, int unsafe)
{
git_hash_ctx ctx;
unsigned char hash[GIT_MAX_HEXSZ];
@@ -9,6 +9,8 @@ int cmd_hash_impl(int ac, const char **av, int algo)
int binary = 0;
char *buffer;
const struct git_hash_algo *algop = &hash_algos[algo];
+ if (unsafe)
+ algop = unsafe_hash_algo(algop);
if (ac == 2) {
if (!strcmp(av[1], "-b"))
diff --git a/t/helper/test-sha1.c b/t/helper/test-sha1.c
index e60d000c03..349540c4df 100644
--- a/t/helper/test-sha1.c
+++ b/t/helper/test-sha1.c
@@ -3,7 +3,7 @@
int cmd__sha1(int ac, const char **av)
{
- return cmd_hash_impl(ac, av, GIT_HASH_SHA1);
+ return cmd_hash_impl(ac, av, GIT_HASH_SHA1, 0);
}
int cmd__sha1_is_sha1dc(int argc UNUSED, const char **argv UNUSED)
@@ -13,3 +13,8 @@ int cmd__sha1_is_sha1dc(int argc UNUSED, const char **argv UNUSED)
#endif
return 1;
}
+
+int cmd__sha1_unsafe(int ac, const char **av)
+{
+ return cmd_hash_impl(ac, av, GIT_HASH_SHA1, 1);
+}
diff --git a/t/helper/test-sha1.sh b/t/helper/test-sha1.sh
index 84594885c7..bf387d3db1 100755
--- a/t/helper/test-sha1.sh
+++ b/t/helper/test-sha1.sh
@@ -3,25 +3,31 @@
dd if=/dev/zero bs=1048576 count=100 2>/dev/null |
/usr/bin/time t/helper/test-tool sha1 >/dev/null
+dd if=/dev/zero bs=1048576 count=100 2>/dev/null |
+/usr/bin/time t/helper/test-tool sha1-unsafe >/dev/null
+
while read expect cnt pfx
do
case "$expect" in '#'*) continue ;; esac
- actual=$(
- {
- test -z "$pfx" || echo "$pfx"
- dd if=/dev/zero bs=1048576 count=$cnt 2>/dev/null |
- perl -pe 'y/\000/g/'
- } | ./t/helper/test-tool sha1 $cnt
- )
- if test "$expect" = "$actual"
- then
- echo "OK: $expect $cnt $pfx"
- else
- echo >&2 "OOPS: $cnt"
- echo >&2 "expect: $expect"
- echo >&2 "actual: $actual"
- exit 1
- fi
+ for sha1 in sha1 sha1-unsafe
+ do
+ actual=$(
+ {
+ test -z "$pfx" || echo "$pfx"
+ dd if=/dev/zero bs=1048576 count=$cnt 2>/dev/null |
+ perl -pe 'y/\000/g/'
+ } | ./t/helper/test-tool $sha1 $cnt
+ )
+ if test "$expect" = "$actual"
+ then
+ echo "OK ($sha1): $expect $cnt $pfx"
+ else
+ echo >&2 "OOPS ($sha1): $cnt"
+ echo >&2 "expect ($sha1): $expect"
+ echo >&2 "actual ($sha1): $actual"
+ exit 1
+ fi
+ done
done <<EOF
da39a3ee5e6b4b0d3255bfef95601890afd80709 0
3f786850e387550fdab836ed7e6dc881de23001b 0 a
diff --git a/t/helper/test-sha256.c b/t/helper/test-sha256.c
index 2fb20438f3..7fd0aa1fcd 100644
--- a/t/helper/test-sha256.c
+++ b/t/helper/test-sha256.c
@@ -3,5 +3,5 @@
int cmd__sha256(int ac, const char **av)
{
- return cmd_hash_impl(ac, av, GIT_HASH_SHA256);
+ return cmd_hash_impl(ac, av, GIT_HASH_SHA256, 0);
}
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index 69a9ffa1eb..e8bc94862e 100644
--- a/t/helper/test-tool.c
+++ b/t/helper/test-tool.c
@@ -71,6 +71,7 @@ static struct test_cmd cmds[] = {
{ "serve-v2", cmd__serve_v2 },
{ "sha1", cmd__sha1 },
{ "sha1-is-sha1dc", cmd__sha1_is_sha1dc },
+ { "sha1-unsafe", cmd__sha1_unsafe },
{ "sha256", cmd__sha256 },
{ "sigchain", cmd__sigchain },
{ "simple-ipc", cmd__simple_ipc },
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index 9cfc5da6e5..fb4c609254 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -64,6 +64,7 @@ int cmd__scrap_cache_tree(int argc, const char **argv);
int cmd__serve_v2(int argc, const char **argv);
int cmd__sha1(int argc, const char **argv);
int cmd__sha1_is_sha1dc(int argc, const char **argv);
+int cmd__sha1_unsafe(int argc, const char **argv);
int cmd__sha256(int argc, const char **argv);
int cmd__sigchain(int argc, const char **argv);
int cmd__simple_ipc(int argc, const char **argv);
@@ -82,6 +83,6 @@ int cmd__windows_named_pipe(int argc, const char **argv);
#endif
int cmd__write_cache(int argc, const char **argv);
-int cmd_hash_impl(int ac, const char **av, int algo);
+int cmd_hash_impl(int ac, const char **av, int algo, int unsafe);
#endif