From: Chuck Lever Date: Mon, 12 Sep 2005 14:56:14 GMT Subject: [PATCH 14/22] move read_cache_unmerged into read-cache.c Message-ID: <20050912145613.28120.32935.stgit@dexter.citi.umich.edu> In-Reply-To: <20050912145543.28120.7086.stgit@dexter.citi.umich.edu> Clean-up: put read_cache_unmerged() right next to read_cache(). read_cache_unmerged() will likely need to be reconstructed if the active cache data type changes. Signed-off-by: Chuck Lever --- cache.h | 1 + read-cache.c | 31 +++++++++++++++++++++++++++++++ read-tree.c | 28 ---------------------------- 3 files changed, 32 insertions(+), 28 deletions(-) diff --git a/cache.h b/cache.h --- a/cache.h +++ b/cache.h @@ -157,6 +157,7 @@ extern char *prefix_path(const char *pre /* Initialize and use the cache information */ extern int read_cache(void); +extern int read_cache_unmerged(void); extern int write_cache(int newfd); extern int cache_name_pos(const char *name, int namelen); #define ADD_CACHE_OK_TO_ADD 1 /* Ok to add */ diff --git a/read-cache.c b/read-cache.c --- a/read-cache.c +++ b/read-cache.c @@ -453,6 +453,37 @@ unmap: return error("verify header failed"); } +static int deleted = 0; +static struct cache_cursor dst; + +static int read_one_unmerged(struct cache_cursor *cc, struct cache_entry *ce) +{ + if (ce_stage(ce)) { + deleted++; + goto out; + } + if (deleted) + set_ce_at_cursor(&dst, ce); + next_cc(&dst); +out: + next_cc(cc); + return 0; +} + +/* + * Read in the cache, then throw away the unmerged entries + */ +int read_cache_unmerged(void) +{ + if (read_cache() > 0) { + init_cc(&dst); + walk_cache(read_one_unmerged); + } + + active_nr -= deleted; + return deleted; +} + #define WRITE_BUFFER_SIZE 8192 static unsigned char write_buffer[WRITE_BUFFER_SIZE]; static unsigned long write_buffer_len; diff --git a/read-tree.c b/read-tree.c --- a/read-tree.c +++ b/read-tree.c @@ -555,34 +555,6 @@ static int oneway_merge(struct cache_ent return merged_entry(a, NULL); } -static int deleted = 0; -static struct cache_cursor dst; - -static int read_one_unmerged(struct cache_cursor *cc, struct cache_entry *ce) -{ - if (ce_stage(ce)) { - deleted++; - goto out; - } - if (deleted) - set_ce_at_cursor(&dst, ce); - next_cc(&dst); -out: - next_cc(cc); - return 0; -} - -static int read_cache_unmerged(void) -{ - if (read_cache() > 0) { - init_cc(&dst); - walk_cache(read_one_unmerged); - } - - active_nr -= deleted; - return deleted; -} - static const char read_tree_usage[] = "git-read-tree ( | -m [-u] [ []])"; static struct cache_file cache_file;