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 <gitster@pobox.com>
This commit is contained in:
13
read-cache.c
13
read-cache.c
@ -181,6 +181,12 @@ static int ce_match_stat_basic(struct cache_entry *ce, struct stat *st)
|
|||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int is_racy_timestamp(struct index_state *istate, struct cache_entry *ce)
|
||||||
|
{
|
||||||
|
return (istate->timestamp &&
|
||||||
|
((unsigned int)istate->timestamp) <= ce->ce_mtime);
|
||||||
|
}
|
||||||
|
|
||||||
int ie_match_stat(struct index_state *istate,
|
int ie_match_stat(struct index_state *istate,
|
||||||
struct cache_entry *ce, struct stat *st,
|
struct cache_entry *ce, struct stat *st,
|
||||||
unsigned int options)
|
unsigned int options)
|
||||||
@ -214,9 +220,7 @@ int ie_match_stat(struct index_state *istate,
|
|||||||
* whose mtime are the same as the index file timestamp more
|
* whose mtime are the same as the index file timestamp more
|
||||||
* carefully than others.
|
* carefully than others.
|
||||||
*/
|
*/
|
||||||
if (!changed &&
|
if (!changed && is_racy_timestamp(istate, ce)) {
|
||||||
istate->timestamp &&
|
|
||||||
istate->timestamp <= ce->ce_mtime) {
|
|
||||||
if (assume_racy_is_modified)
|
if (assume_racy_is_modified)
|
||||||
changed |= DATA_CHANGED;
|
changed |= DATA_CHANGED;
|
||||||
else
|
else
|
||||||
@ -1233,8 +1237,7 @@ int write_index(struct index_state *istate, int newfd)
|
|||||||
struct cache_entry *ce = cache[i];
|
struct cache_entry *ce = cache[i];
|
||||||
if (ce->ce_flags & CE_REMOVE)
|
if (ce->ce_flags & CE_REMOVE)
|
||||||
continue;
|
continue;
|
||||||
if (istate->timestamp &&
|
if (is_racy_timestamp(istate, ce))
|
||||||
istate->timestamp <= ce->ce_mtime)
|
|
||||||
ce_smudge_racily_clean_entry(ce);
|
ce_smudge_racily_clean_entry(ce);
|
||||||
if (ce_write_entry(&c, newfd, ce) < 0)
|
if (ce_write_entry(&c, newfd, ce) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
Reference in New Issue
Block a user