From patchwork Fri Sep 4 13:09:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver via GitGitGadget X-Patchwork-Id: 11757123 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 D7C2713B1 for ; Fri, 4 Sep 2020 13:13:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B5ED42073B for ; Fri, 4 Sep 2020 13:13:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="s5OMDG2G" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730307AbgIDNM2 (ORCPT ); Fri, 4 Sep 2020 09:12:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730354AbgIDNJV (ORCPT ); Fri, 4 Sep 2020 09:09:21 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B081C061245 for ; Fri, 4 Sep 2020 06:09:20 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id q9so6038323wmj.2 for ; Fri, 04 Sep 2020 06:09:20 -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=ZfkgU/gH4H5W+CFiXAoafxfJn1w3A8mviczuXnMlgbE=; b=s5OMDG2G1SmmrdvXYk8d8sWqCKaTcgRp5pnL2i0rHM5qw3rY14itrS8pCYdgv7y9+j CIq1oIxW/fZb47q0bktLZUaQb1Bcj9hyA0/xJSVHmnkBkznNvr0zZg9yzghT28tudvLW FCbkNzWqJ4WbLuK2EaJ+9EqWCRmG63Tk+s8zjbB3WExFCwCb3slN11DbXrsWe3NDrZFN weHbf5az7/CMU2kmCMIMPJTZJdNNVhxifowfrizic/wLHaMpNcgp1VOZKz+j98rVGcTX OK+MZuupgiEpADgYgzhggZCieFnbAQsiE6ZjbwB7X0ulhta1s/LgQduylXwjicvUswfw GZ0Q== 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=ZfkgU/gH4H5W+CFiXAoafxfJn1w3A8mviczuXnMlgbE=; b=HPilFm6IFvc3g+fb7QLOe3KFbvnAQ8AU2Wz9mJuntSrWJg5q03PWld07G97rUH7xI7 pCw7hp8yMkwa+YiDIQQErDpe0mlrQQRz+zO5kiW5H5tWET6uPjZk35kZrwwF4qSoE4qF RbehYMIE5m3+ZtAYXQDKFNTMSaRPsS/I3LG0C5MCkV54G1jRfCGjEBhqqE86dGvOXpGD IAbJ7hs8YrCiQA54tdl8Qpja3prEXwyVuylPcietK80ZYeffERVBicNIrr/d+ZB1tMt7 7/pE44U8BDCaEV625of9BUBPO6n6szaRmiIRqzKy7zR4+nLpn1UlFMTouCfH56AAcYTg f5EQ== X-Gm-Message-State: AOAM532n+N4vaC2hFUF/QsWcvcVmawn3NN+qrtPHQm6/SSO/4qYrnNAO XN4tLMFCCxLKkj1nNmdgHa1aJ1QdZh8= X-Google-Smtp-Source: ABdhPJz60YLhBjbd5Lw8SxH+JkaUbNs1Xv6iMZe8h2LjdFhSmP+xwIfZwnE2SiMCaDm4zgq2L0R4mw== X-Received: by 2002:a05:600c:2109:: with SMTP id u9mr7121724wml.147.1599224958176; Fri, 04 Sep 2020 06:09:18 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id h6sm10822085wmb.22.2020.09.04.06.09.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 06:09:17 -0700 (PDT) Message-Id: In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Fri, 04 Sep 2020 13:09:05 +0000 Subject: [PATCH v4 01/11] maintenance: create basic maintenance runner Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jonathan Tan , Derrick Stolee , Derrick Stolee Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee The 'gc' builtin is our current entrypoint for automatically maintaining a repository. This one tool does many operations, such as repacking the repository, packing refs, and rewriting the commit-graph file. The name implies it performs "garbage collection" which means several different things, and some users may not want to use this operation that rewrites the entire object database. Create a new 'maintenance' builtin that will become a more general- purpose command. To start, it will only support the 'run' subcommand, but will later expand to add subcommands for scheduling maintenance in the background. For now, the 'maintenance' builtin is a thin shim over the 'gc' builtin. In fact, the only option is the '--auto' toggle, which is handed directly to the 'gc' builtin. The current change is isolated to this simple operation to prevent more interesting logic from being lost in all of the boilerplate of adding a new builtin. Use existing builtin/gc.c file because we want to share code between the two builtins. It is possible that we will have 'maintenance' replace the 'gc' builtin entirely at some point, leaving 'git gc' as an alias for some specific arguments to 'git maintenance run'. Create a new test_subcommand helper that allows us to test if a certain subcommand was run. It requires storing the GIT_TRACE2_EVENT logs in a file. A negation mode is available that will be used in later tests. Helped-by: Jonathan Nieder Signed-off-by: Derrick Stolee --- .gitignore | 1 + Documentation/git-maintenance.txt | 57 +++++++++++++++++++++++++++++++ builtin.h | 1 + builtin/gc.c | 57 +++++++++++++++++++++++++++++++ command-list.txt | 1 + git.c | 1 + t/t7900-maintenance.sh | 21 ++++++++++++ t/test-lib-functions.sh | 33 ++++++++++++++++++ 8 files changed, 172 insertions(+) create mode 100644 Documentation/git-maintenance.txt create mode 100755 t/t7900-maintenance.sh diff --git a/.gitignore b/.gitignore index ee509a2ad2..a5808fa30d 100644 --- a/.gitignore +++ b/.gitignore @@ -90,6 +90,7 @@ /git-ls-tree /git-mailinfo /git-mailsplit +/git-maintenance /git-merge /git-merge-base /git-merge-index diff --git a/Documentation/git-maintenance.txt b/Documentation/git-maintenance.txt new file mode 100644 index 0000000000..ff47fb3641 --- /dev/null +++ b/Documentation/git-maintenance.txt @@ -0,0 +1,57 @@ +git-maintenance(1) +================== + +NAME +---- +git-maintenance - Run tasks to optimize Git repository data + + +SYNOPSIS +-------- +[verse] +'git maintenance' run [] + + +DESCRIPTION +----------- +Run tasks to optimize Git repository data, speeding up other Git commands +and reducing storage requirements for the repository. + +Git commands that add repository data, such as `git add` or `git fetch`, +are optimized for a responsive user experience. These commands do not take +time to optimize the Git data, since such optimizations scale with the full +size of the repository while these user commands each perform a relatively +small action. + +The `git maintenance` command provides flexibility for how to optimize the +Git repository. + +SUBCOMMANDS +----------- + +run:: + Run one or more maintenance tasks. + +TASKS +----- + +gc:: + Clean up unnecessary files and optimize the local repository. "GC" + stands for "garbage collection," but this task performs many + smaller tasks. This task can be expensive for large repositories, + as it repacks all Git objects into a single pack-file. It can also + be disruptive in some situations, as it deletes stale data. See + linkgit:git-gc[1] for more details on garbage collection in Git. + +OPTIONS +------- +--auto:: + When combined with the `run` subcommand, run maintenance tasks + only if certain thresholds are met. For example, the `gc` task + runs when the number of loose objects exceeds the number stored + in the `gc.auto` config setting, or when the number of pack-files + exceeds the `gc.autoPackLimit` config setting. + +GIT +--- +Part of the linkgit:git[1] suite diff --git a/builtin.h b/builtin.h index a5ae15bfe5..17c1c0ce49 100644 --- a/builtin.h +++ b/builtin.h @@ -167,6 +167,7 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix); int cmd_ls_remote(int argc, const char **argv, const char *prefix); int cmd_mailinfo(int argc, const char **argv, const char *prefix); int cmd_mailsplit(int argc, const char **argv, const char *prefix); +int cmd_maintenance(int argc, const char **argv, const char *prefix); int cmd_merge(int argc, const char **argv, const char *prefix); int cmd_merge_base(int argc, const char **argv, const char *prefix); int cmd_merge_index(int argc, const char **argv, const char *prefix); diff --git a/builtin/gc.c b/builtin/gc.c index aafa0946f5..7f2771e786 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -699,3 +699,60 @@ int cmd_gc(int argc, const char **argv, const char *prefix) return 0; } + +static const char * const builtin_maintenance_run_usage[] = { + N_("git maintenance run [--auto]"), + NULL +}; + +struct maintenance_run_opts { + int auto_flag; +}; + +static int maintenance_task_gc(struct maintenance_run_opts *opts) +{ + struct child_process child = CHILD_PROCESS_INIT; + + child.git_cmd = 1; + strvec_push(&child.args, "gc"); + + if (opts->auto_flag) + strvec_push(&child.args, "--auto"); + + close_object_store(the_repository->objects); + return run_command(&child); +} + +static int maintenance_run(int argc, const char **argv, const char *prefix) +{ + struct maintenance_run_opts opts; + struct option builtin_maintenance_run_options[] = { + OPT_BOOL(0, "auto", &opts.auto_flag, + N_("run tasks based on the state of the repository")), + OPT_END() + }; + memset(&opts, 0, sizeof(opts)); + + argc = parse_options(argc, argv, prefix, + builtin_maintenance_run_options, + builtin_maintenance_run_usage, + PARSE_OPT_STOP_AT_NON_OPTION); + + if (argc != 0) + usage_with_options(builtin_maintenance_run_usage, + builtin_maintenance_run_options); + return maintenance_task_gc(&opts); +} + +static const char builtin_maintenance_usage[] = N_("git maintenance run []"); + +int cmd_maintenance(int argc, const char **argv, const char *prefix) +{ + if (argc == 2 && !strcmp(argv[1], "-h")) + usage(builtin_maintenance_usage); + + if (!strcmp(argv[1], "run")) + return maintenance_run(argc - 1, argv + 1, prefix); + + die(_("invalid subcommand: %s"), argv[1]); +} diff --git a/command-list.txt b/command-list.txt index e5901f2213..0e3204e7d1 100644 --- a/command-list.txt +++ b/command-list.txt @@ -117,6 +117,7 @@ git-ls-remote plumbinginterrogators git-ls-tree plumbinginterrogators git-mailinfo purehelpers git-mailsplit purehelpers +git-maintenance mainporcelain git-merge mainporcelain history git-merge-base plumbinginterrogators git-merge-file plumbingmanipulators diff --git a/git.c b/git.c index 8bd1d7551d..24f250d29a 100644 --- a/git.c +++ b/git.c @@ -529,6 +529,7 @@ static struct cmd_struct commands[] = { { "ls-tree", cmd_ls_tree, RUN_SETUP }, { "mailinfo", cmd_mailinfo, RUN_SETUP_GENTLY | NO_PARSEOPT }, { "mailsplit", cmd_mailsplit, NO_PARSEOPT }, + { "maintenance", cmd_maintenance, RUN_SETUP_GENTLY | NO_PARSEOPT }, { "merge", cmd_merge, RUN_SETUP | NEED_WORK_TREE }, { "merge-base", cmd_merge_base, RUN_SETUP }, { "merge-file", cmd_merge_file, RUN_SETUP_GENTLY }, diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh new file mode 100755 index 0000000000..14aa691f19 --- /dev/null +++ b/t/t7900-maintenance.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +test_description='git maintenance builtin' + +. ./test-lib.sh + +test_expect_success 'help text' ' + test_expect_code 129 git maintenance -h 2>err && + test_i18ngrep "usage: git maintenance run" err && + test_expect_code 128 git maintenance barf 2>err && + test_i18ngrep "invalid subcommand: barf" err +' + +test_expect_success 'run [--auto]' ' + GIT_TRACE2_EVENT="$(pwd)/run-no-auto.txt" git maintenance run && + GIT_TRACE2_EVENT="$(pwd)/run-auto.txt" git maintenance run --auto && + test_subcommand git gc ... < +# +# For example, to look for an invocation of "git upload-pack +# /path/to/repo" +# +# GIT_TRACE2_EVENT=event.log git fetch ... && +# test_subcommand git upload-pack "$PATH" X-Patchwork-Id: 11757125 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 66B0991F for ; Fri, 4 Sep 2020 13:14:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 49D502078E for ; Fri, 4 Sep 2020 13:14:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XYY/snRK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730368AbgIDNL4 (ORCPT ); Fri, 4 Sep 2020 09:11:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730357AbgIDNJV (ORCPT ); Fri, 4 Sep 2020 09:09:21 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A27FC061246 for ; Fri, 4 Sep 2020 06:09:20 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id w2so6050408wmi.1 for ; Fri, 04 Sep 2020 06:09:20 -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=TNkZA0YzlqgpbaFMJJADNK04OIR3HUTxPD/4oyKldqI=; b=XYY/snRKk3IrqmEbsGwkw7TXrMEutt5gsveoDMGCc0+H8SWF2iQId8SkTdqkyKdCTO DGUje7/ZPhkKz5z9gdrxn+fC1zDJhvF6EqaP35ruC3Ioi2BrG9Y1pSNUBERXkDUy9Edm yvlEj87ZkWL5dmOLmDPBFpwYbx/Vi7vQG8ClRzhOcbq3Rtz+chdoE0PtGwm5cbEg2dqd jAmZPXgYeklMmYwWFnmralcFvE+rV0CXFU8lvd/0xYHV6/uX5JdvCKzwzhd4NBO1IohN xJTXRIJ+rf9h7dD/SjOki2y/YZfQtIql6WkSB8zoROopVCcLlOUXVs7EeUkPxiVEcP14 3fzg== 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=TNkZA0YzlqgpbaFMJJADNK04OIR3HUTxPD/4oyKldqI=; b=HiuS9+3q3xtqvBiqyHQJkt30HapeNHyuQESlMRb79be1dsdE0sIqIXys4R5SAa3H2H lcEwZbhbMq3x6BueXVwwRiTKlF7fuhkDVDi0Fhds+L27gYJHzMQDRc5Xft0HojFQrk4v M2IrwINXtQzR8LtdAiyMEkhTyjnnq3L4HoW1ReSjejmYncrMCbpyuOjVSZeC6zQfHXge GcehrheJ1c44nWJhbTFA4+Um/HkLtrHb7eFJdJKfcNZ0gxw8TlOUEXhAlVLZo2Xi3n87 /4YtBj7CdaQfZlJjyKxhLJIQa6PURQUvL0GMfDlbdg9Vn4/u8WhmOfGD0c+lf8m8p61p YrDQ== X-Gm-Message-State: AOAM533HMjQKFW2KapV6/Qu3jN1iGusUBH4NfquPcqpVV8ZntMVBEbgG Yfa8bAcfnD73h59W0x9InWmZ+YhED30= X-Google-Smtp-Source: ABdhPJzvL+mZTJpgpNIEE7Wn3YJwr226kkQsLeWBoWGG/qaXkKG0g/R3HxThEYETe/4TOnXPPc4KSA== X-Received: by 2002:a1c:b143:: with SMTP id a64mr7466392wmf.43.1599224959073; Fri, 04 Sep 2020 06:09:19 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 31sm11311889wrd.26.2020.09.04.06.09.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 06:09:18 -0700 (PDT) Message-Id: <5386d8a6283d814c0d0d2b7a180409f064cea709.1599224956.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Fri, 04 Sep 2020 13:09:06 +0000 Subject: [PATCH v4 02/11] maintenance: add --quiet option Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jonathan Tan , Derrick Stolee , Derrick Stolee Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee Maintenance activities are commonly used as steps in larger scripts. Providing a '--quiet' option allows those scripts to be less noisy when run on a terminal window. Turn this mode on by default when stderr is not a terminal. Pipe the option to the 'git gc' child process. Signed-off-by: Derrick Stolee --- Documentation/git-maintenance.txt | 3 +++ builtin/gc.c | 11 ++++++++++- t/t7900-maintenance.sh | 15 ++++++++++----- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/Documentation/git-maintenance.txt b/Documentation/git-maintenance.txt index ff47fb3641..04fa0fe329 100644 --- a/Documentation/git-maintenance.txt +++ b/Documentation/git-maintenance.txt @@ -52,6 +52,9 @@ OPTIONS in the `gc.auto` config setting, or when the number of pack-files exceeds the `gc.autoPackLimit` config setting. +--quiet:: + Do not report progress or other information over `stderr`. + GIT --- Part of the linkgit:git[1] suite diff --git a/builtin/gc.c b/builtin/gc.c index 7f2771e786..da11f1edcd 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -701,12 +701,13 @@ int cmd_gc(int argc, const char **argv, const char *prefix) } static const char * const builtin_maintenance_run_usage[] = { - N_("git maintenance run [--auto]"), + N_("git maintenance run [--auto] [--[no-]quiet]"), NULL }; struct maintenance_run_opts { int auto_flag; + int quiet; }; static int maintenance_task_gc(struct maintenance_run_opts *opts) @@ -718,6 +719,10 @@ static int maintenance_task_gc(struct maintenance_run_opts *opts) if (opts->auto_flag) strvec_push(&child.args, "--auto"); + if (opts->quiet) + strvec_push(&child.args, "--quiet"); + else + strvec_push(&child.args, "--no-quiet"); close_object_store(the_repository->objects); return run_command(&child); @@ -729,10 +734,14 @@ static int maintenance_run(int argc, const char **argv, const char *prefix) struct option builtin_maintenance_run_options[] = { OPT_BOOL(0, "auto", &opts.auto_flag, N_("run tasks based on the state of the repository")), + OPT_BOOL(0, "quiet", &opts.quiet, + N_("do not report progress or other information over stderr")), OPT_END() }; memset(&opts, 0, sizeof(opts)); + opts.quiet = !isatty(2); + argc = parse_options(argc, argv, prefix, builtin_maintenance_run_options, builtin_maintenance_run_usage, diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh index 14aa691f19..47d512464c 100755 --- a/t/t7900-maintenance.sh +++ b/t/t7900-maintenance.sh @@ -11,11 +11,16 @@ test_expect_success 'help text' ' test_i18ngrep "invalid subcommand: barf" err ' -test_expect_success 'run [--auto]' ' - GIT_TRACE2_EVENT="$(pwd)/run-no-auto.txt" git maintenance run && - GIT_TRACE2_EVENT="$(pwd)/run-auto.txt" git maintenance run --auto && - test_subcommand git gc /dev/null && + GIT_TRACE2_EVENT="$(pwd)/run-auto.txt" \ + git maintenance run --auto 2>/dev/null && + GIT_TRACE2_EVENT="$(pwd)/run-no-quiet.txt" \ + git maintenance run --no-quiet 2>/dev/null && + test_subcommand git gc --quiet X-Patchwork-Id: 11757107 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 D859D91F for ; Fri, 4 Sep 2020 13:10:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B5D092074D for ; Fri, 4 Sep 2020 13:10:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cGERB+D9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730400AbgIDNJ4 (ORCPT ); Fri, 4 Sep 2020 09:09:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730369AbgIDNJZ (ORCPT ); Fri, 4 Sep 2020 09:09:25 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77348C061249 for ; Fri, 4 Sep 2020 06:09:24 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id c19so7497804wmd.1 for ; Fri, 04 Sep 2020 06:09:24 -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=ZLD9qTyuUt057D6hwair//y9YNofza2ZxPWALwJ/KXI=; b=cGERB+D9d8099lvfHukXMh+inX2q8azqFivx1j2yx/p+mbCSaWzpelF6BMru0Q/Z1Q E/SIrmp/+KK2j+iB4X4oyO+G9ceKYjG3QUTqU7DE4sxXDDtKWWdzSe0XchIVVOAoQm2V k8Hgw5Cjv9k3bM7RgvHCizFrwVBEsGFdvmprr7RzHMQ/TRS7dgpa72nqxa8l2IMw96W7 aj7rBHKhT8BMxG04gdjYj4ZCdIGQyplklif7SjOb3364cF0Epue6FfO3nauLGmVTXUQ8 nDKmMUbFMGsjGlnQD4i3/qRyvbNiWtws3vbDM+2tgSDHxwtfAltO1c3jbB5NoO44kfM1 UwRQ== 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=ZLD9qTyuUt057D6hwair//y9YNofza2ZxPWALwJ/KXI=; b=DlDwargxUdChThOe+JpwJloj6l2hqUZg2AmCTmvyi4GQVFvqfVN3SmUfJB/T+d2pAD HwBw1HLcXm83S33Yt6EQhrhygDHSk5yryd+GBVNieDvvncOo/QW+lC+ft0C7rzwkh93L PGqfL0f/1B7s3C3BwA/mApvxEEG9bLWefcQeOF7uNNRWUazq5+EL7adk0MssPRCoGP92 9iWjG/pA2lvMgAspwkRKjwJ/HHRXdmx9f9AufEgYRE1XxQy9aYmEQz1sEGU/D6hHJqsW lW85DGW3FkDFUdUU87EGtkmV16T5/G74yviXtONsLPAtxoWkW6ZGx0auhiUK7Ajekh6j CALQ== X-Gm-Message-State: AOAM531+h+B6pcSmMTgNilXFRjhmNEyRzvXNatmzOiwPIi2zFJUyHLTT vjwFVU53ci8PNfeD/mBDdgXLe/9kRRk= X-Google-Smtp-Source: ABdhPJw8AA3CQ8DbJNkcAVUNWIU1JBRRUqGC8QadMiXOSe1dLiiz6sJf61AsuGA4mt4BNw0ZC/80+Q== X-Received: by 2002:a7b:cb47:: with SMTP id v7mr7998793wmj.129.1599224959883; Fri, 04 Sep 2020 06:09:19 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id x10sm11606703wmi.37.2020.09.04.06.09.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 06:09:19 -0700 (PDT) Message-Id: In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Fri, 04 Sep 2020 13:09:07 +0000 Subject: [PATCH v4 03/11] maintenance: replace run_auto_gc() Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jonathan Tan , Derrick Stolee , Derrick Stolee Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee The run_auto_gc() method is used in several places to trigger a check for repo maintenance after some Git commands, such as 'git commit' or 'git fetch'. To allow for extra customization of this maintenance activity, replace the 'git gc --auto [--quiet]' call with one to 'git maintenance run --auto [--quiet]'. As we extend the maintenance builtin with other steps, users will be able to select different maintenance activities. Rename run_auto_gc() to run_auto_maintenance() to be clearer what is happening on this call, and to expose all callers in the current diff. Rewrite the method to use a struct child_process to simplify the calls slightly. Since 'git fetch' already allows disabling the 'git gc --auto' subprocess, add an equivalent option with a different name to be more descriptive of the new behavior: '--[no-]maintenance'. Update the documentation to include these options at the same time. Signed-off-by: Derrick Stolee --- Documentation/fetch-options.txt | 6 ++++-- Documentation/git-clone.txt | 6 +++--- builtin/am.c | 2 +- builtin/commit.c | 2 +- builtin/fetch.c | 6 ++++-- builtin/merge.c | 2 +- builtin/rebase.c | 4 ++-- run-command.c | 16 +++++++--------- run-command.h | 2 +- t/t5510-fetch.sh | 2 +- 10 files changed, 25 insertions(+), 23 deletions(-) diff --git a/Documentation/fetch-options.txt b/Documentation/fetch-options.txt index 07d06ff445..b65a758661 100644 --- a/Documentation/fetch-options.txt +++ b/Documentation/fetch-options.txt @@ -95,9 +95,11 @@ ifndef::git-pull[] Allow several and arguments to be specified. No s may be specified. +--[no-]auto-maintenance:: --[no-]auto-gc:: - Run `git gc --auto` at the end to perform garbage collection - if needed. This is enabled by default. + Run `git maintenance run --auto` at the end to perform automatic + repository maintenance if needed. (`--[no-]auto-gc` is a synonym.) + This is enabled by default. --[no-]write-commit-graph:: Write a commit-graph after fetching. This overrides the config diff --git a/Documentation/git-clone.txt b/Documentation/git-clone.txt index c898310099..097e6a86c5 100644 --- a/Documentation/git-clone.txt +++ b/Documentation/git-clone.txt @@ -78,9 +78,9 @@ repository using this option and then delete branches (or use any other Git command that makes any existing commit unreferenced) in the source repository, some objects may become unreferenced (or dangling). These objects may be removed by normal Git operations (such as `git commit`) -which automatically call `git gc --auto`. (See linkgit:git-gc[1].) -If these objects are removed and were referenced by the cloned repository, -then the cloned repository will become corrupt. +which automatically call `git maintenance run --auto`. (See +linkgit:git-maintenance[1].) If these objects are removed and were referenced +by the cloned repository, then the cloned repository will become corrupt. + Note that running `git repack` without the `--local` option in a repository cloned with `--shared` will copy objects from the source repository into a pack diff --git a/builtin/am.c b/builtin/am.c index dd4e6c2d9b..68e9d17379 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -1795,7 +1795,7 @@ static void am_run(struct am_state *state, int resume) if (!state->rebasing) { am_destroy(state); close_object_store(the_repository->objects); - run_auto_gc(state->quiet); + run_auto_maintenance(state->quiet); } } diff --git a/builtin/commit.c b/builtin/commit.c index 69ac78d5e5..f9b0a0c05d 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -1702,7 +1702,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix) git_test_write_commit_graph_or_die(); repo_rerere(the_repository, 0); - run_auto_gc(quiet); + run_auto_maintenance(quiet); run_commit_hook(use_editor, get_index_file(), "post-commit", NULL); if (amend && !no_post_rewrite) { commit_post_rewrite(the_repository, current_head, &oid); diff --git a/builtin/fetch.c b/builtin/fetch.c index 2eb8d6a5a5..cb38e6f5ec 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -199,8 +199,10 @@ static struct option builtin_fetch_options[] = { OPT_STRING_LIST(0, "negotiation-tip", &negotiation_tip, N_("revision"), N_("report that we have only objects reachable from this object")), OPT_PARSE_LIST_OBJECTS_FILTER(&filter_options), + OPT_BOOL(0, "auto-maintenance", &enable_auto_gc, + N_("run 'maintenance --auto' after fetching")), OPT_BOOL(0, "auto-gc", &enable_auto_gc, - N_("run 'gc --auto' after fetching")), + N_("run 'maintenance --auto' after fetching")), OPT_BOOL(0, "show-forced-updates", &fetch_show_forced_updates, N_("check for forced-updates on all updated branches")), OPT_BOOL(0, "write-commit-graph", &fetch_write_commit_graph, @@ -1891,7 +1893,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix) close_object_store(the_repository->objects); if (enable_auto_gc) - run_auto_gc(verbosity < 0); + run_auto_maintenance(verbosity < 0); return result; } diff --git a/builtin/merge.c b/builtin/merge.c index 74829a838e..8f31bfab56 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -456,7 +456,7 @@ static void finish(struct commit *head_commit, * user should see them. */ close_object_store(the_repository->objects); - run_auto_gc(verbosity < 0); + run_auto_maintenance(verbosity < 0); } } if (new_head && show_diffstat) { diff --git a/builtin/rebase.c b/builtin/rebase.c index dadb52fa92..9ffba9009d 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -728,10 +728,10 @@ static int finish_rebase(struct rebase_options *opts) apply_autostash(state_dir_path("autostash", opts)); close_object_store(the_repository->objects); /* - * We ignore errors in 'gc --auto', since the + * We ignore errors in 'git maintenance run --auto', since the * user should see them. */ - run_auto_gc(!(opts->flags & (REBASE_NO_QUIET|REBASE_VERBOSE))); + run_auto_maintenance(!(opts->flags & (REBASE_NO_QUIET|REBASE_VERBOSE))); if (opts->type == REBASE_MERGE) { struct replay_opts replay = REPLAY_OPTS_INIT; diff --git a/run-command.c b/run-command.c index cc9c3296ba..2ee59acdc8 100644 --- a/run-command.c +++ b/run-command.c @@ -1866,15 +1866,13 @@ int run_processes_parallel_tr2(int n, get_next_task_fn get_next_task, return result; } -int run_auto_gc(int quiet) +int run_auto_maintenance(int quiet) { - struct strvec argv_gc_auto = STRVEC_INIT; - int status; + struct child_process maint = CHILD_PROCESS_INIT; - strvec_pushl(&argv_gc_auto, "gc", "--auto", NULL); - if (quiet) - strvec_push(&argv_gc_auto, "--quiet"); - status = run_command_v_opt(argv_gc_auto.v, RUN_GIT_CMD); - strvec_clear(&argv_gc_auto); - return status; + maint.git_cmd = 1; + strvec_pushl(&maint.args, "maintenance", "run", "--auto", NULL); + strvec_push(&maint.args, quiet ? "--quiet" : "--no-quiet"); + + return run_command(&maint); } diff --git a/run-command.h b/run-command.h index 8b9bfaef16..6472b38bde 100644 --- a/run-command.h +++ b/run-command.h @@ -221,7 +221,7 @@ int run_hook_ve(const char *const *env, const char *name, va_list args); /* * Trigger an auto-gc */ -int run_auto_gc(int quiet); +int run_auto_maintenance(int quiet); #define RUN_COMMAND_NO_STDIN 1 #define RUN_GIT_CMD 2 /*If this is to be git sub-command */ diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh index 2a1abe91f0..a9682c5669 100755 --- a/t/t5510-fetch.sh +++ b/t/t5510-fetch.sh @@ -934,7 +934,7 @@ test_expect_success 'fetching with auto-gc does not lock up' ' git config fetch.unpackLimit 1 && git config gc.autoPackLimit 1 && git config gc.autoDetach false && - GIT_ASK_YESNO="$D/askyesno" git fetch >fetch.out 2>&1 && + GIT_ASK_YESNO="$D/askyesno" git fetch --verbose >fetch.out 2>&1 && test_i18ngrep "Auto packing the repository" fetch.out && ! grep "Should I try again" fetch.out ) From patchwork Fri Sep 4 13:09:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver via GitGitGadget X-Patchwork-Id: 11757103 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 A286091F for ; Fri, 4 Sep 2020 13:09:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7B4402073B for ; Fri, 4 Sep 2020 13:09:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fWCxKm7A" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730395AbgIDNJt (ORCPT ); Fri, 4 Sep 2020 09:09:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730367AbgIDNJY (ORCPT ); Fri, 4 Sep 2020 09:09:24 -0400 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08698C061247 for ; Fri, 4 Sep 2020 06:09:22 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id o5so6650654wrn.13 for ; Fri, 04 Sep 2020 06:09:21 -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=Vl2kTUl6dSX+CyNd8PSqD1JASPC5be8B3MIBf7geL1k=; b=fWCxKm7AWCg764wP4Iml15zyPv3LvHTwNymAZdW8uMNeT205p2rhCXV9u4AqdO6XIA poepcIeg03hX/ow+leWyVGg7V6r74gi3sXz6rtYrol3dEIH98UORiTukBZjRs+3vKsyH 8PQ3P263JZminTJZH046GIWL8qYpzbyrUfO8WhaHubSsMb0cdIO5LK6Fm3GE/eXZgLKV ILg27mGjLF0p5+qUHwPUd+HmA7PIHqWolOVnY3cQxAO11OdN5MzWHmpctv2nuAigirWK i8BLHvpnzzmRKoExkx90HB3+Qt+nGpYTGzoJKdEEbPoSO2FY8iD4mVmrpyDXxHkbBrfH SwzA== 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=Vl2kTUl6dSX+CyNd8PSqD1JASPC5be8B3MIBf7geL1k=; b=ggHW9Qc1r9/ZN/FNrgYofOgOUQiXGPMN/0OmmKiBcomkuJe6401cK57YBwjGNEmxHH 3OiOh4AQ139TaEMneSCFTSyX+QfL9SWH6FPB0JAqCYL3MDqxY5zDtM2aiKEO1lzIRpOa LgGkrFHFq0PYKDHcz8VS4jMiv2iOg7iSAQmInHnE9iyGv0pdA/alGQ8sExGU2Egj58cp 4qhrDjGs3Fv5FYmsseYCY7U3cKaWyXUOW43BqF0oosbeGv6ksrPd18XLAEzCU8blhkJx 0RblmObR0FY8PMgaZAt7CK8rmk3bQhk6S3Yv8o+1dLaOxQCMGUpQak0G3YUSPVB3LtOA w9Hg== X-Gm-Message-State: AOAM533h19sbdbXtDkdmziLeoqp99Y6eRYD9ckije3Ur7T8OacNKfmlQ 9XgyX/6P2bU4ZoP84xrSvFxqTr9vpQk= X-Google-Smtp-Source: ABdhPJyN4fHumoarhV4fzEcp/jyynGr9rMHOFx8Xpx9vVUqQtv+rEbox2N7LAVSieDVY3liSNbEbOA== X-Received: by 2002:a5d:4388:: with SMTP id i8mr7543872wrq.365.1599224960567; Fri, 04 Sep 2020 06:09:20 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 128sm11128679wmz.43.2020.09.04.06.09.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 06:09:20 -0700 (PDT) Message-Id: <82326c1c38ca6d7ec71bddb50d33c1e5bc3421fb.1599224956.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Fri, 04 Sep 2020 13:09:08 +0000 Subject: [PATCH v4 04/11] maintenance: initialize task array Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jonathan Tan , Derrick Stolee , Derrick Stolee Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee In anticipation of implementing multiple maintenance tasks inside the 'maintenance' builtin, use a list of structs to describe the work to be done. The struct maintenance_task stores the name of the task (as given by a future command-line argument) along with a function pointer to its implementation and a boolean for whether the step is enabled. A list these structs are initialized with the full list of implemented tasks along with a default order. For now, this list only contains the "gc" task. This task is also the only task enabled by default. The run subcommand will return a nonzero exit code if any task fails. However, it will attempt all tasks in its loop before returning with the failure. Also each failed task will print an error message. Helped-by: Taylor Blau Helped-by: Junio C Hamano Signed-off-by: Derrick Stolee --- builtin/gc.c | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/builtin/gc.c b/builtin/gc.c index da11f1edcd..81643515e5 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -728,6 +728,47 @@ static int maintenance_task_gc(struct maintenance_run_opts *opts) return run_command(&child); } +typedef int maintenance_task_fn(struct maintenance_run_opts *opts); + +struct maintenance_task { + const char *name; + maintenance_task_fn *fn; + unsigned enabled:1; +}; + +enum maintenance_task_label { + TASK_GC, + + /* Leave as final value */ + TASK__COUNT +}; + +static struct maintenance_task tasks[] = { + [TASK_GC] = { + "gc", + maintenance_task_gc, + 1, + }, +}; + +static int maintenance_run_tasks(struct maintenance_run_opts *opts) +{ + int i; + int result = 0; + + for (i = 0; i < TASK__COUNT; i++) { + if (!tasks[i].enabled) + continue; + + if (tasks[i].fn(opts)) { + error(_("task '%s' failed"), tasks[i].name); + result = 1; + } + } + + return result; +} + static int maintenance_run(int argc, const char **argv, const char *prefix) { struct maintenance_run_opts opts; @@ -750,7 +791,7 @@ static int maintenance_run(int argc, const char **argv, const char *prefix) if (argc != 0) usage_with_options(builtin_maintenance_run_usage, builtin_maintenance_run_options); - return maintenance_task_gc(&opts); + return maintenance_run_tasks(&opts); } static const char builtin_maintenance_usage[] = N_("git maintenance run []"); From patchwork Fri Sep 4 13:09:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver via GitGitGadget X-Patchwork-Id: 11757105 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 6AF7991F for ; Fri, 4 Sep 2020 13:09:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4AEA82074D for ; Fri, 4 Sep 2020 13:09:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RJcUpyhj" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730401AbgIDNJx (ORCPT ); Fri, 4 Sep 2020 09:09:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730362AbgIDNJX (ORCPT ); Fri, 4 Sep 2020 09:09:23 -0400 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9A15C061244 for ; Fri, 4 Sep 2020 06:09:22 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id k15so6669723wrn.10 for ; Fri, 04 Sep 2020 06:09:22 -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=DYDzdATbEtsle88tIWHcnPVQI2YF/b2jAlzqwzreowg=; b=RJcUpyhjqlQV8Ia+RZeN/IVVO5Pi3ZZo9HY+WHHeXboSa9LJXmwDDkV3X8kegXv1NN gAOrd3ifPdelNsGZ+1bvVnK00VDDRCaP+5KuIpyhUN8vZQzcOevLae+g8VBFHmuBhLEn eantDuqXMgB1TJd2EBJThg+TEqDNIvfmC046Z2KNJYBcIAm1185SaxCgeg5jfAwuswY1 xFWWWw1V6Qo6QKA8sk4RV5VV4GfJPb7kzw5cF3DBbGoxj8T3LQvoY3J2XjQ7lFHvjxix qJZVUYd5S7m2mrYG3rf3ZjMn3wUFEuudjR5XqlW9KQXESrLeoPM5d+6Zd3uk3CX0eOj6 aXlg== 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=DYDzdATbEtsle88tIWHcnPVQI2YF/b2jAlzqwzreowg=; b=TUBMuMVaa88rfajgS12GfVAF9qvfi9jZc+BBkOCgC1dua7PjhS4q1nv5/BN4Vxh5Ad 1xXazwb79TaIXobf3bLMQJo69YW30Txo85fk1RBFhNOd2+ee95vadTygj1xbPVWSZ9Xj sbbDZCKQrW389BSXUAK7P2BeXyHiPvKbqnxjtxC6WidP+AiGvuT8KZxj+H57E0m7z/Bw e30tGv7e1SOMjLh/C2LuTBw6XuWvm/LH67DH8ulVQv4tG+FKaDuz8m/6VSHkDV4rGBeo VVzOACXrKsSJthAW6vk73Fdg6XwaL0By6qTVBnzCCmqVm9bt1/YfPhiHEa5m3e2hAY5z dpBQ== X-Gm-Message-State: AOAM532w1Gr4Ed1QultVPwHQq8HnVf5yWUeJ5+DmP3vhaPaow/rxVeMe nzTknP4XYLE/sOY65exO5zpdWfkY3Hw= X-Google-Smtp-Source: ABdhPJxZgdA9EWp0Zqfl727zYC73S0vCVT4B1v9dTKCiL5hZMLu6nUMprBJsVrIxOW4bRl8II0ADng== X-Received: by 2002:a5d:4246:: with SMTP id s6mr7322021wrr.414.1599224961367; Fri, 04 Sep 2020 06:09:21 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id f3sm11166185wmb.35.2020.09.04.06.09.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 06:09:20 -0700 (PDT) Message-Id: <06984a42bfc892b82f7b39a1aa366158fcf3fd20.1599224956.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Fri, 04 Sep 2020 13:09:09 +0000 Subject: [PATCH v4 05/11] maintenance: add commit-graph task Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jonathan Tan , Derrick Stolee , Derrick Stolee Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee The first new task in the 'git maintenance' builtin is the 'commit-graph' task. This updates the commit-graph file incrementally with the command git commit-graph write --reachable --split By writing an incremental commit-graph file using the "--split" option we minimize the disruption from this operation. The default behavior is to merge layers until the new "top" layer is less than half the size of the layer below. This provides quick writes most of the time, with the longer writes following a power law distribution. Most importantly, concurrent Git processes only look at the commit-graph-chain file for a very short amount of time, so they will verly likely not be holding a handle to the file when we try to replace it. (This only matters on Windows.) If a concurrent process reads the old commit-graph-chain file, but our job expires some of the .graph files before they can be read, then those processes will see a warning message (but not fail). This could be avoided by a future update to use the --expire-time argument when writing the commit-graph. Signed-off-by: Derrick Stolee --- Documentation/git-maintenance.txt | 8 ++++++++ builtin/gc.c | 30 ++++++++++++++++++++++++++++++ commit-graph.c | 8 ++++---- commit-graph.h | 1 + t/t7900-maintenance.sh | 2 ++ 5 files changed, 45 insertions(+), 4 deletions(-) diff --git a/Documentation/git-maintenance.txt b/Documentation/git-maintenance.txt index 04fa0fe329..fc5dbcf0b9 100644 --- a/Documentation/git-maintenance.txt +++ b/Documentation/git-maintenance.txt @@ -35,6 +35,14 @@ run:: TASKS ----- +commit-graph:: + The `commit-graph` job updates the `commit-graph` files incrementally, + then verifies that the written data is correct. The incremental + write is safe to run alongside concurrent Git processes since it + will not expire `.graph` files that were in the previous + `commit-graph-chain` file. They will be deleted by a later run based + on the expiration delay. + gc:: Clean up unnecessary files and optimize the local repository. "GC" stands for "garbage collection," but this task performs many diff --git a/builtin/gc.c b/builtin/gc.c index 81643515e5..16e567992e 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -710,6 +710,31 @@ struct maintenance_run_opts { int quiet; }; +static int run_write_commit_graph(struct maintenance_run_opts *opts) +{ + struct child_process child = CHILD_PROCESS_INIT; + + child.git_cmd = 1; + strvec_pushl(&child.args, "commit-graph", "write", + "--split", "--reachable", NULL); + + if (opts->quiet) + strvec_push(&child.args, "--no-progress"); + + return !!run_command(&child); +} + +static int maintenance_task_commit_graph(struct maintenance_run_opts *opts) +{ + close_object_store(the_repository->objects); + if (run_write_commit_graph(opts)) { + error(_("failed to write commit-graph")); + return 1; + } + + return 0; +} + static int maintenance_task_gc(struct maintenance_run_opts *opts) { struct child_process child = CHILD_PROCESS_INIT; @@ -738,6 +763,7 @@ struct maintenance_task { enum maintenance_task_label { TASK_GC, + TASK_COMMIT_GRAPH, /* Leave as final value */ TASK__COUNT @@ -749,6 +775,10 @@ static struct maintenance_task tasks[] = { maintenance_task_gc, 1, }, + [TASK_COMMIT_GRAPH] = { + "commit-graph", + maintenance_task_commit_graph, + }, }; static int maintenance_run_tasks(struct maintenance_run_opts *opts) diff --git a/commit-graph.c b/commit-graph.c index e51c91dd5b..a9b0db7d4a 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -172,7 +172,7 @@ static char *get_split_graph_filename(struct object_directory *odb, oid_hex); } -static char *get_chain_filename(struct object_directory *odb) +char *get_commit_graph_chain_filename(struct object_directory *odb) { return xstrfmt("%s/info/commit-graphs/commit-graph-chain", odb->path); } @@ -516,7 +516,7 @@ static struct commit_graph *load_commit_graph_chain(struct repository *r, struct stat st; struct object_id *oids; int i = 0, valid = 1, count; - char *chain_name = get_chain_filename(odb); + char *chain_name = get_commit_graph_chain_filename(odb); FILE *fp; int stat_res; @@ -1668,7 +1668,7 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx) } if (ctx->split) { - char *lock_name = get_chain_filename(ctx->odb); + char *lock_name = get_commit_graph_chain_filename(ctx->odb); hold_lock_file_for_update_mode(&lk, lock_name, LOCK_DIE_ON_ERROR, 0444); @@ -2038,7 +2038,7 @@ static void expire_commit_graphs(struct write_commit_graph_context *ctx) if (ctx->split_opts && ctx->split_opts->expire_time) expire_time = ctx->split_opts->expire_time; if (!ctx->split) { - char *chain_file_name = get_chain_filename(ctx->odb); + char *chain_file_name = get_commit_graph_chain_filename(ctx->odb); unlink(chain_file_name); free(chain_file_name); ctx->num_commit_graphs_after = 0; diff --git a/commit-graph.h b/commit-graph.h index 09a97030dc..765221cdcc 100644 --- a/commit-graph.h +++ b/commit-graph.h @@ -25,6 +25,7 @@ struct raw_object_store; struct string_list; char *get_commit_graph_filename(struct object_directory *odb); +char *get_commit_graph_chain_filename(struct object_directory *odb); int open_commit_graph(const char *graph_file, int *fd, struct stat *st); /* diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh index 47d512464c..c0c4e6846e 100755 --- a/t/t7900-maintenance.sh +++ b/t/t7900-maintenance.sh @@ -4,6 +4,8 @@ test_description='git maintenance builtin' . ./test-lib.sh +GIT_TEST_COMMIT_GRAPH=0 + test_expect_success 'help text' ' test_expect_code 129 git maintenance -h 2>err && test_i18ngrep "usage: git maintenance run" err && From patchwork Fri Sep 4 13:09:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver via GitGitGadget X-Patchwork-Id: 11757119 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 8D8EC91F for ; Fri, 4 Sep 2020 13:11:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6BF9F2073B for ; Fri, 4 Sep 2020 13:11:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YTFXBF7Z" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728588AbgIDNLI (ORCPT ); Fri, 4 Sep 2020 09:11:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730382AbgIDNJn (ORCPT ); Fri, 4 Sep 2020 09:09:43 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A237CC061258 for ; Fri, 4 Sep 2020 06:09:26 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id l9so6047008wme.3 for ; Fri, 04 Sep 2020 06:09:26 -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=305uUdjHb+4q6rX/VtEHpGfhWHIvwXgJSbT7kEvsmqc=; b=YTFXBF7Zu+AOFLu1q+WhffY58QTbAUyzZx2Gvz1nzCrJAidJAN8usGbpG+lbyrvOui DU/4LcjTysTy1uZriicAPGLVbUog6JxiJuHzUqRxUxPF/R+G4MCGfawQ9WtFRDmJ3/4X IZUjCebQjgjEe6NFACFIXr+nOx8+IWOcM3h33Vc2fu6qTyZGfaQmFbxXaoO7iQYK25la xzDgapjoqGNPpJyYk0u1EEa2KOzRYvIeQQoWE0fXDs1DUC9K7wUlwyr/lr79jywdWo9i 2LIOzkh+BTHruxMKqHXorIPMtdo4HN3U9O82YkH84KPgtuITcIuXQ9DkUt38YaVII+Kc MvOQ== 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=305uUdjHb+4q6rX/VtEHpGfhWHIvwXgJSbT7kEvsmqc=; b=dObB3D4KdPv5k6fxRsdgX+KVua8+Moziu3hGOVLq+dWo5UdegaWmIETqKkhxTzFWSV BrZ/7mMUlmmrOP1LI51WsiHdHv1DtJr694dS/dBpZYisd+odmvwuyHlyPWTUG2n99jTg tWMq8OTd8QqeJAwvV527bladBvEIfIJg8gHm+gRG9MZw5ueLw1U65cS3ZF3zOh/2cJZN bAOOHKvu+USNcdE6grGvbHhoVXB9Zj+HLhqWIRM5/tLS9QJYTjmxoJBGGevlX0Z+O3Np 2p/OKc59uOITURok4RTFSMydu/z/dgjCcw+epExbobKcJbndNEzc/yHlUYlSRKDlaLKt Khqw== X-Gm-Message-State: AOAM53197lRzz73Tmee8gibvJhIHE1TTF++TVN8lYyJyW+sKhtLvnJOx VPahCAAWfYJI4anuFTfsuCno6Ppcq2c= X-Google-Smtp-Source: ABdhPJzC0mHIEk+Tc69typbWSBi7tqY8iDbZXQsaNJV61VGtl1E+b9uDHyFSnIujogog4XCdnwN0Sg== X-Received: by 2002:a1c:415:: with SMTP id 21mr7203813wme.183.1599224962168; Fri, 04 Sep 2020 06:09:22 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id p16sm11521400wro.71.2020.09.04.06.09.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 06:09:21 -0700 (PDT) Message-Id: <69298aee24f317b03c39eef341f4d6ebebd88bc7.1599224956.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Fri, 04 Sep 2020 13:09:10 +0000 Subject: [PATCH v4 06/11] maintenance: add --task option Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jonathan Tan , Derrick Stolee , Derrick Stolee Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee A user may want to only run certain maintenance tasks in a certain order. Add the --task= option, which allows a user to specify an ordered list of tasks to run. These cannot be run multiple times, however. Here is where our array of maintenance_task pointers becomes critical. We can sort the array of pointers based on the task order, but we do not want to move the struct data itself in order to preserve the hashmap references. We use the hashmap to match the --task= arguments into the task struct data. Keep in mind that the 'enabled' member of the maintenance_task struct is a placeholder for a future 'maintenance..enabled' config option. Thus, we use the 'enabled' member to specify which tasks are run when the user does not specify any --task= arguments. The 'enabled' member should be ignored if --task= appears. Signed-off-by: Derrick Stolee --- Documentation/git-maintenance.txt | 9 ++++- builtin/gc.c | 66 +++++++++++++++++++++++++++++-- t/t7900-maintenance.sh | 27 +++++++++++++ 3 files changed, 98 insertions(+), 4 deletions(-) diff --git a/Documentation/git-maintenance.txt b/Documentation/git-maintenance.txt index fc5dbcf0b9..819ca41ab6 100644 --- a/Documentation/git-maintenance.txt +++ b/Documentation/git-maintenance.txt @@ -30,7 +30,9 @@ SUBCOMMANDS ----------- run:: - Run one or more maintenance tasks. + Run one or more maintenance tasks. If one or more `--task=` + options are specified, then those tasks are run in the provided + order. Otherwise, only the `gc` task is run. TASKS ----- @@ -63,6 +65,11 @@ OPTIONS --quiet:: Do not report progress or other information over `stderr`. +--task=:: + If this option is specified one or more times, then only run the + specified tasks in the specified order. See the 'TASKS' section + for the list of accepted `` values. + GIT --- Part of the linkgit:git[1] suite diff --git a/builtin/gc.c b/builtin/gc.c index 16e567992e..e94f263c77 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -701,7 +701,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix) } static const char * const builtin_maintenance_run_usage[] = { - N_("git maintenance run [--auto] [--[no-]quiet]"), + N_("git maintenance run [--auto] [--[no-]quiet] [--task=]"), NULL }; @@ -759,6 +759,9 @@ struct maintenance_task { const char *name; maintenance_task_fn *fn; unsigned enabled:1; + + /* -1 if not selected. */ + int selected_order; }; enum maintenance_task_label { @@ -781,13 +784,32 @@ static struct maintenance_task tasks[] = { }, }; +static int compare_tasks_by_selection(const void *a_, const void *b_) +{ + const struct maintenance_task *a, *b; + + a = (const struct maintenance_task *)&a_; + b = (const struct maintenance_task *)&b_; + + return b->selected_order - a->selected_order; +} + static int maintenance_run_tasks(struct maintenance_run_opts *opts) { - int i; + int i, found_selected = 0; int result = 0; + for (i = 0; !found_selected && i < TASK__COUNT; i++) + found_selected = tasks[i].selected_order >= 0; + + if (found_selected) + QSORT(tasks, TASK__COUNT, compare_tasks_by_selection); + for (i = 0; i < TASK__COUNT; i++) { - if (!tasks[i].enabled) + if (found_selected && tasks[i].selected_order < 0) + continue; + + if (!found_selected && !tasks[i].enabled) continue; if (tasks[i].fn(opts)) { @@ -799,20 +821,58 @@ static int maintenance_run_tasks(struct maintenance_run_opts *opts) return result; } +static int task_option_parse(const struct option *opt, + const char *arg, int unset) +{ + int i, num_selected = 0; + struct maintenance_task *task = NULL; + + BUG_ON_OPT_NEG(unset); + + for (i = 0; i < TASK__COUNT; i++) { + if (tasks[i].selected_order >= 0) + num_selected++; + if (!strcasecmp(tasks[i].name, arg)) { + task = &tasks[i]; + } + } + + if (!task) { + error(_("'%s' is not a valid task"), arg); + return 1; + } + + if (task->selected_order >= 0) { + error(_("task '%s' cannot be selected multiple times"), arg); + return 1; + } + + task->selected_order = num_selected + 1; + + return 0; +} + static int maintenance_run(int argc, const char **argv, const char *prefix) { + int i; struct maintenance_run_opts opts; struct option builtin_maintenance_run_options[] = { OPT_BOOL(0, "auto", &opts.auto_flag, N_("run tasks based on the state of the repository")), OPT_BOOL(0, "quiet", &opts.quiet, N_("do not report progress or other information over stderr")), + OPT_CALLBACK_F(0, "task", NULL, N_("task"), + N_("run a specific task"), + PARSE_OPT_NONEG, task_option_parse), OPT_END() }; memset(&opts, 0, sizeof(opts)); opts.quiet = !isatty(2); + for (i = 0; i < TASK__COUNT; i++) + tasks[i].selected_order = -1; + argc = parse_options(argc, argv, prefix, builtin_maintenance_run_options, builtin_maintenance_run_usage, diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh index c0c4e6846e..792765aff7 100755 --- a/t/t7900-maintenance.sh +++ b/t/t7900-maintenance.sh @@ -25,4 +25,31 @@ test_expect_success 'run [--auto|--quiet]' ' test_subcommand git gc --no-quiet ' ' + GIT_TRACE2_EVENT="$(pwd)/run-commit-graph.txt" \ + git maintenance run --task=commit-graph 2>/dev/null && + GIT_TRACE2_EVENT="$(pwd)/run-gc.txt" \ + git maintenance run --task=gc 2>/dev/null && + GIT_TRACE2_EVENT="$(pwd)/run-commit-graph.txt" \ + git maintenance run --task=commit-graph 2>/dev/null && + GIT_TRACE2_EVENT="$(pwd)/run-both.txt" \ + git maintenance run --task=commit-graph --task=gc 2>/dev/null && + test_subcommand ! git gc --quiet err && + test_i18ngrep "is not a valid task" err +' + +test_expect_success 'run --task duplicate' ' + test_must_fail git maintenance run --task=gc --task=gc 2>err && + test_i18ngrep "cannot be selected multiple times" err +' + test_done From patchwork Fri Sep 4 13:09:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver via GitGitGadget X-Patchwork-Id: 11757109 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 DE5D313B1 for ; Fri, 4 Sep 2020 13:10:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C1596206F2 for ; Fri, 4 Sep 2020 13:10:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IS1yQg56" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730404AbgIDNKB (ORCPT ); Fri, 4 Sep 2020 09:10:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730379AbgIDNJZ (ORCPT ); Fri, 4 Sep 2020 09:09:25 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8EA44C06124F for ; Fri, 4 Sep 2020 06:09:24 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id a9so6056235wmm.2 for ; Fri, 04 Sep 2020 06:09:24 -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=M2VGT+0ymSl4SLlTLpbNJM/6HbTEkqPEnqmtuttPwRc=; b=IS1yQg56ZMy+523g9DFLchLkJptyoU8oP6t0HEZuaDHdP6HRj2MKjG9EBGK8PTuv9i ShPQaxCfeh3XhNZ0ig8sYp2k6qYHcUdZW4qf8p+gqGBtRLMQdu02P61epZTplUpy7M2K LWj/o/uNAB0uXTOrrwBTx87mcODIK/ryyOiZyIp70dfehZp3GSlEDf5A2uO4XuoQ9Po4 9Is0KwSCGP/KD4F3DZyanOUxdeLUH6M3Sr7CSiY/1gB0W1uyKt+pcEKJgMwKqKx3xqyl 8fItZuVWE+1Wjymt6s/DOkHCA+jaJSpVA6Ac76Ynmea1P2Mvel97oLyD59wi2cr1fYRP A8Qg== 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=M2VGT+0ymSl4SLlTLpbNJM/6HbTEkqPEnqmtuttPwRc=; b=MHtjBiyyb9RBJwf8LqLdObfSxK5Y8a2Z+/ncpvmpMIXlA5jpZVkGb7dNvixn5j30O3 evKAQHkSxtB9LIPhwAdGeyMxgRUtnRZ1SeLGKVEPezmKt2kXfMiJ7E9ec+R3e1yPHE18 7zVVXp62sAPbDAPiZcJYMdmtxfkUahKg50vk89QNRgdU6XUKPzVlV7A/NRoxc4nylJor iOVDIydUWpNTln+5gl6grQvJ1JcvwqQtwZvWZUuN5/++5DrSVJSUTyz12rCkB9Ed0ug8 kS9NKo7srYGEaiMPMX3Voo4Z6iQ90k2rja/optgxyCuTSp902bXs80gwVV2rXREm8ixY NL+Q== X-Gm-Message-State: AOAM531uMgB14D4FGMMQ3y9gp4nZpfONGcQRh5gQmpseKInM6nZc5isl 06v49wvzBcaqL4f5NTjqc5L3+0sWMdU= X-Google-Smtp-Source: ABdhPJyts7/OkHfCrZuAPM7Ko+guxQs0XkbdxVsmgsFDNfel9oRUCaOu907ny8LycCbublAZRlYfwQ== X-Received: by 2002:a05:600c:22d1:: with SMTP id 17mr3525939wmg.58.1599224963044; Fri, 04 Sep 2020 06:09:23 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id c14sm11052437wrv.12.2020.09.04.06.09.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 06:09:22 -0700 (PDT) Message-Id: In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Fri, 04 Sep 2020 13:09:11 +0000 Subject: [PATCH v4 07/11] maintenance: take a lock on the objects directory Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jonathan Tan , Derrick Stolee , Derrick Stolee Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee Performing maintenance on a Git repository involves writing data to the .git directory, which is not safe to do with multiple writers attempting the same operation. Ensure that only one 'git maintenance' process is running at a time by holding a file-based lock. Simply the presence of the .git/maintenance.lock file will prevent future maintenance. This lock is never committed, since it does not represent meaningful data. Instead, it is only a placeholder. If the lock file already exists, then no maintenance tasks are attempted. This will become very important later when we implement the 'prefetch' task, as this is our stop-gap from creating a recursive process loop between 'git fetch' and 'git maintenance run --auto'. Signed-off-by: Derrick Stolee --- builtin/gc.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/builtin/gc.c b/builtin/gc.c index e94f263c77..1cebb7282d 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -798,6 +798,25 @@ static int maintenance_run_tasks(struct maintenance_run_opts *opts) { int i, found_selected = 0; int result = 0; + struct lock_file lk; + struct repository *r = the_repository; + char *lock_path = xstrfmt("%s/maintenance", r->objects->odb->path); + + if (hold_lock_file_for_update(&lk, lock_path, LOCK_NO_DEREF) < 0) { + /* + * Another maintenance command is running. + * + * If --auto was provided, then it is likely due to a + * recursive process stack. Do not report an error in + * that case. + */ + if (!opts->auto_flag && !opts->quiet) + warning(_("lock file '%s' exists, skipping maintenance"), + lock_path); + free(lock_path); + return 0; + } + free(lock_path); for (i = 0; !found_selected && i < TASK__COUNT; i++) found_selected = tasks[i].selected_order >= 0; @@ -818,6 +837,7 @@ static int maintenance_run_tasks(struct maintenance_run_opts *opts) } } + rollback_lock_file(&lk); return result; } From patchwork Fri Sep 4 13:09:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver via GitGitGadget X-Patchwork-Id: 11757121 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 72B5191F for ; Fri, 4 Sep 2020 13:11:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 547202074D for ; Fri, 4 Sep 2020 13:11:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="P6v7QAzq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730415AbgIDNLQ (ORCPT ); Fri, 4 Sep 2020 09:11:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730329AbgIDNJn (ORCPT ); Fri, 4 Sep 2020 09:09:43 -0400 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2114C061251 for ; Fri, 4 Sep 2020 06:09:25 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id x14so6661301wrl.12 for ; Fri, 04 Sep 2020 06:09:25 -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=vK6iK0+RvphJs0HeXxn440+72BWzbhU3tPC7lZ3S1Hw=; b=P6v7QAzq1/Zjdr4RUlhplxdfHXJtz3L5YhleIey0JDqZNLiX2+n9BS+W3uHpCv9wGI P+E6j7/bYJ085GrNF4GquUreDEGRaQWOmtqs0XGdPc7/kTYkIj2MUq6i/HWvBjfaI3Lq 2l3jmFAIUsbsONbdvhbpKHe3UZuVsJw1lXVqHuRxFQ+XIU/u6qg9rn1a7iMFKnseEjPw Pso+H4m18wNcxdeU1CVRH0G+tBAK923jJ3crrjYM7Fvy8h5Spy4+v2OoJ/pFpL7TuLXB UFWbc4IUg7716qa0gu1bnduLghfEz9h2kc3THSdhikFMfvidaFk/hYOvQ5sQnd7QDSfa z+IA== 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=vK6iK0+RvphJs0HeXxn440+72BWzbhU3tPC7lZ3S1Hw=; b=dfVscw2HAc0T91M/eQ6Vrv2toJ9EOEzZIKKIZ1DxZ5zgOi+YyPQJbUGhManwzNiUgQ L1CaGKXtOiMTpmpzde/mZQBM3DG8J4HTzMjGxrFF1fO6LyAN1jDmE1na9a7lnmdIq0/P BPfrSvEqGz7Ijttb8nOWKeKsoLPpyu4VEuIaqji0L7xLECXorMhadnK/DSJ4PkvE4I2P EeQjmdCfqNR2XQNZJOrU/Kkfl5m3QHCX+EiYKFpEdIymyqVgE121n2q0bUMic8+EFHZx 4F5JUL3kwLXqF02ZwOwCck5Dli8GkKefITo1VL4nPuMdTGYFYzUA50g6dCzc9XWr/wQB g3Dw== X-Gm-Message-State: AOAM531ANhewrUTCadJrfnI/UmSt89PuPcyAqfmszm0IrxsRhnadS3ik uyKUqHdNCSxYzuk+a09dhR/OW2xMofk= X-Google-Smtp-Source: ABdhPJzV7T9T6RM5GxGjHXCg96Bw22UwplnU2jx+BQzQ93eXuQ2oJSxVW1kJAw02dUjtL8ifAuaxuw== X-Received: by 2002:adf:8405:: with SMTP id 5mr7524716wrf.393.1599224963876; Fri, 04 Sep 2020 06:09:23 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id t1sm10327039wmi.16.2020.09.04.06.09.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 06:09:23 -0700 (PDT) Message-Id: In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Fri, 04 Sep 2020 13:09:12 +0000 Subject: [PATCH v4 08/11] maintenance: create maintenance..enabled config Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jonathan Tan , Derrick Stolee , Derrick Stolee Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee Currently, a normal run of "git maintenance run" will only run the 'gc' task, as it is the only one enabled. This is mostly for backwards- compatible reasons since "git maintenance run --auto" commands replaced previous "git gc --auto" commands after some Git processes. Users could manually run specific maintenance tasks by calling "git maintenance run --task=" directly. Allow users to customize which steps are run automatically using config. The 'maintenance..enabled' option then can turn on these other tasks (or turn off the 'gc' task). Signed-off-by: Derrick Stolee --- Documentation/config.txt | 2 ++ Documentation/config/maintenance.txt | 6 ++++++ Documentation/git-maintenance.txt | 14 +++++++++----- builtin/gc.c | 19 +++++++++++++++++++ t/t7900-maintenance.sh | 8 ++++++++ 5 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 Documentation/config/maintenance.txt diff --git a/Documentation/config.txt b/Documentation/config.txt index 3042d80978..f93b6837e4 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -398,6 +398,8 @@ include::config/mailinfo.txt[] include::config/mailmap.txt[] +include::config/maintenance.txt[] + include::config/man.txt[] include::config/merge.txt[] diff --git a/Documentation/config/maintenance.txt b/Documentation/config/maintenance.txt new file mode 100644 index 0000000000..4402b8b49f --- /dev/null +++ b/Documentation/config/maintenance.txt @@ -0,0 +1,6 @@ +maintenance..enabled:: + This boolean config option controls whether the maintenance task + with name `` is run when no `--task` option is specified to + `git maintenance run`. These config values are ignored if a + `--task` option exists. By default, only `maintenance.gc.enabled` + is true. diff --git a/Documentation/git-maintenance.txt b/Documentation/git-maintenance.txt index 819ca41ab6..6abcb8255a 100644 --- a/Documentation/git-maintenance.txt +++ b/Documentation/git-maintenance.txt @@ -30,9 +30,11 @@ SUBCOMMANDS ----------- run:: - Run one or more maintenance tasks. If one or more `--task=` - options are specified, then those tasks are run in the provided - order. Otherwise, only the `gc` task is run. + Run one or more maintenance tasks. If one or more `--task` options + are specified, then those tasks are run in that order. Otherwise, + the tasks are determined by which `maintenance..enabled` + config options are true. By default, only `maintenance.gc.enabled` + is true. TASKS ----- @@ -67,8 +69,10 @@ OPTIONS --task=:: If this option is specified one or more times, then only run the - specified tasks in the specified order. See the 'TASKS' section - for the list of accepted `` values. + specified tasks in the specified order. If no `--task=` + arguments are specified, then only the tasks with + `maintenance..enabled` configured as `true` are considered. + See the 'TASKS' section for the list of accepted `` values. GIT --- diff --git a/builtin/gc.c b/builtin/gc.c index 1cebb7282d..67a8d405a1 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -841,6 +841,24 @@ static int maintenance_run_tasks(struct maintenance_run_opts *opts) return result; } +static void initialize_task_config(void) +{ + int i; + struct strbuf config_name = STRBUF_INIT; + for (i = 0; i < TASK__COUNT; i++) { + int config_value; + + strbuf_setlen(&config_name, 0); + strbuf_addf(&config_name, "maintenance.%s.enabled", + tasks[i].name); + + if (!git_config_get_bool(config_name.buf, &config_value)) + tasks[i].enabled = config_value; + } + + strbuf_release(&config_name); +} + static int task_option_parse(const struct option *opt, const char *arg, int unset) { @@ -889,6 +907,7 @@ static int maintenance_run(int argc, const char **argv, const char *prefix) memset(&opts, 0, sizeof(opts)); opts.quiet = !isatty(2); + initialize_task_config(); for (i = 0; i < TASK__COUNT; i++) tasks[i].selected_order = -1; diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh index 792765aff7..290abb7832 100755 --- a/t/t7900-maintenance.sh +++ b/t/t7900-maintenance.sh @@ -25,6 +25,14 @@ test_expect_success 'run [--auto|--quiet]' ' test_subcommand git gc --no-quiet .enabled' ' + git config maintenance.gc.enabled false && + git config maintenance.commit-graph.enabled true && + GIT_TRACE2_EVENT="$(pwd)/run-config.txt" git maintenance run 2>err && + test_subcommand ! git gc --quiet ' ' GIT_TRACE2_EVENT="$(pwd)/run-commit-graph.txt" \ git maintenance run --task=commit-graph 2>/dev/null && From patchwork Fri Sep 4 13:09:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver via GitGitGadget X-Patchwork-Id: 11757115 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 DBA4991F for ; Fri, 4 Sep 2020 13:10:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C0B1C2073B for ; Fri, 4 Sep 2020 13:10:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ra0eBoqD" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730371AbgIDNKc (ORCPT ); Fri, 4 Sep 2020 09:10:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730310AbgIDNJo (ORCPT ); Fri, 4 Sep 2020 09:09:44 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A561C06125F for ; Fri, 4 Sep 2020 06:09:29 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id c18so6674222wrm.9 for ; Fri, 04 Sep 2020 06:09:29 -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=vM0TuBEUY0vrapOf9Ut/0RUxanAqe66yuP0tCUJZssI=; b=ra0eBoqDvpwpl4l0/WutvwI/Co4gIEAl+omM2rqmUZorvLAg8Cyii7PNyQdnGjFPhx TLPm9VQWAZxGecor6BzRVpXL2PdqR4XThS4lWH7XCByl2xqV7kD+BqAqR+6xIrQxySmt B45RI4Flma59LBpSy9nbA8VkGnb9dj4NXC0ZJgmWAjVr/JUeqFOvYqKjL0Z9Y0pUY0mt h/jQQ82xUAFCgLB+jsOViwD1qsayARlP0DiC81tBnGu1It8MrXW6okN29UwqwoTIXzNP vnmU70BdMGmYlSbIO1gbZs6KsIK273MgjSmfzXck+3k3XR6SGcsjZJ7EdMCdUq6Avwn7 1uNA== 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=vM0TuBEUY0vrapOf9Ut/0RUxanAqe66yuP0tCUJZssI=; b=pt3Ma0oZcRwIFb9fnWaemSnsS768UtI+QLZdAsQ3ija+bmQeFlH/RwON2wuf1+S0Lf qslWveB8OF1SsxjZVbloYUHvPV0Voj47fXsdJvDn9bIT6kYdotSbT1wv1k4TCbnoBuy0 i0jE9tT4kB2GBEd6X5XLsGmCFEU92zTVznUkdgw/9TKrT0YX4nSKI3wdAf6h4bzzEvTr 5qMtxWzqxnf/NLAWqyVgvSqyL1lCRroxtQA6xEJtMthaE/vfSGy2JGdOAKwxTv7wpe0H 75HMZQDgRi1t9c2ddFrJqxNlQyCm9IlEJySsm461SQlHfQmFbFf75rQLtoNl/zCsZguT 85Yg== X-Gm-Message-State: AOAM533TpV6xD0FL1cd//kHpP9dRkv8ssjLEnaFvGfRj8CYJum/nhXUX 8qEi6Is1IAvWwVdVw7Hcjwn3XIckAtU= X-Google-Smtp-Source: ABdhPJw+QThH6BxVlt2GdMQWXXo79+3VJw6/AVrTIxaIUqBCiSoj2SqJHXdKeorh4FFWRwVBOC8KNA== X-Received: by 2002:a5d:69cd:: with SMTP id s13mr7320907wrw.379.1599224965005; Fri, 04 Sep 2020 06:09:25 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id y6sm11413855wrt.80.2020.09.04.06.09.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 06:09:24 -0700 (PDT) Message-Id: In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Fri, 04 Sep 2020 13:09:13 +0000 Subject: [PATCH v4 09/11] maintenance: use pointers to check --auto Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jonathan Tan , Derrick Stolee , Derrick Stolee Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee The 'git maintenance run' command has an '--auto' option. This is used by other Git commands such as 'git commit' or 'git fetch' to check if maintenance should be run after adding data to the repository. Previously, this --auto option was only used to add the argument to the 'git gc' command as part of the 'gc' task. We will be expanding the other tasks to perform a check to see if they should do work as part of the --auto flag, when they are enabled by config. First, update the 'gc' task to perform the auto check inside the maintenance process. This prevents running an extra 'git gc --auto' command when not needed. It also shows a model for other tasks. Second, use the 'auto_condition' function pointer as a signal for whether we enable the maintenance task under '--auto'. For instance, we do not want to enable the 'fetch' task in '--auto' mode, so that function pointer will remain NULL. Now that we are not automatically calling 'git gc', a test in t5514-fetch-multiple.sh must be changed to watch for 'git maintenance' instead. We continue to pass the '--auto' option to the 'git gc' command when necessary, because of the gc.autoDetach config option changes behavior. Likely, we will want to absorb the daemonizing behavior implied by gc.autoDetach as a maintenance.autoDetach config option. Signed-off-by: Derrick Stolee --- builtin/gc.c | 16 ++++++++++++++++ t/t5514-fetch-multiple.sh | 2 +- t/t7900-maintenance.sh | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/builtin/gc.c b/builtin/gc.c index 67a8d405a1..709d13553b 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -755,9 +755,17 @@ static int maintenance_task_gc(struct maintenance_run_opts *opts) typedef int maintenance_task_fn(struct maintenance_run_opts *opts); +/* + * An auto condition function returns 1 if the task should run + * and 0 if the task should NOT run. See needs_to_gc() for an + * example. + */ +typedef int maintenance_auto_fn(void); + struct maintenance_task { const char *name; maintenance_task_fn *fn; + maintenance_auto_fn *auto_condition; unsigned enabled:1; /* -1 if not selected. */ @@ -776,6 +784,7 @@ static struct maintenance_task tasks[] = { [TASK_GC] = { "gc", maintenance_task_gc, + need_to_gc, 1, }, [TASK_COMMIT_GRAPH] = { @@ -831,6 +840,11 @@ static int maintenance_run_tasks(struct maintenance_run_opts *opts) if (!found_selected && !tasks[i].enabled) continue; + if (opts->auto_flag && + (!tasks[i].auto_condition || + !tasks[i].auto_condition())) + continue; + if (tasks[i].fn(opts)) { error(_("task '%s' failed"), tasks[i].name); result = 1; @@ -845,6 +859,8 @@ static void initialize_task_config(void) { int i; struct strbuf config_name = STRBUF_INIT; + gc_config(); + for (i = 0; i < TASK__COUNT; i++) { int config_value; diff --git a/t/t5514-fetch-multiple.sh b/t/t5514-fetch-multiple.sh index de8e2f1531..bd202ec6f3 100755 --- a/t/t5514-fetch-multiple.sh +++ b/t/t5514-fetch-multiple.sh @@ -108,7 +108,7 @@ test_expect_success 'git fetch --multiple (two remotes)' ' GIT_TRACE=1 git fetch --multiple one two 2>trace && git branch -r > output && test_cmp ../expect output && - grep "built-in: git gc" trace >gc && + grep "built-in: git maintenance" trace >gc && test_line_count = 1 gc ) ' diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh index 290abb7832..4f6a04ddb1 100755 --- a/t/t7900-maintenance.sh +++ b/t/t7900-maintenance.sh @@ -21,7 +21,7 @@ test_expect_success 'run [--auto|--quiet]' ' GIT_TRACE2_EVENT="$(pwd)/run-no-quiet.txt" \ git maintenance run --no-quiet 2>/dev/null && test_subcommand git gc --quiet X-Patchwork-Id: 11757117 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 B38E991F for ; Fri, 4 Sep 2020 13:11:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 966732078E for ; Fri, 4 Sep 2020 13:11:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="goxmNeNr" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730406AbgIDNKf (ORCPT ); Fri, 4 Sep 2020 09:10:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730360AbgIDNJo (ORCPT ); Fri, 4 Sep 2020 09:09:44 -0400 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69618C06125C for ; Fri, 4 Sep 2020 06:09:27 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id m6so6738253wrn.0 for ; Fri, 04 Sep 2020 06:09:27 -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=IqlsW4gQipo4j4B7Cy/KcruVIvhTi311pawh+Do+0uA=; b=goxmNeNr19Sy1271h7Ts3no9g6Kj3uCbVRqtZdDanUPo5Ay9rkHC1UqNTDIe5HbiKv Jw+Bit7tHJMkvxCYT4c3c6V76lE9wg8A24O29pxN+6SDOJMrcTkzXygNGFY+YFlhAn7Q KSC5XSooa0LESQWX2rTEGrl8nmDO7U/7QAD9yqJs1hhtgYJ9cK0euVQVYo1HuMKvjxe9 uDVEKmoswLUmmteaSL9LSUiPFD37F6dvT1+ttutT2BM5zx5rapzlG653wM9rXOcMoGb8 z16UzLoaptvUYmslcTpQI5yAZh9dj0T9UKPDNGR3uofTQ9rkJdkpQ0cC70zvNJzVOSNI wckA== 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=IqlsW4gQipo4j4B7Cy/KcruVIvhTi311pawh+Do+0uA=; b=mRwFH1YO/GOeQIZlcLJjHGGyOGrcY4YZiHfaliOxD0mGWtYX4DbA4J4TyfLD1SNwEg qv0Qn6JstYmvTY7uuWVC+Hniwk4g/MsaZcw41oGQgxuQoZfHRLi7B86UV5sdZ1NXVVBn lwxgD2c732CfYcWw3ahHxm1dYnN+qlybFd7IJDC8OLkl1wMfxXiIExFM7JZHZayL84Lz Wb7HPZR7r3BY1t9dHSY433/ui7TdU5Zd+ghES7IJziymofQFia6/w2GLqlfkq2LjiGVs 91hdUct4yeiDXnmqugQ5WtJtmv0jBwOXZV65K3xFXuZqDX5oURi602ZRY2TXNxEo6zxt aQSg== X-Gm-Message-State: AOAM532fYDCMBHs+3dVJjYqXRt96DucKat6Wznf6xCuiWLu9kKM6LacM UF5MMN0UBNTHKKht6+5K9uN+3dJRuxg= X-Google-Smtp-Source: ABdhPJzxmxJ+NCZHw47KveIwmuaeJQ/9A4cAbiygBWU2NjIhJtEGaYLNflKj8KkkKyJ5mwrMfXs5tQ== X-Received: by 2002:adf:f0c7:: with SMTP id x7mr7417141wro.315.1599224965898; Fri, 04 Sep 2020 06:09:25 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id f126sm10492123wmf.13.2020.09.04.06.09.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 06:09:25 -0700 (PDT) Message-Id: <8f84b03c4651681af1eb3512bd7c062c3a4c6d95.1599224956.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Fri, 04 Sep 2020 13:09:14 +0000 Subject: [PATCH v4 10/11] maintenance: add auto condition for commit-graph task Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jonathan Tan , Derrick Stolee , Derrick Stolee Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee Instead of writing a new commit-graph in every 'git maintenance run --auto' process (when maintenance.commit-graph.enalbed is configured to be true), only write when there are "enough" commits not in a commit-graph file. This count is controlled by the maintenance.commit-graph.auto config option. To compute the count, use a depth-first search starting at each ref, and leaving markers using the SEEN flag. If this count reaches the limit, then terminate early and start the task. Otherwise, this operation will peel every ref and parse the commit it points to. If these are all in the commit-graph, then this is typically a very fast operation. Users with many refs might feel a slow-down, and hence could consider updating their limit to be very small. A negative value will force the step to run every time. Signed-off-by: Derrick Stolee --- Documentation/config/maintenance.txt | 10 ++++ builtin/gc.c | 82 ++++++++++++++++++++++++++++ object.h | 1 + 3 files changed, 93 insertions(+) diff --git a/Documentation/config/maintenance.txt b/Documentation/config/maintenance.txt index 4402b8b49f..7cc6700d57 100644 --- a/Documentation/config/maintenance.txt +++ b/Documentation/config/maintenance.txt @@ -4,3 +4,13 @@ maintenance..enabled:: `git maintenance run`. These config values are ignored if a `--task` option exists. By default, only `maintenance.gc.enabled` is true. + +maintenance.commit-graph.auto:: + This integer config option controls how often the `commit-graph` task + should be run as part of `git maintenance run --auto`. If zero, then + the `commit-graph` task will not run with the `--auto` option. A + negative value will force the task to run every time. Otherwise, a + positive value implies the command should run when the number of + reachable commits that are not in the commit-graph file is at least + the value of `maintenance.commit-graph.auto`. The default value is + 100. diff --git a/builtin/gc.c b/builtin/gc.c index 709d13553b..8c4edf19ba 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -28,6 +28,7 @@ #include "blob.h" #include "tree.h" #include "promisor-remote.h" +#include "refs.h" #define FAILED_RUN "failed to run %s" @@ -710,6 +711,86 @@ struct maintenance_run_opts { int quiet; }; +/* Remember to update object flag allocation in object.h */ +#define SEEN (1u<<0) + +struct cg_auto_data { + int num_not_in_graph; + int limit; +}; + +static int dfs_on_ref(const char *refname, + const struct object_id *oid, int flags, + void *cb_data) +{ + struct cg_auto_data *data = (struct cg_auto_data *)cb_data; + int result = 0; + struct object_id peeled; + struct commit_list *stack = NULL; + struct commit *commit; + + if (!peel_ref(refname, &peeled)) + oid = &peeled; + if (oid_object_info(the_repository, oid, NULL) != OBJ_COMMIT) + return 0; + + commit = lookup_commit(the_repository, oid); + if (!commit) + return 0; + if (parse_commit(commit)) + return 0; + + commit_list_append(commit, &stack); + + while (!result && stack) { + struct commit_list *parent; + + commit = pop_commit(&stack); + + for (parent = commit->parents; parent; parent = parent->next) { + if (parse_commit(parent->item) || + commit_graph_position(parent->item) != COMMIT_NOT_FROM_GRAPH || + parent->item->object.flags & SEEN) + continue; + + parent->item->object.flags |= SEEN; + data->num_not_in_graph++; + + if (data->num_not_in_graph >= data->limit) { + result = 1; + break; + } + + commit_list_append(parent->item, &stack); + } + } + + free_commit_list(stack); + return result; +} + +static int should_write_commit_graph(void) +{ + int result; + struct cg_auto_data data; + + data.num_not_in_graph = 0; + data.limit = 100; + git_config_get_int("maintenance.commit-graph.auto", + &data.limit); + + if (!data.limit) + return 0; + if (data.limit < 0) + return 1; + + result = for_each_ref(dfs_on_ref, &data); + + clear_commit_marks_all(SEEN); + + return result; +} + static int run_write_commit_graph(struct maintenance_run_opts *opts) { struct child_process child = CHILD_PROCESS_INIT; @@ -790,6 +871,7 @@ static struct maintenance_task tasks[] = { [TASK_COMMIT_GRAPH] = { "commit-graph", maintenance_task_commit_graph, + should_write_commit_graph, }, }; diff --git a/object.h b/object.h index 96a2105859..20b18805f0 100644 --- a/object.h +++ b/object.h @@ -73,6 +73,7 @@ struct object_array { * sha1-name.c: 20 * list-objects-filter.c: 21 * builtin/fsck.c: 0--3 + * builtin/gc.c: 0 * builtin/index-pack.c: 2021 * builtin/pack-objects.c: 20 * builtin/reflog.c: 10--12 From patchwork Fri Sep 4 13:09:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver via GitGitGadget X-Patchwork-Id: 11757111 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 DCB5613B1 for ; Fri, 4 Sep 2020 13:10:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C376D2074D for ; Fri, 4 Sep 2020 13:10:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dH7EQ7T3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730010AbgIDNKU (ORCPT ); Fri, 4 Sep 2020 09:10:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730380AbgIDNJn (ORCPT ); Fri, 4 Sep 2020 09:09:43 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DB19C06125E for ; Fri, 4 Sep 2020 06:09:28 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id e11so7505631wme.0 for ; Fri, 04 Sep 2020 06:09:27 -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=3BP+V47fkAW0XOrc+qRv9CzrUpLDeEi54vnAws/gvxo=; b=dH7EQ7T3oKMV0XpqZk15i594C1y0PLV9CVboYr+w6Ph3OTRDcZhrAnBf1lb13lXcB4 xCgFXqIHK817S5FIAQ2qEXPswU59u0lD3bH/0CbQrZOiUgNrH0APCkafs6d2Taaxz4TE Ux57dTrwTOC32JaPABgBaAocYiSJCTdn6uAenZ6ZPqrGPMMzvEl6xiJgYE2PxdSUZ4ZX m8EWGRzsN8ToQXbp25EwmLsI6yxS7GjjKdh2tTL8Vz2fTnpTkXJUnos+GA59eZb+3sWg kS2N1GY4SwMyNCo/CROFMyh/+IGkb9SWeYAHp0hExy1vSRuJ08MzrE3EgEU9xviJO0Mu 3BeA== 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=3BP+V47fkAW0XOrc+qRv9CzrUpLDeEi54vnAws/gvxo=; b=dRhcL6H9eLCBk+a5XgG51YTnhSpn/p6VQG9U77Ubz4Ke6wonPD9Q73/Sng9UeMJKOF wIKrOwkJ/aUsQMfJduRPTgUBc2ODEt5Z/YHy0YD/TX3Nnv7oKwrk7lccq4enL2+LQuf+ 4XjgkFh5A93eFgdO8pPfZiNwiVwwXylFPxPcf20NGMwm9GiRrPjGyaxA2qRpbbe/J3rV NQuPwaF+0h4FM7MFLEkAdQx69LpaUosfl28wdpSEaAOC1LKMju4ViVG23e9JdUiKGLB6 kvIhlAaAh6iwDsAEnOaQYj3Wi9e9T5G0N7CIO8V3qFxxVrG1K5m9mdfmuQliw86zS1g6 O7kg== X-Gm-Message-State: AOAM532cZZ9encSZrtdiTWULlELKEaQ75Yn4a/KqEE1YG5FioIJtQpHi 9gypsFd9/p/ny6Hh0WblWgzcmlmzqmk= X-Google-Smtp-Source: ABdhPJz32dUViI2x8fjIpdGKtD0C//gMHMmhpbv0Bc/ByaZx/kaDIpMMMNtDhm8s31B6V592opwl2w== X-Received: by 2002:a05:600c:204e:: with SMTP id p14mr7215881wmg.182.1599224966690; Fri, 04 Sep 2020 06:09:26 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id b11sm11654596wrt.38.2020.09.04.06.09.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 06:09:26 -0700 (PDT) Message-Id: <2d6414d89ba447d6b2ad652f56038eb24004f408.1599224956.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Fri, 04 Sep 2020 13:09:15 +0000 Subject: [PATCH v4 11/11] maintenance: add trace2 regions for task execution Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jonathan Tan , Derrick Stolee , Derrick Stolee Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee Signed-off-by: Derrick Stolee --- builtin/gc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/builtin/gc.c b/builtin/gc.c index 8c4edf19ba..c3bcdc1167 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -927,10 +927,12 @@ static int maintenance_run_tasks(struct maintenance_run_opts *opts) !tasks[i].auto_condition())) continue; + trace2_region_enter("maintenance", tasks[i].name, r); if (tasks[i].fn(opts)) { error(_("task '%s' failed"), tasks[i].name); result = 1; } + trace2_region_leave("maintenance", tasks[i].name, r); } rollback_lock_file(&lk);