Skip to content

Commit d668d16

Browse files
rsahlberggitster
authored andcommitted
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> Reviewed-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent c0fe1ed commit d668d16

1 file changed

Lines changed: 18 additions & 8 deletions

File tree

sequencer.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -272,23 +272,33 @@ static int error_dirty_index(struct replay_opts *opts)
272272
static int fast_forward_to(const unsigned char *to, const unsigned char *from,
273273
int unborn, struct replay_opts *opts)
274274
{
275-
struct ref_lock *ref_lock;
275+
struct ref_transaction *transaction;
276276
struct strbuf sb = STRBUF_INIT;
277-
int ret;
277+
struct strbuf err = STRBUF_INIT;
278278

279279
read_cache();
280280
if (checkout_fast_forward(from, to, 1))
281281
exit(1); /* the callee should have complained already */
282-
ref_lock = lock_any_ref_for_update("HEAD", unborn ? null_sha1 : from,
283-
0, NULL);
284-
if (!ref_lock)
285-
return error(_("Failed to lock HEAD during fast_forward_to"));
286282

287283
strbuf_addf(&sb, "%s: fast-forward", action_name(opts));
288-
ret = write_ref_sha1(ref_lock, to, sb.buf);
284+
285+
transaction = ref_transaction_begin(&err);
286+
if (!transaction ||
287+
ref_transaction_update(transaction, "HEAD",
288+
to, unborn ? null_sha1 : from,
289+
0, 1, &err) ||
290+
ref_transaction_commit(transaction, sb.buf, &err)) {
291+
ref_transaction_free(transaction);
292+
error("%s", err.buf);
293+
strbuf_release(&sb);
294+
strbuf_release(&err);
295+
return -1;
296+
}
289297

290298
strbuf_release(&sb);
291-
return ret;
299+
strbuf_release(&err);
300+
ref_transaction_free(transaction);
301+
return 0;
292302
}
293303

294304
static int do_recursive_merge(struct commit *base, struct commit *next,

0 commit comments

Comments
 (0)