summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRonnie Sahlberg <sahlberg@google.com>2014-05-15 10:29:31 -0700
committerJunio C Hamano <gitster@pobox.com>2014-05-15 14:02:52 -0700
commit0f119d081bb035309a0609cdcc6350bfd059b75a (patch)
treef8b3c76c179fa8954bab05e114d929986c58865f
parentf82fc9426d7e599ea0e69275a03080d86572311d (diff)
downloadgit-0f119d081bb035309a0609cdcc6350bfd059b75a.tar.gz
sequencer.c: use ref transactions for all ref updates
Change to use ref transactions for all updates to refs. Signed-off-by: Ronnie Sahlberg <sahlberg@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--sequencer.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/sequencer.c b/sequencer.c
index 0a80c58d11..9282a12541 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -272,23 +272,31 @@ static int error_dirty_index(struct replay_opts *opts)
static int fast_forward_to(const unsigned char *to, const unsigned char *from,
int unborn, struct replay_opts *opts)
{
- struct ref_lock *ref_lock;
+ struct ref_transaction *transaction;
struct strbuf sb = STRBUF_INIT;
- int ret;
+ struct strbuf err = STRBUF_INIT;
read_cache();
if (checkout_fast_forward(from, to, 1))
exit(1); /* the callee should have complained already */
- ref_lock = lock_any_ref_for_update("HEAD", unborn ? null_sha1 : from,
- 0, NULL);
- if (!ref_lock)
- return error(_("Failed to lock HEAD during fast_forward_to"));
strbuf_addf(&sb, "%s: fast-forward", action_name(opts));
- ret = write_ref_sha1(ref_lock, to, sb.buf);
+
+ transaction = ref_transaction_begin();
+ if ((!transaction ||
+ ref_transaction_update(transaction, "HEAD", to, from,
+ 0, !unborn)) ||
+ (ref_transaction_commit(transaction, sb.buf, &err) &&
+ !(transaction = NULL))) {
+ ref_transaction_rollback(transaction);
+ error(_("HEAD: Could not fast-forward: %s\n"), err.buf);
+ strbuf_release(&sb);
+ strbuf_release(&err);
+ return -1;
+ }
strbuf_release(&sb);
- return ret;
+ return 0;
}
static int do_recursive_merge(struct commit *base, struct commit *next,