resolve_ref_recursively(): new function

Add a new function, resolve_ref_recursively(), which is basically like
the old resolve_ref_unsafe() except that it takes a (ref_store *)
argument and also works for submodules.

Re-implement resolve_ref_unsafe() as a thin wrapper around
resolve_ref_recursively().

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Michael Haggerty 2016-09-04 18:08:21 +02:00 committed by Junio C Hamano
parent 34c7ad8ffc
commit bd40dcda27

12
refs.c
View File

@ -1216,13 +1216,14 @@ int for_each_rawref(each_ref_fn fn, void *cb_data)
}
/* This function needs to return a meaningful errno on failure */
const char *resolve_ref_unsafe(const char *refname, int resolve_flags,
static const char *resolve_ref_recursively(struct ref_store *refs,
const char *refname,
int resolve_flags,
unsigned char *sha1, int *flags)
{
static struct strbuf sb_refname = STRBUF_INIT;
int unused_flags;
int symref_count;
struct ref_store *refs = get_ref_store(NULL);
if (!flags)
flags = &unused_flags;
@ -1291,6 +1292,13 @@ const char *resolve_ref_unsafe(const char *refname, int resolve_flags,
return NULL;
}
const char *resolve_ref_unsafe(const char *refname, int resolve_flags,
unsigned char *sha1, int *flags)
{
return resolve_ref_recursively(get_ref_store(NULL), refname,
resolve_flags, sha1, flags);
}
/* A pointer to the ref_store for the main repository: */
static struct ref_store *main_ref_store;