Remove public users of refs_resolve_ref_unsafe() over to refs_resolve_ref_unsafe_with_errno(), and explicitly ignore the provided errno in those callers. At that point the only remaining users are the legacy functions in refs.c itself, so we can make the wrapper static. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@xxxxxxxxx> --- refs.c | 29 +++++++++++++++-------------- refs.h | 8 +------- refs/files-backend.c | 24 ++++++++++++++---------- t/helper/test-ref-store.c | 5 +++-- worktree.c | 18 ++++++++++++------ 5 files changed, 45 insertions(+), 39 deletions(-) diff --git a/refs.c b/refs.c index 7a9cdb1d720..214f3f4f79f 100644 --- a/refs.c +++ b/refs.c @@ -267,6 +267,21 @@ int ref_resolves_to_object(const char *refname, return 1; } +static const char *refs_resolve_ref_unsafe(struct ref_store *refs, + const char *refname, + int resolve_flags, + struct object_id *oid, int *flags) +{ + int failure_errno = 0; + const char *refn; + refn = refs_resolve_ref_unsafe_with_errno(refs, refname, resolve_flags, + oid, flags, &failure_errno); + if (!refn) + /* For unmigrated legacy callers */ + errno = failure_errno; + return refn; +} + char *refs_resolve_refdup(struct ref_store *refs, const char *refname, int resolve_flags, struct object_id *oid, int *flags) @@ -1780,20 +1795,6 @@ const char *refs_resolve_ref_unsafe_with_errno(struct ref_store *refs, return NULL; } -const char *refs_resolve_ref_unsafe(struct ref_store *refs, const char *refname, - int resolve_flags, struct object_id *oid, - int *flags) -{ - int failure_errno = 0; - const char *refn; - refn = refs_resolve_ref_unsafe_with_errno(refs, refname, resolve_flags, - oid, flags, &failure_errno); - if (!refn) - /* For unmigrated legacy callers */ - errno = failure_errno; - return refn; -} - /* backend functions */ int refs_init_db(struct strbuf *err) { diff --git a/refs.h b/refs.h index d80184dd8e0..a3284adb8f8 100644 --- a/refs.h +++ b/refs.h @@ -63,14 +63,8 @@ struct worktree; #define RESOLVE_REF_NO_RECURSE 0x02 #define RESOLVE_REF_ALLOW_BAD_NAME 0x04 -const char *refs_resolve_ref_unsafe(struct ref_store *refs, - const char *refname, - int resolve_flags, - struct object_id *oid, - int *flags); /** - * refs_resolve_ref_unsafe_with_errno() is like - * refs_resolve_ref_unsafe(), but provide access to errno code that + * refs_resolve_ref_unsafe_with_errno() provides access to errno code that * lead to a failure. We guarantee that errno is set to a meaningful * value on non-zero return. */ diff --git a/refs/files-backend.c b/refs/files-backend.c index b3bc2f57387..158c0146484 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -280,10 +280,11 @@ static void loose_fill_ref_dir(struct ref_store *ref_store, create_dir_entry(dir->cache, refname.buf, refname.len, 1)); } else { - if (!refs_resolve_ref_unsafe(&refs->base, - refname.buf, - RESOLVE_REF_READING, - &oid, &flag)) { + int ignore_errno; + if (!refs_resolve_ref_unsafe_with_errno(&refs->base, + refname.buf, + RESOLVE_REF_READING, + &oid, &flag, &ignore_errno)) { oidclr(&oid); flag |= REF_ISBROKEN; } else if (is_null_oid(&oid)) { @@ -1354,9 +1355,9 @@ static int files_copy_or_rename_ref(struct ref_store *ref_store, goto out; } - if (!refs_resolve_ref_unsafe(&refs->base, oldrefname, - RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE, - &orig_oid, &flag)) { + if (!refs_resolve_ref_unsafe_with_errno(&refs->base, oldrefname, + RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE, + &orig_oid, &flag, &ignore_errno)) { ret = error("refname %s not found", oldrefname); goto out; } @@ -1769,10 +1770,13 @@ static int commit_ref_update(struct files_ref_store *refs, */ int head_flag; const char *head_ref; + int ignore_errno; - head_ref = refs_resolve_ref_unsafe(&refs->base, "HEAD", - RESOLVE_REF_READING, - NULL, &head_flag); + head_ref = refs_resolve_ref_unsafe_with_errno(&refs->base, + "HEAD", + RESOLVE_REF_READING, + NULL, &head_flag, + &ignore_errno); if (head_ref && (head_flag & REF_ISSYMREF) && !strcmp(head_ref, lock->ref_name)) { struct strbuf log_err = STRBUF_INIT; diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c index bba5f841c6a..ca69a793171 100644 --- a/t/helper/test-ref-store.c +++ b/t/helper/test-ref-store.c @@ -123,9 +123,10 @@ static int cmd_resolve_ref(struct ref_store *refs, const char **argv) int resolve_flags = arg_flags(*argv++, "resolve-flags"); int flags; const char *ref; + int ignore_errno; - ref = refs_resolve_ref_unsafe(refs, refname, resolve_flags, - &oid, &flags); + ref = refs_resolve_ref_unsafe_with_errno(refs, refname, resolve_flags, + &oid, &flags, &ignore_errno); printf("%s %s 0x%x\n", oid_to_hex(&oid), ref ? ref : "(null)", flags); return ref ? 0 : 1; } diff --git a/worktree.c b/worktree.c index 1dcdb481d61..1dbdec82461 100644 --- a/worktree.c +++ b/worktree.c @@ -28,11 +28,13 @@ static void add_head_info(struct worktree *wt) { int flags; const char *target; + int ignore_errno; - target = refs_resolve_ref_unsafe(get_worktree_ref_store(wt), - "HEAD", - 0, - &wt->head_oid, &flags); + target = refs_resolve_ref_unsafe_with_errno(get_worktree_ref_store(wt), + "HEAD", + 0, + &wt->head_oid, &flags, + &ignore_errno); if (!target) return; @@ -417,6 +419,7 @@ const struct worktree *find_shared_symref(const char *symref, const char *symref_target; struct ref_store *refs; int flags; + int ignore_errno; if (wt->is_bare) continue; @@ -433,8 +436,11 @@ const struct worktree *find_shared_symref(const char *symref, } refs = get_worktree_ref_store(wt); - symref_target = refs_resolve_ref_unsafe(refs, symref, 0, - NULL, &flags); + symref_target = refs_resolve_ref_unsafe_with_errno(refs, + symref, + 0, NULL, + &flags, + &ignore_errno); if ((flags & REF_ISSYMREF) && symref_target && !strcmp(symref_target, target)) { existing = wt; -- 2.32.0-dev