diff options
| author | Taylor Blau <me@ttaylorr.com> | 2025-01-23 12:34:36 -0500 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2025-01-23 10:28:17 -0800 |
| commit | 3339180b28da5138eacb6b64f89c03e21493a73d (patch) | |
| tree | 929f84e6ade42a2db28bfaa4b5b2cbd9e29069eb /t/helper/test-hash.c | |
| parent | f0c266af4ea7e4d9b84955f8fed8ee8cb009cbd8 (diff) | |
| download | git-3339180b28da5138eacb6b64f89c03e21493a73d.tar.gz | |
t/helper/test-hash.c: use unsafe_hash_algo()
Remove a series of conditionals within the shared cmd_hash_impl() helper
that powers the 'sha1' and 'sha1-unsafe' helpers.
Instead, replace them with a single conditional that transforms the
specified hash algorithm into its unsafe variant. Then all subsequent
calls can directly use whatever function it wants to call without having
to decide between the safe and unsafe variants.
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/helper/test-hash.c')
| -rw-r--r-- | t/helper/test-hash.c | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/t/helper/test-hash.c b/t/helper/test-hash.c index d0ee668df9..aa82638c62 100644 --- a/t/helper/test-hash.c +++ b/t/helper/test-hash.c @@ -9,6 +9,8 @@ int cmd_hash_impl(int ac, const char **av, int algo, int unsafe) 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")) @@ -27,10 +29,7 @@ int cmd_hash_impl(int ac, const char **av, int algo, int unsafe) die("OOPS"); } - if (unsafe) - algop->unsafe_init_fn(&ctx); - else - algop->init_fn(&ctx); + algop->init_fn(&ctx); while (1) { ssize_t sz, this_sz; @@ -49,15 +48,9 @@ int cmd_hash_impl(int ac, const char **av, int algo, int unsafe) } if (this_sz == 0) break; - if (unsafe) - algop->unsafe_update_fn(&ctx, buffer, this_sz); - else - algop->update_fn(&ctx, buffer, this_sz); + algop->update_fn(&ctx, buffer, this_sz); } - if (unsafe) - algop->unsafe_final_fn(hash, &ctx); - else - algop->final_fn(hash, &ctx); + algop->final_fn(hash, &ctx); if (binary) fwrite(hash, 1, algop->rawsz, stdout); |
