{"thread":{"id":"1992","subject":"Re-instate index file write optimization","startedAt":"2005-10-01T20:39:47Z","lastAt":"2005-10-01T20:39:47Z","messageCount":1,"participants":["Linus Torvalds"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"9597","messageId":"Pine.LNX.4.64.0510011331570.3378@g5.osdl.org","threadId":"1992","inReplyTo":null,"subject":"Re-instate index file write optimization","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2005-10-01T20:39:47Z","receivedAt":"2005-10-01T20:39:47Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\nThis makes \"git-update-index\" avoid the new index file write if it didn't \nmake any changes to the index.\n\nIt still doesn't make things like \"git status\" be read-only operations in \ngeneral, but if the index file doesn't need refreshing, it now will at \nleast avoid making unnecessary changes.\n\nSigned-off-by: Linus Torvalds <torvalds@osdl.org>\n---\n\nThis only makes sense after applying my previous patch, since otherwise a \n\"--refresh\" will always end up marking the index dirty anyway.\n\nAlso, while I tried to verify that we always mark the index dirty when we \nchange it, I can't guarantee it. In particular, since we now map the index \nfile with PROT_READ | PROT_WRITE, somebody can modify the index entries in \nplace without getting a SIGSEGV.\n\nOriginally you couldn't do the modify-in-place, and used to be that you \ncould depend on the active_cache[] being unmodified only by actually \nassigning to the pointer array itself.\n\nI don't think git-update-index writes to the entries directly, though \n(git-read-tree does, but it doesn't do the optimization).\n\ndiff --git a/update-index.c b/update-index.c\n--- a/update-index.c\n+++ b/update-index.c\n@@ -391,9 +391,11 @@ int main(int argc, const char **argv)\n \t\t\tupdate_one(buf.buf, prefix, prefix_length);\n \t\t}\n \t}\n-\tif (write_cache(newfd, active_cache, active_nr) ||\n-\t    commit_index_file(&cache_file))\n-\t\tdie(\"Unable to write new cachefile\");\n+\tif (active_cache_changed) {\n+\t\tif (write_cache(newfd, active_cache, active_nr) ||\n+\t\t    commit_index_file(&cache_file))\n+\t\t\tdie(\"Unable to write new cachefile\");\n+\t}\n \n \treturn has_errors ? 1 : 0;\n }\n"}]}