aboutsummaryrefslogtreecommitdiff
path: root/remote.c
diff options
context:
space:
mode:
authorDaniel Barkalow <barkalow@iabervon.org>2007-07-10 00:47:23 -0400
committerJunio C Hamano <gitster@pobox.com>2007-07-09 23:39:59 -0700
commitdfd255dd1a7c04ad24891db50e5d80d96f93fd4a (patch)
tree0a7640ebb74f4f2b60ccc1dbc7cc87070b777f04 /remote.c
parent54dadbdb29668fbd51effefd0a0c65d915f5422b (diff)
downloadgit-dfd255dd1a7c04ad24891db50e5d80d96f93fd4a.tar.gz
git-dfd255dd1a7c04ad24891db50e5d80d96f93fd4a.tar.xz
Add allocation and freeing functions for struct refs
Instead of open-coding allocation wherever it happens, have a function. Also, add a function to free a list of refs, which we currently never actually do. Signed-off-by: Daniel Barkalow <barkalow@iabervon.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'remote.c')
-rw-r--r--remote.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/remote.c b/remote.c
index cf98a4436..616f6f216 100644
--- a/remote.c
+++ b/remote.c
@@ -320,6 +320,25 @@ int remote_find_tracking(struct remote *remote, struct refspec *refspec)
return -1;
}
+struct ref *alloc_ref(unsigned namelen)
+{
+ struct ref *ret = xmalloc(sizeof(struct ref) + namelen);
+ memset(ret, 0, sizeof(struct ref) + namelen);
+ return ret;
+}
+
+void free_refs(struct ref *ref)
+{
+ struct ref *next;
+ while (ref) {
+ next = ref->next;
+ if (ref->peer_ref)
+ free(ref->peer_ref);
+ free(ref);
+ ref = next;
+ }
+}
+
static int count_refspec_match(const char *pattern,
struct ref *refs,
struct ref **matched_ref)
@@ -391,7 +410,7 @@ static struct ref *try_explicit_object_name(const char *name)
int len;
if (!*name) {
- ref = xcalloc(1, sizeof(*ref) + 20);
+ ref = alloc_ref(20);
strcpy(ref->name, "(delete)");
hashclr(ref->new_sha1);
return ref;
@@ -399,7 +418,7 @@ static struct ref *try_explicit_object_name(const char *name)
if (get_sha1(name, sha1))
return NULL;
len = strlen(name) + 1;
- ref = xcalloc(1, sizeof(*ref) + len);
+ ref = alloc_ref(len);
memcpy(ref->name, name, len);
hashcpy(ref->new_sha1, sha1);
return ref;
@@ -411,7 +430,7 @@ static struct ref *make_dst(const char *name, struct ref ***dst_tail)
size_t len;
len = strlen(name) + 1;
- dst = xcalloc(1, sizeof(*dst) + len);
+ dst = alloc_ref(len);
memcpy(dst->name, name, len);
link_dst_tail(dst, dst_tail);
return dst;