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>
Michael Haggerty committed
Dec 12, 2011 at 06:38 UTC
cddc42587cbb37f8ff2f34b53550b5e331aa3aa5
1 file changed
+22
-15
refs.c
+22
-15
@@ -53,28 +53,35 @@ static const char *parse_ref_line(char *line, unsigned char *sha1)
53
return line;
54
}
55
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)
59
{
60
int len;
62
- struct ref_entry *entry;
61
+ struct ref_entry *ref;
62
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);
63
if (check_name &&
64
check_refname_format(refname, REFNAME_ALLOW_ONELEVEL|REFNAME_DOT_COMPONENT))
65
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;
83
ALLOC_GROW(refs->refs, refs->nr + 1, refs->alloc);
77
- refs->refs[refs->nr++] = entry;
84
+ refs->refs[refs->nr++] = ref;
85
}
86
87
static int ref_entry_cmp(const void *a, const void *b)