cache-tree: mark istate->cache_changed on cache tree update

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 d0cfc3e866a77eed98ab2caf41a39a87837950e6
5 files changed +18 -24
cache-tree.c
+11 -14
@@ -151,7 +151,7 @@ void cache_tree_invalidate_path(struct index_state *istate, const char *path)
151 istate->cache_changed |= CACHE_TREE_CHANGED;
152 }
153
154 -static int verify_cache(const struct cache_entry * const *cache,
154 +static int verify_cache(struct cache_entry **cache,
155 int entries, int flags)
156 {
157 int i, funny;
@@ -236,7 +236,7 @@ int cache_tree_fully_valid(struct cache_tree *it)
236 }
237
238 static int update_one(struct cache_tree *it,
239 - const struct cache_entry * const *cache,
239 + struct cache_entry **cache,
240 int entries,
241 const char *base,
242 int baselen,
@@ -398,18 +398,19 @@ static int update_one(struct cache_tree *it,
398 return i;
399 }
400
401 -int cache_tree_update(struct cache_tree *it,
402 - const struct cache_entry * const *cache,
403 - int entries,
404 - int flags)
401 +int cache_tree_update(struct index_state *istate, int flags)
402 {
406 - int i, skip;
407 - i = verify_cache(cache, entries, flags);
403 + struct cache_tree *it = istate->cache_tree;
404 + struct cache_entry **cache = istate->cache;
405 + int entries = istate->cache_nr;
406 + int skip, i = verify_cache(cache, entries, flags);
407 +
408 if (i)
409 return i;
410 i = update_one(it, cache, entries, "", 0, &skip, flags);
411 if (i < 0)
412 return i;
413 + istate->cache_changed |= CACHE_TREE_CHANGED;
414 return 0;
415 }
416
@@ -597,9 +598,7 @@ int write_cache_as_tree(unsigned char *sha1, int flags, const char *prefix)
598
599 was_valid = cache_tree_fully_valid(active_cache_tree);
600 if (!was_valid) {
600 - if (cache_tree_update(active_cache_tree,
601 - (const struct cache_entry * const *)active_cache,
602 - active_nr, flags) < 0)
601 + if (cache_tree_update(&the_index, flags) < 0)
602 return WRITE_TREE_UNMERGED_INDEX;
603 if (0 <= newfd) {
604 if (!write_locked_index(&the_index, lock_file, COMMIT_LOCK))
@@ -698,7 +697,5 @@ int update_main_cache_tree(int flags)
697 {
698 if (!the_index.cache_tree)
699 the_index.cache_tree = cache_tree();
701 - return cache_tree_update(the_index.cache_tree,
702 - (const struct cache_entry * const *)the_index.cache,
703 - the_index.cache_nr, flags);
700 + return cache_tree_update(&the_index, flags);
701 }
cache-tree.h
+1 -1
@@ -30,7 +30,7 @@ void cache_tree_write(struct strbuf *, struct cache_tree *root);
30 struct cache_tree *cache_tree_read(const char *buffer, unsigned long size);
31
32 int cache_tree_fully_valid(struct cache_tree *);
33 -int cache_tree_update(struct cache_tree *, const struct cache_entry * const *, int, int);
33 +int cache_tree_update(struct index_state *, int);
34
35 int update_main_cache_tree(int);
36
merge-recursive.c
+1 -3
@@ -265,9 +265,7 @@ struct tree *write_tree_from_memory(struct merge_options *o)
265 active_cache_tree = cache_tree();
266
267 if (!cache_tree_fully_valid(active_cache_tree) &&
268 - cache_tree_update(active_cache_tree,
269 - (const struct cache_entry * const *)active_cache,
270 - active_nr, 0) < 0)
268 + cache_tree_update(&the_index, 0) < 0)
269 die(_("error building trees"));
270
271 result = lookup_tree(active_cache_tree->sha1);
sequencer.c
+1 -3
@@ -371,9 +371,7 @@ static int is_index_unchanged(void)
371 active_cache_tree = cache_tree();
372
373 if (!cache_tree_fully_valid(active_cache_tree))
374 - if (cache_tree_update(active_cache_tree,
375 - (const struct cache_entry * const *)active_cache,
376 - active_nr, 0))
374 + if (cache_tree_update(&the_index, 0))
375 return error(_("Unable to update cache tree\n"));
376
377 return !hashcmp(active_cache_tree->sha1, head_commit->tree->object.sha1);
test-dump-cache-tree.c
+4 -3
@@ -56,11 +56,12 @@ static int dump_cache_tree(struct cache_tree *it,
56
57 int main(int ac, char **av)
58 {
59 + struct index_state istate;
60 struct cache_tree *another = cache_tree();
61 if (read_cache() < 0)
62 die("unable to read index file");
62 - cache_tree_update(another,
63 - (const struct cache_entry * const *)active_cache,
64 - active_nr, WRITE_TREE_DRY_RUN);
63 + istate = the_index;
64 + istate.cache_tree = another;
65 + cache_tree_update(&istate, WRITE_TREE_DRY_RUN);
66 return dump_cache_tree(active_cache_tree, another, "");
67 }