Re: [PATCH v3 17/17] sequencer: ensure to release the lock when we could not read the index
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Sep 9, 2016, 18:26 UTC
- Message-ID
- <xmqqvay5aq03.fsf@gitster.mtv.corp.google.com>
- In-Reply-To
- <4c7876d88eac80d9cf05847477d4d468a7c01acc.1473431645.git.johannes.schindelin@gmx.de>
Johannes Schindelin <johannes.schindelin@gmx.de> writes:
> A future caller of read_and_refresh_cache() may want to do more than just > print some helpful advice in case of failure.
I recall commenting on unreleased locks on other parts of the series but didn't see this. Looks good. Thanks for being thorough.
Show 25 quoted lines
> 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;