diff options
| author | Taylor Blau <me@ttaylorr.com> | 2025-01-23 12:34:26 -0500 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2025-01-23 10:28:16 -0800 |
| commit | 5fcc683338e947d1226a9426174e7c48ce849c47 (patch) | |
| tree | f82df4632dbcf62074948c9143980051ab5fb823 | |
| parent | 48524fac643afd7ec70d43684902598ad6d5b954 (diff) | |
| download | git-5fcc683338e947d1226a9426174e7c48ce849c47.tar.gz | |
csum-file.c: extract algop from hashfile_checksum_valid()
Perform a similar transformation as in the previous commit, but focused
instead on hashfile_checksum_valid(). This function does not work with a
hashfile structure itself, and instead validates the raw contents of a
file written using the hashfile API.
We'll want to be prepared for a similar change to this function in the
future, so prepare ourselves for that by extracting 'the_hash_algo' into
its own field for use within this function.
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
| -rw-r--r-- | csum-file.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/csum-file.c b/csum-file.c index b28cd047e3..7a71121e34 100644 --- a/csum-file.c +++ b/csum-file.c @@ -242,14 +242,15 @@ int hashfile_checksum_valid(const unsigned char *data, size_t total_len) { unsigned char got[GIT_MAX_RAWSZ]; git_hash_ctx ctx; - size_t data_len = total_len - the_hash_algo->rawsz; + const struct git_hash_algo *algop = the_hash_algo; + size_t data_len = total_len - algop->rawsz; - if (total_len < the_hash_algo->rawsz) + if (total_len < algop->rawsz) return 0; /* say "too short"? */ - the_hash_algo->unsafe_init_fn(&ctx); - the_hash_algo->unsafe_update_fn(&ctx, data, data_len); - the_hash_algo->unsafe_final_fn(got, &ctx); + algop->unsafe_init_fn(&ctx); + algop->unsafe_update_fn(&ctx, data, data_len); + algop->unsafe_final_fn(got, &ctx); - return hasheq(got, data + data_len, the_repository->hash_algo); + return hasheq(got, data + data_len, algop); } |
