Skip to content

Commit b9ca5e2

Browse files
vdyegitster
authored andcommitted
update-index: reduce scope of index expansion in do_reupdate
Replace unconditional index expansion in 'do_reupdate()' with one scoped to only where a full index is needed. A full index is only required in 'do_reupdate()' when a sparse directory in the index differs from HEAD; in that case, the index is expanded and the operation restarted. Because the index should only be expanded if a sparse directory is modified, add a test ensuring the index is not expanded when differences only exist within the sparse cone. Signed-off-by: Victoria Dye <[email protected]> Reviewed-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c35e9f5 commit b9ca5e2

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

builtin/update-index.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ static struct cache_entry *read_one_ent(const char *which,
606606
error("%s: not in %s branch.", path, which);
607607
return NULL;
608608
}
609-
if (mode == S_IFDIR) {
609+
if (!the_index.sparse_index && mode == S_IFDIR) {
610610
if (which)
611611
error("%s: not a blob in %s branch.", path, which);
612612
return NULL;
@@ -743,8 +743,6 @@ static int do_reupdate(int ac, const char **av,
743743
*/
744744
has_head = 0;
745745
redo:
746-
/* TODO: audit for interaction with sparse-index. */
747-
ensure_full_index(&the_index);
748746
for (pos = 0; pos < active_nr; pos++) {
749747
const struct cache_entry *ce = active_cache[pos];
750748
struct cache_entry *old = NULL;
@@ -761,6 +759,16 @@ static int do_reupdate(int ac, const char **av,
761759
discard_cache_entry(old);
762760
continue; /* unchanged */
763761
}
762+
763+
/* At this point, we know the contents of the sparse directory are
764+
* modified with respect to HEAD, so we expand the index and restart
765+
* to process each path individually
766+
*/
767+
if (S_ISSPARSEDIR(ce->ce_mode)) {
768+
ensure_full_index(&the_index);
769+
goto redo;
770+
}
771+
764772
/* Be careful. The working tree may not have the
765773
* path anymore, in which case, under 'allow_remove',
766774
* or worse yet 'allow_replace', active_nr may decrease.

t/t1092-sparse-checkout-compatibility.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,10 @@ test_expect_success 'sparse index is not expanded: update-index' '
12651265
12661266
ensure_not_expanded update-index --add README.md &&
12671267
ensure_not_expanded update-index a &&
1268-
ensure_not_expanded update-index --remove deep/a
1268+
ensure_not_expanded update-index --remove deep/a &&
1269+
1270+
ensure_not_expanded reset --soft update-deep &&
1271+
ensure_not_expanded update-index --add --remove --again
12691272
'
12701273

12711274
test_expect_success 'sparse index is not expanded: blame' '

0 commit comments

Comments
 (0)