Skip to content

Commit 51dfddf

Browse files
committed
update-index: remove unnecessary index expansion in do_reupdate
Instead of ensuring the full index, only need to prevent reupdating sparse directory entries to maintain expected behavior. Corresponding addition to index expansion test verifies the sparse index is not expanded. Signed-off-by: Victoria Dye <[email protected]>
1 parent c39d7f2 commit 51dfddf

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

builtin/update-index.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -748,17 +748,23 @@ static int do_reupdate(int ac, const char **av,
748748
* commit. Update everything in the index.
749749
*/
750750
has_head = 0;
751+
751752
redo:
752-
/* TODO: audit for interaction with sparse-index. */
753-
ensure_full_index(&the_index);
754753
for (pos = 0; pos < active_nr; pos++) {
755754
const struct cache_entry *ce = active_cache[pos];
756755
struct cache_entry *old = NULL;
757756
int save_nr;
758757
char *path;
759758

760-
if (ce_stage(ce) || !ce_path_match(&the_index, ce, &pathspec, NULL))
759+
/*
760+
* We can safely skip re-updating sparse directories because if there
761+
* were any changes to re-update inside of the sparse directory, it
762+
* would not be sparse.
763+
*/
764+
if (S_ISSPARSEDIR(ce->ce_mode) || ce_stage(ce) ||
765+
!ce_path_match(&the_index, ce, &pathspec, NULL))
761766
continue;
767+
762768
if (has_head)
763769
old = read_one_ent(NULL, &head_oid,
764770
ce->name, ce_namelen(ce), 0);

t/t1092-sparse-checkout-compatibility.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,9 @@ test_expect_success 'sparse index is not expanded: update-index' '
10281028
ensure_not_expanded update-index --add README.md &&
10291029
ensure_not_expanded update-index a &&
10301030
ensure_not_expanded update-index --remove deep/a &&
1031+
1032+
rm -f sparse-index/README.md sparse-index/a &&
1033+
ensure_not_expanded update-index --add --remove --again
10311034
'
10321035

10331036
# NEEDSWORK: a sparse-checkout behaves differently from a full checkout

0 commit comments

Comments
 (0)