Skip to content

Commit 6fdc205

Browse files
tgummerergitster
authored andcommitted
read-cache: add invalidate parameter to remove_marked_cache_entries
When marking cache entries for removal, and later removing them all at once using 'remove_marked_cache_entries()', cache entries currently have to be invalidated manually in the cache tree and in the untracked cache. Add an invalidate flag to the function. With the flag set, the function will take care of invalidating the path in the cache tree and in the untracked cache. Note that the current callsites already do the invalidation properly in other places, so we're just passing 0 from there to keep the status quo. This will be useful in a subsequent commit. Signed-off-by: Thomas Gummerer <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 536ec18 commit 6fdc205

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

cache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ extern void rename_index_entry_at(struct index_state *, int pos, const char *new
751751
/* Remove entry, return true if there are more entries to go. */
752752
extern int remove_index_entry_at(struct index_state *, int pos);
753753

754-
extern void remove_marked_cache_entries(struct index_state *istate);
754+
extern void remove_marked_cache_entries(struct index_state *istate, int invalidate);
755755
extern int remove_file_from_index(struct index_state *, const char *path);
756756
#define ADD_CACHE_VERBOSE 1
757757
#define ADD_CACHE_PRETEND 2

read-cache.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,13 +590,19 @@ int remove_index_entry_at(struct index_state *istate, int pos)
590590
* CE_REMOVE is set in ce_flags. This is much more effective than
591591
* calling remove_index_entry_at() for each entry to be removed.
592592
*/
593-
void remove_marked_cache_entries(struct index_state *istate)
593+
void remove_marked_cache_entries(struct index_state *istate, int invalidate)
594594
{
595595
struct cache_entry **ce_array = istate->cache;
596596
unsigned int i, j;
597597

598598
for (i = j = 0; i < istate->cache_nr; i++) {
599599
if (ce_array[i]->ce_flags & CE_REMOVE) {
600+
if (invalidate) {
601+
cache_tree_invalidate_path(istate,
602+
ce_array[i]->name);
603+
untracked_cache_remove_from_index(istate,
604+
ce_array[i]->name);
605+
}
600606
remove_name_hash(istate, ce_array[i]);
601607
save_or_free_index_entry(istate, ce_array[i]);
602608
}

split-index.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ void merge_base_index(struct index_state *istate)
162162
ewah_each_bit(si->replace_bitmap, replace_entry, istate);
163163
ewah_each_bit(si->delete_bitmap, mark_entry_for_delete, istate);
164164
if (si->nr_deletions)
165-
remove_marked_cache_entries(istate);
165+
remove_marked_cache_entries(istate, 0);
166166

167167
for (i = si->nr_replacements; i < si->saved_cache_nr; i++) {
168168
if (!ce_namelen(si->saved_cache[i]))

unpack-trees.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ static int check_updates(struct unpack_trees_options *o)
392392
unlink_entry(ce);
393393
}
394394
}
395-
remove_marked_cache_entries(index);
395+
remove_marked_cache_entries(index, 0);
396396
remove_scheduled_dirs();
397397

398398
if (should_update_submodules() && o->update && !o->dry_run)

0 commit comments

Comments
 (0)