summaryrefslogtreecommitdiff
path: root/remote.c
diff options
context:
space:
mode:
authorKrzysztof Kowalczyk <kkowalczyk@gmail.com>2008-05-10 16:26:58 -0700
committerJunio C Hamano <gitster@pobox.com>2008-05-11 09:04:37 -0700
commit737922aa648c43bc6a61170bee5bfd46ff953f32 (patch)
treeebcdb2c587f0a5b781f0613a711f5501d6b89860 /remote.c
parent1f8115b113def8ee03701aa87b26c5e8b7c94434 (diff)
downloadgit-737922aa648c43bc6a61170bee5bfd46ff953f32.tar.gz
alloc_ref_from_str(): factor out a common pattern of alloc_ref from string
Also fix an underallocation in walker.c::interpret_target(). Signed-off-by: Krzysztof Kowalczyk <kkowalczyk@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'remote.c')
-rw-r--r--remote.c23
1 files changed, 10 insertions, 13 deletions
diff --git a/remote.c b/remote.c
index 6b480cbb98..91cbb72dde 100644
--- a/remote.c
+++ b/remote.c
@@ -691,6 +691,13 @@ struct ref *alloc_ref(unsigned namelen)
return ret;
}
+struct ref *alloc_ref_from_str(const char* str)
+{
+ struct ref *ret = alloc_ref(strlen(str) + 1);
+ strcpy(ret->name, str);
+ return ret;
+}
+
static struct ref *copy_ref(const struct ref *ref)
{
struct ref *ret = xmalloc(sizeof(struct ref) + strlen(ref->name) + 1);
@@ -797,7 +804,6 @@ static struct ref *try_explicit_object_name(const char *name)
{
unsigned char sha1[20];
struct ref *ref;
- int len;
if (!*name) {
ref = alloc_ref(20);
@@ -807,21 +813,14 @@ static struct ref *try_explicit_object_name(const char *name)
}
if (get_sha1(name, sha1))
return NULL;
- len = strlen(name) + 1;
- ref = alloc_ref(len);
- memcpy(ref->name, name, len);
+ ref = alloc_ref_from_str(name);
hashcpy(ref->new_sha1, sha1);
return ref;
}
static struct ref *make_linked_ref(const char *name, struct ref ***tail)
{
- struct ref *ret;
- size_t len;
-
- len = strlen(name) + 1;
- ret = alloc_ref(len);
- memcpy(ret->name, name, len);
+ struct ref *ret = alloc_ref_from_str(name);
tail_link_ref(ret, tail);
return ret;
}
@@ -1125,9 +1124,7 @@ static struct ref *get_local_ref(const char *name)
return NULL;
if (!prefixcmp(name, "refs/")) {
- ret = alloc_ref(strlen(name) + 1);
- strcpy(ret->name, name);
- return ret;
+ return alloc_ref_from_str(name);
}
if (!prefixcmp(name, "heads/") ||