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>
Taylor Blau committed
Jan 23, 2025 at 12:34 UTC
5fcc683338e947d1226a9426174e7c48ce849c47
1 file changed
+7
-6
csum-file.c
+7
-6
@@ -242,14 +242,15 @@ int hashfile_checksum_valid(const unsigned char *data, size_t total_len)
242
{
243
unsigned char got[GIT_MAX_RAWSZ];
244
git_hash_ctx ctx;
245
- size_t data_len = total_len - the_hash_algo->rawsz;
245
+ const struct git_hash_algo *algop = the_hash_algo;
246
+ size_t data_len = total_len - algop->rawsz;
247
247
- if (total_len < the_hash_algo->rawsz)
248
+ if (total_len < algop->rawsz)
249
return 0; /* say "too short"? */
250
250
- the_hash_algo->unsafe_init_fn(&ctx);
251
- the_hash_algo->unsafe_update_fn(&ctx, data, data_len);
252
- the_hash_algo->unsafe_final_fn(got, &ctx);
251
+ algop->unsafe_init_fn(&ctx);
252
+ algop->unsafe_update_fn(&ctx, data, data_len);
253
+ algop->unsafe_final_fn(got, &ctx);
254
254
- return hasheq(got, data + data_len, the_repository->hash_algo);
255
+ return hasheq(got, data + data_len, algop);
256
}