Merge branch 'kn/ref-transaction-symref'

Updates to symbolic refs can now be made as a part of ref
transaction.

* kn/ref-transaction-symref:
  refs: remove `create_symref` and associated dead code
  refs: rename `refs_create_symref()` to `refs_update_symref()`
  refs: use transaction in `refs_create_symref()`
  refs: add support for transactional symref updates
  refs: move `original_update_refname` to 'refs.c'
  refs: support symrefs in 'reference-transaction' hook
  files-backend: extract out `create_symref_lock()`
  refs: accept symref values in `ref_transaction_update()`
This commit is contained in:
Junio C Hamano
2024-05-20 11:20:04 -07:00
28 changed files with 386 additions and 311 deletions

20
refs.h
View File

@@ -563,7 +563,7 @@ int refs_rename_ref(struct ref_store *refs, const char *oldref,
int refs_copy_existing_ref(struct ref_store *refs, const char *oldref,
const char *newref, const char *logmsg);
int refs_create_symref(struct ref_store *refs, const char *refname,
int refs_update_symref(struct ref_store *refs, const char *refname,
const char *target, const char *logmsg);
enum action_on_err {
@@ -603,6 +603,16 @@ struct ref_transaction *ref_store_transaction_begin(struct ref_store *refs,
* before the update. A copy of this value is made in the
* transaction.
*
* new_target -- the target reference that the reference will be
* updated to point to. If the reference is a regular reference,
* it will be converted to a symbolic reference. Cannot be set
* together with `new_oid`. A copy of this value is made in the
* transaction.
*
* old_target -- the reference that the reference must be pointing to.
* Canont be set together with `old_oid`. A copy of this value is
* made in the transaction.
*
* flags -- flags affecting the update, passed to
* update_ref_lock(). Possible flags: REF_NO_DEREF,
* REF_FORCE_CREATE_REFLOG. See those constants for more
@@ -668,7 +678,11 @@ struct ref_transaction *ref_store_transaction_begin(struct ref_store *refs,
* beforehand. The old value is checked after the lock is taken to
* prevent races. If the old value doesn't agree with old_oid, the
* whole transaction fails. If old_oid is NULL, then the previous
* value is not checked.
* value is not checked. If `old_target` is not NULL, treat the reference
* as a symbolic ref and validate that its target before the update is
* `old_target`. If the `new_target` is not NULL, then the reference
* will be updated to a symbolic ref which targets `new_target`.
* Together, these allow us to update between regular refs and symrefs.
*
* See the above comment "Reference transaction updates" for more
* information.
@@ -677,6 +691,8 @@ int ref_transaction_update(struct ref_transaction *transaction,
const char *refname,
const struct object_id *new_oid,
const struct object_id *old_oid,
const char *new_target,
const char *old_target,
unsigned int flags, const char *msg,
struct strbuf *err);