@@ -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 /*
@@ -420,7 +422,7 @@ int add_file_to_index(struct index_state *istate, const char *path, int verbose)
420422 pos = index_name_pos (istate , ce -> name , namelen );
421423 if (0 <= pos &&
422424 !ce_stage (istate -> cache [pos ]) &&
423- !ie_modified (istate , istate -> cache [pos ], & st , 1 )) {
425+ !ie_modified (istate , istate -> cache [pos ], & st , CE_MATCH_IGNORE_VALID )) {
424426 /* Nothing changed, really */
425427 free (ce );
426428 return 0 ;
@@ -782,28 +784,37 @@ int add_index_entry(struct index_state *istate, struct cache_entry *ce, int opti
782784 * to link up the stat cache details with the proper files.
783785 */
784786static struct cache_entry * refresh_cache_ent (struct index_state * istate ,
785- struct cache_entry * ce , int really , int * err )
787+ struct cache_entry * ce ,
788+ unsigned int options , int * err )
786789{
787790 struct stat st ;
788791 struct cache_entry * updated ;
789792 int changed , size ;
793+ int ignore_valid = options & CE_MATCH_IGNORE_VALID ;
790794
791795 if (lstat (ce -> name , & st ) < 0 ) {
792796 if (err )
793797 * err = errno ;
794798 return NULL ;
795799 }
796800
797- changed = ie_match_stat (istate , ce , & st , really );
801+ changed = ie_match_stat (istate , ce , & st , options );
798802 if (!changed ) {
799- if (really && assume_unchanged &&
803+ /*
804+ * The path is unchanged. If we were told to ignore
805+ * valid bit, then we did the actual stat check and
806+ * found that the entry is unmodified. If the entry
807+ * is not marked VALID, this is the place to mark it
808+ * valid again, under "assume unchanged" mode.
809+ */
810+ if (ignore_valid && assume_unchanged &&
800811 !(ce -> ce_flags & htons (CE_VALID )))
801812 ; /* mark this one VALID again */
802813 else
803814 return ce ;
804815 }
805816
806- if (ie_modified (istate , ce , & st , really )) {
817+ if (ie_modified (istate , ce , & st , options )) {
807818 if (err )
808819 * err = EINVAL ;
809820 return NULL ;
@@ -814,13 +825,14 @@ static struct cache_entry *refresh_cache_ent(struct index_state *istate,
814825 memcpy (updated , ce , size );
815826 fill_stat_cache_info (updated , & st );
816827
817- /* In this case, if really is not set, we should leave
818- * CE_VALID bit alone. Otherwise, paths marked with
819- * --no-assume-unchanged (i.e. things to be edited) will
820- * reacquire CE_VALID bit automatically, which is not
821- * really what we want.
828+ /*
829+ * If ignore_valid is not set, we should leave CE_VALID bit
830+ * alone. Otherwise, paths marked with --no-assume-unchanged
831+ * (i.e. things to be edited) will reacquire CE_VALID bit
832+ * automatically, which is not really what we want.
822833 */
823- if (!really && assume_unchanged && !(ce -> ce_flags & htons (CE_VALID )))
834+ if (!ignore_valid && assume_unchanged &&
835+ !(ce -> ce_flags & htons (CE_VALID )))
824836 updated -> ce_flags &= ~htons (CE_VALID );
825837
826838 return updated ;
@@ -834,6 +846,7 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p
834846 int allow_unmerged = (flags & REFRESH_UNMERGED ) != 0 ;
835847 int quiet = (flags & REFRESH_QUIET ) != 0 ;
836848 int not_new = (flags & REFRESH_IGNORE_MISSING ) != 0 ;
849+ unsigned int options = really ? CE_MATCH_IGNORE_VALID : 0 ;
837850
838851 for (i = 0 ; i < istate -> cache_nr ; i ++ ) {
839852 struct cache_entry * ce , * new ;
@@ -855,7 +868,7 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p
855868 if (pathspec && !match_pathspec (pathspec , ce -> name , strlen (ce -> name ), 0 , seen ))
856869 continue ;
857870
858- new = refresh_cache_ent (istate , ce , really , & cache_errno );
871+ new = refresh_cache_ent (istate , ce , options , & cache_errno );
859872 if (new == ce )
860873 continue ;
861874 if (!new ) {
0 commit comments