diff options
Diffstat (limited to 'csum-file.c')
| -rw-r--r-- | csum-file.c | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/csum-file.c b/csum-file.c index cce13c0f04..bf82ad8f9f 100644 --- a/csum-file.c +++ b/csum-file.c @@ -7,9 +7,13 @@ * files. Useful when you write a file that you want to be * able to verify hasn't been messed with afterwards. */ -#include "cache.h" + +#define USE_THE_REPOSITORY_VARIABLE + +#include "git-compat-util.h" #include "progress.h" #include "csum-file.h" +#include "hash.h" static void verify_buffer_or_die(struct hashfile *f, const void *buf, @@ -52,7 +56,7 @@ void hashflush(struct hashfile *f) } } -static void free_hashfile(struct hashfile *f) +void free_hashfile(struct hashfile *f) { free(f->buffer); free(f->check_buffer); @@ -67,12 +71,12 @@ int finalize_hashfile(struct hashfile *f, unsigned char *result, hashflush(f); if (f->skip_hash) - hashclr(f->buffer); + hashclr(f->buffer, the_repository->hash_algo); else the_hash_algo->final_fn(f->buffer, &f->ctx); if (result) - hashcpy(result, f->buffer); + hashcpy(result, f->buffer, the_repository->hash_algo); if (flags & CSUM_HASH_IN_STREAM) flush(f, f->buffer, the_hash_algo->rawsz); if (flags & CSUM_FSYNC) @@ -98,6 +102,15 @@ int finalize_hashfile(struct hashfile *f, unsigned char *result, return fd; } +void discard_hashfile(struct hashfile *f) +{ + if (0 <= f->check_fd) + close(f->check_fd); + if (0 <= f->fd) + close(f->fd); + free_hashfile(f); +} + void hashwrite(struct hashfile *f, const void *buf, unsigned int count) { while (count) { @@ -206,7 +219,7 @@ int hashfile_truncate(struct hashfile *f, struct hashfile_checkpoint *checkpoint lseek(f->fd, offset, SEEK_SET) != offset) return -1; f->total = offset; - f->ctx = checkpoint->ctx; + the_hash_algo->clone_fn(&f->ctx, &checkpoint->ctx); f->offset = 0; /* hashflush() was called in checkpoint */ return 0; } @@ -236,5 +249,5 @@ int hashfile_checksum_valid(const unsigned char *data, size_t total_len) the_hash_algo->update_fn(&ctx, data, data_len); the_hash_algo->final_fn(got, &ctx); - return hasheq(got, data + data_len); + return hasheq(got, data + data_len, the_repository->hash_algo); } |
