From patchwork Tue Aug 24 10:37:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 12454605 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.7 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 2B37BC4338F for ; Tue, 24 Aug 2021 10:37:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1377E61008 for ; Tue, 24 Aug 2021 10:37:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236342AbhHXKi0 (ORCPT ); Tue, 24 Aug 2021 06:38:26 -0400 Received: from out4-smtp.messagingengine.com ([66.111.4.28]:52065 "EHLO out4-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236285AbhHXKiA (ORCPT ); Tue, 24 Aug 2021 06:38:00 -0400 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 656BB5C013B; Tue, 24 Aug 2021 06:37:16 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Tue, 24 Aug 2021 06:37:16 -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=ydwJQMST+meK/8kus6/KfBJhg1U n+26LX7CfoObwmbc=; b=UWaBOPIDJpUC8BggSOHnJ5TARL4VCvAjC2kPcqc2byS R/rBOfbAN0SZs2XLXTZnIRIVYd2rLwPn5oYy4tG1a3syRTPyDo1Ec4+TpvGhicP7 qiby0bW2DeNu9Jl9auffvTetLr8irvYtc86Lk1FYyvZgQYmczJhncXTOzHVTw53+ Lk84eq8oVSrZNOFZ9VAVuHBMBSl0atINNrQR5nB9meOpSaJZBVeabTMfDcR5pk3K GdC+o/mVIK5DrnFFVP4lbAQ/Rk8cUTEzfa2e2CBozgwUvdYocHkKbOw3t9gZJXsL uFNpgsPGNUYlp+GSFB+VBvAYsyy1GSgfKY+ZlYEIFvQ== 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=ydwJQM ST+meK/8kus6/KfBJhg1Un+26LX7CfoObwmbc=; b=ILk+mvAMiJsFGZ0JgcY0iI At09Kby4cODHH8/3G1BuvLcnJXEewYjPkArw3onR3fVonudwb9I89FDv9fDzvSV8 x2k8qbjcA1pzNjD4wW8HewFQPcx7jVkB/jVZsu5YAIT+kwUSZ2UOG1lMRkxuOxQI Okolub+RtLU6Q84wKF45wdCje3Ny3d87SnpNCcqJ2iHFnngE90PV19zFqkm1NUrZ 6gdwk8yA3FUSiQDpLZTK32jfMFse/tQcHAAdYGPCPhoNB0rORWNbJpJxPpAtvcTL vApEAxu1Sh4fn4gi0N1WStjfVh4Eol/j4gTnekXEss9Pi6R6B03EyhkTZffIUFXw == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddruddtjedgfedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrghtrhhi tghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrh hnpeehgefhtdefueffheekgfffudelffejtdfhvdejkedthfehvdelgfetgfdvtedthfen ucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesph hkshdrihhm X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 24 Aug 2021 06:37:15 -0400 (EDT) Received: from localhost (ncase [10.192.0.11]) by vm-mail.pks.im (OpenSMTPD) with ESMTPSA id dd71eb36 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 24 Aug 2021 10:37:14 +0000 (UTC) Date: Tue, 24 Aug 2021 12:37:13 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , =?iso-8859-1?q?=C6var_Arnfj=F6r=F0?= Bjarmason , Junio C Hamano , Derrick Stolee , =?iso-8859-1?q?Ren=E9?= Scharfe Subject: [PATCH v2 5/7] fetch: refactor fetch refs to be more extendable Message-ID: <56a9158ac331f9911a4347d7d4afc2bbd2cf4d33.1629800774.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 | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/builtin/fetch.c b/builtin/fetch.c index cdf0d0d671..da0e283288 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -1293,20 +1293,28 @@ 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); + 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) { 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; + } } - 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; + + /* + * 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 */