]> git.99rst.org Git - git.git/commit
hash: make git_hash_discard() idempotent
authorJeff King <redacted>
Wed, 8 Jul 2026 03:52:57 +0000 (23:52 -0400)
committerJunio C Hamano <redacted>
Wed, 8 Jul 2026 04:56:00 +0000 (21:56 -0700)
commit2c51615d3f57e116c60e825b4a0d587a6f0da12a
tree47f35519388faf1cff4d8c23bb75bc42885ceead
parent90a55e3a51525370798d9b484a74a51ad2b3f047
hash: make git_hash_discard() idempotent

You must always either finalize or discard a hash context to release any
resources, but you must call only one such function. This creates extra
work for some callers, since their cleanup code paths need to know
whether they got there via their happy path (and the finalization
happened) or due to an error (in which case they need to discard).

Let's add an "active" flag that turns a redundant discard into a noop.
That lets you safely do this:

    git_hash_init(&ctx, algo);
    ...
    if (some_error)
            goto out;
    ...
    git_hash_final(result, &ctx);

  out:
    git_hash_discard(&ctx);

This should avoid future errors, and will also let us simplify a few
existing callers (in future patches).

Signed-off-by: Jeff King <redacted>
Signed-off-by: Junio C Hamano <redacted>
hash.c
hash.h
git clone https://git.99rst.org/PROJECT