use alloc_ref rather than hand-allocating "struct ref"
authorJeff King <peff@peff.net>
Thu, 24 Sep 2015 21:08:09 +0000 (17:08 -0400)
committerJunio C Hamano <gitster@pobox.com>
Mon, 5 Oct 2015 18:08:05 +0000 (11:08 -0700)
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>
builtin/fetch.c
remote-curl.c
index 841880ec2c8259c5ad15e21f716f58652096a29b..ed84963a57b692ab36aecfed61606afcfaa6d2cd 100644 (file)
@@ -639,8 +639,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
                                continue;
 
                        if (rm->peer_ref) {
-                               ref = xcalloc(1, sizeof(*ref) + strlen(rm->peer_ref->name) + 1);
-                               strcpy(ref->name, rm->peer_ref->name);
+                               ref = alloc_ref(rm->peer_ref->name);
                                hashcpy(ref->old_sha1, rm->peer_ref->old_sha1);
                                hashcpy(ref->new_sha1, rm->old_sha1);
                                ref->force = rm->peer_ref->force;
index 71fbbb694fc78471343f568a5e93b8013a7bb9cb..cc7a8a66faa96ba9bc8ae82e72d0202c0a802ba1 100644 (file)
@@ -168,10 +168,7 @@ static struct ref *parse_info_refs(struct discovery *heads)
                                    url.buf);
                        data[i] = 0;
                        ref_name = mid + 1;
-                       ref = xmalloc(sizeof(struct ref) +
-                                     strlen(ref_name) + 1);
-                       memset(ref, 0, sizeof(struct ref));
-                       strcpy(ref->name, ref_name);
+                       ref = alloc_ref(ref_name);
                        get_sha1_hex(start, ref->old_sha1);
                        if (!refs)
                                refs = ref;