Re: [PATCH 2/7] hash: convert remaining direct function calls
Jeff King <peff@peff.net> writes:
Show 30 quoted lines
> The previous patch added a coccinelle rule to make sure callers always
> use git_hash_init() rather than direct function pointers from the algo
> struct.
>
> Let's do the same for the rest of the git_hash_*() wrappers. I split
> these out because they're a bit different: they implicitly use the algop
> pointer in the git_hash_ctx. So when we convert:
>
> -algo->update_fn(&ctx, buf, len);
> +git_hash_update(&ctx, buf, len);
>
> we drop the reference to algo entirely! But this is always going to be
> the right thing. If "algo" does not match what is in ctx.algop, then
> we'd already be invoking undefined behavior.
>
> So in addition to making it possible to add more logic to the
> git_hash_*() functions, we're avoiding the need to pass around the extra
> algo pointer and make sure that it matches what's in "ctx".
>
> The rest of the patch is the mechanical application of that coccinelle
> patch, plus a minor cleanup in test-synthesize.c to drop a now-unused
> function parameter (since we don't have to pass around the algo
> separately anymore).
>
> Signed-off-by: Jeff King <peff@peff.net>
> ---
> builtin/submodule--helper.c | 8 +++---
> t/helper/test-synthesize.c | 29 ++++++++++----------
> tools/coccinelle/hash.cocci | 53 +++++++++++++++++++++++++++++++++++++
> 3 files changed, 71 insertions(+), 19 deletions(-)
Looks very straight-forward.