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 <vdye@github.com> Reviewed-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
c35e9f5ecd
commit
b9ca5e2657
@ -606,7 +606,7 @@ static struct cache_entry *read_one_ent(const char *which,
|
|||||||
error("%s: not in %s branch.", path, which);
|
error("%s: not in %s branch.", path, which);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (mode == S_IFDIR) {
|
if (!the_index.sparse_index && mode == S_IFDIR) {
|
||||||
if (which)
|
if (which)
|
||||||
error("%s: not a blob in %s branch.", path, which);
|
error("%s: not a blob in %s branch.", path, which);
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -743,8 +743,6 @@ static int do_reupdate(int ac, const char **av,
|
|||||||
*/
|
*/
|
||||||
has_head = 0;
|
has_head = 0;
|
||||||
redo:
|
redo:
|
||||||
/* TODO: audit for interaction with sparse-index. */
|
|
||||||
ensure_full_index(&the_index);
|
|
||||||
for (pos = 0; pos < active_nr; pos++) {
|
for (pos = 0; pos < active_nr; pos++) {
|
||||||
const struct cache_entry *ce = active_cache[pos];
|
const struct cache_entry *ce = active_cache[pos];
|
||||||
struct cache_entry *old = NULL;
|
struct cache_entry *old = NULL;
|
||||||
@ -761,6 +759,16 @@ static int do_reupdate(int ac, const char **av,
|
|||||||
discard_cache_entry(old);
|
discard_cache_entry(old);
|
||||||
continue; /* unchanged */
|
continue; /* unchanged */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* At this point, we know the contents of the sparse directory are
|
||||||
|
* modified with respect to HEAD, so we expand the index and restart
|
||||||
|
* to process each path individually
|
||||||
|
*/
|
||||||
|
if (S_ISSPARSEDIR(ce->ce_mode)) {
|
||||||
|
ensure_full_index(&the_index);
|
||||||
|
goto redo;
|
||||||
|
}
|
||||||
|
|
||||||
/* Be careful. The working tree may not have the
|
/* Be careful. The working tree may not have the
|
||||||
* path anymore, in which case, under 'allow_remove',
|
* path anymore, in which case, under 'allow_remove',
|
||||||
* or worse yet 'allow_replace', active_nr may decrease.
|
* or worse yet 'allow_replace', active_nr may decrease.
|
||||||
|
@ -1265,7 +1265,10 @@ test_expect_success 'sparse index is not expanded: update-index' '
|
|||||||
|
|
||||||
ensure_not_expanded update-index --add README.md &&
|
ensure_not_expanded update-index --add README.md &&
|
||||||
ensure_not_expanded update-index a &&
|
ensure_not_expanded update-index a &&
|
||||||
ensure_not_expanded update-index --remove deep/a
|
ensure_not_expanded update-index --remove deep/a &&
|
||||||
|
|
||||||
|
ensure_not_expanded reset --soft update-deep &&
|
||||||
|
ensure_not_expanded update-index --add --remove --again
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'sparse index is not expanded: blame' '
|
test_expect_success 'sparse index is not expanded: blame' '
|
||||||
|
Loading…
Reference in New Issue
Block a user