Skip to content

Commit 8e2748e

Browse files
committed
unpack-trees: expand conditions for sparse result index
After `unpack-trees` processing, the index would only be considered "sparse" if it contains any sparse directories. That condition missed the case where the index contains only files inside the sparse checkout definition. By explicitly checking for that condition and setting `sparse_index` accordingly, later processing to ensure the index "remains" full can be avoided. Signed-off-by: Victoria Dye <[email protected]>
1 parent 234b880 commit 8e2748e

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

unpack-trees.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1945,6 +1945,30 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
19451945
}
19461946
}
19471947

1948+
/*
1949+
* After unpacking trees, the index will be marked "sparse" if any sparse
1950+
* directories have been encountered. However, the index may still be
1951+
* sparse if there are no sparse directories. To make sure the index is
1952+
* marked "sparse" as often as possible, the index is marked sparse if
1953+
* all of the following are true:
1954+
* - the command in progress allows use of a sparse index
1955+
* - the index is not already sparse
1956+
* - cone-mode sparse checkout with sparse index is enabled for the repo
1957+
* - all index entries are inside of the sparse checkout cone
1958+
*/
1959+
if (!repo->settings.command_requires_full_index && !o->result.sparse_index &&
1960+
core_apply_sparse_checkout && core_sparse_checkout_cone && repo->settings.sparse_index) {
1961+
o->result.sparse_index = COLLAPSED;
1962+
for (i = 0; i < o->result.cache_nr; i++) {
1963+
struct cache_entry *ce = o->result.cache[i];
1964+
1965+
if (!path_in_cone_modesparse_checkout(ce->name, &o->result)) {
1966+
o->result.sparse_index = COMPLETELY_FULL;
1967+
break;
1968+
}
1969+
}
1970+
}
1971+
19481972
ret = check_updates(o, &o->result) ? (-2) : 0;
19491973
if (o->dst_index) {
19501974
move_index_extensions(&o->result, o->src_index);

0 commit comments

Comments
 (0)