Skip to content

Commit

Permalink
Merge branch 'js/sparse-vs-split-index' into jch
Browse files Browse the repository at this point in the history
Mark in various places in the code that the sparse index and the
split index features are mutually incompatible.

* js/sparse-vs-split-index:
  split-index: it really is incompatible with the sparse index
  t1091: disable split index
  sparse-index: sparse index is disallowed when split index is active
  • Loading branch information
gitster committed Feb 8, 2022
2 parents d9c5c0b + 451b66c commit 3c99780
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
Expand Up @@ -3010,6 +3010,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
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
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
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 @@ -234,36 +237,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 3c99780

Please sign in to comment.