gvfs: add the feature to skip writing the index' SHA-1

This takes a substantial amount of time, and if the user is reasonably
sure that the files' integrity is not compromised, that time can be saved.

Git no longer verifies the SHA-1 by default, anyway.

Signed-off-by: Kevin Willford <kewillf@microsoft.com>
This commit is contained in:
Kevin Willford 2017-01-24 17:38:59 +01:00 коммит произвёл Johannes Schindelin
Родитель 392cd07572
Коммит 10eecbfe76
6 изменённых файлов: 61 добавлений и 3 удалений

Просмотреть файл

@ -729,7 +729,15 @@ core.multiPackIndex::
information. Defaults to true.
core.gvfs::
Enable the features needed for GVFS.
Enable the features needed for GVFS. This value can be set to true
to indicate all features should be turned on or the bit values listed
below can be used to turn on specific features.
+
--
GVFS_SKIP_SHA_ON_INDEX::
Bit value 1
Disables the calculation of the sha when writing the index
--
core.sparseCheckout::
Enable "sparse checkout" feature. See linkgit:git-sparse-checkout[1]

Просмотреть файл

@ -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,16 @@ int finalize_hashfile(struct hashfile *f, unsigned char *result,
int fd;
hashflush(f);
the_hash_algo->final_fn(f->buffer, &f->ctx);
/*
* If we skip the hash function, be sure to create an empty hash
* for the results.
*/
if (f->skip_hash)
memset(f->buffer, 0, the_hash_algo->rawsz);
else
the_hash_algo->final_fn(f->buffer, &f->ctx);
if (result)
hashcpy(result, f->buffer);
if (flags & CSUM_HASH_IN_STREAM)
@ -158,6 +168,7 @@ static struct hashfile *hashfd_internal(int fd, const char *name,
f->buffer_len = buffer_len;
f->buffer = xmalloc(buffer_len);
f->check_buffer = NULL;
f->skip_hash = 0;
return f;
}

Просмотреть файл

@ -20,6 +20,13 @@ struct hashfile {
size_t buffer_len;
unsigned char *buffer;
unsigned char *check_buffer;
/*
* If set to 1, skip_hash indicates that we should
* not actually compute the hash for this hashfile and
* instead only use it as a buffered write.
*/
int skip_hash;
};
/* Checkpoint */

6
gvfs.h
Просмотреть файл

@ -9,6 +9,12 @@
* used for GVFS functionality
*/
/*
* The list of bits in the core_gvfs setting
*/
#define GVFS_SKIP_SHA_ON_INDEX (1 << 0)
static inline int gvfs_config_is_set(int mask) {
return (core_gvfs & mask) == mask;
}

Просмотреть файл

@ -4,6 +4,7 @@
* Copyright (C) Linus Torvalds, 2005
*/
#include "cache.h"
#include "gvfs.h"
#include "config.h"
#include "diff.h"
#include "diffcore.h"
@ -2910,6 +2911,9 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
f = hashfd(tempfile->fd, tempfile->filename.buf);
if (gvfs_config_is_set(GVFS_SKIP_SHA_ON_INDEX))
f->skip_hash = 1;
for (i = removed = extended = 0; i < entries; i++) {
if (cache[i]->ce_flags & CE_REMOVE)
removed++;

Просмотреть файл

@ -0,0 +1,22 @@
#!/bin/sh
test_description='check that read-tree works with core.gvfs config value'
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-read-tree.sh
test_expect_success setup '
echo one >a &&
git add a &&
git commit -m initial
'
test_expect_success 'read-tree without core.gvsf' '
read_tree_u_must_succeed -m -u HEAD
'
test_expect_success 'read-tree with core.gvfs set to 1' '
git config core.gvfs 1 &&
read_tree_u_must_succeed -m -u HEAD
'
test_done