refs: add support for transactional symref updates

The reference backends currently support transactional reference
updates. While this is exposed to users via 'git-update-ref' and its
'--stdin' mode, it is also used internally within various commands.

However, we do not support transactional updates of symrefs. This commit
adds support for symrefs in both the 'files' and the 'reftable' backend.

Here, we add and use `ref_update_has_null_new_value()`, a helper
function which is used to check if there is a new_value in a reference
update. The new value could either be a symref target `new_target` or a
OID `new_oid`.

We also add another common function `ref_update_check_old_target` which
will be used to check if the update's old_target corresponds to a
reference's current target.

Now transactional updates (verify, create, delete, update) can be used
for:
- regular refs
- symbolic refs
- conversion of regular to symbolic refs and vice versa

This also allows us to expose this to users via new commands in
'git-update-ref' in the future.

Note that a dangling symref update does not record a new reflog entry,
which is unchanged before and after this commit.

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:56 +02:00
committed by Junio C Hamano
parent e9965ba477
commit 644daf7785
4 changed files with 196 additions and 39 deletions

View File

@@ -754,4 +754,20 @@ struct ref_store *maybe_debug_wrap_ref_store(const char *gitdir, struct ref_stor
*/
const char *ref_update_original_update_refname(struct ref_update *update);
/*
* Helper function to check if the new value is null, this
* takes into consideration that the update could be a regular
* ref or a symbolic ref.
*/
int ref_update_has_null_new_value(struct ref_update *update);
/*
* Check whether the old_target values stored in update are consistent
* with the referent, which is the symbolic reference's current value.
* If everything is OK, return 0; otherwise, write an error message to
* err and return -1.
*/
int ref_update_check_old_target(const char *referent, struct ref_update *update,
struct strbuf *err);
#endif /* REFS_REFS_INTERNAL_H */