Skip to content

Commit 00ebd6a

Browse files
committed
sparse-checkout: integrate with sparse index
When modifying the sparse-checkout definition, the sparse-checkout builtin calls update_sparsity() to modify the SKIP_WORKTREE bits of all cache entries in the index. Before, we needed the index to be fully expanded in order to ensure we had the full list of files necessary that match the new patterns. Insert a call to reset_sparse_directories() that expands sparse directories that are within the new pattern list, but only far enough that every necessary file path now exists as a cache entry. The remaining logic within update_sparsity() will modify the SKIP_WORKTREE bits appropriately. This allows us to disable command_requires_full_index within the sparse-checkout builtin. Add tests that demonstrate that we are not expanding to a full index unnecessarily. Signed-off-by: Derrick Stolee <[email protected]>
1 parent 41a1461 commit 00ebd6a

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

builtin/sparse-checkout.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,9 @@ int cmd_sparse_checkout(int argc, const char **argv, const char *prefix)
763763

764764
git_config(git_default_config, NULL);
765765

766+
prepare_repo_settings(the_repository);
767+
the_repository->settings.command_requires_full_index = 0;
768+
766769
if (argc > 0) {
767770
if (!strcmp(argv[0], "list"))
768771
return sparse_checkout_list(argc, argv);

t/t1092-sparse-checkout-compatibility.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,23 @@ test_expect_success 'sparse-index is not expanded: merge conflict in cone' '
722722
)
723723
'
724724

725+
test_expect_success 'sparse index is not expanded: sparse-checkout' '
726+
init_repos &&
727+
728+
ensure_not_expanded sparse-checkout set deep/deeper2 &&
729+
ensure_not_expanded sparse-checkout set deep/deeper1 &&
730+
ensure_not_expanded sparse-checkout set deep &&
731+
ensure_not_expanded sparse-checkout add folder1 &&
732+
ensure_not_expanded sparse-checkout set deep/deeper1 &&
733+
ensure_not_expanded sparse-checkout set folder2 &&
734+
735+
echo >>sparse-index/folder2/a &&
736+
git -C sparse-index add folder2/a &&
737+
ensure_not_expanded sparse-checkout add folder1 &&
738+
ensure_not_expanded sparse-checkout set deep/deeper1 &&
739+
ensure_not_expanded sparse-checkout set
740+
'
741+
725742
# NEEDSWORK: a sparse-checkout behaves differently from a full checkout
726743
# in this scenario, but it shouldn't.
727744
test_expect_success 'reset mixed and checkout orphan' '

unpack-trees.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "promisor-remote.h"
2222
#include "entry.h"
2323
#include "parallel-checkout.h"
24+
#include "sparse-index.h"
2425

2526
/*
2627
* Error messages expected by scripts out of plumbing commands such as
@@ -1955,6 +1956,9 @@ enum update_sparsity_result update_sparsity(struct unpack_trees_options *o)
19551956
goto skip_sparse_checkout;
19561957
}
19571958

1959+
/* Expand sparse directories as needed */
1960+
expand_to_pattern_list(o->src_index, o->pl);
1961+
19581962
/* Set NEW_SKIP_WORKTREE on existing entries. */
19591963
mark_all_ce_unused(o->src_index);
19601964
mark_new_skip_worktree(o->pl, o->src_index, 0,

0 commit comments

Comments
 (0)