Skip to content

Commit 22a1646

Browse files
rscharfegitster
authored andcommitted
fetch-pack: load tip_oids eagerly iff needed
tip_oids_contain() lazily loads refs into an oidset at its first call. It abuses the internal (sub)member .map.tablesize of that oidset to check if it has done that already. Determine if the oidset needs to be populated upfront and then do that instead. This duplicates a loop, but simplifies the existing one by separating concerns between the two. Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bf73282 commit 22a1646

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

fetch-pack.c

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -526,23 +526,6 @@ static void add_refs_to_oidset(struct oidset *oids, struct ref *refs)
526526
oidset_insert(oids, &refs->old_oid);
527527
}
528528

529-
static int tip_oids_contain(struct oidset *tip_oids,
530-
struct ref *unmatched, struct ref *newlist,
531-
const struct object_id *id)
532-
{
533-
/*
534-
* Note that this only looks at the ref lists the first time it's
535-
* called. This works out in filter_refs() because even though it may
536-
* add to "newlist" between calls, the additions will always be for
537-
* oids that are already in the set.
538-
*/
539-
if (!tip_oids->map.map.tablesize) {
540-
add_refs_to_oidset(tip_oids, unmatched);
541-
add_refs_to_oidset(tip_oids, newlist);
542-
}
543-
return oidset_contains(tip_oids, id);
544-
}
545-
546529
static int is_unmatched_ref(const struct ref *ref)
547530
{
548531
struct object_id oid;
@@ -563,6 +546,8 @@ static void filter_refs(struct fetch_pack_args *args,
563546
struct ref *ref, *next;
564547
struct oidset tip_oids = OIDSET_INIT;
565548
int i;
549+
int strict = !(allow_unadvertised_object_request &
550+
(ALLOW_TIP_SHA1 | ALLOW_REACHABLE_SHA1));
566551

567552
i = 0;
568553
for (ref = *refs; ref; ref = next) {
@@ -599,16 +584,25 @@ static void filter_refs(struct fetch_pack_args *args,
599584
}
600585
}
601586

587+
if (strict) {
588+
for (i = 0; i < nr_sought; i++) {
589+
ref = sought[i];
590+
if (!is_unmatched_ref(ref))
591+
continue;
592+
593+
add_refs_to_oidset(&tip_oids, unmatched);
594+
add_refs_to_oidset(&tip_oids, newlist);
595+
break;
596+
}
597+
}
598+
602599
/* Append unmatched requests to the list */
603600
for (i = 0; i < nr_sought; i++) {
604601
ref = sought[i];
605602
if (!is_unmatched_ref(ref))
606603
continue;
607604

608-
if ((allow_unadvertised_object_request &
609-
(ALLOW_TIP_SHA1 | ALLOW_REACHABLE_SHA1)) ||
610-
tip_oids_contain(&tip_oids, unmatched, newlist,
611-
&ref->old_oid)) {
605+
if (!strict || oidset_contains(&tip_oids, &ref->old_oid)) {
612606
ref->match_status = REF_MATCHED;
613607
*newtail = copy_ref(ref);
614608
newtail = &(*newtail)->next;

0 commit comments

Comments
 (0)