summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ccdc4ec)
raw | patch | inline | side by side (parent: ccdc4ec)
author | Junio C Hamano <gitster@pobox.com> | |
Mon, 21 Mar 2011 17:18:19 +0000 (10:18 -0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 21 Mar 2011 21:49:46 +0000 (14:49 -0700) |
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 <gitster@pobox.com>
"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 <gitster@pobox.com>
read-cache.c | patch | blob | history |
diff --git a/read-cache.c b/read-cache.c
index 7a0421cba47bf370ac3d6ef560da60ecb6c36b21..971e27705c37b7a1a5708026043dd48a15e7e87f 100644 (file)
--- a/read-cache.c
+++ b/read-cache.c
return result;
}
+static int has_racy_timestamp(struct index_state *istate)
+{
+ int entries = istate->cache_nr;
+ int i;
+
+ for (i = 0; i < entries; i++) {
+ struct cache_entry *ce = istate->cache[i];
+ if (is_racy_timestamp(istate, ce))
+ return 1;
+ }
+ return 0;
+}
+
/*
* Opportunisticly update the index but do not complain if we can't
*/
void update_index_if_able(struct index_state *istate, struct lock_file *lockfile)
{
- if (istate->cache_changed &&
+ if ((istate->cache_changed || has_racy_timestamp(istate)) &&
!write_index(istate, lockfile->fd))
commit_locked_index(lockfile);
else