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>
Ronnie Sahlberg committed
Apr 16, 2014 at 15:37 UTC
d668d16ca7f6c31ee60cb4cc061dd1b62ea658de
1 file changed
+18
-8
sequencer.c
+18
-8
@@ -272,23 +272,33 @@ static int error_dirty_index(struct replay_opts *opts)
272
static int fast_forward_to(const unsigned char *to, const unsigned char *from,
273
int unborn, struct replay_opts *opts)
274
{
275
- struct ref_lock *ref_lock;
275
+ struct ref_transaction *transaction;
276
struct strbuf sb = STRBUF_INIT;
277
- int ret;
277
+ struct strbuf err = STRBUF_INIT;
278
279
read_cache();
280
if (checkout_fast_forward(from, to, 1))
281
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"));
282
283
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
+ }
297
298
strbuf_release(&sb);
291
- return ret;
299
+ strbuf_release(&err);
300
+ ref_transaction_free(transaction);
301
+ return 0;
302
}
303
304
static int do_recursive_merge(struct commit *base, struct commit *next,