{"thread":{"id":"17949","subject":"[PATCH] write_index(): update index_stat->timestamp after flushing to disk","startedAt":"2009-02-22T14:09:21Z","lastAt":"2009-02-22T14:09:21Z","messageCount":1,"participants":["Kjetil Barvik"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"105769","messageId":"1235311761-30776-1-git-send-email-barvik@broadpark.no","threadId":"17949","inReplyTo":null,"subject":"[PATCH] write_index(): update index_stat->timestamp after flushing to disk","fromName":"Kjetil Barvik","fromEmail":"barvik@broadpark.no","sentAt":"2009-02-22T14:09:21Z","receivedAt":"2009-02-22T14:09:21Z","isPatch":true,"sender":{"key":"barvik@broadpark.no","avatar":null},"body":"Since this timestamp is used to check for racy-clean files, it is\nimportant to keep it uptodate.\n\nFor the 'git checkout' command without the '-q' option, this make a\nhuge difference.  Before, each and every file which was updated, was\nracy-clean after the call to unpack_trees() and write_index() but\nbefore the GIT process ended.\n\nAnd because of the call to show_local_changes() in builtin-checkout.c,\nwe ended up reading those files back into memory, doing a SHA1 to\ncheck if the files was really different from the index.  And, of\ncourse, no file was different.\n\nWith this fix, 'git checkout' without the '-q' option should now be\nalmost as fast as with the '-q' option, but not quite, as we still do\nsome few lstat(2) calls more without the '-q' option.\n\nSigned-off-by: Kjetil Barvik <barvik@broadpark.no>\n---\n  patch aginst the 'next' branch this time!  :-)\n\n cache.h      |    2 +-\n read-cache.c |   11 +++++++++--\n 2 files changed, 10 insertions(+), 3 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex 20446c1..7e454a7 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -430,7 +430,7 @@ extern int read_index_preload(struct index_state *, const char **pathspec);\n extern int read_index_from(struct index_state *, const char *path);\n extern int is_index_unborn(struct index_state *);\n extern int read_index_unmerged(struct index_state *);\n-extern int write_index(const struct index_state *, int newfd);\n+extern int write_index(struct index_state *, int newfd);\n extern int discard_index(struct index_state *);\n extern int unmerged_index(const struct index_state *);\n extern int verify_path(const char *path);\ndiff --git a/read-cache.c b/read-cache.c\nindex bb07371..4212719 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -1528,13 +1528,14 @@ static int ce_write_entry(git_SHA_CTX *c, int fd, struct cache_entry *ce)\n \treturn ce_write(c, fd, ondisk, size);\n }\n \n-int write_index(const struct index_state *istate, int newfd)\n+int write_index(struct index_state *istate, int newfd)\n {\n \tgit_SHA_CTX c;\n \tstruct cache_header hdr;\n \tint i, err, removed, extended;\n \tstruct cache_entry **cache = istate->cache;\n \tint entries = istate->cache_nr;\n+\tstruct stat st;\n \n \tfor (i = removed = extended = 0; i < entries; i++) {\n \t\tif (cache[i]->ce_flags & CE_REMOVE)\n@@ -1578,7 +1579,13 @@ int write_index(const struct index_state *istate, int newfd)\n \t\tif (err)\n \t\t\treturn -1;\n \t}\n-\treturn ce_flush(&c, newfd);\n+\tif (ce_flush(&c, newfd) || fstat(newfd, &st))\n+\t\treturn -1;\n+\tistate->timestamp.sec = (unsigned int)st.st_ctime;\n+#ifdef USE_NSEC\n+\tistate->timestamp.nsec = (unsigned int)st.st_ctim.tv_nsec;\n+#endif\n+\treturn 0;\n }\n \n /*\n-- \n1.6.1.349.g99fa5\n"}]}