mirror of
https://github.com/git/git.git
synced 2026-01-09 17:46:37 +00:00
Merge branch 'ps/hash-cleanup'
Further code clean-up on the use of hash functions. Now the context object knows what hash function it is working with. * ps/hash-cleanup: global: adapt callers to use generic hash context helpers hash: provide generic wrappers to update hash contexts hash: stop typedeffing the hash context hash: convert hashing context to a structure
This commit is contained in:
16
csum-file.c
16
csum-file.c
@@ -51,7 +51,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;
|
||||
}
|
||||
@@ -74,7 +74,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);
|
||||
@@ -129,7 +129,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 {
|
||||
/*
|
||||
@@ -218,7 +218,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)
|
||||
@@ -229,7 +229,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;
|
||||
}
|
||||
@@ -249,7 +249,7 @@ uint32_t crc32_end(struct hashfile *f)
|
||||
int hashfile_checksum_valid(const unsigned char *data, size_t total_len)
|
||||
{
|
||||
unsigned char got[GIT_MAX_RAWSZ];
|
||||
git_hash_ctx ctx;
|
||||
struct git_hash_ctx ctx;
|
||||
const struct git_hash_algo *algop = unsafe_hash_algo(the_hash_algo);
|
||||
size_t data_len = total_len - algop->rawsz;
|
||||
|
||||
@@ -257,8 +257,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