Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Documentation/config/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ index.skipHash::
checksum, write a trailing set of bytes with value zero, indicating
that the computation was skipped.
+
With a split index (see `core.splitIndex`), only the split index, which
is written on every index update, skips the hash. The shared index is
still hashed, as it is named after its hash, but it is rewritten only
when too many entries are not in it (see `splitIndex.maxPercentChange`).
+
If you enable `index.skipHash`, then Git clients older than 2.13.0 will
refuse to parse the index and Git clients older than 2.40.0 will report an
error during `git fsck`.
18 changes: 12 additions & 6 deletions read-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -2878,7 +2878,8 @@ enum write_extensions {
* rely on it.
*/
static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
enum write_extensions write_extensions, unsigned flags)
enum write_extensions write_extensions, unsigned flags,
int skip_hash)
{
uint64_t start = getnanotime();
struct hashfile *f;
Expand All @@ -2900,9 +2901,7 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
int nr, nr_threads, ret;

f = hashfd(the_repository->hash_algo, tempfile->fd, tempfile->filename.buf);

prepare_repo_settings(r);
f->skip_hash = r->settings.index_skip_hash;
f->skip_hash = skip_hash;

for (i = removed = extended = 0; i < entries; i++) {
if (cache[i]->ce_flags & CE_REMOVE)
Expand Down Expand Up @@ -3224,9 +3223,11 @@ static int do_write_locked_index(struct index_state *istate,
return ret;
}

prepare_repo_settings(istate->repo);
trace2_region_enter_printf("index", "do_write_index", istate->repo,
"%s", get_lock_file_path(lock));
ret = do_write_index(istate, lock->tempfile, write_extensions, flags);
ret = do_write_index(istate, lock->tempfile, write_extensions, flags,
istate->repo->settings.index_skip_hash);
trace2_region_leave_printf("index", "do_write_index", istate->repo,
"%s", get_lock_file_path(lock));

Expand Down Expand Up @@ -3339,9 +3340,14 @@ static int write_shared_index(struct index_state *istate,
move_cache_to_base_index(istate);
convert_to_sparse(istate, 0);

/*
* The shared index is named after its trailing hash, which the
* split index records to find it: compute it even with
* index.skipHash.
*/
trace2_region_enter_printf("index", "shared/do_write_index",
the_repository, "%s", get_tempfile_path(*temp));
ret = do_write_index(si->base, *temp, WRITE_NO_EXTENSION, flags);
ret = do_write_index(si->base, *temp, WRITE_NO_EXTENSION, flags, 0);
trace2_region_leave_printf("index", "shared/do_write_index",
the_repository, "%s", get_tempfile_path(*temp));

Expand Down
23 changes: 23 additions & 0 deletions t/t1700-split-index.sh
Original file line number Diff line number Diff line change
Expand Up @@ -544,4 +544,27 @@ test_expect_success 'GIT_TEST_SPLIT_INDEX works' '
)
'

test_expect_success 'shared index is hashed even with index.skipHash' '
git init skip-hash &&
(
cd skip-hash &&
git config core.splitIndex true &&
git config index.skipHash true &&
test_commit one &&
test_commit two &&

test-tool dump-split-index .git/index >dump &&
echo "own $ZERO_OID" >expect &&
grep "^own " dump >actual &&
test_cmp expect actual &&
base=$(sed -n "s/^base //p" dump) &&
test "$base" != "$ZERO_OID" &&
test_path_is_file .git/sharedindex.$base &&

git ls-files >actual &&
test_write_lines one.t two.t >expect &&
test_cmp expect actual
)
'

test_done
10 changes: 0 additions & 10 deletions t/t7508-status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1691,11 +1691,6 @@ do
git init update-after-read &&
(
cd update-after-read &&
if test $skip_hash = true
then
# index.skipHash does not work with a split index.
sane_unset GIT_TEST_SPLIT_INDEX
fi &&
git config index.skipHash $skip_hash &&
test_commit base &&
write_script .git/fsmonitor-hook <<-\EOF &&
Expand Down Expand Up @@ -1769,11 +1764,6 @@ do
test_expect_success "status refresh does not overwrite an index update made while collecting (index.skipHash=$skip_hash)" '
test_when_finished "rm -rf refresh-while-collecting" &&
(
if test $skip_hash = true
then
# index.skipHash does not work with a split index.
sane_unset GIT_TEST_SPLIT_INDEX
fi &&
setup_index_update_during_collection refresh-while-collecting &&
cd refresh-while-collecting &&
git config index.skipHash $skip_hash &&
Expand Down
10 changes: 0 additions & 10 deletions t/t9210-scalar.sh
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,6 @@ test_expect_success 'set up repository to clone' '
'

test_expect_success 'scalar clone' '
# index.skipHash (Scalar default) and GIT_TEST_SPLIT_INDEX are
# incompatible: the shared index gets a null OID and fails to
# load on re-read.
sane_unset GIT_TEST_SPLIT_INDEX &&
second=$(git rev-parse --verify second:second.t) &&
scalar clone "file://$(pwd)" cloned --single-branch &&
(
Expand Down Expand Up @@ -186,7 +182,6 @@ test_expect_success 'scalar clone' '
'

test_expect_success 'scalar clone --no-... opts' '
sane_unset GIT_TEST_SPLIT_INDEX &&
# Note: redirect stderr always to avoid having a verbose test
# run result in a difference in the --[no-]progress option.
GIT_TRACE2_EVENT="$(pwd)/no-opt-trace" scalar clone \
Expand Down Expand Up @@ -251,10 +246,6 @@ test_expect_success 'scalar reconfigure --all with includeIf.onbranch' '
'

test_expect_success 'scalar reconfigure --all with detached HEADs' '
# This test demonstrates an issue with index.skipHash=true and
# this test variable for the split index. Disable the test variable.
sane_unset GIT_TEST_SPLIT_INDEX &&

repos="two three four" &&
for num in $repos
do
Expand Down Expand Up @@ -317,7 +308,6 @@ test_expect_success '`scalar [...] <dir>` errors out when dir is missing' '

SQ="'"
test_expect_success UNZIP 'scalar diagnose' '
sane_unset GIT_TEST_SPLIT_INDEX &&
scalar clone "file://$(pwd)" cloned --single-branch &&
git repack &&
echo "$(pwd)/.git/objects/" >>cloned/src/.git/objects/info/alternates &&
Expand Down
5 changes: 0 additions & 5 deletions t/t9211-scalar-clone.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ test_description='test the `scalar clone` subcommand'
GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt,launchctl:true,schtasks:true"
export GIT_TEST_MAINT_SCHEDULER

# index.skipHash (Scalar default) and GIT_TEST_SPLIT_INDEX are
# incompatible: the shared index gets a null OID and fails to
# load on re-read. Every test here uses scalar clone.
sane_unset GIT_TEST_SPLIT_INDEX

test_expect_success 'set up repository to clone' '
rm -rf .git &&
git init to-clone &&
Expand Down
Loading