cache-tree: update API to take abitrary flags
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
828ea97de4
commit
e859c69b26
@ -400,7 +400,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix,
|
|||||||
fd = hold_locked_index(&index_lock, 1);
|
fd = hold_locked_index(&index_lock, 1);
|
||||||
add_files_to_cache(also ? prefix : NULL, pathspec, 0);
|
add_files_to_cache(also ? prefix : NULL, pathspec, 0);
|
||||||
refresh_cache_or_die(refresh_flags);
|
refresh_cache_or_die(refresh_flags);
|
||||||
update_main_cache_tree(1);
|
update_main_cache_tree(WRITE_TREE_SILENT);
|
||||||
if (write_cache(fd, active_cache, active_nr) ||
|
if (write_cache(fd, active_cache, active_nr) ||
|
||||||
close_lock_file(&index_lock))
|
close_lock_file(&index_lock))
|
||||||
die(_("unable to write new_index file"));
|
die(_("unable to write new_index file"));
|
||||||
@ -421,7 +421,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix,
|
|||||||
fd = hold_locked_index(&index_lock, 1);
|
fd = hold_locked_index(&index_lock, 1);
|
||||||
refresh_cache_or_die(refresh_flags);
|
refresh_cache_or_die(refresh_flags);
|
||||||
if (active_cache_changed) {
|
if (active_cache_changed) {
|
||||||
update_main_cache_tree(1);
|
update_main_cache_tree(WRITE_TREE_SILENT);
|
||||||
if (write_cache(fd, active_cache, active_nr) ||
|
if (write_cache(fd, active_cache, active_nr) ||
|
||||||
commit_locked_index(&index_lock))
|
commit_locked_index(&index_lock))
|
||||||
die(_("unable to write new_index file"));
|
die(_("unable to write new_index file"));
|
||||||
|
27
cache-tree.c
27
cache-tree.c
@ -150,9 +150,10 @@ void cache_tree_invalidate_path(struct cache_tree *it, const char *path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int verify_cache(struct cache_entry **cache,
|
static int verify_cache(struct cache_entry **cache,
|
||||||
int entries, int silent)
|
int entries, int flags)
|
||||||
{
|
{
|
||||||
int i, funny;
|
int i, funny;
|
||||||
|
int silent = flags & WRITE_TREE_SILENT;
|
||||||
|
|
||||||
/* Verify that the tree is merged */
|
/* Verify that the tree is merged */
|
||||||
funny = 0;
|
funny = 0;
|
||||||
@ -241,10 +242,11 @@ static int update_one(struct cache_tree *it,
|
|||||||
int entries,
|
int entries,
|
||||||
const char *base,
|
const char *base,
|
||||||
int baselen,
|
int baselen,
|
||||||
int missing_ok,
|
int flags)
|
||||||
int dryrun)
|
|
||||||
{
|
{
|
||||||
struct strbuf buffer;
|
struct strbuf buffer;
|
||||||
|
int missing_ok = flags & WRITE_TREE_MISSING_OK;
|
||||||
|
int dryrun = flags & WRITE_TREE_DRY_RUN;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (0 <= it->entry_count && has_sha1_file(it->sha1))
|
if (0 <= it->entry_count && has_sha1_file(it->sha1))
|
||||||
@ -288,8 +290,7 @@ static int update_one(struct cache_tree *it,
|
|||||||
cache + i, entries - i,
|
cache + i, entries - i,
|
||||||
path,
|
path,
|
||||||
baselen + sublen + 1,
|
baselen + sublen + 1,
|
||||||
missing_ok,
|
flags);
|
||||||
dryrun);
|
|
||||||
if (subcnt < 0)
|
if (subcnt < 0)
|
||||||
return subcnt;
|
return subcnt;
|
||||||
i += subcnt - 1;
|
i += subcnt - 1;
|
||||||
@ -371,15 +372,13 @@ static int update_one(struct cache_tree *it,
|
|||||||
int cache_tree_update(struct cache_tree *it,
|
int cache_tree_update(struct cache_tree *it,
|
||||||
struct cache_entry **cache,
|
struct cache_entry **cache,
|
||||||
int entries,
|
int entries,
|
||||||
int missing_ok,
|
int flags)
|
||||||
int dryrun,
|
|
||||||
int silent)
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
i = verify_cache(cache, entries, silent);
|
i = verify_cache(cache, entries, flags);
|
||||||
if (i)
|
if (i)
|
||||||
return i;
|
return i;
|
||||||
i = update_one(it, cache, entries, "", 0, missing_ok, dryrun);
|
i = update_one(it, cache, entries, "", 0, flags);
|
||||||
if (i < 0)
|
if (i < 0)
|
||||||
return i;
|
return i;
|
||||||
return 0;
|
return 0;
|
||||||
@ -572,11 +571,9 @@ int write_cache_as_tree(unsigned char *sha1, int flags, const char *prefix)
|
|||||||
|
|
||||||
was_valid = cache_tree_fully_valid(active_cache_tree);
|
was_valid = cache_tree_fully_valid(active_cache_tree);
|
||||||
if (!was_valid) {
|
if (!was_valid) {
|
||||||
int missing_ok = flags & WRITE_TREE_MISSING_OK;
|
|
||||||
|
|
||||||
if (cache_tree_update(active_cache_tree,
|
if (cache_tree_update(active_cache_tree,
|
||||||
active_cache, active_nr,
|
active_cache, active_nr,
|
||||||
missing_ok, 0, 0) < 0)
|
flags) < 0)
|
||||||
return WRITE_TREE_UNMERGED_INDEX;
|
return WRITE_TREE_UNMERGED_INDEX;
|
||||||
if (0 <= newfd) {
|
if (0 <= newfd) {
|
||||||
if (!write_cache(newfd, active_cache, active_nr) &&
|
if (!write_cache(newfd, active_cache, active_nr) &&
|
||||||
@ -672,10 +669,10 @@ int cache_tree_matches_traversal(struct cache_tree *root,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int update_main_cache_tree (int silent)
|
int update_main_cache_tree(int flags)
|
||||||
{
|
{
|
||||||
if (!the_index.cache_tree)
|
if (!the_index.cache_tree)
|
||||||
the_index.cache_tree = cache_tree();
|
the_index.cache_tree = cache_tree();
|
||||||
return cache_tree_update(the_index.cache_tree,
|
return cache_tree_update(the_index.cache_tree,
|
||||||
the_index.cache, the_index.cache_nr, 0, 0, silent);
|
the_index.cache, the_index.cache_nr, flags);
|
||||||
}
|
}
|
||||||
|
@ -29,13 +29,15 @@ void cache_tree_write(struct strbuf *, struct cache_tree *root);
|
|||||||
struct cache_tree *cache_tree_read(const char *buffer, unsigned long size);
|
struct cache_tree *cache_tree_read(const char *buffer, unsigned long size);
|
||||||
|
|
||||||
int cache_tree_fully_valid(struct cache_tree *);
|
int cache_tree_fully_valid(struct cache_tree *);
|
||||||
int cache_tree_update(struct cache_tree *, struct cache_entry **, int, int, int, int);
|
int cache_tree_update(struct cache_tree *, struct cache_entry **, int, int);
|
||||||
|
|
||||||
int update_main_cache_tree(int);
|
int update_main_cache_tree(int);
|
||||||
|
|
||||||
/* bitmasks to write_cache_as_tree flags */
|
/* bitmasks to write_cache_as_tree flags */
|
||||||
#define WRITE_TREE_MISSING_OK 1
|
#define WRITE_TREE_MISSING_OK 1
|
||||||
#define WRITE_TREE_IGNORE_CACHE_TREE 2
|
#define WRITE_TREE_IGNORE_CACHE_TREE 2
|
||||||
|
#define WRITE_TREE_DRY_RUN 4
|
||||||
|
#define WRITE_TREE_SILENT 8
|
||||||
|
|
||||||
/* error return codes */
|
/* error return codes */
|
||||||
#define WRITE_TREE_UNREADABLE_INDEX (-1)
|
#define WRITE_TREE_UNREADABLE_INDEX (-1)
|
||||||
|
@ -264,7 +264,7 @@ struct tree *write_tree_from_memory(struct merge_options *o)
|
|||||||
|
|
||||||
if (!cache_tree_fully_valid(active_cache_tree) &&
|
if (!cache_tree_fully_valid(active_cache_tree) &&
|
||||||
cache_tree_update(active_cache_tree,
|
cache_tree_update(active_cache_tree,
|
||||||
active_cache, active_nr, 0, 0, 0) < 0)
|
active_cache, active_nr, 0) < 0)
|
||||||
die("error building trees");
|
die("error building trees");
|
||||||
|
|
||||||
result = lookup_tree(active_cache_tree->sha1);
|
result = lookup_tree(active_cache_tree->sha1);
|
||||||
|
@ -59,6 +59,6 @@ int main(int ac, char **av)
|
|||||||
struct cache_tree *another = cache_tree();
|
struct cache_tree *another = cache_tree();
|
||||||
if (read_cache() < 0)
|
if (read_cache() < 0)
|
||||||
die("unable to read index file");
|
die("unable to read index file");
|
||||||
cache_tree_update(another, active_cache, active_nr, 0, 1, 0);
|
cache_tree_update(another, active_cache, active_nr, WRITE_TREE_DRY_RUN);
|
||||||
return dump_cache_tree(active_cache_tree, another, "");
|
return dump_cache_tree(active_cache_tree, another, "");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user