From patchwork Fri Aug 20 10:08:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 12448825 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5577FC4338F for ; Fri, 20 Aug 2021 10:08:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 39547610D2 for ; Fri, 20 Aug 2021 10:08:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238882AbhHTKJb (ORCPT ); Fri, 20 Aug 2021 06:09:31 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:33259 "EHLO out3-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238492AbhHTKJ0 (ORCPT ); Fri, 20 Aug 2021 06:09:26 -0400 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 4510D5C008E; Fri, 20 Aug 2021 06:08:48 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Fri, 20 Aug 2021 06:08:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm1; bh=SfCRg8AncORoKzoD8jgUsNnr77n /s9Y1vMAtQGdGvWM=; b=BgdjiyD1h0SZFGF4RdT0x/yL7iya4ct2/gKwIZCtkCg n8bHAAaooNEXXH6ztjzRTVyxqEQjIb2z1zC0VFOXHF7Nzhpz0LawRi5dMzE47VRZ 21ANaf9eIegAxreRSxUbnrdWrrBqWHWVWB7oBTyx6WTqLI932VfuW95ieqkdTygB TOOCuJClrRPghMu+oagDbuYoTp0N3v3HzHAC7iyr4PbwznBW734zaJXlqk9neTLi FRdxGZU92YJz4AoyGUzOtZyz0+sG8fUWYj8zp72ov5lwKf655R0obPcwoCTjSd5h XF1x+CH6PexXsGmEzzb/S3spn6AURhbMIdyNRAkDq5g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=SfCRg8 AncORoKzoD8jgUsNnr77n/s9Y1vMAtQGdGvWM=; b=LwcsfJIkUmiQrzJoEC03TS 17w/LxMANAc2ZNb4XxtJCHaMNUBY+TGOu5CC8ygZe2Y9z/a5GdLR4IT7CqoaB6wc Wsdrb3Ebm6zZ2SDcTAm60fmj22wL4oLbU7bMpkkzkeQ54OZeJGr10l4PkS7BfCEK /ofsVUb0DnW/7XGWyz/Kbb+akZae5wr+eyKUf2QqV+rY1jmvwpSHJkfRvC+hMG38 WHQnHxbRpQf8/q9UU0zLHdjG597ytPLauNejbv/DTOTb1941IT44OuFqlcjXNZJP RFcP2KNjR+X4ULiYFoeY1Vz6yT0LYdmoc1y4uUmRxYSprIKtX6GCkO20Fs7gp5Vg == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrleelgddvfecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 20 Aug 2021 06:08:47 -0400 (EDT) Received: from localhost (ncase [10.192.0.11]) by vm-mail.pks.im (OpenSMTPD) with ESMTPSA id dff0bf99 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 20 Aug 2021 10:08:46 +0000 (UTC) Date: Fri, 20 Aug 2021 12:08:45 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , =?iso-8859-1?q?=C6var_Arnfj=F6r=F0?= Bjarmason , Junio C Hamano Subject: [PATCH 5/6] fetch: refactor fetch refs to be more extendable Message-ID: <7653f8eabc1eb9c26e06ad3efa3d7e19dc9547cb.1629452412.git.ps@pks.im> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Refactor `fetch_refs()` code to make it more extendable by explicitly handling error cases. The refactored code should behave the same. Signed-off-by: Patrick Steinhardt --- builtin/fetch.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/builtin/fetch.c b/builtin/fetch.c index 76ce73ccf5..20fcfe0f45 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -1284,20 +1284,29 @@ static int check_exist_and_connected(struct ref *ref_map) static int fetch_refs(struct transport *transport, struct ref *ref_map) { - int ret = check_exist_and_connected(ref_map); - if (ret) { - trace2_region_enter("fetch", "fetch_refs", the_repository); - ret = transport_fetch_refs(transport, ref_map); - trace2_region_leave("fetch", "fetch_refs", the_repository); - } + int ret; + + /* + * We don't need to perform a fetch in case we can already satisfy all + * refs. + */ + ret = check_exist_and_connected(ref_map); if (!ret) - /* - * Keep the new pack's ".keep" file around to allow the caller - * time to update refs to reference the new objects. - */ return 0; - transport_unlock_pack(transport); - return ret; + + trace2_region_enter("fetch", "fetch_refs", the_repository); + ret = transport_fetch_refs(transport, ref_map); + trace2_region_leave("fetch", "fetch_refs", the_repository); + if (ret) { + transport_unlock_pack(transport); + return ret; + } + + /* + * Keep the new pack's ".keep" file around to allow the caller + * time to update refs to reference the new objects. + */ + return 0; } /* Update local refs based on the ref values fetched from a remote */