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(...)