mirror of
https://github.com/git/git.git
synced 2026-01-09 17:46:37 +00:00
global: adapt callers to use generic hash context helpers
Adapt callers to use generic hash context helpers instead of using the hash algorithm to update them. This makes the callsites easier to reason about and removes the possibility that the wrong hash algorithm is used to update the hash context's state. And as a nice side effect this also gets rid of a bunch of users of `the_hash_algo`. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
b2755c15e2
commit
0578f1e66a
14
csum-file.c
14
csum-file.c
@@ -50,7 +50,7 @@ void hashflush(struct hashfile *f)
|
||||
|
||||
if (offset) {
|
||||
if (!f->skip_hash)
|
||||
f->algop->update_fn(&f->ctx, f->buffer, offset);
|
||||
git_hash_update(&f->ctx, f->buffer, offset);
|
||||
flush(f, f->buffer, offset);
|
||||
f->offset = 0;
|
||||
}
|
||||
@@ -73,7 +73,7 @@ int finalize_hashfile(struct hashfile *f, unsigned char *result,
|
||||
if (f->skip_hash)
|
||||
hashclr(f->buffer, f->algop);
|
||||
else
|
||||
f->algop->final_fn(f->buffer, &f->ctx);
|
||||
git_hash_final(f->buffer, &f->ctx);
|
||||
|
||||
if (result)
|
||||
hashcpy(result, f->buffer, f->algop);
|
||||
@@ -128,7 +128,7 @@ void hashwrite(struct hashfile *f, const void *buf, unsigned int count)
|
||||
* f->offset is necessarily zero.
|
||||
*/
|
||||
if (!f->skip_hash)
|
||||
f->algop->update_fn(&f->ctx, buf, nr);
|
||||
git_hash_update(&f->ctx, buf, nr);
|
||||
flush(f, buf, nr);
|
||||
} else {
|
||||
/*
|
||||
@@ -217,7 +217,7 @@ void hashfile_checkpoint(struct hashfile *f, struct hashfile_checkpoint *checkpo
|
||||
{
|
||||
hashflush(f);
|
||||
checkpoint->offset = f->total;
|
||||
f->algop->clone_fn(&checkpoint->ctx, &f->ctx);
|
||||
git_hash_clone(&checkpoint->ctx, &f->ctx);
|
||||
}
|
||||
|
||||
int hashfile_truncate(struct hashfile *f, struct hashfile_checkpoint *checkpoint)
|
||||
@@ -228,7 +228,7 @@ int hashfile_truncate(struct hashfile *f, struct hashfile_checkpoint *checkpoint
|
||||
lseek(f->fd, offset, SEEK_SET) != offset)
|
||||
return -1;
|
||||
f->total = offset;
|
||||
f->algop->clone_fn(&f->ctx, &checkpoint->ctx);
|
||||
git_hash_clone(&f->ctx, &checkpoint->ctx);
|
||||
f->offset = 0; /* hashflush() was called in checkpoint */
|
||||
return 0;
|
||||
}
|
||||
@@ -256,8 +256,8 @@ int hashfile_checksum_valid(const unsigned char *data, size_t total_len)
|
||||
return 0; /* say "too short"? */
|
||||
|
||||
algop->init_fn(&ctx);
|
||||
algop->update_fn(&ctx, data, data_len);
|
||||
algop->final_fn(got, &ctx);
|
||||
git_hash_update(&ctx, data, data_len);
|
||||
git_hash_final(got, &ctx);
|
||||
|
||||
return hasheq(got, data + data_len, algop);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user