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 <brad.king@kitware.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Brad King committed Jan 27, 2014 at 09:45 UTC 257627268ad19cb616ad3feb6ca8171d400df287
3 files changed +16 -12
cache.h
+3 -1
@@ -477,7 +477,7 @@ extern int remove_file_from_index(struct index_state *, const char *path);
477 #define ADD_CACHE_IMPLICIT_DOT 32 /* internal to "git add -u/-A" */
478 extern int add_to_index(struct index_state *, const char *path, struct stat *, int flags);
479 extern int add_file_to_index(struct index_state *, const char *path, int flags);
480 -extern struct cache_entry *make_cache_entry(unsigned int mode, const unsigned char *sha1, const char *path, int stage, int refresh);
480 +extern struct cache_entry *make_cache_entry(unsigned int mode, const unsigned char *sha1, const char *path, int stage, unsigned int refresh_options);
481 extern int ce_same_name(const struct cache_entry *a, const struct cache_entry *b);
482 extern int index_name_is_other(const struct index_state *, const char *, int);
483 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
490 #define CE_MATCH_IGNORE_SKIP_WORKTREE 04
491 /* ignore non-existent files during stat update */
492 #define CE_MATCH_IGNORE_MISSING 0x08
493 +/* enable stat refresh */
494 +#define CE_MATCH_REFRESH 0x10
495 extern int ie_match_stat(const struct index_state *, const struct cache_entry *, struct stat *, unsigned int);
496 extern int ie_modified(const struct index_state *, const struct cache_entry *, struct stat *, unsigned int);
497
merge-recursive.c
+2 -1
@@ -201,7 +201,8 @@ static int add_cacheinfo(unsigned int mode, const unsigned char *sha1,
201 const char *path, int stage, int refresh, int options)
202 {
203 struct cache_entry *ce;
204 - ce = make_cache_entry(mode, sha1 ? sha1 : null_sha1, path, stage, refresh);
204 + ce = make_cache_entry(mode, sha1 ? sha1 : null_sha1, path, stage,
205 + (refresh ? CE_MATCH_REFRESH : 0 ));
206 if (!ce)
207 return error(_("addinfo_cache failed for path '%s'"), path);
208 return add_cache_entry(ce, options);
read-cache.c
+11 -10
@@ -15,7 +15,8 @@
15 #include "strbuf.h"
16 #include "varint.h"
17
18 -static struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int really);
18 +static struct cache_entry *refresh_cache_entry(struct cache_entry *ce,
19 + unsigned int options);
20
21 /* Mask for the name length in ce_flags in the on-disk index */
22
@@ -696,7 +697,7 @@ int add_file_to_index(struct index_state *istate, const char *path, int flags)
697
698 struct cache_entry *make_cache_entry(unsigned int mode,
699 const unsigned char *sha1, const char *path, int stage,
699 - int refresh)
700 + unsigned int refresh_options)
701 {
702 int size, len;
703 struct cache_entry *ce;
@@ -716,10 +717,7 @@ struct cache_entry *make_cache_entry(unsigned int mode,
717 ce->ce_namelen = len;
718 ce->ce_mode = create_ce_mode(mode);
719
719 - if (refresh)
720 - return refresh_cache_entry(ce, 0);
721 -
722 - return ce;
720 + return refresh_cache_entry(ce, refresh_options);
721 }
722
723 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,
1027 struct stat st;
1028 struct cache_entry *updated;
1029 int changed, size;
1030 + int refresh = options & CE_MATCH_REFRESH;
1031 int ignore_valid = options & CE_MATCH_IGNORE_VALID;
1032 int ignore_skip_worktree = options & CE_MATCH_IGNORE_SKIP_WORKTREE;
1033 int ignore_missing = options & CE_MATCH_IGNORE_MISSING;
1034
1036 - if (ce_uptodate(ce))
1035 + if (!refresh || ce_uptodate(ce))
1036 return ce;
1037
1038 /*
@@ -1129,7 +1128,8 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p
1128 int ignore_submodules = (flags & REFRESH_IGNORE_SUBMODULES) != 0;
1129 int first = 1;
1130 int in_porcelain = (flags & REFRESH_IN_PORCELAIN);
1132 - unsigned int options = ((really ? CE_MATCH_IGNORE_VALID : 0) |
1131 + unsigned int options = (CE_MATCH_REFRESH |
1132 + (really ? CE_MATCH_IGNORE_VALID : 0) |
1133 (not_new ? CE_MATCH_IGNORE_MISSING : 0));
1134 const char *modified_fmt;
1135 const char *deleted_fmt;
@@ -1208,9 +1208,10 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p
1208 return has_errors;
1209 }
1210
1211 -static struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int really)
1211 +static struct cache_entry *refresh_cache_entry(struct cache_entry *ce,
1212 + unsigned int options)
1213 {
1213 - return refresh_cache_ent(&the_index, ce, really, NULL, NULL);
1214 + return refresh_cache_ent(&the_index, ce, options, NULL, NULL);
1215 }
1216
1217