Skip to content

Commit 6332a0c

Browse files
vdyederrickstolee
authored andcommitted
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 <vdye@github.com>
1 parent 2c0563c commit 6332a0c

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
@@ -747,17 +747,23 @@ static int do_reupdate(int ac, const char **av,
747747
* commit. Update everything in the index.
748748
*/
749749
has_head = 0;
750+
750751
redo:
751-
/* TODO: audit for interaction with sparse-index. */
752-
ensure_full_index(&the_index);
753752
for (pos = 0; pos < active_nr; pos++) {
754753
const struct cache_entry *ce = active_cache[pos];
755754
struct cache_entry *old = NULL;
756755
int save_nr;
757756
char *path;
758757

759-
if (ce_stage(ce) || !ce_path_match(&the_index, ce, &pathspec, NULL))
758+
/*
759+
* We can safely skip re-updating sparse directories because if there
760+
* were any changes to re-update inside of the sparse directory, it
761+
* would not be sparse.
762+
*/
763+
if (S_ISSPARSEDIR(ce->ce_mode) || ce_stage(ce) ||
764+
!ce_path_match(&the_index, ce, &pathspec, NULL))
760765
continue;
766+
761767
if (has_head)
762768
old = read_one_ent(NULL, &head_oid,
763769
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
@@ -1111,6 +1111,9 @@ test_expect_success 'sparse index is not expanded: update-index' '
11111111
ensure_not_expanded update-index --add README.md &&
11121112
ensure_not_expanded update-index a &&
11131113
ensure_not_expanded update-index --remove deep/a &&
1114+
1115+
rm -f sparse-index/README.md sparse-index/a &&
1116+
ensure_not_expanded update-index --add --remove --again
11141117
'
11151118

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

0 commit comments

Comments
 (0)