Skip to content

Commit e931371

Browse files
pcloudsgitster
authored andcommitted
untracked cache: invalidate at index addition or removal
Ideally we should implement untracked_cache_remove_from_index() and untracked_cache_add_to_index() so that they update untracked cache right away instead of invalidating it and wait for read_directory() next time to deal with it. But that may need some more work in unpack-trees.c. So stay simple as the first step. The new call in add_index_entry_with_check() may look strange because new calls usually stay close to cache_tree_invalidate_path(). We do it a bit later than c_t_i_p() in this function because if it's about replacing the entry with the same name, we don't care (but cache-tree does). Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f9e6c64 commit e931371

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

dir.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2502,3 +2502,34 @@ struct untracked_cache *read_untracked_extension(const void *data, unsigned long
25022502
}
25032503
return uc;
25042504
}
2505+
2506+
void untracked_cache_invalidate_path(struct index_state *istate,
2507+
const char *path)
2508+
{
2509+
const char *sep;
2510+
struct untracked_cache_dir *d;
2511+
if (!istate->untracked || !istate->untracked->root)
2512+
return;
2513+
sep = strrchr(path, '/');
2514+
if (sep)
2515+
d = lookup_untracked(istate->untracked,
2516+
istate->untracked->root,
2517+
path, sep - path);
2518+
else
2519+
d = istate->untracked->root;
2520+
istate->untracked->dir_invalidated++;
2521+
d->valid = 0;
2522+
d->untracked_nr = 0;
2523+
}
2524+
2525+
void untracked_cache_remove_from_index(struct index_state *istate,
2526+
const char *path)
2527+
{
2528+
untracked_cache_invalidate_path(istate, path);
2529+
}
2530+
2531+
void untracked_cache_add_to_index(struct index_state *istate,
2532+
const char *path)
2533+
{
2534+
untracked_cache_invalidate_path(istate, path);
2535+
}

dir.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,10 @@ static inline int dir_path_match(const struct dir_entry *ent,
298298
has_trailing_dir);
299299
}
300300

301+
void untracked_cache_invalidate_path(struct index_state *, const char *);
302+
void untracked_cache_remove_from_index(struct index_state *, const char *);
303+
void untracked_cache_add_to_index(struct index_state *, const char *);
304+
301305
void free_untracked_cache(struct untracked_cache *);
302306
struct untracked_cache *read_untracked_extension(const void *data, unsigned long sz);
303307
void write_untracked_extension(struct strbuf *out, struct untracked_cache *untracked);

read-cache.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ void rename_index_entry_at(struct index_state *istate, int nr, const char *new_n
8080
memcpy(new->name, new_name, namelen + 1);
8181

8282
cache_tree_invalidate_path(istate, old->name);
83+
untracked_cache_remove_from_index(istate, old->name);
8384
remove_index_entry_at(istate, nr);
8485
add_index_entry(istate, new, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE);
8586
}
@@ -539,6 +540,7 @@ int remove_file_from_index(struct index_state *istate, const char *path)
539540
if (pos < 0)
540541
pos = -pos-1;
541542
cache_tree_invalidate_path(istate, path);
543+
untracked_cache_remove_from_index(istate, path);
542544
while (pos < istate->cache_nr && !strcmp(istate->cache[pos]->name, path))
543545
remove_index_entry_at(istate, pos);
544546
return 0;
@@ -981,6 +983,8 @@ static int add_index_entry_with_check(struct index_state *istate, struct cache_e
981983
}
982984
pos = -pos-1;
983985

986+
untracked_cache_add_to_index(istate, ce->name);
987+
984988
/*
985989
* Inserting a merged entry ("stage 0") into the index
986990
* will always replace all non-merged entries..

unpack-trees.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "refs.h"
1010
#include "attr.h"
1111
#include "split-index.h"
12+
#include "dir.h"
1213

1314
/*
1415
* Error messages expected by scripts out of plumbing commands such as
@@ -1259,8 +1260,10 @@ static int verify_uptodate_sparse(const struct cache_entry *ce,
12591260
static void invalidate_ce_path(const struct cache_entry *ce,
12601261
struct unpack_trees_options *o)
12611262
{
1262-
if (ce)
1263-
cache_tree_invalidate_path(o->src_index, ce->name);
1263+
if (!ce)
1264+
return;
1265+
cache_tree_invalidate_path(o->src_index, ce->name);
1266+
untracked_cache_invalidate_path(o->src_index, ce->name);
12641267
}
12651268

12661269
/*

0 commit comments

Comments
 (0)