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>
Michael Haggerty committed
Sep 9, 2012 at 08:19 UTC
5096e4875303038ffc34af96c28cf2a2b7e103a6
1 file changed
+4
-27
builtin/fetch-pack.c
+4
-27
@@ -537,24 +537,11 @@ static int non_matching_ref(struct string_list_item *item, void *unused)
537
538
static void filter_refs(struct ref **refs, struct string_list *sought)
539
{
540
- struct ref **return_refs;
540
struct ref *newlist = NULL;
541
struct ref **newtail = &newlist;
542
struct ref *ref, *next;
544
- struct ref *fastarray[32];
543
int sought_pos;
544
547
- if (sought->nr && !args.fetch_all) {
548
- if (ARRAY_SIZE(fastarray) < sought->nr)
549
- return_refs = xcalloc(sought->nr, sizeof(struct ref *));
550
- else {
551
- return_refs = fastarray;
552
- memset(return_refs, 0, sizeof(struct ref *) * sought->nr);
553
- }
554
- }
555
- else
556
- return_refs = NULL;
557
-
545
sought_pos = 0;
546
for (ref = *refs; ref; ref = next) {
547
next = ref->next;
@@ -575,8 +562,10 @@ static void filter_refs(struct ref **refs, struct string_list *sought)
562
if (cmp < 0) /* definitely do not have it */
563
break;
564
else if (cmp == 0) { /* definitely have it */
578
- return_refs[sought_pos] = ref;
565
sought->items[sought_pos++].util = "matched";
566
+ *newtail = ref;
567
+ ref->next = NULL;
568
+ newtail = &ref->next;
569
break;
570
}
571
else /* might have it; keep looking */
@@ -588,20 +577,8 @@ static void filter_refs(struct ref **refs, struct string_list *sought)
577
free(ref);
578
}
579
591
- if (!args.fetch_all) {
592
- int i;
593
- for (i = 0; i < sought->nr; i++) {
594
- ref = return_refs[i];
595
- if (ref) {
596
- *newtail = ref;
597
- ref->next = NULL;
598
- newtail = &ref->next;
599
- }
600
- }
601
- if (return_refs != fastarray)
602
- free(return_refs);
580
+ if (!args.fetch_all)
581
filter_string_list(sought, 0, non_matching_ref, NULL);
604
- }
582
*refs = newlist;
583
}
584