From 257627268ad19cb616ad3feb6ca8171d400df287 Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 27 Jan 2014 09:45:08 -0500 Subject: [PATCH] read-cache.c: extend make_cache_entry refresh flag with options Convert the make_cache_entry boolean 'refresh' argument to a more general 'refresh_options' argument. Pass the value through to the underlying refresh_cache_ent call. Add option CE_MATCH_REFRESH to enable stat refresh. Update call sites to use the new signature. Signed-off-by: Brad King Signed-off-by: Junio C Hamano --- cache.h | 4 +++- merge-recursive.c | 3 ++- read-cache.c | 21 +++++++++++---------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/cache.h b/cache.h index 87429db0e4..18ecd77914 100644 --- a/cache.h +++ b/cache.h @@ -477,7 +477,7 @@ extern int remove_file_from_index(struct index_state *, const char *path); #define ADD_CACHE_IMPLICIT_DOT 32 /* internal to "git add -u/-A" */ extern int add_to_index(struct index_state *, const char *path, struct stat *, int flags); extern int add_file_to_index(struct index_state *, const char *path, int flags); -extern struct cache_entry *make_cache_entry(unsigned int mode, const unsigned char *sha1, const char *path, int stage, int refresh); +extern struct cache_entry *make_cache_entry(unsigned int mode, const unsigned char *sha1, const char *path, int stage, unsigned int refresh_options); extern int ce_same_name(const struct cache_entry *a, const struct cache_entry *b); extern int index_name_is_other(const struct index_state *, const char *, int); extern void *read_blob_data_from_index(struct index_state *, const char *, unsigned long *); @@ -490,6 +490,8 @@ extern void *read_blob_data_from_index(struct index_state *, const char *, unsig #define CE_MATCH_IGNORE_SKIP_WORKTREE 04 /* ignore non-existent files during stat update */ #define CE_MATCH_IGNORE_MISSING 0x08 +/* enable stat refresh */ +#define CE_MATCH_REFRESH 0x10 extern int ie_match_stat(const struct index_state *, const struct cache_entry *, struct stat *, unsigned int); extern int ie_modified(const struct index_state *, const struct cache_entry *, struct stat *, unsigned int); diff --git a/merge-recursive.c b/merge-recursive.c index fc2f00176c..05311e411c 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -201,7 +201,8 @@ static int add_cacheinfo(unsigned int mode, const unsigned char *sha1, const char *path, int stage, int refresh, int options) { struct cache_entry *ce; - ce = make_cache_entry(mode, sha1 ? sha1 : null_sha1, path, stage, refresh); + ce = make_cache_entry(mode, sha1 ? sha1 : null_sha1, path, stage, + (refresh ? CE_MATCH_REFRESH : 0 )); if (!ce) return error(_("addinfo_cache failed for path '%s'"), path); return add_cache_entry(ce, options); diff --git a/read-cache.c b/read-cache.c index bb38115a9d..9032550bde 100644 --- a/read-cache.c +++ b/read-cache.c @@ -15,7 +15,8 @@ #include "strbuf.h" #include "varint.h" -static struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int really); +static struct cache_entry *refresh_cache_entry(struct cache_entry *ce, + unsigned int options); /* Mask for the name length in ce_flags in the on-disk index */ @@ -696,7 +697,7 @@ int add_file_to_index(struct index_state *istate, const char *path, int flags) struct cache_entry *make_cache_entry(unsigned int mode, const unsigned char *sha1, const char *path, int stage, - int refresh) + unsigned int refresh_options) { int size, len; struct cache_entry *ce; @@ -716,10 +717,7 @@ struct cache_entry *make_cache_entry(unsigned int mode, ce->ce_namelen = len; ce->ce_mode = create_ce_mode(mode); - if (refresh) - return refresh_cache_entry(ce, 0); - - return ce; + return refresh_cache_entry(ce, refresh_options); } int ce_same_name(const struct cache_entry *a, const struct cache_entry *b) @@ -1029,11 +1027,12 @@ static struct cache_entry *refresh_cache_ent(struct index_state *istate, struct stat st; struct cache_entry *updated; int changed, size; + int refresh = options & CE_MATCH_REFRESH; int ignore_valid = options & CE_MATCH_IGNORE_VALID; int ignore_skip_worktree = options & CE_MATCH_IGNORE_SKIP_WORKTREE; int ignore_missing = options & CE_MATCH_IGNORE_MISSING; - if (ce_uptodate(ce)) + if (!refresh || ce_uptodate(ce)) return ce; /* @@ -1129,7 +1128,8 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p int ignore_submodules = (flags & REFRESH_IGNORE_SUBMODULES) != 0; int first = 1; int in_porcelain = (flags & REFRESH_IN_PORCELAIN); - unsigned int options = ((really ? CE_MATCH_IGNORE_VALID : 0) | + unsigned int options = (CE_MATCH_REFRESH | + (really ? CE_MATCH_IGNORE_VALID : 0) | (not_new ? CE_MATCH_IGNORE_MISSING : 0)); const char *modified_fmt; const char *deleted_fmt; @@ -1208,9 +1208,10 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p return has_errors; } -static struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int really) +static struct cache_entry *refresh_cache_entry(struct cache_entry *ce, + unsigned int options) { - return refresh_cache_ent(&the_index, ce, really, NULL, NULL); + return refresh_cache_ent(&the_index, ce, options, NULL, NULL); } -- 2.11.4.GIT