Re: [PATCH v6 14/42] sequencer.c: use ref transactions for all ref updates
- From
Jonathan Nieder <jrnieder@gmail.com>
- Date
- May 15, 2014, 17:35 UTC
- Message-ID
- <20140515173557.GL9218@google.com>
- In-Reply-To
- <1398976662-6962-15-git-send-email-sahlberg@google.com>
Ronnie Sahlberg wrote:
Show 27 quoted lines
> --- 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)) ||These parentheses make it harder to parse. Other patches in this series do
if (!transaction ||
ref_transaction_update(...) ||
ref_transaction_commit(...)) {so this could do
if (!transaction ||
ref_transaction_update(...) ||
(ref_transaction_commit(...) && !(transaction = NULL))) {> + (ref_transaction_commit(transaction, sb.buf, &err) &&
> + !(transaction = NULL))) {
> + ref_transaction_rollback(transaction);Earlier patches in the series didn't bother rolling back. Should they have?
Thanks, Jonathan