summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2007-09-14 07:31:18 (GMT)
committerJunio C Hamano <gitster@pobox.com>2007-09-19 10:22:30 (GMT)
commit7a2bff45937a60d846abf3ccb42015539aedcb40 (patch)
tree05e1b2a563b3947195b1cc6c522790af18272cbd
parentf1ae391e17be638a14c7505598b73430dbf328f1 (diff)
downloadgit-7a2bff45937a60d846abf3ccb42015539aedcb40.zip
git-7a2bff45937a60d846abf3ccb42015539aedcb40.tar.gz
git-7a2bff45937a60d846abf3ccb42015539aedcb40.tar.bz2
Replace custom memory growth allocator with ALLOC_GROW
The ALLOC_GROW macro is a shorter way to implement an array that grows upon demand as additional items are added to it. We have mostly standardized upon its use within git and transport.c is not an exception. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--transport.c11
1 files changed, 3 insertions, 8 deletions
diff --git a/transport.c b/transport.c
index e0111dc..2258492 100644
--- a/transport.c
+++ b/transport.c
@@ -474,13 +474,11 @@ struct ref *transport_get_remote_refs(struct transport *transport)
return transport->remote_refs;
}
-#define PACK_HEADS_CHUNK_COUNT 256
-
int transport_fetch_refs(struct transport *transport, struct ref *refs)
{
int i;
- int nr_heads = 0;
- char **heads = xmalloc(PACK_HEADS_CHUNK_COUNT * sizeof(char *));
+ int nr_heads = 0, nr_alloc = 0;
+ char **heads = NULL;
struct ref *rm;
int use_objs = !transport->ops->fetch_refs;
@@ -488,15 +486,12 @@ int transport_fetch_refs(struct transport *transport, struct ref *refs)
if (rm->peer_ref &&
!hashcmp(rm->peer_ref->old_sha1, rm->old_sha1))
continue;
+ ALLOC_GROW(heads, nr_heads + 1, nr_alloc);
if (use_objs) {
heads[nr_heads++] = xstrdup(sha1_to_hex(rm->old_sha1));
} else {
heads[nr_heads++] = xstrdup(rm->name);
}
- if (nr_heads % PACK_HEADS_CHUNK_COUNT == 0)
- heads = xrealloc(heads,
- (nr_heads + PACK_HEADS_CHUNK_COUNT) *
- sizeof(char *));
}
if (use_objs) {