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>
This commit is contained in:
committed by
Junio C Hamano
parent
33c297aacc
commit
03b8664772
28
read-cache.c
28
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
|
||||
|
||||
Reference in New Issue
Block a user