Skip to content

Commit 1297590

Browse files
vdyedscho
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 b174737 commit 1297590

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
@@ -1285,6 +1285,9 @@ test_expect_success 'sparse index is not expanded: update-index' '
12851285
ensure_not_expanded update-index --add README.md &&
12861286
ensure_not_expanded update-index a &&
12871287
ensure_not_expanded update-index --remove deep/a &&
1288+
1289+
rm -f sparse-index/README.md sparse-index/a &&
1290+
ensure_not_expanded update-index --add --remove --again
12881291
'
12891292

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

0 commit comments

Comments
 (0)