From 03b86647722f11ccc321cd7279aa49b811d17cc2 Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Fri, 13 Jun 2014 19:19:23 +0700 Subject: read-cache: new API write_locked_index instead of write_index/write_cache MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- read-cache.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'read-cache.c') diff --git a/read-cache.c b/read-cache.c index ba13353b37..44d4732b65 100644 --- a/read-cache.c +++ b/read-cache.c @@ -1779,13 +1779,11 @@ static int has_racy_timestamp(struct index_state *istate) 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 + write_locked_index(istate, lockfile, COMMIT_LOCK)) rollback_lock_file(lockfile); } -int write_index(struct index_state *istate, int newfd) +static int do_write_index(struct index_state *istate, int newfd) { git_SHA_CTX c; struct cache_header hdr; @@ -1877,6 +1875,28 @@ int write_index(struct index_state *istate, int newfd) return 0; } +static int do_write_locked_index(struct index_state *istate, struct lock_file *lock, + unsigned flags) +{ + int ret = do_write_index(istate, lock->fd); + if (ret) + return ret; + assert((flags & (COMMIT_LOCK | CLOSE_LOCK)) != + (COMMIT_LOCK | CLOSE_LOCK)); + if (flags & COMMIT_LOCK) + return commit_locked_index(lock); + else if (flags & CLOSE_LOCK) + return close_lock_file(lock); + else + return ret; +} + +int write_locked_index(struct index_state *istate, struct lock_file *lock, + unsigned flags) +{ + return do_write_locked_index(istate, lock, flags); +} + /* * Read the index file that is potentially unmerged into given * index_state, dropping any unmerged entries. Returns true if -- cgit v1.3-5-g9baa