summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 54dadbd)
raw | patch | inline | side by side (parent: 54dadbd)
author | Daniel Barkalow <barkalow@iabervon.org> | |
Tue, 10 Jul 2007 04:47:23 +0000 (00:47 -0400) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Tue, 10 Jul 2007 06:39:59 +0000 (23:39 -0700) |
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>
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>
connect.c | patch | blob | history | |
remote.c | patch | blob | history | |
remote.h | patch | blob | history |
diff --git a/connect.c b/connect.c
index 65e79edc77101ba4f195d5ce267c712da52b3b0b..715cdc022340f8792c4bad45ba6a84c27bbfaa7f 100644 (file)
--- a/connect.c
+++ b/connect.c
continue;
if (nr_match && !path_match(name, nr_match, match))
continue;
- ref = xcalloc(1, sizeof(*ref) + len - 40);
+ ref = alloc_ref(len - 40);
hashcpy(ref->old_sha1, old_sha1);
memcpy(ref->name, buffer + 41, len - 40);
*list = ref;
diff --git a/remote.c b/remote.c
index cf98a44367cfad364871af4f1e191a9e7412562d..616f6f2165135f2efb6e1773c3ceb43056491ad8 100644 (file)
--- a/remote.c
+++ b/remote.c
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)
int len;
if (!*name) {
- ref = xcalloc(1, sizeof(*ref) + 20);
+ ref = alloc_ref(20);
strcpy(ref->name, "(delete)");
hashclr(ref->new_sha1);
return ref;
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;
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;
diff --git a/remote.h b/remote.h
index 01dbcef67048d2fe068a2ab348013cc3055b5195..080b7dab99348952d8d89fef428a317b1c4bd055 100644 (file)
--- a/remote.h
+++ b/remote.h
char *dst;
};
+struct ref *alloc_ref(unsigned namelen);
+
+/*
+ * Frees the entire list and peers of elements.
+ */
+void free_refs(struct ref *ref);
+
int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail,
int nr_refspec, char **refspec, int all);