refs API: make resolve_ref_unsafe() not set errno
Change the resolve_ref_unsafe() wrapper function to use the underlying
refs_werrres_ref_unsafe() directly.
From a reading of the callers I determined that the only one who cared
about errno was a sequencer.c caller added in e47c6cafcb
(commit:
move print_commit_summary() to libgit, 2017-11-24), I'm migrating it
to using refs_werrres_ref_unsafe() directly.
This adds another "set errno" instance, but in this case it's OK and
idiomatic. We are setting it just before calling die_errno(). We could
have some hypothetical die_errno_var(&saved_errno, ...) here, but I
don't think it's worth it. The problem with errno is subtle action at
distance, not this sort of thing. We already use this pattern in a
couple of places in wrapper.c
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
1e3ccb552f
commit
ed90f04155
6
refs.c
6
refs.c
@ -1785,8 +1785,10 @@ int refs_init_db(struct strbuf *err)
|
|||||||
const char *resolve_ref_unsafe(const char *refname, int resolve_flags,
|
const char *resolve_ref_unsafe(const char *refname, int resolve_flags,
|
||||||
struct object_id *oid, int *flags)
|
struct object_id *oid, int *flags)
|
||||||
{
|
{
|
||||||
return refs_resolve_ref_unsafe(get_main_ref_store(the_repository), refname,
|
int ignore_errno;
|
||||||
resolve_flags, oid, flags);
|
|
||||||
|
return refs_werrres_ref_unsafe(get_main_ref_store(the_repository), refname,
|
||||||
|
resolve_flags, oid, flags, &ignore_errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
int resolve_gitlink_ref(const char *submodule, const char *refname,
|
int resolve_gitlink_ref(const char *submodule, const char *refname,
|
||||||
|
10
sequencer.c
10
sequencer.c
@ -1282,6 +1282,8 @@ void print_commit_summary(struct repository *r,
|
|||||||
struct pretty_print_context pctx = {0};
|
struct pretty_print_context pctx = {0};
|
||||||
struct strbuf author_ident = STRBUF_INIT;
|
struct strbuf author_ident = STRBUF_INIT;
|
||||||
struct strbuf committer_ident = STRBUF_INIT;
|
struct strbuf committer_ident = STRBUF_INIT;
|
||||||
|
struct ref_store *refs;
|
||||||
|
int resolve_errno;
|
||||||
|
|
||||||
commit = lookup_commit(r, oid);
|
commit = lookup_commit(r, oid);
|
||||||
if (!commit)
|
if (!commit)
|
||||||
@ -1331,9 +1333,13 @@ void print_commit_summary(struct repository *r,
|
|||||||
rev.diffopt.break_opt = 0;
|
rev.diffopt.break_opt = 0;
|
||||||
diff_setup_done(&rev.diffopt);
|
diff_setup_done(&rev.diffopt);
|
||||||
|
|
||||||
head = resolve_ref_unsafe("HEAD", 0, NULL, NULL);
|
refs = get_main_ref_store(the_repository);
|
||||||
if (!head)
|
head = refs_werrres_ref_unsafe(refs, "HEAD", 0, NULL, NULL,
|
||||||
|
&resolve_errno);
|
||||||
|
if (!head) {
|
||||||
|
errno = resolve_errno;
|
||||||
die_errno(_("unable to resolve HEAD after creating commit"));
|
die_errno(_("unable to resolve HEAD after creating commit"));
|
||||||
|
}
|
||||||
if (!strcmp(head, "HEAD"))
|
if (!strcmp(head, "HEAD"))
|
||||||
head = _("detached HEAD");
|
head = _("detached HEAD");
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user