Skip to content

Commit cddc425

Browse files
mhaggergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fe9c7b7 commit cddc425

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

refs.c

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,28 +53,35 @@ static const char *parse_ref_line(char *line, unsigned char *sha1)
5353
return line;
5454
}
5555

56-
/* Add a ref_entry to the end of the ref_array (unsorted). */
57-
static void add_ref(const char *refname, const unsigned char *sha1,
58-
int flag, int check_name, struct ref_array *refs,
59-
struct ref_entry **new_entry)
56+
static struct ref_entry *create_ref_entry(const char *refname,
57+
const unsigned char *sha1, int flag,
58+
int check_name)
6059
{
6160
int len;
62-
struct ref_entry *entry;
61+
struct ref_entry *ref;
6362

64-
/* Allocate it and add it in.. */
65-
len = strlen(refname) + 1;
66-
entry = xmalloc(sizeof(struct ref_entry) + len);
67-
hashcpy(entry->sha1, sha1);
68-
hashclr(entry->peeled);
6963
if (check_name &&
7064
check_refname_format(refname, REFNAME_ALLOW_ONELEVEL|REFNAME_DOT_COMPONENT))
7165
die("Reference has invalid format: '%s'", refname);
72-
memcpy(entry->name, refname, len);
73-
entry->flag = flag;
74-
if (new_entry)
75-
*new_entry = entry;
66+
len = strlen(refname) + 1;
67+
ref = xmalloc(sizeof(struct ref_entry) + len);
68+
hashcpy(ref->sha1, sha1);
69+
hashclr(ref->peeled);
70+
memcpy(ref->name, refname, len);
71+
ref->flag = flag;
72+
return ref;
73+
}
74+
75+
/* Add a ref_entry to the end of the ref_array (unsorted). */
76+
static void add_ref(const char *refname, const unsigned char *sha1,
77+
int flag, int check_name, struct ref_array *refs,
78+
struct ref_entry **new_ref)
79+
{
80+
struct ref_entry *ref = create_ref_entry(refname, sha1, flag, check_name);
81+
if (new_ref)
82+
*new_ref = ref;
7683
ALLOC_GROW(refs->refs, refs->nr + 1, refs->alloc);
77-
refs->refs[refs->nr++] = entry;
84+
refs->refs[refs->nr++] = ref;
7885
}
7986

8087
static int ref_entry_cmp(const void *a, const void *b)

0 commit comments

Comments
 (0)