read-cache.c: refactor --ignore-missing implementation

Move lstat ENOENT handling from refresh_index to refresh_cache_ent and activate it with a new CE_MATCH_IGNORE_MISSING option. This will allow other call paths into refresh_cache_ent to use the feature. 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 2e2e7ec1ef567ac0a4ad8294ada15836661e6589
2 files changed +7 -3
cache.h
+2
@@ -488,6 +488,8 @@ extern void *read_blob_data_from_index(struct index_state *, const char *, unsig
488 #define CE_MATCH_RACY_IS_DIRTY 02
489 /* do stat comparison even if CE_SKIP_WORKTREE is true */
490 #define CE_MATCH_IGNORE_SKIP_WORKTREE 04
491 +/* ignore non-existent files during stat update */
492 +#define CE_MATCH_IGNORE_MISSING 0x08
493 extern int ie_match_stat(const struct index_state *, const struct cache_entry *, struct stat *, unsigned int);
494 extern int ie_modified(const struct index_state *, const struct cache_entry *, struct stat *, unsigned int);
495
read-cache.c
+5 -3
@@ -1031,6 +1031,7 @@ static struct cache_entry *refresh_cache_ent(struct index_state *istate,
1031 int changed, size;
1032 int ignore_valid = options & CE_MATCH_IGNORE_VALID;
1033 int ignore_skip_worktree = options & CE_MATCH_IGNORE_SKIP_WORKTREE;
1034 + int ignore_missing = options & CE_MATCH_IGNORE_MISSING;
1035
1036 if (ce_uptodate(ce))
1037 return ce;
@@ -1050,6 +1051,8 @@ static struct cache_entry *refresh_cache_ent(struct index_state *istate,
1051 }
1052
1053 if (lstat(ce->name, &st) < 0) {
1054 + if (ignore_missing && errno == ENOENT)
1055 + return ce;
1056 if (err)
1057 *err = errno;
1058 return NULL;
@@ -1126,7 +1129,8 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p
1129 int ignore_submodules = (flags & REFRESH_IGNORE_SUBMODULES) != 0;
1130 int first = 1;
1131 int in_porcelain = (flags & REFRESH_IN_PORCELAIN);
1129 - unsigned int options = really ? CE_MATCH_IGNORE_VALID : 0;
1132 + unsigned int options = ((really ? CE_MATCH_IGNORE_VALID : 0) |
1133 + (not_new ? CE_MATCH_IGNORE_MISSING : 0));
1134 const char *modified_fmt;
1135 const char *deleted_fmt;
1136 const char *typechange_fmt;
@@ -1175,8 +1179,6 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p
1179 if (!new) {
1180 const char *fmt;
1181
1178 - if (not_new && cache_errno == ENOENT)
1179 - continue;
1182 if (really && cache_errno == EINVAL) {
1183 /* If we are doing --really-refresh that
1184 * means the index is not valid anymore.