Re: [PATCH v20 27/48] sequencer.c: use ref transactions for all ref updates
- From
Michael Haggerty <mhagger@alum.mit.edu>
- Date
- Jul 8, 2014, 12:23 UTC
- Message-ID
- <53BBE2D6.2070809@alum.mit.edu>
- In-Reply-To
- <1403275409-28173-28-git-send-email-sahlberg@google.com>
On 06/20/2014 04:43 PM, Ronnie Sahlberg wrote:
Show 29 quoted lines
> Change to use ref transactions for all updates to refs.
>
> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
> Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
> ---
> sequencer.c | 24 ++++++++++++++++--------
> 1 file changed, 16 insertions(+), 8 deletions(-)
>
> diff --git a/sequencer.c b/sequencer.c
> index 0a80c58..fd8acaf 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"));I think you've changed the semantics when unborn is set. Please note that lock_any_ref_for_update() behaves differently if old_sha1 is NULL (when no check is done) vs. when it is null_sha1 (when it verifies that the reference didn't previously exist). So when unborn is true, the old code verifies that the reference previously didn't exist...
Show 8 quoted lines
> > strbuf_addf(&sb, "%s: fast-forward", action_name(opts)); > - ret = write_ref_sha1(ref_lock, to, sb.buf); > + > + transaction = ref_transaction_begin(&err); > + if (!transaction || > + ref_transaction_update(transaction, "HEAD", to, from, > + 0, !unborn, &err) ||
...whereas when unborn is true, the new code does no check at all. I think you want
ref_transaction_update(transaction, "HEAD",
to, unborn ? null_sha1 : from,
0, 1, &err) ||Show 16 quoted lines
> + ref_transaction_commit(transaction, sb.buf, &err)) {
> + ref_transaction_free(transaction);
> + error("%s", err.buf);
> + strbuf_release(&sb);
> + strbuf_release(&err);
> + return -1;
> + }
>
> strbuf_release(&sb);
> - return ret;
> + ref_transaction_free(transaction);
> + return 0;
> }
>
> static int do_recursive_merge(struct commit *base, struct commit *next,
> Michael
-- Michael Haggerty mhagger@alum.mit.edu http://softwareswirl.blogspot.com/