From patchwork Wed Aug 5 01:20:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Tan X-Patchwork-Id: 11701131 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BFC4B6C1 for ; Wed, 5 Aug 2020 01:21:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B62E8208C7 for ; Wed, 5 Aug 2020 01:21:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="EJAIoUTW" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727800AbgHEBVI (ORCPT ); Tue, 4 Aug 2020 21:21:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726981AbgHEBU6 (ORCPT ); Tue, 4 Aug 2020 21:20:58 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BACDC06174A for ; Tue, 4 Aug 2020 18:20:58 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id a5so38104998ybh.3 for ; Tue, 04 Aug 2020 18:20:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=NGOwp5Ax/Dj/W31vyP2rRIH9UgY9nuf4W9Gq8qSK26Y=; b=EJAIoUTW9EVPZ3QgbGtxzAYNKR7lvALo17R6amFNM8eeXBGZ2zhw+HtZa/JYT0+cA4 8iP8OmkarwIJ7Bf+0MA5AgF6NOgYNKSoHJfLvm+Y2A+klw06HGqGV9wCNn7ync2JYEer jH2MJnLlnzap9pTtIWSHnsAxKJ/HJHaIa8WFV9oyGftvyfAPedusAynNHMiXe9Ze1Idv 3V/pR2BeZ/5UrLwxbaJR5kAfgSY3+HsgSvntXevjTo8NbnIePjB4KcjTM1w6d/mOK0Bm KB16d4omE+VhaWL9Q3VQO/RQORaP/oMTmMhCUC2+UQsA/SX6wy62vQZI0AGcBb6470VK Czig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=NGOwp5Ax/Dj/W31vyP2rRIH9UgY9nuf4W9Gq8qSK26Y=; b=VPrcRdE8z8VjAV5WHX1cFUiioJjrR5YTtoPm2kj9oyFQuFYdYPhCNzOF3JwAXES3eK OUUBOKCvg2aQ/6RXNtbf3CVLLaz1aSAOvrBBLKpk2JIR+sv06uahY7E8V6BmTTxt4Cj7 0bsMsqQd7HH0AcziTq9QHIbkqseYePXKeedgiCPgG5vGR9lFmNDjrGjah8qBawy6pXZQ 9wBdeUvODCwb2n2KR5vLPelIlB9qPE0Ps8QXPxngERJfuz/UDj6hvj1OiMrR1nEc9TMc rDemt2l5+OcaonxJH77kcQOs+9GfbpOk5qYq0SDf87K6XicXUo9d6/cqY17K0Muu4/8v qgfg== X-Gm-Message-State: AOAM532Z6prfZ14WavvAUxaTmG5KKQFZ4Ft5S+5ipNTlj5t2rpZnJHKF 1+8bjvoeLFridK8Vgz55IEOOMx5mXlJVsYgrutBIlti4L4S9iduEuzoAlsvku/8QpL+0l3VE3WU d5YqiKpcFEMjFKrYa/gAFoZG3E/SrNobxpllVroS9iNDHVvi8cQ64zGkII4UOlMcXJdwbO0NcG1 b6 X-Google-Smtp-Source: ABdhPJy5kn1PUCyTyggXJt6+Ee8Y+rZPi/WDTzcgg6R2MopNIsae6/n5hHicEZLuZg/nEdgzvtM8sYRzjEqQEmRkFplc X-Received: by 2002:a25:3446:: with SMTP id b67mr1161420yba.460.1596590457393; Tue, 04 Aug 2020 18:20:57 -0700 (PDT) Date: Tue, 4 Aug 2020 18:20:44 -0700 In-Reply-To: Message-Id: <044a782863dd690ed4e430b3793538f701a850c6.1596590295.git.jonathantanmy@google.com> Mime-Version: 1.0 References: <20200724223844.2723397-1-jonathantanmy@google.com> X-Mailer: git-send-email 2.28.0.163.g6104cc2f0b6-goog Subject: [RFC PATCH 1/7] fetch-pack: allow NULL negotiator->add_tip From: Jonathan Tan To: git@vger.kernel.org Cc: Jonathan Tan , peff@peff.net, gitster@pobox.com Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org 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 --- 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;