| 2103 | } |
| 2104 | |
| 2105 | const char *refs_resolve_ref_unsafe(struct ref_store *refs, |
| 2106 | const char *refname, |
| 2107 | int resolve_flags, |
| 2108 | struct object_id *oid, |
| 2109 | int *flags) |
| 2110 | { |
| 2111 | static struct strbuf sb_refname = STRBUF_INIT; |
| 2112 | struct object_id unused_oid; |
| 2113 | int unused_flags; |
| 2114 | int symref_count; |
| 2115 | |
| 2116 | if (!oid) |
| 2117 | oid = &unused_oid; |
| 2118 | if (!flags) |
| 2119 | flags = &unused_flags; |
| 2120 | |
| 2121 | *flags = 0; |
| 2122 | |
| 2123 | if (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL)) { |
| 2124 | if (!(resolve_flags & RESOLVE_REF_ALLOW_BAD_NAME) || |
| 2125 | !refname_is_safe(refname)) |
| 2126 | return NULL; |
| 2127 | |
| 2128 | /* |
| 2129 | * repo_dwim_ref() uses REF_ISBROKEN to distinguish between |
| 2130 | * missing refs and refs that were present but invalid, |
| 2131 | * to complain about the latter to stderr. |
| 2132 | * |
| 2133 | * We don't know whether the ref exists, so don't set |
| 2134 | * REF_ISBROKEN yet. |
| 2135 | */ |
| 2136 | *flags |= REF_BAD_NAME; |
| 2137 | } |
| 2138 | |
| 2139 | for (symref_count = 0; symref_count < SYMREF_MAXDEPTH; symref_count++) { |
| 2140 | unsigned int read_flags = 0; |
| 2141 | int failure_errno; |
| 2142 | |
| 2143 | if (refs_read_raw_ref(refs, refname, oid, &sb_refname, |
| 2144 | &read_flags, &failure_errno)) { |
| 2145 | *flags |= read_flags; |
| 2146 | |
| 2147 | /* In reading mode, refs must eventually resolve */ |
| 2148 | if (resolve_flags & RESOLVE_REF_READING) |
| 2149 | return NULL; |
| 2150 | |
| 2151 | /* |
| 2152 | * Otherwise a missing ref is OK. But the files backend |
| 2153 | * may show errors besides ENOENT if there are |
| 2154 | * similarly-named refs. |
| 2155 | */ |
| 2156 | if (failure_errno != ENOENT && |
| 2157 | failure_errno != EISDIR && |
| 2158 | failure_errno != ENOTDIR) |
| 2159 | return NULL; |
| 2160 | |
| 2161 | oidclr(oid, refs->repo->hash_algo); |
| 2162 | if (*flags & REF_BAD_NAME) |