Re: [PATCH v8 14/44] replace.c: use the ref transaction functions for updates
From: Jonathan Nieder <hidden>
Date: 2016-06-15 23:01:11
Ronnie Sahlberg wrote:
quoted hunk ↗ jump to hunk
--- a/builtin/replace.c +++ b/builtin/replace.c
[...]
quoted hunk ↗ jump to hunk
@@ -156,11 +157,12 @@ static int replace_object_sha1(const char *object_ref, else if (!force) die("replace ref '%s' already exists", ref); - lock = lock_any_ref_for_update(ref, prev, 0, NULL); - if (!lock) - die("%s: cannot lock the ref", ref); - if (write_ref_sha1(lock, repl, NULL) < 0) - die("%s: cannot update the ref", ref); + transaction = ref_transaction_begin(); + if (!transaction || + ref_transaction_update(transaction, ref, repl, prev, + 0, !is_null_sha1(prev)) || + ref_transaction_commit(transaction, NULL, &err)) + die("%s: failed to replace ref: %s", ref, err.buf);
This would write
fatal: refs/replace/09c779943364d893c190066c385e6112af421db3: failed to replace ref: Cannot lock the ref 'refs/replace/09c779943364d893c190066c385e6112af421db3'.
Perhaps something like
$ git replace foo bar
fatal: replace foo: Cannot lock the ref 'refs/replace/09c779943364d893c190066c385e6112af421db3'.
would make sense (die("replace %s: %s", object_ref, err.buf)). Plain
$ git replace foo bar
fatal: Cannot lock the ref 'refs/replace/09c779943364d893c190066c385e6112af421db3'.
also seems fine (die("%s", err.buf)).
Thanks,
Jonathan