diff options
author | Han-Wen Nienhuys <hanwen@google.com> | 2021-10-16 12:39:10 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2021-10-16 21:17:02 +0300 |
commit | df3458e95710b14bff1e5acb830ad77b2a4b0c73 (patch) | |
tree | db3ba423c183ea78d014c9b116ede474b491d8ea /refs/refs-internal.h | |
parent | 8b72fea7e91b5900c3a35891df1d8ea16d4b2bee (diff) |
refs API: make parse_loose_ref_contents() not set errno
Change the parse_loose_ref_contents() function to stop setting "errno"
and failure, and to instead pass up a "failure_errno" via a
parameter. This requires changing its callers to do the same.
The EINVAL error from parse_loose_ref_contents is used in files-backend
to create a custom error message.
In untangling this we discovered a tricky edge case. The
refs_read_special_head() function was relying on
parse_loose_ref_contents() setting EINVAL.
By converting it to use "saved_errno" we can migrate away from "errno"
in this part of the code entirely, and do away with an existing
"save_errno" pattern, its only purpose was to not clobber the "errno"
we previously needed at the end of files_read_raw_ref().
Let's assert that we can do that by not having files_read_raw_ref()
itself operate on *failure_errno in addition to passing it on. Instead
we'll assert that if we return non-zero we actually do set errno, thus
assuring ourselves and callers that they can trust the resulting
"failure_errno".
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>
Diffstat (limited to 'refs/refs-internal.h')
-rw-r--r-- | refs/refs-internal.h | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/refs/refs-internal.h b/refs/refs-internal.h index c87f1135e5..121b8fdad0 100644 --- a/refs/refs-internal.h +++ b/refs/refs-internal.h @@ -706,10 +706,12 @@ struct ref_store { }; /* - * Parse contents of a loose ref file. + * Parse contents of a loose ref file. *failure_errno maybe be set to EINVAL for + * invalid contents. */ int parse_loose_ref_contents(const char *buf, struct object_id *oid, - struct strbuf *referent, unsigned int *type); + struct strbuf *referent, unsigned int *type, + int *failure_errno); /* * Fill in the generic part of refs and add it to our collection of |