refs: make errno output explicit for read_raw_ref_fn
This makes it explicit how alternative ref backends should report errors in read_raw_ref_fn. read_raw_ref_fn needs to supply a credible errno for a number of cases. These are primarily: 1) The files backend calls read_raw_ref from lock_raw_ref, and uses the resulting error codes to create/remove directories as needed. 2) ENOENT should be translated in a zero OID, optionally with REF_ISBROKEN set, returning the last successfully resolved symref. This is necessary so read_raw_ref("HEAD") on an empty repo returns refs/heads/main (or the default branch du-jour), and we know on which branch to create the first commit. Make this information flow explicit by adding a failure_errno to the signature of read_raw_ref. All errnos from the files backend are still propagated unchanged, even though inspection suggests only ENOTDIR, EISDIR and ENOENT are relevant. Signed-off-by: Han-Wen Nienhuys <hanwen@google.com> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
1ae6ed230a
commit
5b12e16bb1
@ -620,11 +620,15 @@ typedef int reflog_expire_fn(struct ref_store *ref_store,
|
||||
* properly-formatted or even safe reference name. NEITHER INPUT NOR
|
||||
* OUTPUT REFERENCE NAMES ARE VALIDATED WITHIN THIS FUNCTION.
|
||||
*
|
||||
* Return 0 on success. If the ref doesn't exist, set errno to ENOENT
|
||||
* and return -1. If the ref exists but is neither a symbolic ref nor
|
||||
* an object ID, it is broken; set REF_ISBROKEN in type, and return -1
|
||||
* (errno should not be ENOENT) If there is another error reading the
|
||||
* ref, set errno appropriately and return -1.
|
||||
* Return 0 on success, or -1 on failure. If the ref exists but is neither a
|
||||
* symbolic ref nor an object ID, it is broken. In this case set REF_ISBROKEN in
|
||||
* type, and return -1 (failure_errno should not be ENOENT)
|
||||
*
|
||||
* failure_errno provides errno codes that are interpreted beyond error
|
||||
* reporting. The following error codes have special meaning:
|
||||
* * ENOENT: the ref doesn't exist
|
||||
* * EISDIR: ref name is a directory
|
||||
* * ENOTDIR: ref prefix is not a directory
|
||||
*
|
||||
* Backend-specific flags might be set in type as well, regardless of
|
||||
* outcome.
|
||||
@ -638,9 +642,9 @@ typedef int reflog_expire_fn(struct ref_store *ref_store,
|
||||
* - in all other cases, referent will be untouched, and therefore
|
||||
* refname will still be valid and unchanged.
|
||||
*/
|
||||
typedef int read_raw_ref_fn(struct ref_store *ref_store,
|
||||
const char *refname, struct object_id *oid,
|
||||
struct strbuf *referent, unsigned int *type);
|
||||
typedef int read_raw_ref_fn(struct ref_store *ref_store, const char *refname,
|
||||
struct object_id *oid, struct strbuf *referent,
|
||||
unsigned int *type, int *failure_errno);
|
||||
|
||||
struct ref_storage_be {
|
||||
struct ref_storage_be *next;
|
||||
|
Reference in New Issue
Block a user