Skip to content

Commit 0e01d41

Browse files
committed
checkout-index: perform lazy index expansion for --sparse
When `--sparse` is specified for `checkout-index` but no sparse directory entries exist outside the sparse checkout definition, the index does not need to be expanded. For this case, moving the index expansion into an explicit check for a sparse directory entry prevents unnecessary expansion. Signed-off-by: Victoria Dye <[email protected]>
1 parent 8e2748e commit 0e01d41

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

builtin/checkout-index.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,18 @@ static int checkout_all(const char *prefix, int prefix_length, int include_spars
128128
int i, errs = 0;
129129
struct cache_entry *last_ce = NULL;
130130

131-
if (include_sparse)
132-
ensure_full_index(&the_index);
133-
134131
for (i = 0; i < active_nr ; i++) {
135132
struct cache_entry *ce = active_cache[i];
133+
if (include_sparse && S_ISSPARSEDIR(ce->ce_mode)) {
134+
/*
135+
* If the current entry is a sparse directory (and entries outside the
136+
* sparse checkout definition are included), expand the index and
137+
* continue the loop on the current index position (now pointing to the
138+
* first entry inside the expanded sparse directory).
139+
*/
140+
ensure_full_index(&the_index);
141+
ce = active_cache[i];
142+
}
136143
if (!include_sparse && !path_in_sparse_checkout(ce->name, &the_index))
137144
continue;
138145
if (ce_stage(ce) != checkout_stage

0 commit comments

Comments
 (0)