summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f1ae391)
raw | patch | inline | side by side (parent: f1ae391)
author | Shawn O. Pearce <spearce@spearce.org> | |
Fri, 14 Sep 2007 07:31:18 +0000 (03:31 -0400) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Wed, 19 Sep 2007 10:22:30 +0000 (03:22 -0700) |
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>
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>
transport.c | patch | blob | history |
diff --git a/transport.c b/transport.c
index e0111dcf0b90e6d284505dd819144e5955cad699..2258492ae736eb6a7e0430de023ece70887dc242 100644 (file)
--- a/transport.c
+++ b/transport.c
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;
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) {