Skip to content

Commit 6f687c2

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cbc8fee commit 6f687c2

File tree

2 files changed

+2
-6
lines changed

2 files changed

+2
-6
lines changed

builtin/fetch.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -639,8 +639,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
639639
continue;
640640

641641
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);
644643
hashcpy(ref->old_sha1, rm->peer_ref->old_sha1);
645644
hashcpy(ref->new_sha1, rm->old_sha1);
646645
ref->force = rm->peer_ref->force;

remote-curl.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,7 @@ static struct ref *parse_info_refs(struct discovery *heads)
168168
url.buf);
169169
data[i] = 0;
170170
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);
175172
get_sha1_hex(start, ref->old_sha1);
176173
if (!refs)
177174
refs = ref;

0 commit comments

Comments
 (0)