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 <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Mar 8, 2015 at 17:12 UTC
e931371a8f1164185486a1f5fdaaa708b4a6217c
4 files changed
+44
-2
dir.c
+31
@@ -2502,3 +2502,34 @@ done2:
2502
}
2503
return uc;
2504
}
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
+4
@@ -298,6 +298,10 @@ static inline int dir_path_match(const struct dir_entry *ent,
298
has_trailing_dir);
299
}
300
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
+
305
void free_untracked_cache(struct untracked_cache *);
306
struct untracked_cache *read_untracked_extension(const void *data, unsigned long sz);
307
void write_untracked_extension(struct strbuf *out, struct untracked_cache *untracked);
read-cache.c
+4
@@ -80,6 +80,7 @@ void rename_index_entry_at(struct index_state *istate, int nr, const char *new_n
80
memcpy(new->name, new_name, namelen + 1);
81
82
cache_tree_invalidate_path(istate, old->name);
83
+ untracked_cache_remove_from_index(istate, old->name);
84
remove_index_entry_at(istate, nr);
85
add_index_entry(istate, new, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE);
86
}
@@ -539,6 +540,7 @@ int remove_file_from_index(struct index_state *istate, const char *path)
540
if (pos < 0)
541
pos = -pos-1;
542
cache_tree_invalidate_path(istate, path);
543
+ untracked_cache_remove_from_index(istate, path);
544
while (pos < istate->cache_nr && !strcmp(istate->cache[pos]->name, path))
545
remove_index_entry_at(istate, pos);
546
return 0;
@@ -981,6 +983,8 @@ static int add_index_entry_with_check(struct index_state *istate, struct cache_e
983
}
984
pos = -pos-1;
985
986
+ untracked_cache_add_to_index(istate, ce->name);
987
+
988
/*
989
* Inserting a merged entry ("stage 0") into the index
990
* will always replace all non-merged entries..
unpack-trees.c
+5
-2
@@ -9,6 +9,7 @@
9
#include "refs.h"
10
#include "attr.h"
11
#include "split-index.h"
12
+#include "dir.h"
13
14
/*
15
* 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,
1260
static void invalidate_ce_path(const struct cache_entry *ce,
1261
struct unpack_trees_options *o)
1262
{
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);
1267
}
1268
1269
/*