create_ref_entry(): extract function from add_ref()
Separate the creation of the ref_entry from its addition to a ref_array. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
fe9c7b78c5
commit
cddc42587c
37
refs.c
37
refs.c
@ -53,28 +53,35 @@ static const char *parse_ref_line(char *line, unsigned char *sha1)
|
|||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add a ref_entry to the end of the ref_array (unsorted). */
|
static struct ref_entry *create_ref_entry(const char *refname,
|
||||||
static void add_ref(const char *refname, const unsigned char *sha1,
|
const unsigned char *sha1, int flag,
|
||||||
int flag, int check_name, struct ref_array *refs,
|
int check_name)
|
||||||
struct ref_entry **new_entry)
|
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
struct ref_entry *entry;
|
struct ref_entry *ref;
|
||||||
|
|
||||||
/* Allocate it and add it in.. */
|
|
||||||
len = strlen(refname) + 1;
|
|
||||||
entry = xmalloc(sizeof(struct ref_entry) + len);
|
|
||||||
hashcpy(entry->sha1, sha1);
|
|
||||||
hashclr(entry->peeled);
|
|
||||||
if (check_name &&
|
if (check_name &&
|
||||||
check_refname_format(refname, REFNAME_ALLOW_ONELEVEL|REFNAME_DOT_COMPONENT))
|
check_refname_format(refname, REFNAME_ALLOW_ONELEVEL|REFNAME_DOT_COMPONENT))
|
||||||
die("Reference has invalid format: '%s'", refname);
|
die("Reference has invalid format: '%s'", refname);
|
||||||
memcpy(entry->name, refname, len);
|
len = strlen(refname) + 1;
|
||||||
entry->flag = flag;
|
ref = xmalloc(sizeof(struct ref_entry) + len);
|
||||||
if (new_entry)
|
hashcpy(ref->sha1, sha1);
|
||||||
*new_entry = entry;
|
hashclr(ref->peeled);
|
||||||
|
memcpy(ref->name, refname, len);
|
||||||
|
ref->flag = flag;
|
||||||
|
return ref;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Add a ref_entry to the end of the ref_array (unsorted). */
|
||||||
|
static void add_ref(const char *refname, const unsigned char *sha1,
|
||||||
|
int flag, int check_name, struct ref_array *refs,
|
||||||
|
struct ref_entry **new_ref)
|
||||||
|
{
|
||||||
|
struct ref_entry *ref = create_ref_entry(refname, sha1, flag, check_name);
|
||||||
|
if (new_ref)
|
||||||
|
*new_ref = ref;
|
||||||
ALLOC_GROW(refs->refs, refs->nr + 1, refs->alloc);
|
ALLOC_GROW(refs->refs, refs->nr + 1, refs->alloc);
|
||||||
refs->refs[refs->nr++] = entry;
|
refs->refs[refs->nr++] = ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ref_entry_cmp(const void *a, const void *b)
|
static int ref_entry_cmp(const void *a, const void *b)
|
||||||
|
Reference in New Issue
Block a user