refs: use transaction in refs_create_symref()

The `refs_create_symref()` function updates a symref to a given new
target. To do this, it uses a ref-backend specific function
`create_symref()`.

In the previous commits, we introduced symref support in transactions.
This means we can now use transactions to perform symref updates and
don't have to resort to `create_symref()`. Doing this allows us to
remove and cleanup `create_symref()`, which we will do in the following
commit.

Modify the expected error message for a test in
't/t0610-reftable-basics.sh', since the error is now thrown from
'refs.c'. This is because in transactional updates, F/D conflicts are
caught before we're in the reference backend.

Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Karthik Nayak
2024-05-07 14:58:57 +02:00
committed by Junio C Hamano
parent 644daf7785
commit 300b38e46f
3 changed files with 41 additions and 8 deletions

24
refs.c
View File

@ -2289,14 +2289,24 @@ int refs_create_symref(struct ref_store *refs,
const char *refs_heads_master,
const char *logmsg)
{
char *msg;
int retval;
struct ref_transaction *transaction;
struct strbuf err = STRBUF_INIT;
int ret = 0;
msg = normalize_reflog_message(logmsg);
retval = refs->be->create_symref(refs, ref_target, refs_heads_master,
msg);
free(msg);
return retval;
transaction = ref_store_transaction_begin(refs, &err);
if (!transaction ||
ref_transaction_update(transaction, ref_target, NULL, NULL,
refs_heads_master, NULL, REF_NO_DEREF,
logmsg, &err) ||
ref_transaction_commit(transaction, &err)) {
ret = error("%s", err.buf);
}
strbuf_release(&err);
if (transaction)
ref_transaction_free(transaction);
return ret;
}
int create_symref(const char *ref_target, const char *refs_heads_master,