summaryrefslogtreecommitdiff
path: root/builtin/fetch-pack.c
diff options
context:
space:
mode:
authorMichael Haggerty <mhagger@alum.mit.edu>2012-09-09 08:19:44 +0200
committerJunio C Hamano <gitster@pobox.com>2012-09-12 11:46:31 -0700
commit5096e4875303038ffc34af96c28cf2a2b7e103a6 (patch)
tree0daa5e5c4abb35ebb95d5b383e57512d73e05253 /builtin/fetch-pack.c
parent4ba159996f6c1b0d6dd0a2a8bd9d6f5b342a4aa5 (diff)
downloadgit-5096e4875303038ffc34af96c28cf2a2b7e103a6.tar.gz
filter_refs(): build refs list as we go
Instead of temporarily storing matched refs to temporary array "return_refs", simply append them to newlist as we go. This changes the order of references in newlist to strictly sorted if "--all" and "--depth" and named references are all specified, but that usage is broken anyway (see the last two tests in t5500). This changes the last test in t5500 from segfaulting into just emitting a spurious error (this will be fixed in a moment). Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/fetch-pack.c')
-rw-r--r--builtin/fetch-pack.c31
1 files changed, 4 insertions, 27 deletions
diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c
index 12ba009c12..4e94aa4635 100644
--- a/builtin/fetch-pack.c
+++ b/builtin/fetch-pack.c
@@ -537,24 +537,11 @@ static int non_matching_ref(struct string_list_item *item, void *unused)
static void filter_refs(struct ref **refs, struct string_list *sought)
{
- struct ref **return_refs;
struct ref *newlist = NULL;
struct ref **newtail = &newlist;
struct ref *ref, *next;
- struct ref *fastarray[32];
int sought_pos;
- if (sought->nr && !args.fetch_all) {
- if (ARRAY_SIZE(fastarray) < sought->nr)
- return_refs = xcalloc(sought->nr, sizeof(struct ref *));
- else {
- return_refs = fastarray;
- memset(return_refs, 0, sizeof(struct ref *) * sought->nr);
- }
- }
- else
- return_refs = NULL;
-
sought_pos = 0;
for (ref = *refs; ref; ref = next) {
next = ref->next;
@@ -575,8 +562,10 @@ static void filter_refs(struct ref **refs, struct string_list *sought)
if (cmp < 0) /* definitely do not have it */
break;
else if (cmp == 0) { /* definitely have it */
- return_refs[sought_pos] = ref;
sought->items[sought_pos++].util = "matched";
+ *newtail = ref;
+ ref->next = NULL;
+ newtail = &ref->next;
break;
}
else /* might have it; keep looking */
@@ -588,20 +577,8 @@ static void filter_refs(struct ref **refs, struct string_list *sought)
free(ref);
}
- if (!args.fetch_all) {
- int i;
- for (i = 0; i < sought->nr; i++) {
- ref = return_refs[i];
- if (ref) {
- *newtail = ref;
- ref->next = NULL;
- newtail = &ref->next;
- }
- }
- if (return_refs != fastarray)
- free(return_refs);
+ if (!args.fetch_all)
filter_string_list(sought, 0, non_matching_ref, NULL);
- }
*refs = newlist;
}