summaryrefslogtreecommitdiff
path: root/read-cache.c
diff options
context:
space:
mode:
authorMartin Ågren <martin.agren@gmail.com>2017-10-06 20:12:14 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-10-07 01:20:56 (GMT)
commitb74c90fb419b002c664b0236f2941c34786b18b9 (patch)
treed26cb73d0fa8435c62884de4a73fde36e4e8aee1 /read-cache.c
parentdf60cf5789782191b092169f86255aa44525b7d1 (diff)
downloadgit-b74c90fb419b002c664b0236f2941c34786b18b9.zip
git-b74c90fb419b002c664b0236f2941c34786b18b9.tar.gz
git-b74c90fb419b002c664b0236f2941c34786b18b9.tar.bz2
read_cache: roll back lock in `update_index_if_able()`
`update_index_if_able()` used to always commit the lock or roll it back. Commit 03b866477 (read-cache: new API write_locked_index instead of write_index/write_cache, 2014-06-13) stopped rolling it back in case a write was not even attempted. This change in behavior is not motivated in the commit message and appears to be accidental: the `else`-path was removed, although that changed the behavior in case the `if` shortcuts. Reintroduce the rollback and document this behavior. While at it, move the documentation on this function from the function definition to the function declaration in cache.h. If `write_locked_index(..., COMMIT_LOCK)` fails, it will roll back the lock for us (see the previous commit). Noticed-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Martin Ågren <martin.agren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'read-cache.c')
-rw-r--r--read-cache.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/read-cache.c b/read-cache.c
index 0d8d2de..87188d3 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -2176,14 +2176,13 @@ static int has_racy_timestamp(struct index_state *istate)
return 0;
}
-/*
- * Opportunistically 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)) &&
verify_index(istate))
write_locked_index(istate, lockfile, COMMIT_LOCK);
+ else
+ rollback_lock_file(lockfile);
}
/*