refs: standardize output of refs_read_symbolic_ref

When the symbolic reference we want to read with refs_read_symbolic_ref
is actually not a symbolic reference, the files and the reftable
backends return different values (1 and -1 respectively). Standardize
the returned values so that 0 is success, -1 is a generic error and -2
is that the reference was actually non-symbolic.

Signed-off-by: Bence Ferdinandy <bence@ferdinandy.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Bence Ferdinandy
2024-11-22 13:28:44 +01:00
committed by Junio C Hamano
parent 2fd5555895
commit 8102d10ff8
4 changed files with 23 additions and 6 deletions

11
refs.h
View File

@@ -83,6 +83,17 @@ int refs_read_ref_full(struct ref_store *refs, const char *refname,
int refs_read_ref(struct ref_store *refs, const char *refname, struct object_id *oid);
#define NOT_A_SYMREF -2
/*
* Read the symbolic ref named "refname" and write its immediate referent into
* the provided buffer. Referent is left empty if "refname" is not a symbolic
* ref. It does not resolve the symbolic reference recursively in case the
* target is also a symbolic ref.
*
* Returns 0 on success, -2 if the "refname" is not a symbolic ref,
* -1 otherwise.
*/
int refs_read_symbolic_ref(struct ref_store *ref_store, const char *refname,
struct strbuf *referent);