Skip to content

Commit c39d7f2

Browse files
committed
update-index: remove sparse index expansion for --cacheinfo
Rearrange `add_index_entry_with_check` to allow `index_name_stage_pos` to expand the index _before_ attempting to invalidate the relevant cache tree path. This permits implicit index expansion when adding a cache entry outside the sparse checkout definition. Signed-off-by: Victoria Dye <[email protected]>
1 parent 6adbbab commit c39d7f2

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

builtin/update-index.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,10 +426,6 @@ static int add_cacheinfo(unsigned int mode, const struct object_id *oid,
426426
ce->ce_flags |= CE_VALID;
427427
option = allow_add ? ADD_CACHE_OK_TO_ADD : 0;
428428
option |= allow_replace ? ADD_CACHE_OK_TO_REPLACE : 0;
429-
430-
/* TODO: ensure full index to maintain expected behavior */
431-
ensure_full_index(&the_index);
432-
433429
if (add_cache_entry(ce, option))
434430
return error("%s: cannot add to the index - missing --add option?",
435431
path);

read-cache.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,9 +1324,6 @@ static int add_index_entry_with_check(struct index_state *istate, struct cache_e
13241324
int skip_df_check = option & ADD_CACHE_SKIP_DFCHECK;
13251325
int new_only = option & ADD_CACHE_NEW_ONLY;
13261326

1327-
if (!(option & ADD_CACHE_KEEP_CACHE_TREE))
1328-
cache_tree_invalidate_path(istate, ce->name);
1329-
13301327
/*
13311328
* If this entry's path sorts after the last entry in the index,
13321329
* we can avoid searching for it.
@@ -1337,6 +1334,13 @@ static int add_index_entry_with_check(struct index_state *istate, struct cache_e
13371334
else
13381335
pos = index_name_stage_pos(istate, ce->name, ce_namelen(ce), ce_stage(ce));
13391336

1337+
/*
1338+
* Cache tree path should be invalidated only after index_name_stage_pos,
1339+
* in case it expands a sparse index.
1340+
*/
1341+
if (!(option & ADD_CACHE_KEEP_CACHE_TREE))
1342+
cache_tree_invalidate_path(istate, ce->name);
1343+
13401344
/* existing match? Just replace it. */
13411345
if (pos >= 0) {
13421346
if (!new_only)

0 commit comments

Comments
 (0)