diff options
| author | Junio C Hamano <gitster@pobox.com> | 2023-01-16 12:07:47 -0800 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2023-01-16 12:07:47 -0800 |
| commit | ffd923868574a004ec20a80dbc3b813da9a93b08 (patch) | |
| tree | fb80c1309a6cd0528d7dcc77d20a18451ef278fc /csum-file.c | |
| parent | Merge branch 'ws/single-file-cone' (diff) | |
| parent | features: feature.manyFiles implies fast index writes (diff) | |
| download | git-ffd923868574a004ec20a80dbc3b813da9a93b08.tar.gz git-ffd923868574a004ec20a80dbc3b813da9a93b08.zip | |
Merge branch 'ds/omit-trailing-hash-in-index'
Introduce an optional configuration to allow the trailing hash that
protects the index file from bit flipping.
* ds/omit-trailing-hash-in-index:
features: feature.manyFiles implies fast index writes
test-lib-functions: add helper for trailing hash
read-cache: add index.skipHash config option
hashfile: allow skipping the hash function
Diffstat (limited to 'csum-file.c')
| -rw-r--r-- | csum-file.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/csum-file.c b/csum-file.c index 59ef3398ca..cce13c0f04 100644 --- a/csum-file.c +++ b/csum-file.c @@ -45,7 +45,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 +65,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 +114,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 +160,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; |
