Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit a5400ef

Browse files
pcloudsgitster
authored andcommitted
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>
1 parent a5c446f commit a5400ef

File tree

7 files changed

+20
-12
lines changed

7 files changed

+20
-12
lines changed

builtin/blame.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2126,7 +2126,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
21262126
* right now, but someday we might optimize diff-index --cached
21272127
* with cache-tree information.
21282128
*/
2129-
cache_tree_invalidate_path(active_cache_tree, path);
2129+
cache_tree_invalidate_path(&the_index, path);
21302130

21312131
return commit;
21322132
}

builtin/update-index.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static int mark_ce_flags(const char *path, int flag, int mark)
5555
active_cache[pos]->ce_flags |= flag;
5656
else
5757
active_cache[pos]->ce_flags &= ~flag;
58-
cache_tree_invalidate_path(active_cache_tree, path);
58+
cache_tree_invalidate_path(&the_index, path);
5959
active_cache_changed |= CE_ENTRY_CHANGED;
6060
return 0;
6161
}
@@ -267,7 +267,7 @@ static void chmod_path(int flip, const char *path)
267267
default:
268268
goto fail;
269269
}
270-
cache_tree_invalidate_path(active_cache_tree, path);
270+
cache_tree_invalidate_path(&the_index, path);
271271
active_cache_changed |= CE_ENTRY_CHANGED;
272272
report("chmod %cx '%s'", flip, path);
273273
return;

cache-tree.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ struct cache_tree_sub *cache_tree_sub(struct cache_tree *it, const char *path)
9898
return find_subtree(it, path, pathlen, 1);
9999
}
100100

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)
102102
{
103103
/* a/b/c
104104
* ==> invalidate self
@@ -116,7 +116,7 @@ void cache_tree_invalidate_path(struct cache_tree *it, const char *path)
116116
#endif
117117

118118
if (!it)
119-
return;
119+
return 0;
120120
slash = strchrnul(path, '/');
121121
namelen = slash - path;
122122
it->entry_count = -1;
@@ -137,11 +137,18 @@ void cache_tree_invalidate_path(struct cache_tree *it, const char *path)
137137
(it->subtree_nr - pos - 1));
138138
it->subtree_nr--;
139139
}
140-
return;
140+
return 1;
141141
}
142142
down = find_subtree(it, path, namelen, 0);
143143
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;
145152
}
146153

147154
static int verify_cache(const struct cache_entry * const *cache,

cache-tree.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct cache_tree {
2323

2424
struct cache_tree *cache_tree(void);
2525
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 *);
2727
struct cache_tree_sub *cache_tree_sub(struct cache_tree *, const char *);
2828

2929
void cache_tree_write(struct strbuf *, struct cache_tree *root);

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ static inline unsigned int canon_mode(unsigned int mode)
273273
#define CE_ENTRY_REMOVED (1 << 2)
274274
#define CE_ENTRY_ADDED (1 << 3)
275275
#define RESOLVE_UNDO_CHANGED (1 << 4)
276+
#define CACHE_TREE_CHANGED (1 << 5)
276277

277278
struct index_state {
278279
struct cache_entry **cache;

read-cache.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void rename_index_entry_at(struct index_state *istate, int nr, const char *new_n
6565
new->ce_namelen = namelen;
6666
memcpy(new->name, new_name, namelen + 1);
6767

68-
cache_tree_invalidate_path(istate->cache_tree, old->name);
68+
cache_tree_invalidate_path(istate, old->name);
6969
remove_index_entry_at(istate, nr);
7070
add_index_entry(istate, new, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE);
7171
}
@@ -521,7 +521,7 @@ int remove_file_from_index(struct index_state *istate, const char *path)
521521
int pos = index_name_pos(istate, path, strlen(path));
522522
if (pos < 0)
523523
pos = -pos-1;
524-
cache_tree_invalidate_path(istate->cache_tree, path);
524+
cache_tree_invalidate_path(istate, path);
525525
while (pos < istate->cache_nr && !strcmp(istate->cache[pos]->name, path))
526526
remove_index_entry_at(istate, pos);
527527
return 0;
@@ -939,7 +939,7 @@ static int add_index_entry_with_check(struct index_state *istate, struct cache_e
939939
int skip_df_check = option & ADD_CACHE_SKIP_DFCHECK;
940940
int new_only = option & ADD_CACHE_NEW_ONLY;
941941

942-
cache_tree_invalidate_path(istate->cache_tree, ce->name);
942+
cache_tree_invalidate_path(istate, ce->name);
943943
pos = index_name_stage_pos(istate, ce->name, ce_namelen(ce), ce_stage(ce));
944944

945945
/* existing match? Just replace it. */

unpack-trees.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1263,7 +1263,7 @@ static void invalidate_ce_path(const struct cache_entry *ce,
12631263
struct unpack_trees_options *o)
12641264
{
12651265
if (ce)
1266-
cache_tree_invalidate_path(o->src_index->cache_tree, ce->name);
1266+
cache_tree_invalidate_path(o->src_index, ce->name);
12671267
}
12681268

12691269
/*

0 commit comments

Comments
 (0)