Skip to content

Commit d0cfc3e

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

File tree

5 files changed

+18
-24
lines changed

5 files changed

+18
-24
lines changed

cache-tree.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ void cache_tree_invalidate_path(struct index_state *istate, const char *path)
151151
istate->cache_changed |= CACHE_TREE_CHANGED;
152152
}
153153

154-
static int verify_cache(const struct cache_entry * const *cache,
154+
static int verify_cache(struct cache_entry **cache,
155155
int entries, int flags)
156156
{
157157
int i, funny;
@@ -236,7 +236,7 @@ int cache_tree_fully_valid(struct cache_tree *it)
236236
}
237237

238238
static int update_one(struct cache_tree *it,
239-
const struct cache_entry * const *cache,
239+
struct cache_entry **cache,
240240
int entries,
241241
const char *base,
242242
int baselen,
@@ -398,18 +398,19 @@ static int update_one(struct cache_tree *it,
398398
return i;
399399
}
400400

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)
405402
{
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+
408408
if (i)
409409
return i;
410410
i = update_one(it, cache, entries, "", 0, &skip, flags);
411411
if (i < 0)
412412
return i;
413+
istate->cache_changed |= CACHE_TREE_CHANGED;
413414
return 0;
414415
}
415416

@@ -597,9 +598,7 @@ int write_cache_as_tree(unsigned char *sha1, int flags, const char *prefix)
597598

598599
was_valid = cache_tree_fully_valid(active_cache_tree);
599600
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)
603602
return WRITE_TREE_UNMERGED_INDEX;
604603
if (0 <= newfd) {
605604
if (!write_locked_index(&the_index, lock_file, COMMIT_LOCK))
@@ -698,7 +697,5 @@ int update_main_cache_tree(int flags)
698697
{
699698
if (!the_index.cache_tree)
700699
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);
704701
}

cache-tree.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ void cache_tree_write(struct strbuf *, struct cache_tree *root);
3030
struct cache_tree *cache_tree_read(const char *buffer, unsigned long size);
3131

3232
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);
3434

3535
int update_main_cache_tree(int);
3636

merge-recursive.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,7 @@ struct tree *write_tree_from_memory(struct merge_options *o)
265265
active_cache_tree = cache_tree();
266266

267267
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)
271269
die(_("error building trees"));
272270

273271
result = lookup_tree(active_cache_tree->sha1);

sequencer.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,9 +371,7 @@ static int is_index_unchanged(void)
371371
active_cache_tree = cache_tree();
372372

373373
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))
377375
return error(_("Unable to update cache tree\n"));
378376

379377
return !hashcmp(active_cache_tree->sha1, head_commit->tree->object.sha1);

test-dump-cache-tree.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,12 @@ static int dump_cache_tree(struct cache_tree *it,
5656

5757
int main(int ac, char **av)
5858
{
59+
struct index_state istate;
5960
struct cache_tree *another = cache_tree();
6061
if (read_cache() < 0)
6162
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);
6566
return dump_cache_tree(active_cache_tree, another, "");
6667
}

0 commit comments

Comments
 (0)