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>
This commit is contained in:
Johannes Schindelin 2016-09-09 16:38:20 +02:00 коммит произвёл Junio C Hamano
Родитель 55f5704da6
Коммит 49fb937e9a
1 изменённых файлов: 6 добавлений и 2 удалений

Просмотреть файл

@ -644,14 +644,18 @@ static int read_and_refresh_cache(struct replay_opts *opts)
{ {
static struct lock_file index_lock; static struct lock_file index_lock;
int index_fd = hold_locked_index(&index_lock, 0); 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"), return error(_("git %s: failed to read the index"),
action_name(opts)); action_name(opts));
}
refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, NULL, NULL, NULL); refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, NULL, NULL, NULL);
if (the_index.cache_changed && index_fd >= 0) { 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"), return error(_("git %s: failed to refresh the index"),
action_name(opts)); action_name(opts));
}
} }
rollback_lock_file(&index_lock); rollback_lock_file(&index_lock);
return 0; return 0;