diff options
author | Ronnie Sahlberg <sahlberg@google.com> | 2014-04-28 13:49:07 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-10-15 10:47:23 -0700 |
commit | cd94f765720e32ea0bf72996c8dc7dd0b1cc30d0 (patch) | |
tree | af0f79dd9ff3bb93a99f53c4181afc7f56437720 /builtin | |
parent | 28e6a97e39edb84599693db971e36d793d36e413 (diff) | |
download | git-cd94f765720e32ea0bf72996c8dc7dd0b1cc30d0.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: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/fetch.c | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/builtin/fetch.c b/builtin/fetch.c index 159fb7e916..6ffd02388b 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -404,23 +404,37 @@ 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; + struct strbuf err = STRBUF_INIT; + int ret, df_conflict = 0; if (dry_run) return 0; if (!rla) rla = default_rla.buf; snprintf(msg, sizeof(msg), "%s: %s", rla, action); - 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) - return errno == ENOTDIR ? STORE_REF_ERROR_DF_CONFLICT : - STORE_REF_ERROR_OTHER; + + transaction = ref_transaction_begin(&err); + if (!transaction || + ref_transaction_update(transaction, ref->name, ref->new_sha1, + ref->old_sha1, 0, check_old, msg, &err)) + goto fail; + + ret = ref_transaction_commit(transaction, &err); + if (ret) { + df_conflict = (ret == TRANSACTION_NAME_CONFLICT); + goto fail; + } + + ref_transaction_free(transaction); + strbuf_release(&err); return 0; +fail: + ref_transaction_free(transaction); + error("%s", err.buf); + strbuf_release(&err); + return df_conflict ? STORE_REF_ERROR_DF_CONFLICT + : STORE_REF_ERROR_OTHER; } #define REFCOL_WIDTH 10 |