git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/2] update $GIT_INDEX_FILE when there are racily clean entries

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 21, 2011, 17:18 UTC
Message-ID
<7voc54qtmf.fsf@alter.siamese.dyndns.org>
In-Reply-To
<7vipvcs9xt.fsf@alter.siamese.dyndns.org>

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 to when there are racily clean entries that will ceas to be racily clean by updating $GIT_INDEX_FILE.

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 |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)
diff --git a/read-cache.c b/read-cache.c
index 561dc66..971e277 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -1545,12 +1545,25 @@ static int ce_write_entry(git_SHA_CTX *c, int fd, struct cache_entry *ce)
 	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
-- 
1.7.4.1.554.gfdad8
Previous: Junio C HamanoNext: Lasse Makholm
Message 6 of 9 in “git status reads too many files”
  1. Lasse MakholmMar 21, 2011
  2. Junio C HamanoMar 21, 2011
  3. 1/2 diff/status: refactor opportunistic index updateJunio C Hamano, Mar 21, 2011
  4. Piotr KrukowieckiMar 21, 2011
  5. Junio C HamanoMar 21, 2011
  6. 2/2 update $GIT_INDEX_FILE when there are racily clean entriesJunio C Hamano, Mar 21, 2011
  7. Lasse MakholmMar 21, 2011
  8. Eric RaibleMar 22, 2011
  9. Lasse MakholmMar 21, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.