]> git.ipfire.org Git - thirdparty/git.git/commit - refs/refs-internal.h
refs API: make parse_loose_ref_contents() not set errno
authorHan-Wen Nienhuys <hanwen@google.com>
Sat, 16 Oct 2021 09:39:10 +0000 (11:39 +0200)
committerJunio C Hamano <gitster@pobox.com>
Sat, 16 Oct 2021 18:17:02 +0000 (11:17 -0700)
commitdf3458e95710b14bff1e5acb830ad77b2a4b0c73
treedb3ba423c183ea78d014c9b116ede474b491d8ea
parent8b72fea7e91b5900c3a35891df1d8ea16d4b2bee
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>
refs.c
refs/files-backend.c
refs/refs-internal.h