Re: [PATCH] refs.c: handle locking failure during transaction better
- From
Stefan Beller <sbeller@google.com>
- Date
- Nov 18, 2014, 23:34 UTC
- Message-ID
- <CAGZ79kbH=pqSizhUeuiCeYXZWk015K49Pj0F5pPvkOTqg4PMuQ@mail.gmail.com>
- In-Reply-To
- <1416352639-10150-1-git-send-email-sbeller@google.com>
I messed up authorship on this one. This was of course found and authored by Ronnie.
On Tue, Nov 18, 2014 at 3:17 PM, Stefan Beller <sbeller@google.com> wrote:
Show 52 quoted lines
> Change lock_ref_sha1_basic to return an error instead of dying,
> when we fail to lock a file during a transaction. This function is
> only called from transaction_commit() and it knows how to handle
> these failures.
>
> Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
> Cherry-picked-to-master: Stefan Beller <sbeller@google.com>
> Signed-off-by: Stefan Beller <sbeller@google.com>
> ---
> refs.c | 10 ++++++++--
> 1 file changed, 8 insertions(+), 2 deletions(-)
>
> This was part of the ref-transactions-rename series[1],
> but it makes sense to send this one as a separate patch.
>
> Thanks,
> Stefan
>
> [1] https://www.mail-archive.com/git@vger.kernel.org/msg60604.html
>
> diff --git a/refs.c b/refs.c
> index 5ff457e..0347328 100644
> --- a/refs.c
> +++ b/refs.c
> @@ -2318,6 +2318,7 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
>
> lock->lock_fd = hold_lock_file_for_update(lock->lk, ref_file, lflags);
> if (lock->lock_fd < 0) {
> + last_errno = errno;
> if (errno == ENOENT && --attempts_remaining > 0)
> /*
> * Maybe somebody just deleted one of the
> @@ -2325,8 +2326,13 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
> * again:
> */
> goto retry;
> - else
> - unable_to_lock_die(ref_file, errno);
> + else {
> + struct strbuf err = STRBUF_INIT;
> + unable_to_lock_message(ref_file, errno, &err);
> + error("%s", err.buf);
> + strbuf_reset(&err);
> + goto error_return;
> + }
> }
> return old_sha1 ? verify_lock(lock, old_sha1, mustexist) : lock;
>
> --
> 2.2.0.rc2.5.gf7b9fb2
>