summaryrefslogtreecommitdiff
path: root/read-cache.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2011-03-27 03:13:16 (GMT)
committerJunio C Hamano <gitster@pobox.com>2011-03-27 03:13:16 (GMT)
commit149971badc562f4e5ee66c045f40c904fb29eab6 (patch)
tree020dbffb91e75d4a001bffe52c804018ca2f1e66 /read-cache.c
parent4d46ee74e11416e7edf6624611242fe2f98f078c (diff)
parent483fbe2b7cb89ddcf700a677735d21aa176bc5a6 (diff)
downloadgit-149971badc562f4e5ee66c045f40c904fb29eab6.zip
git-149971badc562f4e5ee66c045f40c904fb29eab6.tar.gz
git-149971badc562f4e5ee66c045f40c904fb29eab6.tar.bz2
Merge branch 'jc/index-update-if-able'
* jc/index-update-if-able: update $GIT_INDEX_FILE when there are racily clean entries diff/status: refactor opportunistic index update
Diffstat (limited to 'read-cache.c')
-rw-r--r--read-cache.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/read-cache.c b/read-cache.c
index 98d526b..f38471c 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -1547,6 +1547,31 @@ 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 || has_racy_timestamp(istate)) &&
+ !write_index(istate, lockfile->fd))
+ commit_locked_index(lockfile);
+ else
+ rollback_lock_file(lockfile);
+}
+
int write_index(struct index_state *istate, int newfd)
{
git_SHA_CTX c;