Skip to content

Commit b05892f

Browse files
authored
Merge pull request git-for-windows#433 from vdye/remove-index-expansions
Remove sparse index expansions from untracked file stashes
2 parents 234b880 + 8b83ef8 commit b05892f

File tree

3 files changed

+37
-25
lines changed

3 files changed

+37
-25
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

t/t1092-sparse-checkout-compatibility.sh

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,6 +1185,9 @@ test_expect_success 'sparse-index is not expanded' '
11851185
ensure_not_expanded stash apply stash@{0} &&
11861186
ensure_not_expanded stash drop stash@{0} &&
11871187
1188+
ensure_not_expanded stash -u &&
1189+
ensure_not_expanded stash pop &&
1190+
11881191
ensure_not_expanded stash create &&
11891192
oid=$(git -C sparse-index stash create) &&
11901193
ensure_not_expanded stash store -m "test" $oid &&
@@ -1301,28 +1304,6 @@ test_expect_success 'sparse index is not expanded: read-tree' '
13011304
ensure_not_expanded read-tree --prefix=deep/deeper2 -u deepest
13021305
'
13031306

1304-
# NEEDSWORK: although the full repository's index is _not_ expanded as part of
1305-
# stash, a temporary index, which is _not_ sparse, is created when stashing and
1306-
# applying a stash of untracked files. As a result, the test reports that it
1307-
# finds an instance of `ensure_full_index`, but it does not carry with it the
1308-
# performance implications of expanding the full repository index.
1309-
test_expect_success 'sparse index is not expanded: stash -u' '
1310-
init_repos &&
1311-
1312-
mkdir -p sparse-index/folder1 &&
1313-
echo >>sparse-index/README.md &&
1314-
echo >>sparse-index/a &&
1315-
echo >>sparse-index/folder1/new &&
1316-
1317-
GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \
1318-
git -C sparse-index stash -u &&
1319-
test_region index ensure_full_index trace2.txt &&
1320-
1321-
GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \
1322-
git -C sparse-index stash pop &&
1323-
test_region index ensure_full_index trace2.txt
1324-
'
1325-
13261307
# NEEDSWORK: similar to `git add`, untracked files outside of the sparse
13271308
# checkout definition are successfully stashed and unstashed.
13281309
test_expect_success 'stash -u outside sparse checkout definition' '

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)