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>
Johannes Schindelin committed
Sep 9, 2016 at 16:38 UTC
49fb937e9a082b3bdecd85f1c539a1e1683e1a3d
1 file changed
+6
-2
sequencer.c
+6
-2
@@ -644,14 +644,18 @@ static int read_and_refresh_cache(struct replay_opts *opts)
644
{
645
static struct lock_file index_lock;
646
int index_fd = hold_locked_index(&index_lock, 0);
647
- if (read_index_preload(&the_index, NULL) < 0)
647
+ if (read_index_preload(&the_index, NULL) < 0) {
648
+ rollback_lock_file(&index_lock);
649
return error(_("git %s: failed to read the index"),
650
action_name(opts));
651
+ }
652
refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, NULL, NULL, NULL);
653
if (the_index.cache_changed && index_fd >= 0) {
652
- if (write_locked_index(&the_index, &index_lock, COMMIT_LOCK))
654
+ if (write_locked_index(&the_index, &index_lock, COMMIT_LOCK)) {
655
+ rollback_lock_file(&index_lock);
656
return error(_("git %s: failed to refresh the index"),
657
action_name(opts));
658
+ }
659
}
660
rollback_lock_file(&index_lock);
661
return 0;