]> git.ipfire.org Git - thirdparty/git.git/commit - unpack-trees.c
unpack-trees: unpack new trees as sparse directories
authorVictoria Dye <vdye@github.com>
Mon, 8 Aug 2022 19:07:52 +0000 (19:07 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 8 Aug 2022 20:21:50 +0000 (13:21 -0700)
commitb15207b8cf1a1930fe5eb076c08c6ddc92d9282d
tree0839b08ddffac0b7c5810e53958e7efd6b92afb6
parent9553aa0f6c844085b3fbf05da5440dd7096dd764
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>
t/t1092-sparse-checkout-compatibility.sh
unpack-trees.c