15
15
#include "strbuf.h"
16
16
#include "varint.h"
17
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 );
19
20
20
21
/* Mask for the name length in ce_flags in the on-disk index */
21
22
@@ -700,7 +701,7 @@ int add_file_to_index(struct index_state *istate, const char *path, int flags)
700
701
701
702
struct cache_entry * make_cache_entry (unsigned int mode ,
702
703
const unsigned char * sha1 , const char * path , int stage ,
703
- int refresh )
704
+ unsigned int refresh_options )
704
705
{
705
706
int size , len ;
706
707
struct cache_entry * ce ;
@@ -720,10 +721,7 @@ struct cache_entry *make_cache_entry(unsigned int mode,
720
721
ce -> ce_namelen = len ;
721
722
ce -> ce_mode = create_ce_mode (mode );
722
723
723
- if (refresh )
724
- return refresh_cache_entry (ce , 0 );
725
-
726
- return ce ;
724
+ return refresh_cache_entry (ce , refresh_options );
727
725
}
728
726
729
727
int ce_same_name (const struct cache_entry * a , const struct cache_entry * b )
@@ -1033,10 +1031,12 @@ static struct cache_entry *refresh_cache_ent(struct index_state *istate,
1033
1031
struct stat st ;
1034
1032
struct cache_entry * updated ;
1035
1033
int changed , size ;
1034
+ int refresh = options & CE_MATCH_REFRESH ;
1036
1035
int ignore_valid = options & CE_MATCH_IGNORE_VALID ;
1037
1036
int ignore_skip_worktree = options & CE_MATCH_IGNORE_SKIP_WORKTREE ;
1037
+ int ignore_missing = options & CE_MATCH_IGNORE_MISSING ;
1038
1038
1039
- if (ce_uptodate (ce ))
1039
+ if (! refresh || ce_uptodate (ce ))
1040
1040
return ce ;
1041
1041
1042
1042
/*
@@ -1054,6 +1054,8 @@ static struct cache_entry *refresh_cache_ent(struct index_state *istate,
1054
1054
}
1055
1055
1056
1056
if (lstat (ce -> name , & st ) < 0 ) {
1057
+ if (ignore_missing && errno == ENOENT )
1058
+ return ce ;
1057
1059
if (err )
1058
1060
* err = errno ;
1059
1061
return NULL ;
@@ -1131,7 +1133,9 @@ int refresh_index(struct index_state *istate, unsigned int flags,
1131
1133
int ignore_submodules = (flags & REFRESH_IGNORE_SUBMODULES ) != 0 ;
1132
1134
int first = 1 ;
1133
1135
int in_porcelain = (flags & REFRESH_IN_PORCELAIN );
1134
- unsigned int options = really ? CE_MATCH_IGNORE_VALID : 0 ;
1136
+ unsigned int options = (CE_MATCH_REFRESH |
1137
+ (really ? CE_MATCH_IGNORE_VALID : 0 ) |
1138
+ (not_new ? CE_MATCH_IGNORE_MISSING : 0 ));
1135
1139
const char * modified_fmt ;
1136
1140
const char * deleted_fmt ;
1137
1141
const char * typechange_fmt ;
@@ -1180,8 +1184,6 @@ int refresh_index(struct index_state *istate, unsigned int flags,
1180
1184
if (!new ) {
1181
1185
const char * fmt ;
1182
1186
1183
- if (not_new && cache_errno == ENOENT )
1184
- continue ;
1185
1187
if (really && cache_errno == EINVAL ) {
1186
1188
/* If we are doing --really-refresh that
1187
1189
* means the index is not valid anymore.
@@ -1211,9 +1213,10 @@ int refresh_index(struct index_state *istate, unsigned int flags,
1211
1213
return has_errors ;
1212
1214
}
1213
1215
1214
- static struct cache_entry * refresh_cache_entry (struct cache_entry * ce , int really )
1216
+ static struct cache_entry * refresh_cache_entry (struct cache_entry * ce ,
1217
+ unsigned int options )
1215
1218
{
1216
- return refresh_cache_ent (& the_index , ce , really , NULL , NULL );
1219
+ return refresh_cache_ent (& the_index , ce , options , NULL , NULL );
1217
1220
}
1218
1221
1219
1222
0 commit comments