diff --git a/hash.c b/hash.c index e925b9754e..63672a3d22 100644 --- a/hash.c +++ b/hash.c @@ -283,6 +283,18 @@ void git_hash_final_oid(struct object_id *oid, struct git_hash_ctx *ctx) ctx->algop->final_oid_fn(oid, ctx); } +void git_hash_discard(struct git_hash_ctx *ctx) +{ + /* + * XXX Many implementations do not need to do anything here, + * and a dummy final() call is wasteful. But we can't fix + * that unless our implementation API exposes a discard + * primitive. + */ + unsigned char dummy[GIT_MAX_RAWSZ]; + git_hash_final(dummy, ctx); +} + uint32_t hash_algo_by_name(const char *name) { if (!name) diff --git a/hash.h b/hash.h index c082a53c9a..6b2f04e2a4 100644 --- a/hash.h +++ b/hash.h @@ -325,6 +325,7 @@ void git_hash_clone(struct git_hash_ctx *dst, const struct git_hash_ctx *src); void git_hash_update(struct git_hash_ctx *ctx, const void *in, size_t len); void git_hash_final(unsigned char *hash, struct git_hash_ctx *ctx); void git_hash_final_oid(struct object_id *oid, struct git_hash_ctx *ctx); +void git_hash_discard(struct git_hash_ctx *ctx); const struct git_hash_algo *hash_algo_ptr_by_number(uint32_t algo); struct git_hash_ctx *git_hash_alloc(void); void git_hash_free(struct git_hash_ctx *ctx);