Re: [PATCH v8 14/44] replace.c: use the ref transaction functions for updates
- From
Ronnie Sahlberg <sahlberg@google.com>
- Date
- May 15, 2014, 22:30 UTC
- Message-ID
- <CAL=YDWk0S4StNcZhz6JDBEe2dpvVsCTqROZ+100Cv012t9FNrg@mail.gmail.com>
- In-Reply-To
- <20140515211835.GL26471@google.com>
On Thu, May 15, 2014 at 2:18 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:
Show 36 quoted lines
> Ronnie Sahlberg wrote:
>
>> --- a/builtin/replace.c
>> +++ b/builtin/replace.c
> [...]
>> @@ -156,11 +157,12 @@ static int replace_object_sha1(const char *object_ref,
>> else if (!force)
>> die("replace ref '%s' already exists", ref);
>>
>> - lock = lock_any_ref_for_update(ref, prev, 0, NULL);
>> - if (!lock)
>> - die("%s: cannot lock the ref", ref);
>> - if (write_ref_sha1(lock, repl, NULL) < 0)
>> - die("%s: cannot update the ref", ref);
>> + transaction = ref_transaction_begin();
>> + if (!transaction ||
>> + ref_transaction_update(transaction, ref, repl, prev,
>> + 0, !is_null_sha1(prev)) ||
>> + ref_transaction_commit(transaction, NULL, &err))
>> + die("%s: failed to replace ref: %s", ref, err.buf);
>
> This would write
>
> fatal: refs/replace/09c779943364d893c190066c385e6112af421db3: failed to replace ref: Cannot lock the ref 'refs/replace/09c779943364d893c190066c385e6112af421db3'.
>
> Perhaps something like
>
> $ git replace foo bar
> fatal: replace foo: Cannot lock the ref 'refs/replace/09c779943364d893c190066c385e6112af421db3'.
>
> would make sense (die("replace %s: %s", object_ref, err.buf)). Plain
>
> $ git replace foo bar
> fatal: Cannot lock the ref 'refs/replace/09c779943364d893c190066c385e6112af421db3'.
>
> also seems fine (die("%s", err.buf)).Done.
I used : die("%s", err.buf) since this is consistent with most of the other if-transaction-failed-die()
> > Thanks, > Jonathan