unpack-trees: unpack new trees as sparse directories
If 'unpack_single_entry()' is unpacking a new directory tree (that is, one not already present in the index) into a sparse index, unpack the tree as a sparse directory rather than traversing its contents and unpacking each file individually. This helps keep the sparse index as collapsed as possible in cases such as 'git reset --hard' restoring a outside-of-cone directory removed with 'git rm -r --sparse'. Without this patch, 'unpack_single_entry()' will only unpack a directory into the index as a sparse directory (rather than traversing into it and unpacking its files one-by-one) if an entry with the same name already exists in the index. This patch allows sparse directory unpacking without a matching index entry when the following conditions are met: 1. the directory's path is outside the sparse cone, and 2. there are no children of the directory in the index If a directory meets these requirements (as determined by 'is_new_sparse_dir()'), 'unpack_single_entry()' unpacks the sparse directory index entry and propagates the decision back up to 'unpack_callback()' to prevent unnecessary tree traversal into the unpacked directory. Reported-by: Shaoxuan Yuan <shaoxuan.yuan02@gmail.com> Signed-off-by: Victoria Dye <vdye@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
9553aa0f6c
commit
b15207b8cf
@ -695,6 +695,23 @@ test_expect_success 'reset with wildcard pathspec' '
|
||||
test_all_match git ls-files -s -- folder1
|
||||
'
|
||||
|
||||
test_expect_success 'reset hard with removed sparse dir' '
|
||||
init_repos &&
|
||||
|
||||
run_on_all git rm -r --sparse folder1 &&
|
||||
test_all_match git status --porcelain=v2 &&
|
||||
|
||||
test_all_match git reset --hard &&
|
||||
test_all_match git status --porcelain=v2 &&
|
||||
|
||||
cat >expect <<-\EOF &&
|
||||
folder1/
|
||||
EOF
|
||||
|
||||
git -C sparse-index ls-files --sparse folder1 >out &&
|
||||
test_cmp expect out
|
||||
'
|
||||
|
||||
test_expect_success 'update-index modify outside sparse definition' '
|
||||
init_repos &&
|
||||
|
||||
|
Reference in New Issue
Block a user