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> Reviewed-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
e5074bfe8c
commit
867c2fac0a
@ -153,7 +153,8 @@ static int replace_object_sha1(const char *object_ref,
|
|||||||
unsigned char prev[20];
|
unsigned char prev[20];
|
||||||
enum object_type obj_type, repl_type;
|
enum object_type obj_type, repl_type;
|
||||||
char ref[PATH_MAX];
|
char ref[PATH_MAX];
|
||||||
struct ref_lock *lock;
|
struct ref_transaction *transaction;
|
||||||
|
struct strbuf err = STRBUF_INIT;
|
||||||
|
|
||||||
obj_type = sha1_object_info(object, NULL);
|
obj_type = sha1_object_info(object, NULL);
|
||||||
repl_type = sha1_object_info(repl, NULL);
|
repl_type = sha1_object_info(repl, NULL);
|
||||||
@ -166,12 +167,13 @@ static int replace_object_sha1(const char *object_ref,
|
|||||||
|
|
||||||
check_ref_valid(object, prev, ref, sizeof(ref), force);
|
check_ref_valid(object, prev, ref, sizeof(ref), force);
|
||||||
|
|
||||||
lock = lock_any_ref_for_update(ref, prev, 0, NULL);
|
transaction = ref_transaction_begin(&err);
|
||||||
if (!lock)
|
if (!transaction ||
|
||||||
die("%s: cannot lock the ref", ref);
|
ref_transaction_update(transaction, ref, repl, prev, 0, 1, &err) ||
|
||||||
if (write_ref_sha1(lock, repl, NULL) < 0)
|
ref_transaction_commit(transaction, NULL, &err))
|
||||||
die("%s: cannot update the ref", ref);
|
die("%s", err.buf);
|
||||||
|
|
||||||
|
ref_transaction_free(transaction);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user