Skip to content

Commit 3339180

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

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

t/helper/test-hash.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ int cmd_hash_impl(int ac, const char **av, int algo, int unsafe)
99
int binary = 0;
1010
char *buffer;
1111
const struct git_hash_algo *algop = &hash_algos[algo];
12+
if (unsafe)
13+
algop = unsafe_hash_algo(algop);
1214

1315
if (ac == 2) {
1416
if (!strcmp(av[1], "-b"))
@@ -27,10 +29,7 @@ int cmd_hash_impl(int ac, const char **av, int algo, int unsafe)
2729
die("OOPS");
2830
}
2931

30-
if (unsafe)
31-
algop->unsafe_init_fn(&ctx);
32-
else
33-
algop->init_fn(&ctx);
32+
algop->init_fn(&ctx);
3433

3534
while (1) {
3635
ssize_t sz, this_sz;
@@ -49,15 +48,9 @@ int cmd_hash_impl(int ac, const char **av, int algo, int unsafe)
4948
}
5049
if (this_sz == 0)
5150
break;
52-
if (unsafe)
53-
algop->unsafe_update_fn(&ctx, buffer, this_sz);
54-
else
55-
algop->update_fn(&ctx, buffer, this_sz);
51+
algop->update_fn(&ctx, buffer, this_sz);
5652
}
57-
if (unsafe)
58-
algop->unsafe_final_fn(hash, &ctx);
59-
else
60-
algop->final_fn(hash, &ctx);
53+
algop->final_fn(hash, &ctx);
6154

6255
if (binary)
6356
fwrite(hash, 1, algop->rawsz, stdout);

0 commit comments

Comments
 (0)