cache-tree: mark istate->cache_changed on cache tree invalidation
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
Jun 13, 2014 at 19:19 UTC
a5400efe29fdaabbe5266d11d255b2ef5a4c3a66
7 files changed
+20
-12
builtin/blame.c
+1
-1
@@ -2126,7 +2126,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
2126
* right now, but someday we might optimize diff-index --cached
2127
* with cache-tree information.
2128
*/
2129
- cache_tree_invalidate_path(active_cache_tree, path);
2129
+ cache_tree_invalidate_path(&the_index, path);
2130
2131
return commit;
2132
}
builtin/update-index.c
+2
-2
@@ -55,7 +55,7 @@ static int mark_ce_flags(const char *path, int flag, int mark)
55
active_cache[pos]->ce_flags |= flag;
56
else
57
active_cache[pos]->ce_flags &= ~flag;
58
- cache_tree_invalidate_path(active_cache_tree, path);
58
+ cache_tree_invalidate_path(&the_index, path);
59
active_cache_changed |= CE_ENTRY_CHANGED;
60
return 0;
61
}
@@ -267,7 +267,7 @@ static void chmod_path(int flip, const char *path)
267
default:
268
goto fail;
269
}
270
- cache_tree_invalidate_path(active_cache_tree, path);
270
+ cache_tree_invalidate_path(&the_index, path);
271
active_cache_changed |= CE_ENTRY_CHANGED;
272
report("chmod %cx '%s'", flip, path);
273
return;
cache-tree.c
+11
-4
@@ -98,7 +98,7 @@ struct cache_tree_sub *cache_tree_sub(struct cache_tree *it, const char *path)
98
return find_subtree(it, path, pathlen, 1);
99
}
100
101
-void cache_tree_invalidate_path(struct cache_tree *it, const char *path)
101
+static int do_invalidate_path(struct cache_tree *it, const char *path)
102
{
103
/* a/b/c
104
* ==> invalidate self
@@ -116,7 +116,7 @@ void cache_tree_invalidate_path(struct cache_tree *it, const char *path)
116
#endif
117
118
if (!it)
119
- return;
119
+ return 0;
120
slash = strchrnul(path, '/');
121
namelen = slash - path;
122
it->entry_count = -1;
@@ -137,11 +137,18 @@ void cache_tree_invalidate_path(struct cache_tree *it, const char *path)
137
(it->subtree_nr - pos - 1));
138
it->subtree_nr--;
139
}
140
- return;
140
+ return 1;
141
}
142
down = find_subtree(it, path, namelen, 0);
143
if (down)
144
- cache_tree_invalidate_path(down->cache_tree, slash + 1);
144
+ do_invalidate_path(down->cache_tree, slash + 1);
145
+ return 1;
146
+}
147
+
148
+void cache_tree_invalidate_path(struct index_state *istate, const char *path)
149
+{
150
+ if (do_invalidate_path(istate->cache_tree, path))
151
+ istate->cache_changed |= CACHE_TREE_CHANGED;
152
}
153
154
static int verify_cache(const struct cache_entry * const *cache,
cache-tree.h
+1
-1
@@ -23,7 +23,7 @@ struct cache_tree {
23
24
struct cache_tree *cache_tree(void);
25
void cache_tree_free(struct cache_tree **);
26
-void cache_tree_invalidate_path(struct cache_tree *, const char *);
26
+void cache_tree_invalidate_path(struct index_state *, const char *);
27
struct cache_tree_sub *cache_tree_sub(struct cache_tree *, const char *);
28
29
void cache_tree_write(struct strbuf *, struct cache_tree *root);
cache.h
+1
@@ -273,6 +273,7 @@ static inline unsigned int canon_mode(unsigned int mode)
273
#define CE_ENTRY_REMOVED (1 << 2)
274
#define CE_ENTRY_ADDED (1 << 3)
275
#define RESOLVE_UNDO_CHANGED (1 << 4)
276
+#define CACHE_TREE_CHANGED (1 << 5)
277
278
struct index_state {
279
struct cache_entry **cache;
read-cache.c
+3
-3
@@ -65,7 +65,7 @@ void rename_index_entry_at(struct index_state *istate, int nr, const char *new_n
65
new->ce_namelen = namelen;
66
memcpy(new->name, new_name, namelen + 1);
67
68
- cache_tree_invalidate_path(istate->cache_tree, old->name);
68
+ cache_tree_invalidate_path(istate, old->name);
69
remove_index_entry_at(istate, nr);
70
add_index_entry(istate, new, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE);
71
}
@@ -521,7 +521,7 @@ int remove_file_from_index(struct index_state *istate, const char *path)
521
int pos = index_name_pos(istate, path, strlen(path));
522
if (pos < 0)
523
pos = -pos-1;
524
- cache_tree_invalidate_path(istate->cache_tree, path);
524
+ cache_tree_invalidate_path(istate, path);
525
while (pos < istate->cache_nr && !strcmp(istate->cache[pos]->name, path))
526
remove_index_entry_at(istate, pos);
527
return 0;
@@ -939,7 +939,7 @@ static int add_index_entry_with_check(struct index_state *istate, struct cache_e
939
int skip_df_check = option & ADD_CACHE_SKIP_DFCHECK;
940
int new_only = option & ADD_CACHE_NEW_ONLY;
941
942
- cache_tree_invalidate_path(istate->cache_tree, ce->name);
942
+ cache_tree_invalidate_path(istate, ce->name);
943
pos = index_name_stage_pos(istate, ce->name, ce_namelen(ce), ce_stage(ce));
944
945
/* existing match? Just replace it. */
unpack-trees.c
+1
-1
@@ -1263,7 +1263,7 @@ static void invalidate_ce_path(const struct cache_entry *ce,
1263
struct unpack_trees_options *o)
1264
{
1265
if (ce)
1266
- cache_tree_invalidate_path(o->src_index->cache_tree, ce->name);
1266
+ cache_tree_invalidate_path(o->src_index, ce->name);
1267
}
1268
1269
/*