]> git.ipfire.org Git - thirdparty/git.git/commit
restore: avoid sparse index expansion
authorDerrick Stolee <stolee@gmail.com>
Tue, 26 May 2026 20:26:34 +0000 (20:26 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 27 May 2026 04:42:59 +0000 (13:42 +0900)
commit105aacd072e41c55948d016b46f86f75db2487b3
treeadc9720f503c7059c903d6b8b8175f3f7a1a4f32
parentca7b9ae3403b1a46fffbdae312092c4029470eee
restore: avoid sparse index expansion

Teach update_some() to handle sparse directory entries at the tree
level rather than expanding the entire sparse index. When iterating a
source tree during checkout/restore operations:

 - If a directory matches a sparse directory entry with the same OID,
   skip it entirely (no change needed).

 - If the OID differs and we are in non-overlay mode (e.g., restore
   --staged), update the sparse directory entry's OID in place. This
   is semantically correct because non-overlay mode removes paths not
   in the source tree anyway.

 - In overlay mode (e.g., checkout <tree> -- .), fall through to
   recursive descent so individual file entries are preserved
   correctly.

Also switch from index_name_pos() to index_name_pos_sparse() for
individual file lookups to avoid triggering ensure_full_index() when
the file is already individually tracked in the index.

Update the test expectation in t1092 to assert that 'restore --staged'
no longer expands the sparse index.

Signed-off-by: Derrick Stolee <stolee@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/checkout.c
t/t1092-sparse-checkout-compatibility.sh