global: adapt callers to use generic hash context helpers
Adapt callers to use generic hash context helpers instead of using the hash algorithm to update them. This makes the callsites easier to reason about and removes the possibility that the wrong hash algorithm is used to update the hash context's state. And as a nice side effect this also gets rid of a bunch of users of `the_hash_algo`. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
b2755c15e2
commit
0578f1e66a
@ -6,8 +6,8 @@
|
||||
static inline void compute_hash(const struct git_hash_algo *algo, struct git_hash_ctx *ctx, uint8_t *final, const void *p, size_t len)
|
||||
{
|
||||
algo->init_fn(ctx);
|
||||
algo->update_fn(ctx, p, len);
|
||||
algo->final_fn(final, ctx);
|
||||
git_hash_update(ctx, p, len);
|
||||
git_hash_final(final, ctx);
|
||||
}
|
||||
|
||||
int cmd__hash_speed(int ac, const char **av)
|
||||
|
@ -48,9 +48,9 @@ int cmd_hash_impl(int ac, const char **av, int algo, int unsafe)
|
||||
}
|
||||
if (this_sz == 0)
|
||||
break;
|
||||
algop->update_fn(&ctx, buffer, this_sz);
|
||||
git_hash_update(&ctx, buffer, this_sz);
|
||||
}
|
||||
algop->final_fn(hash, &ctx);
|
||||
git_hash_final(hash, &ctx);
|
||||
|
||||
if (binary)
|
||||
fwrite(hash, 1, algop->rawsz, stdout);
|
||||
|
Reference in New Issue
Block a user