summaryrefslogtreecommitdiff
path: root/sequencer.c
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2016-09-09 14:38:20 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-09-09 18:24:52 (GMT)
commit49fb937e9a082b3bdecd85f1c539a1e1683e1a3d (patch)
treee528aca28a18c363d1daa020f205037780e54cf6 /sequencer.c
parent55f5704da69d3e6836620f01bee0093ad5e331e8 (diff)
downloadgit-49fb937e9a082b3bdecd85f1c539a1e1683e1a3d.zip
git-49fb937e9a082b3bdecd85f1c539a1e1683e1a3d.tar.gz
git-49fb937e9a082b3bdecd85f1c539a1e1683e1a3d.tar.bz2
sequencer: ensure to release the lock when we could not read the index
A future caller of read_and_refresh_cache() may want to do more than just print some helpful advice in case of failure. Suggested by Junio Hamano. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sequencer.c')
-rw-r--r--sequencer.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/sequencer.c b/sequencer.c
index d92a632..eec8a60 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -644,14 +644,18 @@ static int read_and_refresh_cache(struct replay_opts *opts)
{
static struct lock_file index_lock;
int index_fd = hold_locked_index(&index_lock, 0);
- if (read_index_preload(&the_index, NULL) < 0)
+ if (read_index_preload(&the_index, NULL) < 0) {
+ rollback_lock_file(&index_lock);
return error(_("git %s: failed to read the index"),
action_name(opts));
+ }
refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, NULL, NULL, NULL);
if (the_index.cache_changed && index_fd >= 0) {
- if (write_locked_index(&the_index, &index_lock, COMMIT_LOCK))
+ if (write_locked_index(&the_index, &index_lock, COMMIT_LOCK)) {
+ rollback_lock_file(&index_lock);
return error(_("git %s: failed to refresh the index"),
action_name(opts));
+ }
}
rollback_lock_file(&index_lock);
return 0;