Message ID | 20240330224623.579457-7-knayak@gitlab.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | update-ref: add support for update-symref option | expand |
On Sat, Mar 30, 2024 at 11:46:21PM +0100, Karthik Nayak wrote: > From: Karthik Nayak <karthik.188@gmail.com> > > Add support for transactional symbolic reference updates in the reftable > backend. > > While this commit is setting up the reftable-backend to support symrefs > in transaction's. It will only be used in a consequent commit, when we > wire up the `update-symref` option for `git-update-ref`. > > Signed-off-by: Karthik Nayak <karthik.188@gmail.com> > --- > refs/reftable-backend.c | 23 +++++++++++++++++++---- > 1 file changed, 19 insertions(+), 4 deletions(-) > > diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c > index 92f2803e90..35f2e8e050 100644 > --- a/refs/reftable-backend.c > +++ b/refs/reftable-backend.c > @@ -884,7 +884,7 @@ static int reftable_be_transaction_prepare(struct ref_store *ref_store, > new_update = ref_transaction_add_update( > transaction, "HEAD", > u->flags | REF_LOG_ONLY | REF_NO_DEREF, > - &u->new_oid, &u->old_oid, u->msg, NULL); > + &u->new_oid, &u->old_oid, u->msg, u->symref_target); > string_list_insert(&affected_refnames, new_update->refname); > } > > @@ -909,9 +909,11 @@ static int reftable_be_transaction_prepare(struct ref_store *ref_store, > > /* > * There is no need to write the reference deletion > - * when the reference in question doesn't exist. > + * when the reference in question doesn't exist except > + * when we want to create new symrefs. Nit: it's not really an exception because it's not a reference deletion in the first place when we write a symref. Patrick > */ > - if (u->flags & REF_HAVE_NEW && !is_null_oid(&u->new_oid)) { > + if ((u->flags & REF_HAVE_NEW && !is_null_oid(&u->new_oid)) || > + u->flags & REF_UPDATE_SYMREF) { > ret = queue_transaction_update(refs, tx_data, u, > ¤t_oid, err); > if (ret) > @@ -963,7 +965,7 @@ static int reftable_be_transaction_prepare(struct ref_store *ref_store, > */ > new_update = ref_transaction_add_update( > transaction, referent.buf, new_flags, > - &u->new_oid, &u->old_oid, u->msg, NULL); > + &u->new_oid, &u->old_oid, u->msg, u->symref_target); > new_update->parent_update = u; > > /* > @@ -1026,6 +1028,7 @@ static int reftable_be_transaction_prepare(struct ref_store *ref_store, > */ > if ((u->type & REF_ISSYMREF) || > (u->flags & REF_LOG_ONLY) || > + (u->flags & REF_UPDATE_SYMREF) || > (u->flags & REF_HAVE_NEW && !oideq(¤t_oid, &u->new_oid))) { > ret = queue_transaction_update(refs, tx_data, u, > ¤t_oid, err); > @@ -1187,6 +1190,18 @@ static int write_transaction_table(struct reftable_writer *writer, void *cb_data > ret = reftable_writer_add_ref(writer, &ref); > if (ret < 0) > goto done; > + } else if (u->flags & REF_UPDATE_SYMREF) { > + struct write_create_symref_arg create = { > + .refs = arg->refs, > + .stack = arg->stack, > + .refname = u->refname, > + .target = u->symref_target, > + .logmsg = u->msg, > + }; > + > + write_symref_with_log(writer, &create, ts); > + if (ret < 0) > + goto done; > } > } > > -- > 2.43.GIT >
diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c index 92f2803e90..35f2e8e050 100644 --- a/refs/reftable-backend.c +++ b/refs/reftable-backend.c @@ -884,7 +884,7 @@ static int reftable_be_transaction_prepare(struct ref_store *ref_store, new_update = ref_transaction_add_update( transaction, "HEAD", u->flags | REF_LOG_ONLY | REF_NO_DEREF, - &u->new_oid, &u->old_oid, u->msg, NULL); + &u->new_oid, &u->old_oid, u->msg, u->symref_target); string_list_insert(&affected_refnames, new_update->refname); } @@ -909,9 +909,11 @@ static int reftable_be_transaction_prepare(struct ref_store *ref_store, /* * There is no need to write the reference deletion - * when the reference in question doesn't exist. + * when the reference in question doesn't exist except + * when we want to create new symrefs. */ - if (u->flags & REF_HAVE_NEW && !is_null_oid(&u->new_oid)) { + if ((u->flags & REF_HAVE_NEW && !is_null_oid(&u->new_oid)) || + u->flags & REF_UPDATE_SYMREF) { ret = queue_transaction_update(refs, tx_data, u, ¤t_oid, err); if (ret) @@ -963,7 +965,7 @@ static int reftable_be_transaction_prepare(struct ref_store *ref_store, */ new_update = ref_transaction_add_update( transaction, referent.buf, new_flags, - &u->new_oid, &u->old_oid, u->msg, NULL); + &u->new_oid, &u->old_oid, u->msg, u->symref_target); new_update->parent_update = u; /* @@ -1026,6 +1028,7 @@ static int reftable_be_transaction_prepare(struct ref_store *ref_store, */ if ((u->type & REF_ISSYMREF) || (u->flags & REF_LOG_ONLY) || + (u->flags & REF_UPDATE_SYMREF) || (u->flags & REF_HAVE_NEW && !oideq(¤t_oid, &u->new_oid))) { ret = queue_transaction_update(refs, tx_data, u, ¤t_oid, err); @@ -1187,6 +1190,18 @@ static int write_transaction_table(struct reftable_writer *writer, void *cb_data ret = reftable_writer_add_ref(writer, &ref); if (ret < 0) goto done; + } else if (u->flags & REF_UPDATE_SYMREF) { + struct write_create_symref_arg create = { + .refs = arg->refs, + .stack = arg->stack, + .refname = u->refname, + .target = u->symref_target, + .logmsg = u->msg, + }; + + write_symref_with_log(writer, &create, ts); + if (ret < 0) + goto done; } }