Thread (135 messages) flat view 135 messages, 4 authors, 2021-08-23

Re: [PATCH v6? 15/17] refs API: make resolve_ref_unsafe() not set errno

From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2021-07-14 08:35:40

On Tue, Jul 13 2021, Han-Wen Nienhuys wrote:
On Sun, Jul 11, 2021 at 6:30 PM Ævar Arnfjörð Bjarmason
[off-list ref] wrote:
quoted
+       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(...)
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help