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:
committed by
Junio C Hamano
parent
2fd5555895
commit
8102d10ff8
11
refs.h
11
refs.h
@@ -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);
|
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,
|
int refs_read_symbolic_ref(struct ref_store *ref_store, const char *refname,
|
||||||
struct strbuf *referent);
|
struct strbuf *referent);
|
||||||
|
|
||||||
|
|||||||
@@ -596,10 +596,9 @@ static int files_read_symbolic_ref(struct ref_store *ref_store, const char *refn
|
|||||||
unsigned int type;
|
unsigned int type;
|
||||||
|
|
||||||
ret = read_ref_internal(ref_store, refname, &oid, referent, &type, &failure_errno, 1);
|
ret = read_ref_internal(ref_store, refname, &oid, referent, &type, &failure_errno, 1);
|
||||||
if (ret)
|
if (!ret && !(type & REF_ISSYMREF))
|
||||||
return ret;
|
return NOT_A_SYMREF;
|
||||||
|
return ret;
|
||||||
return !(type & REF_ISSYMREF);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int parse_loose_ref_contents(const struct git_hash_algo *algop,
|
int parse_loose_ref_contents(const struct git_hash_algo *algop,
|
||||||
|
|||||||
@@ -673,6 +673,11 @@ struct ref_storage_be {
|
|||||||
|
|
||||||
ref_iterator_begin_fn *iterator_begin;
|
ref_iterator_begin_fn *iterator_begin;
|
||||||
read_raw_ref_fn *read_raw_ref;
|
read_raw_ref_fn *read_raw_ref;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Please refer to `refs_read_symbolic_ref()` for the expected
|
||||||
|
* behaviour.
|
||||||
|
*/
|
||||||
read_symbolic_ref_fn *read_symbolic_ref;
|
read_symbolic_ref_fn *read_symbolic_ref;
|
||||||
|
|
||||||
reflog_iterator_begin_fn *reflog_iterator_begin;
|
reflog_iterator_begin_fn *reflog_iterator_begin;
|
||||||
|
|||||||
@@ -830,10 +830,12 @@ static int reftable_be_read_symbolic_ref(struct ref_store *ref_store,
|
|||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
ret = reftable_stack_read_ref(stack, refname, &ref);
|
ret = reftable_stack_read_ref(stack, refname, &ref);
|
||||||
if (ret == 0 && ref.value_type == REFTABLE_REF_SYMREF)
|
if (ret)
|
||||||
|
ret = -1;
|
||||||
|
else if (ref.value_type == REFTABLE_REF_SYMREF)
|
||||||
strbuf_addstr(referent, ref.value.symref);
|
strbuf_addstr(referent, ref.value.symref);
|
||||||
else
|
else
|
||||||
ret = -1;
|
ret = NOT_A_SYMREF;
|
||||||
|
|
||||||
reftable_ref_record_release(&ref);
|
reftable_ref_record_release(&ref);
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
Reference in New Issue
Block a user