Skip to content

Commit 6d91da6

Browse files
committed
read-cache.c: introduce is_racy_timestamp() helper
This moves a common boolean expression into a helper function, and makes the comparison between filesystem timestamp and index timestamp done in the function in line with the other places. st.st_mtime should be casted to (unsigned int) when compared to an index timestamp ce_mtime. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 077c48d commit 6d91da6

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

read-cache.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,12 @@ static int ce_match_stat_basic(struct cache_entry *ce, struct stat *st)
181181
return changed;
182182
}
183183

184+
static int is_racy_timestamp(struct index_state *istate, struct cache_entry *ce)
185+
{
186+
return (istate->timestamp &&
187+
((unsigned int)istate->timestamp) <= ce->ce_mtime);
188+
}
189+
184190
int ie_match_stat(struct index_state *istate,
185191
struct cache_entry *ce, struct stat *st,
186192
unsigned int options)
@@ -214,9 +220,7 @@ int ie_match_stat(struct index_state *istate,
214220
* whose mtime are the same as the index file timestamp more
215221
* carefully than others.
216222
*/
217-
if (!changed &&
218-
istate->timestamp &&
219-
istate->timestamp <= ce->ce_mtime) {
223+
if (!changed && is_racy_timestamp(istate, ce)) {
220224
if (assume_racy_is_modified)
221225
changed |= DATA_CHANGED;
222226
else
@@ -1233,8 +1237,7 @@ int write_index(struct index_state *istate, int newfd)
12331237
struct cache_entry *ce = cache[i];
12341238
if (ce->ce_flags & CE_REMOVE)
12351239
continue;
1236-
if (istate->timestamp &&
1237-
istate->timestamp <= ce->ce_mtime)
1240+
if (is_racy_timestamp(istate, ce))
12381241
ce_smudge_racily_clean_entry(ce);
12391242
if (ce_write_entry(&c, newfd, ce) < 0)
12401243
return -1;

0 commit comments

Comments
 (0)