Skip to content

Commit

Permalink
sparse-checkout: add config to disable deleting dirs
Browse files Browse the repository at this point in the history
The clean_tracked_sparse_directories() method deletes the tracked
directories that go out of scope when the sparse-checkout cone changes,
at least in cone mode. This is new behavior, but is recommended based on
our understanding of how users are interacting with the feature in most
cases.

It is possible that some users will object to the new behavior, so
create a new configuration option 'index.deleteSparseDirectories' that
can be set to 'false' to make clean_tracked_sparse_directories() do
nothing. This will keep all untracked files in the working tree and
cause performance problems with the sparse index, but those trade-offs
are for the user to decide.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
  • Loading branch information
derrickstolee committed Aug 24, 2021
1 parent 3a2f316 commit fb47b56
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Documentation/config/index.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
index.deleteSparseDirectories::
When enabled, the cone mode sparse-checkout feature will delete
directories that are outside of the sparse-checkout cone, unless
such a directory contains an untracked, non-ignored file. Defaults
to true.

index.recordEndOfIndexEntries::
Specifies whether the index file should include an "End Of Index
Entry" section. This reduces index load time on multiprocessor
Expand Down
9 changes: 8 additions & 1 deletion builtin/sparse-checkout.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ static int sparse_checkout_list(int argc, const char **argv)

static void clean_tracked_sparse_directories(struct repository *r)
{
int i, was_full = 0;
int i, value, was_full = 0;
struct strbuf path = STRBUF_INIT;
size_t pathlen;
struct string_list_item *item;
Expand All @@ -119,6 +119,13 @@ static void clean_tracked_sparse_directories(struct repository *r)
!r->index->sparse_checkout_patterns->use_cone_patterns)
return;

/*
* Users can disable this behavior.
*/
if (!repo_config_get_bool(r, "index.deletesparsedirectories", &value) &&
!value)
return;

/*
* Use the sparse index as a data structure to assist finding
* directories that are safe to delete. This conversion to a
Expand Down
4 changes: 4 additions & 0 deletions t/t1091-sparse-checkout-builtin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,10 @@ test_expect_success 'cone mode clears ignored subdirectories' '
git -C repo status --porcelain=v2 >out &&
test_must_be_empty out &&
git -C repo -c index.deleteSparseDirectories=false sparse-checkout reapply &&
test_path_is_dir repo/folder1 &&
test_path_is_dir repo/deep/deeper2 &&
git -C repo sparse-checkout reapply &&
test_path_is_missing repo/folder1 &&
test_path_is_missing repo/deep/deeper2 &&
Expand Down

0 comments on commit fb47b56

Please sign in to comment.