Skip to content

Commit

Permalink
update-index: remove unnecessary index expansion in do_reupdate
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
vdye authored and ldennington committed Jan 20, 2022
1 parent 1831e1b commit 3bca4a2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
12 changes: 9 additions & 3 deletions builtin/update-index.c
Original file line number Diff line number Diff line change
Expand Up @@ -747,17 +747,23 @@ static int do_reupdate(int ac, const char **av,
* commit. Update everything in the index.
*/
has_head = 0;

redo:
/* TODO: audit for interaction with sparse-index. */
ensure_full_index(&the_index);
for (pos = 0; pos < active_nr; pos++) {
const struct cache_entry *ce = active_cache[pos];
struct cache_entry *old = NULL;
int save_nr;
char *path;

if (ce_stage(ce) || !ce_path_match(&the_index, ce, &pathspec, NULL))
/*
* We can safely skip re-updating sparse directories because if there
* were any changes to re-update inside of the sparse directory, it
* would not be sparse.
*/
if (S_ISSPARSEDIR(ce->ce_mode) || ce_stage(ce) ||
!ce_path_match(&the_index, ce, &pathspec, NULL))
continue;

if (has_head)
old = read_one_ent(NULL, &head_oid,
ce->name, ce_namelen(ce), 0);
Expand Down
3 changes: 3 additions & 0 deletions t/t1092-sparse-checkout-compatibility.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1392,6 +1392,9 @@ test_expect_success 'sparse index is not expanded: update-index' '
ensure_not_expanded update-index --add README.md &&
ensure_not_expanded update-index a &&
ensure_not_expanded update-index --remove deep/a &&
rm -f sparse-index/README.md sparse-index/a &&
ensure_not_expanded update-index --add --remove --again
'

# NEEDSWORK: a sparse-checkout behaves differently from a full checkout
Expand Down

0 comments on commit 3bca4a2

Please sign in to comment.