Skip to content

Commit

Permalink
Replace custom memory growth allocator with ALLOC_GROW
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Shawn O. Pearce authored and Junio C Hamano committed Sep 19, 2007
1 parent f1ae391 commit 7a2bff4
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -474,29 +474,24 @@ 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;

for (rm = refs; rm; rm = rm->next) {
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) {
Expand Down

0 comments on commit 7a2bff4

Please sign in to comment.