15
#include "version.h"
16
#include "prio-queue.h"
17
#include "sha1-array.h"
18
+#include "oidset.h"
19
20
static int transfer_unpack_limit = -1;
21
static int fetch_unpack_limit = -1;
593
}
594
}
595
596
+static void add_refs_to_oidset(struct oidset *oids, struct ref *refs)
597
+{
598
+ for (; refs; refs = refs->next)
599
+ oidset_insert(oids, &refs->old_oid);
600
+}
601
+
602
+static int tip_oids_contain(struct oidset *tip_oids,
603
+ struct ref *unmatched, struct ref *newlist,
604
+ const struct object_id *id)
605
+{
606
+ /*
607
+ * Note that this only looks at the ref lists the first time it's
608
+ * called. This works out in filter_refs() because even though it may
609
+ * add to "newlist" between calls, the additions will always be for
610
+ * oids that are already in the set.
611
+ */
612
+ if (!tip_oids->map.tablesize) {
613
+ add_refs_to_oidset(tip_oids, unmatched);
614
+ add_refs_to_oidset(tip_oids, newlist);
615
+ }
616
+ return oidset_contains(tip_oids, id);
617
+}
618
+
619
static void filter_refs(struct fetch_pack_args *args,
620
struct ref **refs,
621
struct ref **sought, int nr_sought)
622
{
623
struct ref *newlist = NULL;
624
struct ref **newtail = &newlist;
625
+ struct ref *unmatched = NULL;
626
struct ref *ref, *next;
627
+ struct oidset tip_oids = OIDSET_INIT;
628
int i;
629
630
i = 0;
657
ref->next = NULL;
658
newtail = &ref->next;
659
} else {
634
- free(ref);
660
+ ref->next = unmatched;
661
+ unmatched = ref;
662
}
663
}
664
675
continue;
676
677
if ((allow_unadvertised_object_request &
651
- (ALLOW_TIP_SHA1 | ALLOW_REACHABLE_SHA1))) {
678
+ (ALLOW_TIP_SHA1 | ALLOW_REACHABLE_SHA1)) ||
679
+ tip_oids_contain(&tip_oids, unmatched, newlist,
680
+ &ref->old_oid)) {
681
ref->match_status = REF_MATCHED;
682
*newtail = copy_ref(ref);
683
newtail = &(*newtail)->next;
685
ref->match_status = REF_UNADVERTISED_NOT_ALLOWED;
686
}
687
}
688
+
689
+ oidset_clear(&tip_oids);
690
+ for (ref = unmatched; ref; ref = next) {
691
+ next = ref->next;
692
+ free(ref);
693
+ }
694
+
695
*refs = newlist;
696
}
697