Re: [PATCH v6 12/42] replace.c: use the ref transaction functions for updates

2014-05-15 Thread Ronnie Sahlberg
On Wed, May 14, 2014 at 5:30 PM, Jonathan Nieder  wrote:
> Ronnie Sahlberg wrote:
>
> [...]
>> +++ b/builtin/replace.c
> [...]
>> @@ -157,11 +158,12 @@ static int replace_object(const char *object_ref, 
>> const char *replace_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);
>
> Same question about the !transaction case.
>
> This makes the message translated, which is a nice change but not
> mentioned in the commit message.  (Generally speaking, I don't mind
> either way about adding or not adding _() to new messages in files
> that have not already undergone a pass of marking everything for
> translation.)

Removed the _.  This series is long enough as is so lets not start
worrying about translations too.

Same opinion about the ref_transaction_begin() case as before. I think
it will be better to just add err to it
since it is likely this will be useful for future non-file based ref backends.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v6 12/42] replace.c: use the ref transaction functions for updates

2014-05-14 Thread Jonathan Nieder
Ronnie Sahlberg wrote:

[...]
> +++ b/builtin/replace.c
[...]
> @@ -157,11 +158,12 @@ static int replace_object(const char *object_ref, const 
> char *replace_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);

Same question about the !transaction case.

This makes the message translated, which is a nice change but not
mentioned in the commit message.  (Generally speaking, I don't mind
either way about adding or not adding _() to new messages in files
that have not already undergone a pass of marking everything for
translation.)
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v6 12/42] replace.c: use the ref transaction functions for updates

2014-05-01 Thread Ronnie Sahlberg
Update replace.c to use ref transactions for updates.

Signed-off-by: Ronnie Sahlberg 
---
 builtin/replace.c | 14 --
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/builtin/replace.c b/builtin/replace.c
index b62420a..b037b29 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -129,7 +129,8 @@ static int replace_object(const char *object_ref, const 
char *replace_ref,
unsigned char object[20], prev[20], repl[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;
 
if (get_sha1(object_ref, object))
die("Failed to resolve '%s' as a valid ref.", object_ref);
@@ -157,11 +158,12 @@ static int replace_object(const char *object_ref, const 
char *replace_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);
 
return 0;
 }
-- 
2.0.0.rc1.351.g4d2c8e4

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html