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

Re-instate index file write optimization

From
Linus Torvalds <torvalds@osdl.org>
Date
Oct 1, 2005, 20:39 UTC
Message-ID
<Pine.LNX.4.64.0510011331570.3378@g5.osdl.org>

This makes "git-update-index" avoid the new index file write if it didn't make any changes to the index.

It still doesn't make things like "git status" be read-only operations in general, but if the index file doesn't need refreshing, it now will at least avoid making unnecessary changes.

Signed-off-by: Linus Torvalds <torvalds@osdl.org>
---

This only makes sense after applying my previous patch, since otherwise a "--refresh" will always end up marking the index dirty anyway.

Also, while I tried to verify that we always mark the index dirty when we change it, I can't guarantee it. In particular, since we now map the index file with PROT_READ | PROT_WRITE, somebody can modify the index entries in place without getting a SIGSEGV.

Originally you couldn't do the modify-in-place, and used to be that you could depend on the active_cache[] being unmodified only by actually assigning to the pointer array itself.

I don't think git-update-index writes to the entries directly, though (git-read-tree does, but it doesn't do the optimization).

diff --git a/update-index.c b/update-index.c
--- a/update-index.c
+++ b/update-index.c
@@ -391,9 +391,11 @@ int main(int argc, const char **argv)
 			update_one(buf.buf, prefix, prefix_length);
 		}
 	}
-	if (write_cache(newfd, active_cache, active_nr) ||
-	    commit_index_file(&cache_file))
-		die("Unable to write new cachefile");
+	if (active_cache_changed) {
+		if (write_cache(newfd, active_cache, active_nr) ||
+		    commit_index_file(&cache_file))
+			die("Unable to write new cachefile");
+	}
 
 	return has_errors ? 1 : 0;
 }
Message 1 of 1 in “Re-instate index file write optimization”
  1. Linus TorvaldsOct 1, 2005

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.