From 27bc41cf1798c8937b323a7fe6c7fe459c70f8c1 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Fri, 13 Nov 2015 16:31:51 -0500 Subject: [PATCH] index: clear uptodate bit on save The uptodate bit should have a lifecycle of a single read->write on the index. Once the index is written, the files within it should be scanned for racy timestamps against the new index timestamp. --- src/index.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/index.c b/src/index.c index b3fb077cc..ed4079665 100644 --- a/src/index.c +++ b/src/index.c @@ -2746,6 +2746,15 @@ static int write_tree_extension(git_index *index, git_filebuf *file) return error; } +static void clear_uptodate(git_index *index) +{ + git_index_entry *entry; + size_t i; + + git_vector_foreach(&index->entries, i, entry) + entry->flags_extended &= ~GIT_IDXENTRY_UPTODATE; +} + static int write_index(git_oid *checksum, git_index *index, git_filebuf *file) { git_oid hash_final; @@ -2785,7 +2794,13 @@ static int write_index(git_oid *checksum, git_index *index, git_filebuf *file) git_oid_cpy(checksum, &hash_final); /* write it at the end of the file */ - return git_filebuf_write(file, hash_final.id, GIT_OID_RAWSZ); + if (git_filebuf_write(file, hash_final.id, GIT_OID_RAWSZ) < 0) + return -1; + + /* file entries are no longer up to date */ + clear_uptodate(index); + + return 0; } int git_index_entry_stage(const git_index_entry *entry)