Skip to content

Commit 5096e48

Browse files
mhaggergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4ba1599 commit 5096e48

File tree

1 file changed

+4
-27
lines changed

1 file changed

+4
-27
lines changed

builtin/fetch-pack.c

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -537,24 +537,11 @@ static int non_matching_ref(struct string_list_item *item, void *unused)
537537

538538
static void filter_refs(struct ref **refs, struct string_list *sought)
539539
{
540-
struct ref **return_refs;
541540
struct ref *newlist = NULL;
542541
struct ref **newtail = &newlist;
543542
struct ref *ref, *next;
544-
struct ref *fastarray[32];
545543
int sought_pos;
546544

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-
558545
sought_pos = 0;
559546
for (ref = *refs; ref; ref = next) {
560547
next = ref->next;
@@ -575,8 +562,10 @@ static void filter_refs(struct ref **refs, struct string_list *sought)
575562
if (cmp < 0) /* definitely do not have it */
576563
break;
577564
else if (cmp == 0) { /* definitely have it */
578-
return_refs[sought_pos] = ref;
579565
sought->items[sought_pos++].util = "matched";
566+
*newtail = ref;
567+
ref->next = NULL;
568+
newtail = &ref->next;
580569
break;
581570
}
582571
else /* might have it; keep looking */
@@ -588,20 +577,8 @@ static void filter_refs(struct ref **refs, struct string_list *sought)
588577
free(ref);
589578
}
590579

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)
603581
filter_string_list(sought, 0, non_matching_ref, NULL);
604-
}
605582
*refs = newlist;
606583
}
607584

0 commit comments

Comments
 (0)