aboutsummaryrefslogtreecommitdiffstats
path: root/csum-file.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2025-01-31 13:55:31 +0100
committerJunio C Hamano <gitster@pobox.com>2025-01-31 10:06:11 -0800
commit0578f1e66aa381356bfe2f53decf3864d88d23d3 (patch)
treeca26e9efacec048463fe529f72998ba59924f479 /csum-file.c
parenthash: provide generic wrappers to update hash contexts (diff)
downloadgit-0578f1e66aa381356bfe2f53decf3864d88d23d3.tar.gz
git-0578f1e66aa381356bfe2f53decf3864d88d23d3.zip
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>
Diffstat (limited to 'csum-file.c')
-rw-r--r--csum-file.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/csum-file.c b/csum-file.c
index 3383515669..5c54b3a0b9 100644
--- a/csum-file.c
+++ b/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);
}