Re: [PATCH v20 25/48] replace.c: use the ref transaction functions for updates
- From
Ronnie Sahlberg <sahlberg@google.com>
- Date
- Jul 14, 2014, 21:19 UTC
- Message-ID
- <CAL=YDWng3eBnbUAGVBoESio6d75Lz47oY3ntLFa1ktY2513bXg@mail.gmail.com>
- In-Reply-To
- <53BBE578.9030703@alum.mit.edu>
On Tue, Jul 8, 2014 at 5:35 AM, Michael Haggerty <mhagger@alum.mit.edu> wrote:
Show 41 quoted lines
> On 06/20/2014 04:43 PM, Ronnie Sahlberg wrote:
>> Update replace.c to use ref transactions for updates.
>>
>> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
>> Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
>> ---
>> builtin/replace.c | 15 +++++++++------
>> 1 file changed, 9 insertions(+), 6 deletions(-)
>>
>> diff --git a/builtin/replace.c b/builtin/replace.c
>> index 1bb491d..7528f3d 100644
>> --- a/builtin/replace.c
>> +++ b/builtin/replace.c
>> @@ -153,7 +153,8 @@ static int replace_object_sha1(const char *object_ref,
>> unsigned char prev[20];
>> enum object_type obj_type, repl_type;
>> char ref[PATH_MAX];
>> - struct ref_lock *lock;
>> + struct ref_transaction *transaction;
>> + struct strbuf err = STRBUF_INIT;
>>
>> obj_type = sha1_object_info(object, NULL);
>> repl_type = sha1_object_info(repl, NULL);
>> @@ -166,12 +167,14 @@ static int replace_object_sha1(const char *object_ref,
>>
>> check_ref_valid(object, prev, ref, sizeof(ref), force);
>>
>> - 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(&err);
>> + if (!transaction ||
>> + ref_transaction_update(transaction, ref, repl, prev,
>> + 0, !is_null_sha1(prev), &err) ||
>
> Same problem here. You need
>
> s/!is_null_sha1(prev)/1/
>I think we need it. prev can be null_sha1 here if check_ref_valid fails to resolve the ref.
Show 14 quoted lines
>> + ref_transaction_commit(transaction, NULL, &err))
>> + die("%s", err.buf);
>>
>> + ref_transaction_free(transaction);
>> return 0;
>> }
>>
>>
>
>
> --
> Michael Haggerty
> mhagger@alum.mit.edu
>