Update replace.c to use ref transactions for updates.

Reviewed-by: Jonathan Nieder <jrnie...@gmail.com>
Signed-off-by: Ronnie Sahlberg <sahlb...@google.com>
---
 builtin/replace.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/builtin/replace.c b/builtin/replace.c
index b62420a..24f0dc9 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,12 +158,14 @@ 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(&err);
+       if (!transaction ||
+           ref_transaction_update(transaction, ref, repl, prev,
+                                  0, !is_null_sha1(prev), &err) ||
+           ref_transaction_commit(transaction, NULL, &err))
+               die("%s", err.buf);
 
+       ref_transaction_free(transaction);
        return 0;
 }
 
-- 
2.0.0.282.g3799eda.dirty

--
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

Reply via email to