use alloc_ref rather than hand-allocating "struct ref"

This saves us some manual computation, and eliminates a call to strcpy. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Sep 24, 2015 at 17:08 UTC 6f687c21c07bfb83a63049640cba5fb82c174198
2 files changed +2 -6
builtin/fetch.c
+1 -2
@@ -639,8 +639,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
639 continue;
640
641 if (rm->peer_ref) {
642 - ref = xcalloc(1, sizeof(*ref) + strlen(rm->peer_ref->name) + 1);
643 - strcpy(ref->name, rm->peer_ref->name);
642 + ref = alloc_ref(rm->peer_ref->name);
643 hashcpy(ref->old_sha1, rm->peer_ref->old_sha1);
644 hashcpy(ref->new_sha1, rm->old_sha1);
645 ref->force = rm->peer_ref->force;
remote-curl.c
+1 -4
@@ -168,10 +168,7 @@ static struct ref *parse_info_refs(struct discovery *heads)
168 url.buf);
169 data[i] = 0;
170 ref_name = mid + 1;
171 - ref = xmalloc(sizeof(struct ref) +
172 - strlen(ref_name) + 1);
173 - memset(ref, 0, sizeof(struct ref));
174 - strcpy(ref->name, ref_name);
171 + ref = alloc_ref(ref_name);
172 get_sha1_hex(start, ref->old_sha1);
173 if (!refs)
174 refs = ref;