From patchwork Thu Sep 17 18:11:42 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: 11783225 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 BA74159D for ; Thu, 17 Sep 2020 18:14:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8FD66221E3 for ; Thu, 17 Sep 2020 18:14:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="A5mJJrr2" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726411AbgIQSO0 (ORCPT ); Thu, 17 Sep 2020 14:14:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726479AbgIQSNI (ORCPT ); Thu, 17 Sep 2020 14:13:08 -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 03FB8C06178C for ; Thu, 17 Sep 2020 11:11:57 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id z9so2993698wmk.1 for ; Thu, 17 Sep 2020 11:11:56 -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=vNtWHBN7M0cYUSQ8zQboy/d2MWOPkS9i3tmUGka7CzU=; b=A5mJJrr2mSYkYw9fJICFdGwiWH0GOyUvdQgFK+uDnpln22ff1WlOIlGCC/3P1WhpVJ ZhjiodmuYT6o7BbqA52Gprv46Nf+6E6P+6HZhuZk7Z6A7hNuXTKznwdizOtltB3GC7Id wTaVRFM8jSINZJMyBGRD1z8d+ReSUb5wfomyNAqruS8nSsCJwJUbFaD17m9Jgde6xudZ PaikEoqJOkonN1OPJqZPtVv2dobAjCDH8vphzKXNK7EXO+3OoaVdI/rBVLdqB2QjQ6l7 EFouUy9FR0It5agNu4eyIkBwItBmCkUbjKQ8hQUC90/oevG/YVINb9+A9IFT5fWTutUC E2Yg== 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=vNtWHBN7M0cYUSQ8zQboy/d2MWOPkS9i3tmUGka7CzU=; b=A4FripClTwQdbE1WLv0iqNhfk0OAA0r5v9+WZox/gkbG2kg6XzvgSAk2Ses3PeDnn8 HRMMTFXnb+DhrkzXg/+M4gp8dWIJ6bIKJNgLPNA19wDcxRTXYqkznnlqtN0MEB1AN1J3 FKB7AoD4Cu8cw/zdB0o2zepH2rLkogpU0wD6MQXwpYok9mNuN+6z1nXAZiEw90mKobDr LjWjd9kkx/kd97s4vfXC2QbBYJYEcOxIwMYQ951qdwI0tR7+lgCL3w8QvwZTVkfkoXTp qZSYChRKIn9uaAFR3z2p1+0kSucs2NfYgh0fQ9eh8LUJuifE3TqXRcJ+zzfkxlM8IQ1E MNgw== X-Gm-Message-State: AOAM531AQTkQTs3ahWUmVmiZO5WVaON6rwhT2EoIjeid7gBilKxuzDoc /aw1R3asP61GrqMTGjlawJZdEEb2/2o= X-Google-Smtp-Source: ABdhPJypXObR8MlQuDovOpboMi+mb3t0i2fnidrGo1WSeDs0pn/5TPKU7hEAvIlV9MBXTUGCJlKVig== X-Received: by 2002:a05:600c:2207:: with SMTP id z7mr11499908wml.42.1600366315288; Thu, 17 Sep 2020 11:11:55 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id y2sm363842wmg.23.2020.09.17.11.11.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2020 11:11:54 -0700 (PDT) Message-Id: <00a0d63508be1010df547a0ac56c73ec5df116b9.1600366313.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Thu, 17 Sep 2020 18:11:42 +0000 Subject: [PATCH v5 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 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 Signed-off-by: Junio C Hamano --- .gitignore | 1 + Documentation/git-maintenance.txt | 57 ++++++++++++++++++++++++++++++ builtin.h | 1 + builtin/gc.c | 58 +++++++++++++++++++++++++++++++ command-list.txt | 1 + git.c | 1 + t/t7900-maintenance.sh | 23 ++++++++++++ t/test-lib-functions.sh | 33 ++++++++++++++++++ 8 files changed, 175 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..ec064e8686 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -699,3 +699,61 @@ 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 || + (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..c2f0b1d0c0 --- /dev/null +++ b/t/t7900-maintenance.sh @@ -0,0 +1,23 @@ +#!/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_code 129 git maintenance 2>err && + test_i18ngrep "usage: git maintenance" 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: 11783239 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 A5D4B746 for ; Thu, 17 Sep 2020 18:19:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7D96522205 for ; Thu, 17 Sep 2020 18:19:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DoppPAKr" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726621AbgIQSTC (ORCPT ); Thu, 17 Sep 2020 14:19:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726590AbgIQSNI (ORCPT ); Thu, 17 Sep 2020 14:13:08 -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 6A8CCC061797 for ; Thu, 17 Sep 2020 11:11:57 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id m6so3077796wrn.0 for ; Thu, 17 Sep 2020 11:11:57 -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=YU0lapaxqCNKFKJgXd3OQC/nTpExucs8BFW6iQQz3ng=; b=DoppPAKrgE8yumfwHWKulUckI73/f8i5/PkTpSRnXQGtRGAOQndQ7LFQs0jWy0a7UV 3SlWLwEZDqGp8rjB8r/Avxcta1MKgQZPUWKxHSyY9jucYV2K6bjE1c3ZbVkByRf20Nzv kfQwsKPSmI5KmP8iaAKvw7myq1Vh3/2g6E8X3qH6dsvNjz8l5ljjdJzStbyQGwad3LE7 yNrw7F7RWpGAJe2F4oNJxwOUL8cIgs/K21OByBUc/jUOu8keHXx0d2qjFefbLFnp3RUF W6OIPAJ2mgTf0wgc+LH6QU0vT4hWtYR/2IDi5sAvRxcbPp1SSUHnK9YNPBkwPDDXG2ZZ yQOg== 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=YU0lapaxqCNKFKJgXd3OQC/nTpExucs8BFW6iQQz3ng=; b=rftXcThKzegCQezHy1BGaL7OK8WFZjQyoCMc4zTJ2KZePtT1gokY5owNxQnCToPV5l TbRdnGjEaUtNZQwRQkqM1aigZX343tqg4Yn57y2uEj9GrzuZ+HHB9EoLnBUVWH/rrkct xtPIiGY+41MJtJPeLcshacaI6YvxGa/hcHjcKEUBNlH7yy8vEEIvB9fal/J4PqyBdhqf oCMnVGbL96FZT2ofK9hbLtUEGmUbsGqonXF7lf3FgsP4UMHN9HMNaCzaP+mrnzzkkkMC oSbb+RkvdQjgS7yB32I+cWeZ9rZjJiS8UjEXoR5tw3zV1TNwq3XPGMTVcbsVMwAaTeLg aq2Q== X-Gm-Message-State: AOAM533A5V9PisymfriQDqpQul8yq4mSxHvkgolZY0eIUat0haCi96ZU yNVcwpNQQ3GmudnZoJiRGPPw6yte374= X-Google-Smtp-Source: ABdhPJxhztcyjUOZnrp/N/Egd61eB6dFHG5DU40h85xBQGitv4qPMG/KG1KkJbGWEWAOADzOu6wRrA== X-Received: by 2002:a5d:52ca:: with SMTP id r10mr28140258wrv.195.1600366315938; Thu, 17 Sep 2020 11:11:55 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id l8sm513177wrx.22.2020.09.17.11.11.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2020 11:11:55 -0700 (PDT) Message-Id: <52eb937f49a79dfd985e9c6d237ec022b6290094.1600366313.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Thu, 17 Sep 2020 18:11:43 +0000 Subject: [PATCH v5 02/11] maintenance: add --quiet option Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jonathan Tan , Derrick Stolee , Derrick Stolee 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 Signed-off-by: Junio C Hamano --- 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 ec064e8686..bacce0c747 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 c2f0b1d0c0..5637053bf6 100755 --- a/t/t7900-maintenance.sh +++ b/t/t7900-maintenance.sh @@ -13,11 +13,16 @@ test_expect_success 'help text' ' test_i18ngrep "usage: git maintenance" 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: 11783231 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 36622746 for ; Thu, 17 Sep 2020 18:17:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0CF58221EE for ; Thu, 17 Sep 2020 18:17:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="K2CM5dNx" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726649AbgIQSRD (ORCPT ); Thu, 17 Sep 2020 14:17:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726594AbgIQSNI (ORCPT ); Thu, 17 Sep 2020 14:13:08 -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 56D33C061351 for ; Thu, 17 Sep 2020 11:11:58 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id l9so2992235wme.3 for ; Thu, 17 Sep 2020 11:11:58 -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=wqUZx5umBLg5jTAOPXf84VWoThGiY37RPB0IsrmWEJQ=; b=K2CM5dNxM807hG8Lm0vwD63NIAdCdnXyE9EL1JsPnorq9lADeqNTTQM7xDPbD3DzOK cGbnbU79vx67xrLKmGlFiyo5YhQoFfKibc44zMlIOpKKOYzyNm9E1tlX6GxV8PvHBxzN 4l3vaTqdEV5BoxvE0QKJTzoDrkrgLXf5WkLmk3sZv5UpKmeD7oywIGlrYbWCsDSWo7U4 UnP5Pcz4XN+Pm7Zry+xoHAhj5ePruhcliLZoNLaQHZEVYkDcn+PaFgxnnsLty3ToIIpM mKrE8UBKpNJV4p+TBDuPGzt1cjZcJu8rLIek5xz2ik/Q6Z6OSJhiD8QYyJMaGFq9+2DS EQaw== 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=wqUZx5umBLg5jTAOPXf84VWoThGiY37RPB0IsrmWEJQ=; b=MRJdK04tM2+d4pZ+v0cfqu93RJeuy45lVAzV2MrMDZR9I8uBPBH8F5PphE5aqnQ6WY k9AireKZjhD0hZtciosVYytX7ld0zlk+/wiBCKoOcw555ebEIPzMDOB76HVEGo2X9OVF F+ZKA5zdte3KecGGH/Eh8j9wPWRIVQqTvxYKrJQ+/Ppw/KR0srS964k2A4s7XxVoIDy/ 5Q/cJWG+oZLK3c/yP308TSIvyEdh8NABthmBrYE1qVR1L7x8hAd/r25CrKfitwvvYoc7 RaRB3KQYF/uijT8dY7BTiRm5VQVQvD91Zq8JHkTv6DWI3D+iIue8WLDieT1BJp6u95Mq B3BA== X-Gm-Message-State: AOAM531cfN1QcGn+x7ragKDXktJZwThG4/ZblHXr1Yb05oQ5KYT9hsd3 K5MrVzZgh24b9CtEqW54WIzN1ogtZ2s= X-Google-Smtp-Source: ABdhPJxg2wGHwvoZ2g/7vD18jDr/V5cLCwMQrPYFNIRluqNcyVgme6OofowMVbgVQjQq/BTjMMByqw== X-Received: by 2002:a1c:2ed0:: with SMTP id u199mr11008295wmu.125.1600366316747; Thu, 17 Sep 2020 11:11:56 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id t15sm485018wrp.20.2020.09.17.11.11.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2020 11:11:56 -0700 (PDT) Message-Id: <3cbdeeafb56d0cddabbcef7d9ac301704e2616e6.1600366313.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Thu, 17 Sep 2020 18:11:44 +0000 Subject: [PATCH v5 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 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 Signed-off-by: Junio C Hamano --- 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 Thu Sep 17 18:11:45 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: 11783217 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 3D58F59D for ; Thu, 17 Sep 2020 18:13:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1764D21D92 for ; Thu, 17 Sep 2020 18:13:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WYZ8wysa" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726422AbgIQSNV (ORCPT ); Thu, 17 Sep 2020 14:13:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726564AbgIQSNI (ORCPT ); Thu, 17 Sep 2020 14:13:08 -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 137BAC061352 for ; Thu, 17 Sep 2020 11:11:59 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id g4so3055091wrs.5 for ; Thu, 17 Sep 2020 11:11:59 -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=tg2/P5yFktfjeIDaIDVS8JrApj3MT0ERiT8uiaZI3wA=; b=WYZ8wysaYlwfv1sJK+FunnGGqg8KUKJraCgzZgL2BbLGZWMLMwSODLbn/W4CofFQBV pa5/tSjzf6u6WFJZKzU6r5nKwXCyfU4AOsqOnTWPc3PAfuX/CXjYIM/lJN+pkXU95nVY ONuwZOCN2FnOxVQBdXz63n1NQiluaaXx9TdGf6QV+NyXZz6VHgtIccApC4yweLPKiKLb eMXXJnEYgemTJzTlSdS2piUB0VJ1FxmKDHo8b1fsbw2N2NmirZ9OmimZwSz8sxJHfiCB gf2tyDxkTjR95k3PLy7NlVQvodBULzBK+SyAiZVqHPnPBIDWkjgQ6OM0OAdJPor/hc1n G8nw== 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=tg2/P5yFktfjeIDaIDVS8JrApj3MT0ERiT8uiaZI3wA=; b=EuyHn0dH6qYLE+jA2K2H4WVe8jZVtKaNxph+laJPMjzRSrIKl1M8tNKsuZg04wa5a7 nOLln3Nb7Td9dhOM8d2EmdtDfrAmu91l0hkfxNJRzq8dESv/UiHdR7qPATX6z0BJndpi BSGQnoS5ZQArvkzp+B3YmEZxM07eTiE8e+qp1oVEg6EIB5onlOTHoiTrUH5dbrmiNW11 qBkxjs/Ub7PRwR+K60Y2Y07qQHy7V8Edztp2XtAqZCDpcRuC6LE589nJFa274IDTvi+Z UZIrj2mIqQFJ3nB7mLzz5HKTaB1nHz2dERsBhuvZtHptPOcQAU90OOX4WAhAXlB5EJV3 o7sg== X-Gm-Message-State: AOAM530s5zc2Nb0Em8Q3wLT/JNS42JLWS+gsVezyiemMLegBVywchlcm Cvm4XRf69BcNZWCHCuuh8zkRJUIRU3U= X-Google-Smtp-Source: ABdhPJzAItbs1Syrxn6yrF4nGFK/qnqhWIHQPBS4k7fh+vPMhE+fvqfqYDszURb4MHdEz3cH4fjhvQ== X-Received: by 2002:a5d:43cb:: with SMTP id v11mr35368844wrr.188.1600366317631; Thu, 17 Sep 2020 11:11:57 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id y6sm455034wrt.80.2020.09.17.11.11.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2020 11:11:57 -0700 (PDT) Message-Id: <1d2f2731bd3c206dc53fa2610d901b95e53b6295.1600366313.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Thu, 17 Sep 2020 18:11:45 +0000 Subject: [PATCH v5 04/11] maintenance: initialize task array Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jonathan Tan , Derrick Stolee , Derrick Stolee 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 Signed-off-by: Junio C Hamano --- builtin/gc.c | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/builtin/gc.c b/builtin/gc.c index bacce0c747..904fb2d9aa 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 Thu Sep 17 18:11:46 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: 11783221 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 4F62659D for ; Thu, 17 Sep 2020 18:14:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 202AA21D92 for ; Thu, 17 Sep 2020 18:14:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IHv9uLie" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726467AbgIQSN0 (ORCPT ); Thu, 17 Sep 2020 14:13:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726612AbgIQSNI (ORCPT ); Thu, 17 Sep 2020 14:13:08 -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 10C3EC061353 for ; Thu, 17 Sep 2020 11:12:00 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id w5so3048075wrp.8 for ; Thu, 17 Sep 2020 11:11:59 -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=lfbHJbIos3zMffZlHVdVDJP4JsuaHqeN2aDjXEqImOw=; b=IHv9uLieB/dBq67dxKkFPS/cuGehQYVHMzI6Sk4D+dDnPQ5SHgjXAAvlJe2MjDA5Ln DddgPlyytrG2LQ3lPTyUDtG6Mf97+S57aQ9fpmGzfGaXfkoNC7NSKCrIPe93vu7aSwTV Tx0RrN5ScPHj9EoTHnrr7XXWfQrbLrcfi88mS0TdxsbsLk83s2Cs2mu3j03LWgqnO8G5 VZJsLx8EQLUGUIIMEnpC2TAQj2AoOwh0UFNvK8VG+QN6im5caarHD5JZXjAW/Z6kuRt4 Zybt6ibGCqWUO4S/Ee+BYyaI7CdPhzd7sM8QY5A8ih+hr4D0uJRqSWFCefB79sq0w+f4 W6gQ== 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=lfbHJbIos3zMffZlHVdVDJP4JsuaHqeN2aDjXEqImOw=; b=t9dI6PikoMQnjh9gGEEqwmUSxEChJ6RjTiQSXIRI9R3PSbGHzUNTFH+GRiYt5JhbBu yJbBv9S5attR3KGMryCXj4wanZqDdJThTAfaKjEuZ+bNlSN/MBKFrz/dqZs2e3kqNAO4 suE+UnIReZ1ZEJENaMC7foeY1+Z5fCnEEEVo0RaiHxPvTv1ABSCNFljMpSmpYTkRuIRS B3xtv5a+eg3NS6HODG4B+X0FNzEleTKAErIqJkSaR2iiZiCSntpSs6HjYf6pQyVgrYOS +20PJS1+ylPeCJBH39OlShRr9XcSLvesdtEVFtxUKo6GnCbgykCpe2dI/2w5aFk+LO6v O93g== X-Gm-Message-State: AOAM532bTJS78WR7DWzUVUWOi8y+KaHNWH82TXmlaKFCTWBjRi7VDkmr WZVEHlnstY/JAADcJ8pSuI6XSNBHugw= X-Google-Smtp-Source: ABdhPJwYKW4JB1b97fIw4iIoLVdDOJ5aMNnQoCcZkdRNkU27fmf8yPsSMEN6PilntwLCZ3Sj17ONhA== X-Received: by 2002:a5d:4088:: with SMTP id o8mr33110574wrp.112.1600366318484; Thu, 17 Sep 2020 11:11:58 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id u126sm524206wmu.9.2020.09.17.11.11.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2020 11:11:58 -0700 (PDT) Message-Id: <8204ebbf8312b30ee8da38b73f0877cbe1865bcf.1600366313.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Thu, 17 Sep 2020 18:11:46 +0000 Subject: [PATCH v5 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 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 Signed-off-by: Junio C Hamano --- 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 904fb2d9aa..86b807a008 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 5637053bf6..505a1b4d60 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 Thu Sep 17 18:11:47 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: 11783223 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 8AB2592C for ; Thu, 17 Sep 2020 18:14:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 600E9221EC for ; Thu, 17 Sep 2020 18:14:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Wu6nG+sE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726301AbgIQSOI (ORCPT ); Thu, 17 Sep 2020 14:14:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726613AbgIQSNI (ORCPT ); Thu, 17 Sep 2020 14:13:08 -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 E413CC061354 for ; Thu, 17 Sep 2020 11:12:00 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id x14so3034821wrl.12 for ; Thu, 17 Sep 2020 11:12:00 -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=wvYhOhVVjkQBVSBry0FoipyVCLoFwBDrIPzA9kIq/tU=; b=Wu6nG+sERLMctlPDEISLjE+YpGWDNHz1aq5r507LDY1npM8pXzKgTovTITrLFE68du n8j+2TgEiAdKJlEQ1ot7ltJqfEWNJACUNdqSg6er6IuspkJJqzR+gP3QzX6le13jseG1 vggA2xlXDVoJ4ekUlxypPaqiZ1nO/Pxr2wBTIRF33qeu7Op2KbQqqhFK7j0FFWtRUIrx hL5rfUG3c3z85SK0D/lqB6WqGKyfsxK9MDSZEQhCPkezEUCMNsr8PiXsy8KBOJJkLhMF CoNbtSJB5kW26epwrrQxsx+RgQhetkyXmgqOOjLIYzf1ik7KswzfzcJ0SdiNfvjoqNHC AFiQ== 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=wvYhOhVVjkQBVSBry0FoipyVCLoFwBDrIPzA9kIq/tU=; b=IPXI4WNQNHdLfM8hwdmZQj0qqN1+YGBfAThImXKTY7YO2UcgBBSfgxZPV0TqqC6AxL zHxEXDuGazvvXIA0gOTgoDvqQx1aKbnNpzeLO4Ajkf61ky3lD+v8dJezsv0yj7kTB+Rl m/gCz2+kCppydAG9zFhCtjTOXr8kr9UuZUsecRIV25PfK+zHl3HG0M0Rjh5o/Os/4ID4 Jb4wA3ocqW2dfLYB+Mkks9ir9kpUdu+6+Jm7a+7RVy5M+I0icuNICpvgDpsdDhl7uJ3t ImZsJw42YncBPdSn37HxLXsxuGIo4nsLRJQFZE852M692w9PVPar3wlumUA8zssIInla /viw== X-Gm-Message-State: AOAM530yT2WJ8bL1k2cLGIQcrX8/vpevp8lCqhQweDm4PWbHnRF4/DcL pA+moydOkCjV/hEqm0tA4JxMNlT93S8= X-Google-Smtp-Source: ABdhPJzlIwTNHhQdfdQuEzvdaIxP0ioEc0/WUb8wJHqTyT9hpMbt3FfQqdrS1RsXYk22Id11kurkGg== X-Received: by 2002:a5d:4152:: with SMTP id c18mr35441940wrq.277.1600366319326; Thu, 17 Sep 2020 11:11:59 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id h186sm396471wmf.24.2020.09.17.11.11.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2020 11:11:58 -0700 (PDT) Message-Id: <91b8555c9ec9f84690c7bcea01f0c546ada2de1b.1600366313.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Thu, 17 Sep 2020 18:11:47 +0000 Subject: [PATCH v5 06/11] maintenance: add --task option Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jonathan Tan , Derrick Stolee , Derrick Stolee 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 Signed-off-by: Junio C Hamano --- 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 86b807a008..00fff59bdb 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 505a1b4d60..fb4cadd30c 100755 --- a/t/t7900-maintenance.sh +++ b/t/t7900-maintenance.sh @@ -27,4 +27,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 Thu Sep 17 18:11:48 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: 11783237 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 26ADE59D for ; Thu, 17 Sep 2020 18:18:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 01ED82220A for ; Thu, 17 Sep 2020 18:18:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="O5PJr5wo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726642AbgIQSSV (ORCPT ); Thu, 17 Sep 2020 14:18:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726619AbgIQSNI (ORCPT ); Thu, 17 Sep 2020 14:13:08 -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 980DFC061355 for ; Thu, 17 Sep 2020 11:12:01 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id b79so2985808wmb.4 for ; Thu, 17 Sep 2020 11:12:01 -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=OOlQZPDcdCQoXOzd9zTrkzh9yuwtcEqPHqn3vRvk/do=; b=O5PJr5woLR1fjk3nmzcVRwJ26KDzbsL9ZcNfz4FSo4kOgo3Z/3oqubbNNEUcVHBMAr +DIP286w5ielXYss8vGFTvbHg9Q9r688aY7nIMd8tjsMlO6TzMe5cSaIj1X/juOIKIsL OJKB87XXRxfzBHaZaWz6tzc548q9Q25VFZxX49iD3c3zdyJ1CSM3AAxjpktLuaUfDJdW AOgRQM0ftHSWd/yP6rvFeeIv3eTOpKk24fXlUCStfi0ubdMZZ7RPmL89uy82sI7CejRk PjPEQB6IZ+xtBS4lUrsWoZ7N4K556C53sUIyzkYT0wSyM8gu4Co9mP7U+F9ZpPEG0mWE 2+kQ== 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=OOlQZPDcdCQoXOzd9zTrkzh9yuwtcEqPHqn3vRvk/do=; b=pJOy9l+pqh74Ciq6kNXwDUiNlf5oWHCO3biKIwLZarHUHRsDPx+kqkDH0kbe0prOQ/ uwrjIllpKImoR0bgYjjrV+kN76dTNsbVM/ufnY1GsHyVQ4JJSVHVHD8O5hX0hvd8y05s aEXc8gZJlp9CNR991sc9RPNXc1x1uKV7W79q2+5bDNzQXqzc+8J+zJcBHRrN8fpNSghq PFSU23/mEPwVjyoIVs0wDbAquqJLS//4uCmwrowgTa8UUe08cLdwfGI9bLGAUjbJYSJl 3IjC+8GfnDZOT04DcDhK/Cz4STqrTSbh8vwCH54OQHez/9voom5VJ81/GMgNjLOHlizB u5gw== X-Gm-Message-State: AOAM530bOYOCXgs1Tn+KBju/ylcH9RmyqvcCO9qYnkQCeIU26oSQ6zsT GYoAtmYHrFJqVKzKc50U8dxaZ4nL5ME= X-Google-Smtp-Source: ABdhPJy8T283o7xAlKSLKQbf6dkoOH8C3G90XRfIqOk4NxrUTd0oaDQOFX0Ng8cxvad8jxTfBSrp0g== X-Received: by 2002:a1c:7508:: with SMTP id o8mr10885711wmc.127.1600366320175; Thu, 17 Sep 2020 11:12:00 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id h4sm572805wrm.54.2020.09.17.11.11.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2020 11:11:59 -0700 (PDT) Message-Id: <1a0a3eebb825ac3eabfdd86f82ed7ef6abb454c5.1600366313.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Thu, 17 Sep 2020 18:11:48 +0000 Subject: [PATCH v5 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 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 Signed-off-by: Junio C Hamano --- builtin/gc.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/builtin/gc.c b/builtin/gc.c index 00fff59bdb..7ba9c6f7c9 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 Thu Sep 17 18:11:49 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: 11783233 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 0CF4F59D for ; Thu, 17 Sep 2020 18:18:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DA73022205 for ; Thu, 17 Sep 2020 18:18:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NacZJ7Bw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726467AbgIQSRU (ORCPT ); Thu, 17 Sep 2020 14:17:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726626AbgIQSNI (ORCPT ); Thu, 17 Sep 2020 14:13:08 -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 7179FC061356 for ; Thu, 17 Sep 2020 11:12:02 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id q9so2849985wmj.2 for ; Thu, 17 Sep 2020 11:12: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=tz5sP7sFiEQwxuNL1ysFFdMmvvIMmfCgdRD4pehezDg=; b=NacZJ7Bw1y+3uip9bkoI7aK3EHk4kRHXOr4jct7c1wDgx1Our72p376pFeS7M61QkF 1RBA9g0dic0qVZjVHmYs1imZ08ZmBIWcJv5PLDYMW1XzSM4ewaHAq6zi5s0sI8ggq6C+ zTxA/UU0VFNDPsOcWxgWGoOnk011tBnU91TylntC3AF1UBMR5ORS+zs/eOCj77fqsgeG v3vfuXYhiuWWGKfnsqc1PP7PPQaNuSnzaxdczejDKIrBtTyf6GgqpGO8yaV85kFzNKUL z3BYumv7PGyHyS8x1SQJtvkmyI6VvfWDne2i+/eDIjWipqFOewtD3Z6xXSUEo/AewG9y 7Q0A== 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=tz5sP7sFiEQwxuNL1ysFFdMmvvIMmfCgdRD4pehezDg=; b=tDgeasQ8Yt5ZmYbLI1WrreF/rs5AXgUUb2SWyFZZYpIFHwVieEotc2WpocjP0q27Cr WCRKsrwK2jRj5onSnhD3IPL6vbB50OywcXyOu3hQWclhweIHpVNdwkH5jSiLn/IHiROp uCViAoDPrHPccLzcyykr/wYfxT/t0u1Nco/8rFRjTmHlSGN/fJYl3wGdCQEK11yH7LK+ eIycltBp906XQWJMXxscMM4awwP8gO+hLb/2LG9+lOtEvt0tbCMQ90L6kzCprCthCydQ Aa2EdgDKI1rAhR3ErHw7/ANL/mFBRp9mW81y3rPzbKMiG6K5r9q/P19HRgjWgXBDIN3W zd8g== X-Gm-Message-State: AOAM5331ly4u7FNW8vlyO9H7Sw58ryCuJSeyAXlzOvpQYw3x4jC+ruq8 Cl5+gbdmR7ESwexQk9LSxhWSvmu4/Bk= X-Google-Smtp-Source: ABdhPJzgYrJAGyKXpcMC4N3d0+4pw4iuGQEoMctEhfsMvU7pBM7v27p3+M0Ao1gzcabC1KJW4056bw== X-Received: by 2002:a1c:6487:: with SMTP id y129mr11921123wmb.90.1600366320982; Thu, 17 Sep 2020 11:12:00 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id z15sm468151wrv.94.2020.09.17.11.12.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2020 11:12:00 -0700 (PDT) Message-Id: <713207b4a188e16e952b8587f062488f97d403f8.1600366313.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Thu, 17 Sep 2020 18:11:49 +0000 Subject: [PATCH v5 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 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 Signed-off-by: Junio C Hamano --- 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 7ba9c6f7c9..55a3d836f0 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 fb4cadd30c..8a162a18ba 100755 --- a/t/t7900-maintenance.sh +++ b/t/t7900-maintenance.sh @@ -27,6 +27,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 Thu Sep 17 18:11:50 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: 11783235 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 E666D746 for ; Thu, 17 Sep 2020 18:18:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C6A4822205 for ; Thu, 17 Sep 2020 18:18:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="vXkXlgBU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726411AbgIQSSF (ORCPT ); Thu, 17 Sep 2020 14:18:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726475AbgIQSNS (ORCPT ); Thu, 17 Sep 2020 14:13:18 -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 472ECC0612F2 for ; Thu, 17 Sep 2020 11:12:03 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id o5so3030726wrn.13 for ; Thu, 17 Sep 2020 11:12:03 -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=1b2P3nhbjiMTeaIEbQdOCW0yfrkSWrtCcHB2NWXqvU0=; b=vXkXlgBUfAnm2gs3IcDYPSfV+CxHk2APd2jMIDFGRGSosYw3SME2FtsSBVK05bBAI7 rwGNXklIVy4Fs4I/27Hm9bfdtiJK/ehJ+il8V/YNffQojlrBennBdxAEhWRwCk5AFNWX qMu1TTf0gRoyCN0A3CFRM+8cgHU7ssQ0e9ZuyS5DPfL3F+36sC7X7w6xMx+gg0jgcN5j P31W1FvC/9KbNQ/kE15xvucazQ/kfuDUViOLvav4LB3QQRgfnW8oexQMQsQK8pe40u+X soXxIQ1BG+HBZEQLuzQIOxIT1QCmeg12b5zBZb3n8XPhzplWPFh7RJaR52TRzml3pWVJ qvGw== 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=1b2P3nhbjiMTeaIEbQdOCW0yfrkSWrtCcHB2NWXqvU0=; b=jS1kn9JXBhPFEFqb3YKcpya0kl5DQudlF9gfsT0p4Z45bamQ/pFxisvG6jht8XJQ86 fxh04F3HpRbpWMwVlZhH2z5xCvTLx2q50uQ3W66i+FFgExBaoAB3wW2pxhHSUNNV/eeF BnwudIV9UJs1yZsIPVCtynoGc6FLhRzSkbJY5Lo0gWw719IxFnxfhMErIpzpt3GiJ4/M iFHTiBeVmSz5R9rJ8d6RzscTuR74GIV9atk0nQFZYGWsrCDPeMclDxQRdcMknKpbQkcD VOhlCHPDsJzAMEfT3j5gqUfDWWxdLQ5qlLURWeExQWpvhNst6NCOxPBuPVWwZvY3jBSg T10Q== X-Gm-Message-State: AOAM531p4xFtvYm2xtAJGYbZpyoPRY6trI8/jYzt5Dv6CE9FLdLAOjc0 Y7k2WcVaEnLCAl4CORwjx30Y/rh/Wu4= X-Google-Smtp-Source: ABdhPJxfVAMRoWvgUEZbTBgsRh5DryJV1IyE9UnFZU1b/bYtVBS62cZu1LaPOkjUX+UPcXa2HR4b6w== X-Received: by 2002:adf:fc0a:: with SMTP id i10mr33157018wrr.111.1600366321775; Thu, 17 Sep 2020 11:12:01 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id d83sm405051wmf.23.2020.09.17.11.12.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2020 11:12:01 -0700 (PDT) Message-Id: In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Thu, 17 Sep 2020 18:11:50 +0000 Subject: [PATCH v5 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 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 Signed-off-by: Junio C Hamano --- 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 55a3d836f0..13c24bca7d 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 8a162a18ba..53c883531e 100755 --- a/t/t7900-maintenance.sh +++ b/t/t7900-maintenance.sh @@ -23,7 +23,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: 11783227 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 7DD7359D for ; Thu, 17 Sep 2020 18:15:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 59E2D21D92 for ; Thu, 17 Sep 2020 18:15:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fnO6aJvH" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726455AbgIQSOy (ORCPT ); Thu, 17 Sep 2020 14:14:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726534AbgIQSNS (ORCPT ); Thu, 17 Sep 2020 14:13:18 -0400 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22DEDC06121C for ; Thu, 17 Sep 2020 11:12:04 -0700 (PDT) Received: by mail-wm1-x343.google.com with SMTP id k18so2984517wmj.5 for ; Thu, 17 Sep 2020 11:12:04 -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=EwaUtjW05eztNq1hcyuxldE206s1lvSs488NYmfcjfA=; b=fnO6aJvHZwNS1ctkh9swCWsunYf0fH+SZkrlUsQ4IBx/01hfg7PYLQywIjnDNUhyQo YzT8bQeLDCAPT28zrebeOg3QX2xJlIYE+RkM/ejLkeKKL1228BdScimDJ1YU/aJU4x1l LxybKQEMYrCkfeX7ZhtWe6d7jjCCjl7CaX+W4bKCnqGTi1NKX24H/i/q30sESBePx8y3 d9rllHxHUE2lkO1BeYd0MP1nOA1NjdwxHE5uNXkAejC6Flkc/HuvVgAxz/cYSVoMT54l FUyr+j/3T+5nbaKrG7sBKRzlBdj5ROksQIpvnQx1a6GRchQn/5DK9CnkF030xWMmbeF8 /QqQ== 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=EwaUtjW05eztNq1hcyuxldE206s1lvSs488NYmfcjfA=; b=URqNKUExpuTTWSBsI9WTL1NToQjmPBYC7ZgiR+F7J9F4n3b8rIiYkMIcGGyHrEeJtQ MdSB9UITHl9p8to5R9cu4pu4nU+hZ9E4RPMNqPTxbzbVREp3/eJWwNdjYcUmvcSwvR/C +liAUgT+1lIFiieT0Qz0eQddBQajhe6zpw1o4Qq33uYHltoIIn4gHVYPSjuy3sRdu31O yz/UVc7BACDSoRIu+ZZ7gFdZdiAENhWKrbXRofEl6p1SOBUUO13bnZedw84dhjcJ+Bvm 3o9ugMlvmHv5+5A/4wM8emRq95n9pIPU5QVZ6EhJLwVY4tVtKZqXjT/6zEJ4ZwBKgDls Mwkg== X-Gm-Message-State: AOAM530GKpRLsflEME/0YOr+XmuMEas969wCDM3tJKz2jEvKpecwmLRy +V9VQpMizkJcTrSUdrnKpuPTmzzF2m4= X-Google-Smtp-Source: ABdhPJwHM7FiuvXBpDX/+w6SzcI1206seQxxoiSAJ5at1zEnhzrLMdQzGqnbXs6eYs8OY85h14sGgg== X-Received: by 2002:a1c:7918:: with SMTP id l24mr11690571wme.46.1600366322598; Thu, 17 Sep 2020 11:12:02 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id u17sm576697wri.45.2020.09.17.11.12.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2020 11:12:02 -0700 (PDT) Message-Id: <7a2a4e1e5278c7c94e0a6cfe1a1917724f826b0e.1600366313.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Thu, 17 Sep 2020 18:11:51 +0000 Subject: [PATCH v5 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 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 Signed-off-by: Junio C Hamano --- 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 13c24bca7d..4db853c561 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 Thu Sep 17 18:11:52 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: 11783229 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 C0E6E59D for ; Thu, 17 Sep 2020 18:15:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9508620838 for ; Thu, 17 Sep 2020 18:15:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Drz2cQ7q" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726426AbgIQSPY (ORCPT ); Thu, 17 Sep 2020 14:15:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726461AbgIQSNU (ORCPT ); Thu, 17 Sep 2020 14:13:20 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2A1BC06121D for ; Thu, 17 Sep 2020 11:12:04 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id g4so3055340wrs.5 for ; Thu, 17 Sep 2020 11:12:04 -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=oIbVZeD+rKTPRw8kMhl6aKlyG7opgOF8AOrpj9HWgls=; b=Drz2cQ7qpKhEI2uFItSvJA58G7Y2hlWHCWGTL+Z7Y46Vnmvb1G96bsN/+Z43WaYZ78 sYXfZrDJJIMJFvnVMMJsVm2wAwzqrhWktgT6j5t0KWVRez1vpAhxwV26ttV02O/ZJMCI az2pbyxOVyOw3Dy51O2NFm1AgarZlZUsyCuCwK2Nh1CLncwXb3lmUwQBVLaY6lEBDsQE ivafnIpKOGD/46euEkrWDQu5XyBD3z7BDIaIuIkp15tsUUqFuNms0LeN/qLqg5GqOM6U E66epjjWoOTALEFJe9pu9i3qbQyNKFNKsqpCAyR6v2AV5JIS42BBAK4FdtHnJkSxmblU SVhw== 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=oIbVZeD+rKTPRw8kMhl6aKlyG7opgOF8AOrpj9HWgls=; b=NVaGL4pkxMqVxCYFeBR4ZOBAhXkPVsbk4NEfWicgtc7vpMZA3TgpmgHheoLgJgyusk Q9ZtJGlkMknW3VUxDePNYY5Ly1t6cNlMNDVWmKyWNTk3t8vnqqFDIIChZBiiSF7GKp+O AjTGHErq+NCwRn4ISST8lP+hjEeDWwN9nzQV1vhMzDchApOjq74xm0w0xEEIf6wRRpTq tzfSs+DAYxQLaSxBmANjc9NoDP0fXPCHk3KxnVRxwlhOb4vG+pTdp54UTWcg9F8imCFW VlS+91E+iFSH+dOlb4ssdOXM44QylLyqMkJWuMo6toJcgEL+r7DDOo7HqJ86PQSfZteO XK8Q== X-Gm-Message-State: AOAM5327mkSR3zNEvLmHagT4NvkJOOcdWB/SaKEF6V4fY2qs8bNgdQPE UJgR6bb0fUZ+1xDxqylnl0KNRvsM2Jw= X-Google-Smtp-Source: ABdhPJwjeK2tIPq8FHheaAClCc2NJN9VnitwyDF+mgP0GwjbM2wKXGNM371yYMPsoaxSY4xSwDRwiA== X-Received: by 2002:adf:b74b:: with SMTP id n11mr7912226wre.274.1600366323399; Thu, 17 Sep 2020 11:12:03 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id b64sm413844wmh.13.2020.09.17.11.12.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2020 11:12:02 -0700 (PDT) Message-Id: <20a74abd96795d66acc19ea780864cd5f4ea6a2b.1600366313.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Thu, 17 Sep 2020 18:11:52 +0000 Subject: [PATCH v5 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 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee Signed-off-by: Derrick Stolee Signed-off-by: Junio C Hamano --- builtin/gc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/builtin/gc.c b/builtin/gc.c index 4db853c561..090959350e 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);