Skip to content

Commit d5b6629

Browse files
pcloudsgitster
authored andcommitted
Break down no-lstat() condition checks in verify_uptodate()
Make it easier to grok under what conditions we can skip lstat(). While at there, shorten ie_match_stat() line for the sake of my eyes. Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent dd008b3 commit d5b6629

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

unpack-trees.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,11 +1166,22 @@ static int verify_uptodate_1(struct cache_entry *ce,
11661166
{
11671167
struct stat st;
11681168

1169-
if (o->index_only || (!((ce->ce_flags & CE_VALID) || ce_skip_worktree(ce)) && (o->reset || ce_uptodate(ce))))
1169+
if (o->index_only)
1170+
return 0;
1171+
1172+
/*
1173+
* CE_VALID and CE_SKIP_WORKTREE cheat, we better check again
1174+
* if this entry is truly up-to-date because this file may be
1175+
* overwritten.
1176+
*/
1177+
if ((ce->ce_flags & CE_VALID) || ce_skip_worktree(ce))
1178+
; /* keep checking */
1179+
else if (o->reset || ce_uptodate(ce))
11701180
return 0;
11711181

11721182
if (!lstat(ce->name, &st)) {
1173-
unsigned changed = ie_match_stat(o->src_index, ce, &st, CE_MATCH_IGNORE_VALID|CE_MATCH_IGNORE_SKIP_WORKTREE);
1183+
int flags = CE_MATCH_IGNORE_VALID|CE_MATCH_IGNORE_SKIP_WORKTREE;
1184+
unsigned changed = ie_match_stat(o->src_index, ce, &st, flags);
11741185
if (!changed)
11751186
return 0;
11761187
/*

0 commit comments

Comments
 (0)