From patchwork Wed Sep 1 13:09:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 12469353 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 90F0EC432BE for ; Wed, 1 Sep 2021 13:10:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 72CD360FED for ; Wed, 1 Sep 2021 13:10:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344418AbhIANLI (ORCPT ); Wed, 1 Sep 2021 09:11:08 -0400 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:54753 "EHLO out1-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344384AbhIANLA (ORCPT ); Wed, 1 Sep 2021 09:11:00 -0400 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 0661A5C0161; Wed, 1 Sep 2021 09:10:01 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 01 Sep 2021 09:10:01 -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=7vhOzDwM4dU7PF+O6vo3x37sYB2 N4N1+ABlbxmsYUOc=; b=Aeao0gWJgnp/3XJcOP63x7rOZWHp5rV05BxzT+92Dsk JJ8l5ac8CQLuD/Sd9+yJfUpqvzA+qJP8OZ2H1kd5tFv0hMDigiY4nggSKaHK5k+R HxlFUOzCewYAqOq2sVVG/fQwYa8zOmxxg7Sv990ARu5kvKypFrrX17RYBrD23Mav Q8IbVK6cTBXvhG4WJHERU+ACIxbEVzmCcaJoWmGFxbVi1++ZvoOqqH2LZecgagCf ROV0AmQn/zw1poYQOyj+bQ3Emwe+EKhJ7dURUDADV9SbqjmCsHjSJ0soxDVkhUKi r2RZOkHjeeSQVnf6fpQGcCWZh3YwreMQSGxdQrd7J0g== 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=7vhOzD wM4dU7PF+O6vo3x37sYB2N4N1+ABlbxmsYUOc=; b=CC5Uh9lsJmgIO/4XzeUsKO cx5qbBstOAppdN/HaeGeYtk3f7xRjT+IeLeVu3xoBofmUznNvM0bIHcxKEarlN1u CrsinUn6I4WHttRxmkY8gSwZAM5L9VEl2Fb0XcoOMMXGxpGPLh6Zc4dlqHjlryZp Am0I2KuvU9hM2emkUAjZoOWrwq44NKObf0lOurXWrCfzKTcJPHRV1eMG7HKldgbM NWECLZVF/6gKCvJs+U/fNFBME3bGtLkXWp6tTISQhLxlMov5udc9xFQPOYz5VxUA c5NMuq4eP3SpXsuCy2nGkJj4GlD+tOLgl1S5mR0DesAQ33SPMoi6g9CufrWDFcCQ == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddruddvfedgieduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrghtrhhi tghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrh hnpeehgefhtdefueffheekgfffudelffejtdfhvdejkedthfehvdelgfetgfdvtedthfen ucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesph hkshdrihhm X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 1 Sep 2021 09:10:00 -0400 (EDT) Received: from localhost (ncase [10.192.0.11]) by vm-mail.pks.im (OpenSMTPD) with ESMTPSA id 0530a8a2 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 1 Sep 2021 13:09:59 +0000 (UTC) Date: Wed, 1 Sep 2021 15:09:58 +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 v3 5/7] fetch: refactor fetch refs to be more extendable Message-ID: 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 | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/builtin/fetch.c b/builtin/fetch.c index f67fe543ad..bafeb3d44b 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -1293,18 +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) + goto out; } - 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; + + /* + * Keep the new pack's ".keep" file around to allow the caller + * time to update refs to reference the new objects. + */ + return ret; + +out: transport_unlock_pack(transport); return ret; }