From patchwork Fri Apr 16 12:49:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12207577 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=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 989BAC433B4 for ; Fri, 16 Apr 2021 12:50:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 73EB66103D for ; Fri, 16 Apr 2021 12:50:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240445AbhDPMu3 (ORCPT ); Fri, 16 Apr 2021 08:50:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235644AbhDPMu1 (ORCPT ); Fri, 16 Apr 2021 08:50:27 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B0B5C06175F for ; Fri, 16 Apr 2021 05:50:02 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id t14-20020a05600c198eb029012eeb3edfaeso4131693wmq.2 for ; Fri, 16 Apr 2021 05:50:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=Llo0Of7xrxXb6L4qe3wjXKvb7OepjL9FntDDDajZ5Mw=; b=f5DVwKChZSIm5D+z1QI7/oYXDvgdVzGbpi0do2x81D+h1xifF3J0G3mr092x8BPLZz FlrMWtnFx+lFUgD2n0pRI2zW8iCS5yF2km5zqec4co/0yCSQqfK8+mYeQRyIFnafeC8U YAp+Alt5NlwtXy1nb3QmpKDMiYTVONebfqjVq/IuE368dGiS5yCdlxaBkZTtYb4qL3e7 V25Vg/wX/5/BcWJ5glSfKHUY4PRzwX+7GXJim1JkAosrhzXefLTamvDjPrOCId2GcseM PuRSb9+hpr4SIeFWmvu5aP/yWHbVd0Y0x9nN3TbzR8YGxLd4VeeAa/4dBS7vxtWMH5I/ QgCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=Llo0Of7xrxXb6L4qe3wjXKvb7OepjL9FntDDDajZ5Mw=; b=TKR15Nf9Fu/WoOI8wafWDbAZHqtof9doNOs31l57F2yGEvPHOzXxcPTJSCFXaQv+sz s5EN/g1lXCHc5MjQ5OuZ3NzKh/cAEYvGQYH/djfnYVHoGowFmexpC5wOG+pCIZbXYotm D0e4hBzdbAoblPIRC3t1VFKGVPatXYvj6TbFUn98Llvtjbo4nm5MjebIxf+fY1y5Iz1y YRxW0JqkW2fMVkR90OliqRuR6/uKhwy92D73UE4R7zKfbn3wFkgAdbg9Y9ZIC9MQk2rg 6BrKWT0m8UFz5BVt6btboQs+6uxCIHyxhW5WMCzwxM6w+FFujXqFkhsFSinfvjEl5GRP ERcA== X-Gm-Message-State: AOAM531X/uY4gFvKUW4hXgEqpGK/Hrzpmm+nrUAIcyMwv2yENpHUoSVa qoZD9LS+XgTGgvcXAtiZsZTVOzDirSM= X-Google-Smtp-Source: ABdhPJwm5jmdcI5+m2CPCv+YvwdZrE1ChnO+Ql1Fq/LMjNqrZz8Y88i8BHwsbIdZuOHgVHAQevuhdw== X-Received: by 2002:a1c:a78b:: with SMTP id q133mr8267482wme.68.1618577401458; Fri, 16 Apr 2021 05:50:01 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id o62sm20050180wmo.3.2021.04.16.05.50.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Apr 2021 05:50:01 -0700 (PDT) Message-Id: <4c0e983ba56f030851370ef71887117db45e8479.1618577399.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 16 Apr 2021 12:49:56 +0000 Subject: [PATCH v4 1/4] maintenance: simplify prefetch logic Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: tom.saeger@oracle.com, gitster@pobox.com, sunshine@sunshineco.com, Derrick Stolee , Josh Steadmon , Emily Shaffer , Ramsay Jones , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee The previous logic filled a string list with the names of each remote, but instead we could simply run the appropriate 'git fetch' data directly in the remote iterator. Do this for reduced code size, but also because it sets up an upcoming change to use the remote's refspec. This data is accessible from the 'struct remote' data that is now accessible in fetch_remote(). Signed-off-by: Derrick Stolee Reviewed-by: Tom Saeger --- builtin/gc.c | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/builtin/gc.c b/builtin/gc.c index ef7226d7bca4..fa8128de9ae1 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -873,55 +873,38 @@ static int maintenance_task_commit_graph(struct maintenance_run_opts *opts) return 0; } -static int fetch_remote(const char *remote, struct maintenance_run_opts *opts) +static int fetch_remote(struct remote *remote, void *cbdata) { + struct maintenance_run_opts *opts = cbdata; struct child_process child = CHILD_PROCESS_INIT; child.git_cmd = 1; - strvec_pushl(&child.args, "fetch", remote, "--prune", "--no-tags", + strvec_pushl(&child.args, "fetch", remote->name, "--prune", "--no-tags", "--no-write-fetch-head", "--recurse-submodules=no", "--refmap=", NULL); if (opts->quiet) strvec_push(&child.args, "--quiet"); - strvec_pushf(&child.args, "+refs/heads/*:refs/prefetch/%s/*", remote); + strvec_pushf(&child.args, "+refs/heads/*:refs/prefetch/%s/*", remote->name); return !!run_command(&child); } -static int append_remote(struct remote *remote, void *cbdata) -{ - struct string_list *remotes = (struct string_list *)cbdata; - - string_list_append(remotes, remote->name); - return 0; -} - static int maintenance_task_prefetch(struct maintenance_run_opts *opts) { - int result = 0; - struct string_list_item *item; - struct string_list remotes = STRING_LIST_INIT_DUP; - git_config_set_multivar_gently("log.excludedecoration", "refs/prefetch/", "refs/prefetch/", CONFIG_FLAGS_FIXED_VALUE | CONFIG_FLAGS_MULTI_REPLACE); - if (for_each_remote(append_remote, &remotes)) { - error(_("failed to fill remotes")); - result = 1; - goto cleanup; + if (for_each_remote(fetch_remote, opts)) { + error(_("failed to prefetch remotes")); + return 1; } - for_each_string_list_item(item, &remotes) - result |= fetch_remote(item->string, opts); - -cleanup: - string_list_clear(&remotes, 0); - return result; + return 0; } static int maintenance_task_gc(struct maintenance_run_opts *opts)