Re: [PATCH 3/8] refs: make errno output explicit for read_raw_ref_fn
- From
- Jonathan Tan <jonathantanmy@google.com>
- Date
- Jun 3, 2021, 02:37 UTC
- Message-ID
- <20210603023709.345324-1-jonathantanmy@google.com>
- In-Reply-To
- <ebd7b8380bf7aed84d23973a4809d1441aa21692.1619710329.git.gitgitgadget@gmail.com>
Show 17 quoted lines
> From: Han-Wen Nienhuys <hanwen@google.com>
>
> 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.Looks good.
Show 17 quoted lines
> @@ -1675,13 +1675,16 @@ int refs_read_raw_ref(struct ref_store *ref_store,
> const char *refname, struct object_id *oid,
> struct strbuf *referent, unsigned int *type)
> {
> + int result, failure;
> if (!strcmp(refname, "FETCH_HEAD") || !strcmp(refname, "MERGE_HEAD")) {
> return refs_read_special_head(ref_store, refname, oid, referent,
> type);
> }
>
> - return ref_store->be->read_raw_ref(ref_store, refname, oid, referent,
> - type);
> + result = ref_store->be->read_raw_ref(ref_store, refname, oid, referent,
> + type, &failure);
> + errno = failure;
> + return result;
> }Should we initialize "failure" to 0 here? As a reader, I would assume that "failure" has the semantics of errno here, which upon success, may or may not be set.