diff options
author | Ronnie Sahlberg <sahlberg@google.com> | 2014-05-15 10:29:38 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-05-15 14:11:44 -0700 |
commit | a2d450e6bf101164dbe93182d366c8c54e67f002 (patch) | |
tree | fa7be5b8168f5a64215faec6b9b63135770ca59b | |
parent | 45aa12bc7ceeecd44853b92e27810a7eea4adae2 (diff) | |
download | git-a2d450e6bf101164dbe93182d366c8c54e67f002.tar.gz |
fetch.c: change s_update_ref to use a ref transaction
Change s_update_ref to use a ref transaction for the ref update.
Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r-- | builtin/fetch.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/builtin/fetch.c b/builtin/fetch.c index a93c893a85..b41d7b78b1 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -375,7 +375,7 @@ static int s_update_ref(const char *action, { char msg[1024]; char *rla = getenv("GIT_REFLOG_ACTION"); - static struct ref_lock *lock; + struct ref_transaction *transaction; if (dry_run) return 0; @@ -384,15 +384,16 @@ static int s_update_ref(const char *action, snprintf(msg, sizeof(msg), "%s: %s", rla, action); errno = 0; - lock = lock_any_ref_for_update(ref->name, - check_old ? ref->old_sha1 : NULL, - 0, NULL); - if (!lock) - return errno == ENOTDIR ? STORE_REF_ERROR_DF_CONFLICT : - STORE_REF_ERROR_OTHER; - if (write_ref_sha1(lock, ref->new_sha1, msg) < 0) + transaction = ref_transaction_begin(); + if (!transaction || + ref_transaction_update(transaction, ref->name, ref->new_sha1, + ref->old_sha1, 0, check_old) || + ref_transaction_commit(transaction, msg, NULL)) { + ref_transaction_rollback(transaction); return errno == ENOTDIR ? STORE_REF_ERROR_DF_CONFLICT : STORE_REF_ERROR_OTHER; + } + ref_transaction_free(transaction); return 0; } |