@@ -194,11 +194,12 @@ static int ce_match_stat_basic(struct cache_entry *ce, struct stat *st)
194194}
195195
196196int ie_match_stat (struct index_state * istate ,
197- struct cache_entry * ce , struct stat * st , int options )
197+ struct cache_entry * ce , struct stat * st ,
198+ unsigned int options )
198199{
199200 unsigned int changed ;
200- int ignore_valid = options & 01 ;
201- int assume_racy_is_modified = options & 02 ;
201+ int ignore_valid = options & CE_MATCH_IGNORE_VALID ;
202+ int assume_racy_is_modified = options & CE_MATCH_RACY_IS_DIRTY ;
202203
203204 /*
204205 * If it's marked as always valid in the index, it's
@@ -238,10 +239,11 @@ int ie_match_stat(struct index_state *istate,
238239}
239240
240241int ie_modified (struct index_state * istate ,
241- struct cache_entry * ce , struct stat * st , int really )
242+ struct cache_entry * ce , struct stat * st , unsigned int options )
242243{
243244 int changed , changed_fs ;
244- changed = ie_match_stat (istate , ce , st , really );
245+
246+ changed = ie_match_stat (istate , ce , st , options );
245247 if (!changed )
246248 return 0 ;
247249 /*
@@ -387,6 +389,7 @@ int add_file_to_index(struct index_state *istate, const char *path, int verbose)
387389 int size , namelen , pos ;
388390 struct stat st ;
389391 struct cache_entry * ce ;
392+ unsigned ce_option = CE_MATCH_IGNORE_VALID |CE_MATCH_RACY_IS_DIRTY ;
390393
391394 if (lstat (path , & st ))
392395 die ("%s: unable to stat (%s)" , path , strerror (errno ));
@@ -421,7 +424,7 @@ int add_file_to_index(struct index_state *istate, const char *path, int verbose)
421424 pos = index_name_pos (istate , ce -> name , namelen );
422425 if (0 <= pos &&
423426 !ce_stage (istate -> cache [pos ]) &&
424- !ie_modified (istate , istate -> cache [pos ], & st , 1 )) {
427+ !ie_match_stat (istate , istate -> cache [pos ], & st , ce_option )) {
425428 /* Nothing changed, really */
426429 free (ce );
427430 return 0 ;
@@ -783,28 +786,37 @@ int add_index_entry(struct index_state *istate, struct cache_entry *ce, int opti
783786 * to link up the stat cache details with the proper files.
784787 */
785788static struct cache_entry * refresh_cache_ent (struct index_state * istate ,
786- struct cache_entry * ce , int really , int * err )
789+ struct cache_entry * ce ,
790+ unsigned int options , int * err )
787791{
788792 struct stat st ;
789793 struct cache_entry * updated ;
790794 int changed , size ;
795+ int ignore_valid = options & CE_MATCH_IGNORE_VALID ;
791796
792797 if (lstat (ce -> name , & st ) < 0 ) {
793798 if (err )
794799 * err = errno ;
795800 return NULL ;
796801 }
797802
798- changed = ie_match_stat (istate , ce , & st , really );
803+ changed = ie_match_stat (istate , ce , & st , options );
799804 if (!changed ) {
800- if (really && assume_unchanged &&
805+ /*
806+ * The path is unchanged. If we were told to ignore
807+ * valid bit, then we did the actual stat check and
808+ * found that the entry is unmodified. If the entry
809+ * is not marked VALID, this is the place to mark it
810+ * valid again, under "assume unchanged" mode.
811+ */
812+ if (ignore_valid && assume_unchanged &&
801813 !(ce -> ce_flags & htons (CE_VALID )))
802814 ; /* mark this one VALID again */
803815 else
804816 return ce ;
805817 }
806818
807- if (ie_modified (istate , ce , & st , really )) {
819+ if (ie_modified (istate , ce , & st , options )) {
808820 if (err )
809821 * err = EINVAL ;
810822 return NULL ;
@@ -815,13 +827,14 @@ static struct cache_entry *refresh_cache_ent(struct index_state *istate,
815827 memcpy (updated , ce , size );
816828 fill_stat_cache_info (updated , & st );
817829
818- /* In this case, if really is not set, we should leave
819- * CE_VALID bit alone. Otherwise, paths marked with
820- * --no-assume-unchanged (i.e. things to be edited) will
821- * reacquire CE_VALID bit automatically, which is not
822- * really what we want.
830+ /*
831+ * If ignore_valid is not set, we should leave CE_VALID bit
832+ * alone. Otherwise, paths marked with --no-assume-unchanged
833+ * (i.e. things to be edited) will reacquire CE_VALID bit
834+ * automatically, which is not really what we want.
823835 */
824- if (!really && assume_unchanged && !(ce -> ce_flags & htons (CE_VALID )))
836+ if (!ignore_valid && assume_unchanged &&
837+ !(ce -> ce_flags & htons (CE_VALID )))
825838 updated -> ce_flags &= ~htons (CE_VALID );
826839
827840 return updated ;
@@ -835,6 +848,7 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p
835848 int allow_unmerged = (flags & REFRESH_UNMERGED ) != 0 ;
836849 int quiet = (flags & REFRESH_QUIET ) != 0 ;
837850 int not_new = (flags & REFRESH_IGNORE_MISSING ) != 0 ;
851+ unsigned int options = really ? CE_MATCH_IGNORE_VALID : 0 ;
838852
839853 for (i = 0 ; i < istate -> cache_nr ; i ++ ) {
840854 struct cache_entry * ce , * new ;
@@ -856,7 +870,7 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p
856870 if (pathspec && !match_pathspec (pathspec , ce -> name , strlen (ce -> name ), 0 , seen ))
857871 continue ;
858872
859- new = refresh_cache_ent (istate , ce , really , & cache_errno );
873+ new = refresh_cache_ent (istate , ce , options , & cache_errno );
860874 if (new == ce )
861875 continue ;
862876 if (!new ) {
0 commit comments