Merge branch 'vd/sparse-reset-checkout-fixes'

Segfault fix-up to an earlier fix to the topic to teach "git reset"
and "git checkout" work better in a sparse checkout.

* vd/sparse-reset-checkout-fixes:
  unpack-trees: fix sparse directory recursion check
This commit is contained in:
Junio C Hamano 2022-09-09 12:02:25 -07:00
commit fe3939bc2a
2 changed files with 11 additions and 2 deletions

View File

@ -380,6 +380,15 @@ test_expect_success 'checkout with modified sparse directory' '
test_all_match git checkout base test_all_match git checkout base
' '
test_expect_success 'checkout orphan then non-orphan' '
init_repos &&
test_all_match git checkout --orphan test-orphan &&
test_all_match git status --porcelain=v2 &&
test_all_match git checkout base &&
test_all_match git status --porcelain=v2
'
test_expect_success 'add outside sparse cone' ' test_expect_success 'add outside sparse cone' '
init_repos && init_repos &&

View File

@ -1423,7 +1423,7 @@ static void debug_unpack_callback(int n,
* from the tree walk at the given traverse_info. * from the tree walk at the given traverse_info.
*/ */
static int is_sparse_directory_entry(struct cache_entry *ce, static int is_sparse_directory_entry(struct cache_entry *ce,
struct name_entry *name, const struct name_entry *name,
struct traverse_info *info) struct traverse_info *info)
{ {
if (!ce || !name || !S_ISSPARSEDIR(ce->ce_mode)) if (!ce || !name || !S_ISSPARSEDIR(ce->ce_mode))
@ -1562,7 +1562,7 @@ static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str
} }
} }
if (!is_sparse_directory_entry(src[0], names, info) && if (!is_sparse_directory_entry(src[0], p, info) &&
!is_new_sparse_dir && !is_new_sparse_dir &&
traverse_trees_recursive(n, dirmask, mask & ~dirmask, traverse_trees_recursive(n, dirmask, mask & ~dirmask,
names, info) < 0) { names, info) < 0) {