Re: [PATCH v5 3/6] refs: make errno output explicit for read_raw_ref_fn
From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2021-07-11 11:53:29
Subsystem:
the rest · Maintainer:
Linus Torvalds
On Wed, Jul 07 2021, Han-Wen Nienhuys via GitGitGadget wrote:
quoted hunk ↗ jump to hunk
diff --git a/refs.c b/refs.c index 8c9490235ea..5e5e3af8da0 100644 --- a/refs.c +++ b/refs.c@@ -1675,13 +1675,19 @@ 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; + int failure_errno; 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); + failure_errno = 0; + result = ref_store->be->read_raw_ref(ref_store, refname, oid, referent, + type, &failure_errno); + if (failure_errno) + errno = failure_errno; + return result; }
Just reading along again in sequence, and having forgotten where (if anywhere) this was headed I still find this verbose pattern for /looking like/ we'll be doing something that's not setting errno, but actually just setting errno. I.e. the logic is the same as the below squash, but let's read on...
diff --git a/refs.c b/refs.c
index 5e5e3af8da0..7b3f05a66ff 100644
--- a/refs.c
+++ b/refs.c@@ -1675,19 +1675,13 @@ 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; - int failure_errno; if (!strcmp(refname, "FETCH_HEAD") || !strcmp(refname, "MERGE_HEAD")) { return refs_read_special_head(ref_store, refname, oid, referent, type); } - failure_errno = 0; - result = ref_store->be->read_raw_ref(ref_store, refname, oid, referent, - type, &failure_errno); - if (failure_errno) - errno = failure_errno; - return result; + return ref_store->be->read_raw_ref(ref_store, refname, oid, referent, + type, &errno); } /* This function needs to return a meaningful errno on failure */