Skip to content

Commit ed90f04

Browse files
avargitster
authored andcommitted
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 e47c6ca (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1e3ccb5 commit ed90f04

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

refs.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1785,8 +1785,10 @@ int refs_init_db(struct strbuf *err)
17851785
const char *resolve_ref_unsafe(const char *refname, int resolve_flags,
17861786
struct object_id *oid, int *flags)
17871787
{
1788-
return refs_resolve_ref_unsafe(get_main_ref_store(the_repository), refname,
1789-
resolve_flags, oid, flags);
1788+
int ignore_errno;
1789+
1790+
return refs_werrres_ref_unsafe(get_main_ref_store(the_repository), refname,
1791+
resolve_flags, oid, flags, &ignore_errno);
17901792
}
17911793

17921794
int resolve_gitlink_ref(const char *submodule, const char *refname,

sequencer.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,6 +1282,8 @@ void print_commit_summary(struct repository *r,
12821282
struct pretty_print_context pctx = {0};
12831283
struct strbuf author_ident = STRBUF_INIT;
12841284
struct strbuf committer_ident = STRBUF_INIT;
1285+
struct ref_store *refs;
1286+
int resolve_errno;
12851287

12861288
commit = lookup_commit(r, oid);
12871289
if (!commit)
@@ -1331,9 +1333,13 @@ void print_commit_summary(struct repository *r,
13311333
rev.diffopt.break_opt = 0;
13321334
diff_setup_done(&rev.diffopt);
13331335

1334-
head = resolve_ref_unsafe("HEAD", 0, NULL, NULL);
1335-
if (!head)
1336+
refs = get_main_ref_store(the_repository);
1337+
head = refs_werrres_ref_unsafe(refs, "HEAD", 0, NULL, NULL,
1338+
&resolve_errno);
1339+
if (!head) {
1340+
errno = resolve_errno;
13361341
die_errno(_("unable to resolve HEAD after creating commit"));
1342+
}
13371343
if (!strcmp(head, "HEAD"))
13381344
head = _("detached HEAD");
13391345
else

0 commit comments

Comments
 (0)