Skip to content

Commit

Permalink
Merge branch 'sparse-index-vs-split-index'
Browse files Browse the repository at this point in the history
The sparse index feature is (still) incompatible with the split index
feature. This topic helps ensure that we do not use them concurrently by
mistake.

This fixes a couple of test failures in t1091 that were detected during
the rebase of microsoft/git onto v2.35.0-rc*.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
  • Loading branch information
dscho authored and ldennington committed Jan 24, 2022
2 parents 8533731 + 91b2f25 commit 3ff1e71
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 29 deletions.
3 changes: 3 additions & 0 deletions read-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -3022,6 +3022,9 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
!is_null_oid(&istate->split_index->base_oid)) {
struct strbuf sb = STRBUF_INIT;

if (istate->sparse_index)
die(_("cannot write split index for a sparse index"));

err = write_link_extension(&sb, istate) < 0 ||
write_index_ext_header(f, eoie_c, CACHE_EXT_LINK,
sb.len) < 0;
Expand Down
2 changes: 1 addition & 1 deletion sparse-index.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ static int is_sparse_index_allowed(struct index_state *istate, int flags)
/*
* The sparse index is not (yet) integrated with a split index.
*/
if (istate->split_index)
if (istate->split_index || git_env_bool("GIT_TEST_SPLIT_INDEX", 0))
return 0;
/*
* The GIT_TEST_SPARSE_INDEX environment variable triggers the
Expand Down
3 changes: 3 additions & 0 deletions split-index.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
struct split_index *init_split_index(struct index_state *istate)
{
if (!istate->split_index) {
if (istate->sparse_index)
die(_("cannot use split index with a sparse index"));

CALLOC_ARRAY(istate->split_index, 1);
istate->split_index->refcount = 1;
}
Expand Down
54 changes: 26 additions & 28 deletions t/t1091-sparse-checkout-builtin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ test_description='sparse checkout builtin tests'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME

GIT_TEST_SPLIT_INDEX=false
export GIT_TEST_SPLIT_INDEX

. ./test-lib.sh

list_files() {
Expand Down Expand Up @@ -228,36 +231,31 @@ test_expect_success 'sparse-checkout disable' '
'

test_expect_success 'sparse-index enabled and disabled' '
(
sane_unset GIT_TEST_SPLIT_INDEX &&
git -C repo update-index --no-split-index &&
git -C repo sparse-checkout init --cone --sparse-index &&
test_cmp_config -C repo true index.sparse &&
git -C repo ls-files --sparse >sparse &&
git -C repo sparse-checkout disable &&
git -C repo ls-files --sparse >full &&
cat >expect <<-\EOF &&
@@ -1,4 +1,7 @@
a
-deep/
-folder1/
-folder2/
+deep/a
+deep/deeper1/a
+deep/deeper1/deepest/a
+deep/deeper2/a
+folder1/a
+folder2/a
EOF
git -C repo sparse-checkout init --cone --sparse-index &&
test_cmp_config -C repo true index.sparse &&
git -C repo ls-files --sparse >sparse &&
git -C repo sparse-checkout disable &&
git -C repo ls-files --sparse >full &&
diff -u sparse full | tail -n +3 >actual &&
test_cmp expect actual &&
cat >expect <<-\EOF &&
@@ -1,4 +1,7 @@
a
-deep/
-folder1/
-folder2/
+deep/a
+deep/deeper1/a
+deep/deeper1/deepest/a
+deep/deeper2/a
+folder1/a
+folder2/a
EOF
diff -u sparse full | tail -n +3 >actual &&
test_cmp expect actual &&
git -C repo config --list >config &&
! grep index.sparse config
)
git -C repo config --list >config &&
! grep index.sparse config
'

test_expect_success 'cone mode: init and set' '
Expand Down

0 comments on commit 3ff1e71

Please sign in to comment.