From: Han-Wen Nienhuys <hanwen@xxxxxxxxxx> lock_ref_oid_basic() in files-backend.c is the only caller of refs_resolve_ref() that needs error information to make logic decisions. Signed-off-by: Han-Wen Nienhuys <hanwen@xxxxxxxxxx> Reviewed-by: Jonathan Tan <jonathantanmy@xxxxxxxxxx> --- refs/files-backend.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/refs/files-backend.c b/refs/files-backend.c index 8f969c8f711f..5a430aabf623 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -924,6 +924,7 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs, int mustexist = (old_oid && !is_null_oid(old_oid)); int resolve_flags = RESOLVE_REF_NO_RECURSE; int resolved; + int resolve_errno = 0; files_assert_main_repository(refs, "lock_ref_oid_basic"); assert(err); @@ -936,10 +937,11 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs, resolve_flags |= RESOLVE_REF_ALLOW_BAD_NAME; files_ref_path(refs, &ref_file, refname); - resolved = !!refs_resolve_ref_unsafe(&refs->base, - refname, resolve_flags, - &lock->old_oid, type); - if (!resolved && errno == EISDIR) { + resolved = !!refs_resolve_ref_unsafe_with_errno(&refs->base, refname, + resolve_flags, + &lock->old_oid, type, + &resolve_errno); + if (!resolved && resolve_errno == EISDIR) { /* * we are trying to lock foo but we used to * have foo/bar which now does not exist; @@ -959,12 +961,11 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs, &lock->old_oid, type); } if (!resolved) { - int last_errno = errno; - if (last_errno != ENOTDIR || - !refs_verify_refname_available(&refs->base, refname, - extras, skip, err)) + if (resolve_errno != ENOTDIR || + !refs_verify_refname_available(&refs->base, refname, extras, + skip, err)) strbuf_addf(err, "unable to resolve reference '%s': %s", - refname, strerror(last_errno)); + refname, strerror(resolve_errno)); goto error_return; } -- gitgitgadget