Skip to content

Commit e859c69

Browse files
pcloudsgitster
authored andcommitted
cache-tree: update API to take abitrary flags
Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 828ea97 commit e859c69

File tree

5 files changed

+19
-20
lines changed

5 files changed

+19
-20
lines changed

builtin/commit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix,
400400
fd = hold_locked_index(&index_lock, 1);
401401
add_files_to_cache(also ? prefix : NULL, pathspec, 0);
402402
refresh_cache_or_die(refresh_flags);
403-
update_main_cache_tree(1);
403+
update_main_cache_tree(WRITE_TREE_SILENT);
404404
if (write_cache(fd, active_cache, active_nr) ||
405405
close_lock_file(&index_lock))
406406
die(_("unable to write new_index file"));
@@ -421,7 +421,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix,
421421
fd = hold_locked_index(&index_lock, 1);
422422
refresh_cache_or_die(refresh_flags);
423423
if (active_cache_changed) {
424-
update_main_cache_tree(1);
424+
update_main_cache_tree(WRITE_TREE_SILENT);
425425
if (write_cache(fd, active_cache, active_nr) ||
426426
commit_locked_index(&index_lock))
427427
die(_("unable to write new_index file"));

cache-tree.c

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,10 @@ void cache_tree_invalidate_path(struct cache_tree *it, const char *path)
150150
}
151151

152152
static int verify_cache(struct cache_entry **cache,
153-
int entries, int silent)
153+
int entries, int flags)
154154
{
155155
int i, funny;
156+
int silent = flags & WRITE_TREE_SILENT;
156157

157158
/* Verify that the tree is merged */
158159
funny = 0;
@@ -241,10 +242,11 @@ static int update_one(struct cache_tree *it,
241242
int entries,
242243
const char *base,
243244
int baselen,
244-
int missing_ok,
245-
int dryrun)
245+
int flags)
246246
{
247247
struct strbuf buffer;
248+
int missing_ok = flags & WRITE_TREE_MISSING_OK;
249+
int dryrun = flags & WRITE_TREE_DRY_RUN;
248250
int i;
249251

250252
if (0 <= it->entry_count && has_sha1_file(it->sha1))
@@ -288,8 +290,7 @@ static int update_one(struct cache_tree *it,
288290
cache + i, entries - i,
289291
path,
290292
baselen + sublen + 1,
291-
missing_ok,
292-
dryrun);
293+
flags);
293294
if (subcnt < 0)
294295
return subcnt;
295296
i += subcnt - 1;
@@ -371,15 +372,13 @@ static int update_one(struct cache_tree *it,
371372
int cache_tree_update(struct cache_tree *it,
372373
struct cache_entry **cache,
373374
int entries,
374-
int missing_ok,
375-
int dryrun,
376-
int silent)
375+
int flags)
377376
{
378377
int i;
379-
i = verify_cache(cache, entries, silent);
378+
i = verify_cache(cache, entries, flags);
380379
if (i)
381380
return i;
382-
i = update_one(it, cache, entries, "", 0, missing_ok, dryrun);
381+
i = update_one(it, cache, entries, "", 0, flags);
383382
if (i < 0)
384383
return i;
385384
return 0;
@@ -572,11 +571,9 @@ int write_cache_as_tree(unsigned char *sha1, int flags, const char *prefix)
572571

573572
was_valid = cache_tree_fully_valid(active_cache_tree);
574573
if (!was_valid) {
575-
int missing_ok = flags & WRITE_TREE_MISSING_OK;
576-
577574
if (cache_tree_update(active_cache_tree,
578575
active_cache, active_nr,
579-
missing_ok, 0, 0) < 0)
576+
flags) < 0)
580577
return WRITE_TREE_UNMERGED_INDEX;
581578
if (0 <= newfd) {
582579
if (!write_cache(newfd, active_cache, active_nr) &&
@@ -672,10 +669,10 @@ int cache_tree_matches_traversal(struct cache_tree *root,
672669
return 0;
673670
}
674671

675-
int update_main_cache_tree (int silent)
672+
int update_main_cache_tree(int flags)
676673
{
677674
if (!the_index.cache_tree)
678675
the_index.cache_tree = cache_tree();
679676
return cache_tree_update(the_index.cache_tree,
680-
the_index.cache, the_index.cache_nr, 0, 0, silent);
677+
the_index.cache, the_index.cache_nr, flags);
681678
}

cache-tree.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ void cache_tree_write(struct strbuf *, struct cache_tree *root);
2929
struct cache_tree *cache_tree_read(const char *buffer, unsigned long size);
3030

3131
int cache_tree_fully_valid(struct cache_tree *);
32-
int cache_tree_update(struct cache_tree *, struct cache_entry **, int, int, int, int);
32+
int cache_tree_update(struct cache_tree *, struct cache_entry **, int, int);
3333

3434
int update_main_cache_tree(int);
3535

3636
/* bitmasks to write_cache_as_tree flags */
3737
#define WRITE_TREE_MISSING_OK 1
3838
#define WRITE_TREE_IGNORE_CACHE_TREE 2
39+
#define WRITE_TREE_DRY_RUN 4
40+
#define WRITE_TREE_SILENT 8
3941

4042
/* error return codes */
4143
#define WRITE_TREE_UNREADABLE_INDEX (-1)

merge-recursive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ struct tree *write_tree_from_memory(struct merge_options *o)
264264

265265
if (!cache_tree_fully_valid(active_cache_tree) &&
266266
cache_tree_update(active_cache_tree,
267-
active_cache, active_nr, 0, 0, 0) < 0)
267+
active_cache, active_nr, 0) < 0)
268268
die("error building trees");
269269

270270
result = lookup_tree(active_cache_tree->sha1);

test-dump-cache-tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,6 @@ int main(int ac, char **av)
5959
struct cache_tree *another = cache_tree();
6060
if (read_cache() < 0)
6161
die("unable to read index file");
62-
cache_tree_update(another, active_cache, active_nr, 0, 1, 0);
62+
cache_tree_update(another, active_cache, active_nr, WRITE_TREE_DRY_RUN);
6363
return dump_cache_tree(active_cache_tree, another, "");
6464
}

0 commit comments

Comments
 (0)