MCPcopy Create free account
hub / github.com/git/git / refs_resolve_ref_unsafe

Function refs_resolve_ref_unsafe

refs.c:2105–2192  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2103}
2104
2105const 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)

Callers 15

include_by_branchFunction · 0.85
find_symrefFunction · 0.85
set_upstreamsFunction · 0.85
dwim_reverse_initialFunction · 0.85
setup_scoreboardFunction · 0.85
add_head_infoFunction · 0.85
is_shared_symrefFunction · 0.85
other_head_refsFunction · 0.85
diagnose_missing_defaultFunction · 0.85
is_index_unchangedFunction · 0.85
print_commit_summaryFunction · 0.85
apply_save_autostash_refFunction · 0.85

Calls 4

check_refname_formatFunction · 0.85
refname_is_safeFunction · 0.85
refs_read_raw_refFunction · 0.85
oidclrFunction · 0.85

Tested by 1

cmd_resolve_refFunction · 0.68