diff options
Diffstat (limited to 'csum-file.c')
-rw-r--r-- | csum-file.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/csum-file.c b/csum-file.c index 59ef3398ca..daf9b06dff 100644 --- a/csum-file.c +++ b/csum-file.c @@ -7,9 +7,11 @@ * files. Useful when you write a file that you want to be * able to verify hasn't been messed with afterwards. */ -#include "cache.h" +#include "git-compat-util.h" #include "progress.h" #include "csum-file.h" +#include "hash.h" +#include "wrapper.h" static void verify_buffer_or_die(struct hashfile *f, const void *buf, @@ -45,7 +47,8 @@ void hashflush(struct hashfile *f) unsigned offset = f->offset; if (offset) { - the_hash_algo->update_fn(&f->ctx, f->buffer, offset); + if (!f->skip_hash) + the_hash_algo->update_fn(&f->ctx, f->buffer, offset); flush(f, f->buffer, offset); f->offset = 0; } @@ -64,7 +67,12 @@ int finalize_hashfile(struct hashfile *f, unsigned char *result, int fd; hashflush(f); - the_hash_algo->final_fn(f->buffer, &f->ctx); + + if (f->skip_hash) + hashclr(f->buffer); + else + the_hash_algo->final_fn(f->buffer, &f->ctx); + if (result) hashcpy(result, f->buffer); if (flags & CSUM_HASH_IN_STREAM) @@ -108,7 +116,8 @@ void hashwrite(struct hashfile *f, const void *buf, unsigned int count) * the hashfile's buffer. In this block, * f->offset is necessarily zero. */ - the_hash_algo->update_fn(&f->ctx, buf, nr); + if (!f->skip_hash) + the_hash_algo->update_fn(&f->ctx, buf, nr); flush(f, buf, nr); } else { /* @@ -153,6 +162,7 @@ static struct hashfile *hashfd_internal(int fd, const char *name, f->tp = tp; f->name = name; f->do_crc = 0; + f->skip_hash = 0; the_hash_algo->init_fn(&f->ctx); f->buffer_len = buffer_len; |