diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2014-06-13 19:19:23 +0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-06-13 11:49:10 -0700 |
commit | 03b86647722f11ccc321cd7279aa49b811d17cc2 (patch) | |
tree | dc5b717a01867692ce344d1548ad5a82ac1c1881 /read-cache.c | |
parent | sequencer: do not update/refresh index if the lock cannot be held (diff) | |
download | tgif-03b86647722f11ccc321cd7279aa49b811d17cc2.tar.xz |
read-cache: new API write_locked_index instead of write_index/write_cache
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'read-cache.c')
-rw-r--r-- | read-cache.c | 28 |
1 files changed, 24 insertions, 4 deletions
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 |