diff options
author | Junio C Hamano <gitster@pobox.com> | 2011-04-03 12:33:05 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2011-04-03 12:33:05 -0700 |
commit | 44ec754dc766e38684d9ad4563019378730eea82 (patch) | |
tree | e8be72b52ab4827a58dc72518dbc5068313931f1 /read-cache.c | |
parent | Merge branch 'lt/default-abbrev' into maint (diff) | |
parent | update $GIT_INDEX_FILE when there are racily clean entries (diff) | |
download | tgif-44ec754dc766e38684d9ad4563019378730eea82.tar.xz |
Merge branch 'jc/index-update-if-able' into maint
* 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.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/read-cache.c b/read-cache.c index 4f2e890b01..0480d9455c 100644 --- a/read-cache.c +++ b/read-cache.c @@ -1568,6 +1568,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; |