Re: [PATCH v6? 15/17] refs API: make resolve_ref_unsafe() not set errno
- From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
- Date
- Jul 14, 2021, 08:32 UTC
- Message-ID
- <87o8b51eea.fsf@evledraar.gmail.com>
- In-Reply-To
- <CAFQ2z_MNEb=tb+iVjE3n33Lq8tfKNKnaMOvxm6z0cwXChbuSQA@mail.gmail.com>
On Tue, Jul 13 2021, Han-Wen Nienhuys wrote:
Show 10 quoted lines
> On Sun, Jul 11, 2021 at 6:30 PM Ævar Arnfjörð Bjarmason
> <avarab@gmail.com> wrote:
>> + refs = get_main_ref_store(the_repository);
>> + head = refs_resolve_ref_unsafe_with_errno(refs, "HEAD", 0, NULL, NULL,
>> + &resolve_errno);
>> + if (!head) {
>> + errno = resolve_errno;
>
> This adds another place where we'd use global errno to communicate.
> Isn't there a die() function that takes an errno value explicitly?No, not that I know of. I suppose we could refactor fmt_with_err() in usage.c to somehow be exposed and add e.g. a:
die_saved_errno(&saved_errno, "msg %s", ....);
But I really don't see the point.
The trouble with using errno is generally introducing undesired action at a distance, here we're setting it immediately before calling die_errno(), so there's not much action or distance we should/could be worried about.
E.g. xmkstemp() in wrapper.c uses this pattern, i.e.:
errno = saved_errno;
die_errno(...)