]> git.ipfire.org Git - thirdparty/git.git/commitdiff
refs API: make refs_read_raw_ref() not set errno
authorHan-Wen Nienhuys <hanwen@google.com>
Sat, 16 Oct 2021 09:39:09 +0000 (11:39 +0200)
committerJunio C Hamano <gitster@pobox.com>
Sat, 16 Oct 2021 18:17:02 +0000 (11:17 -0700)
Add a "failure_errno" to refs_read_raw_ref(), his allows
refs_werrres_ref_unsafe() to pass along its "failure_errno", as a
first step before its own callers are migrated to pass it further up
the chain.

We are leaving out out the refs_read_special_head() in
refs_read_raw_ref() for now, as noted in a subsequent commit moving it
to "failure_errno" will require some special consideration.

Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
refs.c
refs/files-backend.c
refs/packed-backend.c
refs/refs-internal.h

diff --git a/refs.c b/refs.c
index ad56dbb0125d753332615626f263279ed659c580..200c44e696375a7d337b839ede6518196007e1b9 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -1666,17 +1666,18 @@ done:
        return result;
 }
 
-int refs_read_raw_ref(struct ref_store *ref_store,
-                     const char *refname, struct object_id *oid,
-                     struct strbuf *referent, unsigned int *type)
+int refs_read_raw_ref(struct ref_store *ref_store, const char *refname,
+                     struct object_id *oid, struct strbuf *referent,
+                     unsigned int *type, int *failure_errno)
 {
+       assert(failure_errno);
        if (!strcmp(refname, "FETCH_HEAD") || !strcmp(refname, "MERGE_HEAD")) {
                return refs_read_special_head(ref_store, refname, oid, referent,
                                              type);
        }
 
        return ref_store->be->read_raw_ref(ref_store, refname, oid, referent,
-                                          type, &errno);
+                                          type, failure_errno);
 }
 
 const char *refs_werrres_ref_unsafe(struct ref_store *refs,
@@ -1720,9 +1721,8 @@ const char *refs_werrres_ref_unsafe(struct ref_store *refs,
        for (symref_count = 0; symref_count < SYMREF_MAXDEPTH; symref_count++) {
                unsigned int read_flags = 0;
 
-               errno = 0;
-               if (refs_read_raw_ref(refs, refname,
-                                     oid, &sb_refname, &read_flags)) {
+               if (refs_read_raw_ref(refs, refname, oid, &sb_refname,
+                                     &read_flags, failure_errno)) {
                        *flags |= read_flags;
                        if (errno)
                                *failure_errno = errno;
@@ -2240,6 +2240,13 @@ int refs_verify_refname_available(struct ref_store *refs,
 
        strbuf_grow(&dirname, strlen(refname) + 1);
        for (slash = strchr(refname, '/'); slash; slash = strchr(slash + 1, '/')) {
+               /*
+                * Just saying "Is a directory" when we e.g. can't
+                * lock some multi-level ref isn't very informative,
+                * the user won't be told *what* is a directory, so
+                * let's not use strerror() below.
+                */
+               int ignore_errno;
                /* Expand dirname to the new prefix, not including the trailing slash: */
                strbuf_add(&dirname, refname + dirname.len, slash - refname - dirname.len);
 
@@ -2251,7 +2258,8 @@ int refs_verify_refname_available(struct ref_store *refs,
                if (skip && string_list_has_string(skip, dirname.buf))
                        continue;
 
-               if (!refs_read_raw_ref(refs, dirname.buf, &oid, &referent, &type)) {
+               if (!refs_read_raw_ref(refs, dirname.buf, &oid, &referent,
+                                      &type, &ignore_errno)) {
                        strbuf_addf(err, _("'%s' exists; cannot create '%s'"),
                                    dirname.buf, refname);
                        goto cleanup;
index 6a6ead0b99bbd8b0326081516e3b6cac45366012..94c194665ed98fa11de77586dc5d8bdf0819461f 100644 (file)
@@ -381,10 +381,11 @@ stat_ref:
                goto out;
 
        if (lstat(path, &st) < 0) {
+               int ignore_errno;
                if (errno != ENOENT)
                        goto out;
-               if (refs_read_raw_ref(refs->packed_ref_store, refname,
-                                     oid, referent, type)) {
+               if (refs_read_raw_ref(refs->packed_ref_store, refname, oid,
+                                     referent, type, &ignore_errno)) {
                        errno = ENOENT;
                        goto out;
                }
@@ -418,13 +419,14 @@ stat_ref:
 
        /* Is it a directory? */
        if (S_ISDIR(st.st_mode)) {
+               int ignore_errno;
                /*
                 * Even though there is a directory where the loose
                 * ref is supposed to be, there could still be a
                 * packed ref:
                 */
-               if (refs_read_raw_ref(refs->packed_ref_store, refname,
-                                     oid, referent, type)) {
+               if (refs_read_raw_ref(refs->packed_ref_store, refname, oid,
+                                     referent, type, &ignore_errno)) {
                        errno = EISDIR;
                        goto out;
                }
index 47247a149178f364423f84572c5b2912772d10be..52cdc94a26e2cf296131a96011c6e35212be50e6 100644 (file)
@@ -1347,6 +1347,7 @@ int is_packed_transaction_needed(struct ref_store *ref_store,
        ret = 0;
        for (i = 0; i < transaction->nr; i++) {
                struct ref_update *update = transaction->updates[i];
+               int failure_errno;
                unsigned int type;
                struct object_id oid;
 
@@ -1357,9 +1358,9 @@ int is_packed_transaction_needed(struct ref_store *ref_store,
                         */
                        continue;
 
-               if (!refs_read_raw_ref(ref_store, update->refname,
-                                      &oid, &referent, &type) ||
-                   errno != ENOENT) {
+               if (!refs_read_raw_ref(ref_store, update->refname, &oid,
+                                      &referent, &type, &failure_errno) ||
+                   failure_errno != ENOENT) {
                        /*
                         * We have to actually delete that reference
                         * -> this transaction is needed.
index 72746407fc3dd4df57d17894967cece6804bf0d5..c87f1135e5b6630c5e14b531e811fb221b0f9288 100644 (file)
@@ -149,9 +149,9 @@ struct ref_update {
        const char refname[FLEX_ARRAY];
 };
 
-int refs_read_raw_ref(struct ref_store *ref_store,
-                     const char *refname, struct object_id *oid,
-                     struct strbuf *referent, unsigned int *type);
+int refs_read_raw_ref(struct ref_store *ref_store, const char *refname,
+                     struct object_id *oid, struct strbuf *referent,
+                     unsigned int *type, int *failure_errno);
 
 /*
  * Write an error to `err` and return a nonzero value iff the same