Write pseudorefs through ref backends.

Pseudorefs store transient data in in the repository. Examples are HEAD,
CHERRY_PICK_HEAD, etc.

These refs have always been read through the ref backends, but they were written
in a one-off routine that wrote an object ID or symref directly into
.git/<pseudo_ref_name>.

This causes problems when introducing a new ref storage backend. To remedy this,
extend the ref backend implementation with a write_pseudoref_fn and
update_pseudoref_fn.

Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Han-Wen Nienhuys
2020-06-16 19:20:28 +00:00
committed by Junio C Hamano
parent 82f9fa0d74
commit d05c8e45f1
5 changed files with 184 additions and 99 deletions

View File

@ -556,6 +556,21 @@ typedef int copy_ref_fn(struct ref_store *ref_store,
const char *oldref, const char *newref,
const char *logmsg);
typedef int write_pseudoref_fn(struct ref_store *ref_store,
const char *pseudoref,
const struct object_id *oid,
const struct object_id *old_oid,
struct strbuf *err);
/*
* Deletes a pseudoref. Deletion always succeeds (even if the pseudoref doesn't
* exist.), except if old_oid is specified. If it is, it can fail due to lock
* failure, failure reading the old OID, or an OID mismatch
*/
typedef int delete_pseudoref_fn(struct ref_store *ref_store,
const char *pseudoref,
const struct object_id *old_oid);
/*
* Iterate over the references in `ref_store` whose names start with
* `prefix`. `prefix` is matched as a literal string, without regard
@ -655,6 +670,9 @@ struct ref_storage_be {
rename_ref_fn *rename_ref;
copy_ref_fn *copy_ref;
write_pseudoref_fn *write_pseudoref;
delete_pseudoref_fn *delete_pseudoref;
ref_iterator_begin_fn *iterator_begin;
read_raw_ref_fn *read_raw_ref;