Skip to content

Commit 2e2e7ec

Browse files
bradkinggitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 29d9af5 commit 2e2e7ec

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

cache.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,8 @@ extern void *read_blob_data_from_index(struct index_state *, const char *, unsig
488488
#define CE_MATCH_RACY_IS_DIRTY 02
489489
/* do stat comparison even if CE_SKIP_WORKTREE is true */
490490
#define CE_MATCH_IGNORE_SKIP_WORKTREE 04
491+
/* ignore non-existent files during stat update */
492+
#define CE_MATCH_IGNORE_MISSING 0x08
491493
extern int ie_match_stat(const struct index_state *, const struct cache_entry *, struct stat *, unsigned int);
492494
extern int ie_modified(const struct index_state *, const struct cache_entry *, struct stat *, unsigned int);
493495

read-cache.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,7 @@ static struct cache_entry *refresh_cache_ent(struct index_state *istate,
10311031
int changed, size;
10321032
int ignore_valid = options & CE_MATCH_IGNORE_VALID;
10331033
int ignore_skip_worktree = options & CE_MATCH_IGNORE_SKIP_WORKTREE;
1034+
int ignore_missing = options & CE_MATCH_IGNORE_MISSING;
10341035

10351036
if (ce_uptodate(ce))
10361037
return ce;
@@ -1050,6 +1051,8 @@ static struct cache_entry *refresh_cache_ent(struct index_state *istate,
10501051
}
10511052

10521053
if (lstat(ce->name, &st) < 0) {
1054+
if (ignore_missing && errno == ENOENT)
1055+
return ce;
10531056
if (err)
10541057
*err = errno;
10551058
return NULL;
@@ -1126,7 +1129,8 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p
11261129
int ignore_submodules = (flags & REFRESH_IGNORE_SUBMODULES) != 0;
11271130
int first = 1;
11281131
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));
11301134
const char *modified_fmt;
11311135
const char *deleted_fmt;
11321136
const char *typechange_fmt;
@@ -1175,8 +1179,6 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p
11751179
if (!new) {
11761180
const char *fmt;
11771181

1178-
if (not_new && cache_errno == ENOENT)
1179-
continue;
11801182
if (really && cache_errno == EINVAL) {
11811183
/* If we are doing --really-refresh that
11821184
* means the index is not valid anymore.

0 commit comments

Comments
 (0)