diff options
author | Ronnie Sahlberg <sahlberg@google.com> | 2014-05-15 10:29:29 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-05-15 14:02:37 -0700 |
commit | 9c56ede92653f66671d3292b333e4ba6e8d7b6ef (patch) | |
tree | e9970d40a657d1b86d1e422c4ebc6ab751f2884b | |
parent | 242aeb55702c7da2b3f79685c4027c04301bf0b2 (diff) | |
download | git-9c56ede92653f66671d3292b333e4ba6e8d7b6ef.tar.gz |
replace.c: use the ref transaction functions for updates
Update replace.c to use ref transactions for updates.
Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r-- | builtin/replace.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/builtin/replace.c b/builtin/replace.c index b62420a01a..80692fa348 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; } |