Skip to content

Commit

Permalink
gvfs: add the feature to skip validation of the index' SHA-1
Browse files Browse the repository at this point in the history
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.

Signed-off-by: Kevin Willford <kewillf@microsoft.com>
  • Loading branch information
Kevin Willford authored and dscho committed Jun 11, 2018
1 parent 516cdfa commit 21fed2d
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 4 deletions.
10 changes: 9 additions & 1 deletion Documentation/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,15 @@ This setting defaults to "refs/notes/commits", and it can be overridden by
the `GIT_NOTES_REF` environment variable. See linkgit:git-notes[1].

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_READ::
Bit value 1
Disables the calculation and validation of the sha when reading the index
--

core.sparseCheckout::
Enable "sparse checkout" feature. See section "Sparse checkout" in
Expand Down
6 changes: 6 additions & 0 deletions gvfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
19 changes: 16 additions & 3 deletions read-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "split-index.h"
#include "utf8.h"
#include "fsmonitor.h"
#include "gvfs.h"

/* Mask for the name length in ce_flags in the on-disk index */

Expand Down Expand Up @@ -1586,6 +1587,14 @@ static int verify_hdr(struct cache_header *hdr, unsigned long size)
if (!verify_index_checksum)
return 0;

/*
Since gitmodules_config runs this code
and is called before git_config(git_default_config, ...)
the config values are not loaded and has to be retrieved directly here.
*/
if (gvfs_config_load_and_is_set(GVFS_SKIP_SHA_ON_INDEX))
return 0;

the_hash_algo->init_fn(&c);
the_hash_algo->update_fn(&c, hdr, size - the_hash_algo->rawsz);
the_hash_algo->final_fn(hash, &c);
Expand Down Expand Up @@ -1992,7 +2001,9 @@ static int ce_write_flush(git_hash_ctx *context, int fd)
{
unsigned int buffered = write_buffer_len;
if (buffered) {
the_hash_algo->update_fn(context, write_buffer, buffered);
if (!gvfs_config_is_set(GVFS_SKIP_SHA_ON_INDEX))
the_hash_algo->update_fn(context, write_buffer,
buffered);
if (write_in_full(fd, write_buffer, buffered) < 0)
return -1;
write_buffer_len = 0;
Expand Down Expand Up @@ -2037,7 +2048,8 @@ static int ce_flush(git_hash_ctx *context, int fd, unsigned char *hash)

if (left) {
write_buffer_len = 0;
the_hash_algo->update_fn(context, write_buffer, left);
if (!gvfs_config_is_set(GVFS_SKIP_SHA_ON_INDEX))
the_hash_algo->update_fn(context, write_buffer, left);
}

/* Flush first if not enough space for hash signature */
Expand All @@ -2048,7 +2060,8 @@ static int ce_flush(git_hash_ctx *context, int fd, unsigned char *hash)
}

/* Append the hash signature at the end */
the_hash_algo->final_fn(write_buffer + left, context);
if (!gvfs_config_is_set(GVFS_SKIP_SHA_ON_INDEX))
the_hash_algo->final_fn(write_buffer + left, context);
hashcpy(hash, write_buffer + left);
left += the_hash_algo->rawsz;
return (write_in_full(fd, write_buffer, left) < 0) ? -1 : 0;
Expand Down
22 changes: 22 additions & 0 deletions t/t1015-read-tree-skip-sha-on-read.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 21fed2d

Please sign in to comment.