Skip to content

Commit 483fbe2

Browse files
committed
update $GIT_INDEX_FILE when there are racily clean entries
Traditional "opportunistic index update" done by read-only "diff" and "status" was about updating cached lstat(2) information in the index for the next round. We missed another obvious optimization opportunity: when there are racily clean entries that will cease to be racily clean by updating $GIT_INDEX_FILE. Detect that case and write $GIT_INDEX_FILE out to give it a newer timestamp. Noticed by Lasse Makholm by stracing "git status" in a fresh checkout and counting the number of open(2) calls. Signed-off-by: Junio C Hamano <[email protected]>
1 parent ccdc4ec commit 483fbe2

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

read-cache.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1545,12 +1545,25 @@ static int ce_write_entry(git_SHA_CTX *c, int fd, struct cache_entry *ce)
15451545
return result;
15461546
}
15471547

1548+
static int has_racy_timestamp(struct index_state *istate)
1549+
{
1550+
int entries = istate->cache_nr;
1551+
int i;
1552+
1553+
for (i = 0; i < entries; i++) {
1554+
struct cache_entry *ce = istate->cache[i];
1555+
if (is_racy_timestamp(istate, ce))
1556+
return 1;
1557+
}
1558+
return 0;
1559+
}
1560+
15481561
/*
15491562
* Opportunisticly update the index but do not complain if we can't
15501563
*/
15511564
void update_index_if_able(struct index_state *istate, struct lock_file *lockfile)
15521565
{
1553-
if (istate->cache_changed &&
1566+
if ((istate->cache_changed || has_racy_timestamp(istate)) &&
15541567
!write_index(istate, lockfile->fd))
15551568
commit_locked_index(lockfile);
15561569
else

0 commit comments

Comments
 (0)