Skip to content

Commit 5fcc683

Browse files
ttaylorrgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 48524fa commit 5fcc683

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

csum-file.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,15 @@ int hashfile_checksum_valid(const unsigned char *data, size_t total_len)
242242
{
243243
unsigned char got[GIT_MAX_RAWSZ];
244244
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;
246247

247-
if (total_len < the_hash_algo->rawsz)
248+
if (total_len < algop->rawsz)
248249
return 0; /* say "too short"? */
249250

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);
253254

254-
return hasheq(got, data + data_len, the_repository->hash_algo);
255+
return hasheq(got, data + data_len, algop);
255256
}

0 commit comments

Comments
 (0)