In a subsequent patch, a null fetch negotiator will be introduced. This negotiator, among other things, will not need any tip information and will have a NULL add_tip. Teach fetch-pack to allow this, and to take advantage of this by avoiding a ref and alternate traversal when it can. To do this, this patch combines all invocations of functions that invoke add_tip into one function, and that function first checks whether add_tip is NULL. Signed-off-by: Jonathan Tan <jonathantanmy@xxxxxxxxxx> --- fetch-pack.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/fetch-pack.c b/fetch-pack.c index 80fb3bd899..6c786f5970 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -240,6 +240,16 @@ static void mark_tips(struct fetch_negotiator *negotiator, return; } +static void add_tips_and_alternates(struct fetch_negotiator *negotiator, + const struct oid_array *negotiation_tips) +{ + if (!negotiator->add_tip) + return; + + mark_tips(negotiator, negotiation_tips); + for_each_cached_alternate(negotiator, insert_one_alternate_object); +} + static int find_common(struct fetch_negotiator *negotiator, struct fetch_pack_args *args, int fd[2], struct object_id *result_oid, @@ -262,10 +272,8 @@ static int find_common(struct fetch_negotiator *negotiator, PACKET_READ_CHOMP_NEWLINE | PACKET_READ_DIE_ON_ERR_PACKET); - if (!args->no_dependents) { - mark_tips(negotiator, args->negotiation_tips); - for_each_cached_alternate(negotiator, insert_one_alternate_object); - } + if (!args->no_dependents) + add_tips_and_alternates(negotiator, args->negotiation_tips); fetching = 0; for ( ; refs ; refs = refs->next) { @@ -1575,9 +1583,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args, else state = FETCH_SEND_REQUEST; - mark_tips(negotiator, args->negotiation_tips); - for_each_cached_alternate(negotiator, - insert_one_alternate_object); + add_tips_and_alternates(negotiator, args->negotiation_tips); } else { filter_refs(args, &ref, sought, nr_sought); state = FETCH_SEND_REQUEST; -- 2.28.0.163.g6104cc2f0b6-goog