git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
From: "Đoàn Trần Công Danh" <congdanhqx@gmail.com>
To: Derrick Stolee via GitGitGadget <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, jrnieder@gmail.com,
	jonathantanmy@google.com, sluongng@gmail.com,
	"SZEDER Gábor" <szeder.dev@gmail.com>,
	"Derrick Stolee" <stolee@gmail.com>,
	"Derrick Stolee" <derrickstolee@github.com>,
	"Derrick Stolee" <dstolee@microsoft.com>
Subject: Re: [PATCH v2 4/7] maintenance: add [un]register subcommands
Date: Thu, 17 Sep 2020 21:05:43 +0700	[thread overview]
Message-ID: <20200917140543.GC8664@danh.dev> (raw)
In-Reply-To: <1f49cda18ee8d6c585807506cf89c365de642ea7.1599846561.git.gitgitgadget@gmail.com>


Hi Stolee,

Sorry for reply this late.

On 2020-09-11 17:49:17+0000, Derrick Stolee via GitGitGadget <gitgitgadget@gmail.com> wrote:
> From: Derrick Stolee <dstolee@microsoft.com>
> 
> In preparation for launching background maintenance from the 'git
> maintenance' builtin, create register/unregister subcommands. These
> commands update the new 'maintenance.repos' config option in the global

And also not spot this earlier.

I think you meant 'maintenance.repo' (without s) here
since it's the one that was mentioned in the patch itself.

Other than that, this series looks sane to me.

Thanks
Danh

> config so the background maintenance job knows which repositories to
> maintain.
> 
> These commands allow users to add a repository to the background
> maintenance list without disrupting the actual maintenance mechanism.
> 
> For example, a user can run 'git maintenance register' when no
> background maintenance is running and it will not start the background
> maintenance. A later update to start running background maintenance will
> then pick up this repository automatically.
> 
> The opposite example is that a user can run 'git maintenance unregister'
> to remove the current repository from background maintenance without
> halting maintenance for other repositories.
> 
> Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
> ---
>  Documentation/git-maintenance.txt | 14 ++++++++
>  builtin/gc.c                      | 55 ++++++++++++++++++++++++++++++-
>  t/t7900-maintenance.sh            | 17 +++++++++-
>  3 files changed, 84 insertions(+), 2 deletions(-)
> 
> diff --git a/Documentation/git-maintenance.txt b/Documentation/git-maintenance.txt
> index 3af5907b01..78d0d8df91 100644
> --- a/Documentation/git-maintenance.txt
> +++ b/Documentation/git-maintenance.txt
> @@ -29,6 +29,15 @@ Git repository.
>  SUBCOMMANDS
>  -----------
>  
> +register::
> +	Initialize Git config values so any scheduled maintenance will
> +	start running on this repository. This adds the repository to the
> +	`maintenance.repo` config variable in the current user's global
> +	config and enables some recommended configuration values for
> +	`maintenance.<task>.schedule`. The tasks that are enabled are safe
> +	for running in the background without disrupting foreground
> +	processes.
> +
>  run::
>  	Run one or more maintenance tasks. If one or more `--task` options
>  	are specified, then those tasks are run in that order. Otherwise,
> @@ -36,6 +45,11 @@ run::
>  	config options are true. By default, only `maintenance.gc.enabled`
>  	is true.
>  
> +unregister::
> +	Remove the current repository from background maintenance. This
> +	only removes the repository from the configured list. It does not
> +	stop the background maintenance processes from running.
> +
>  TASKS
>  -----
>  
> diff --git a/builtin/gc.c b/builtin/gc.c
> index e28561b6c5..0290b249c9 100644
> --- a/builtin/gc.c
> +++ b/builtin/gc.c
> @@ -1408,7 +1408,56 @@ static int maintenance_run(int argc, const char **argv, const char *prefix)
>  	return maintenance_run_tasks(&opts);
>  }
>  
> -static const char builtin_maintenance_usage[] = N_("git maintenance run [<options>]");
> +static int maintenance_register(void)
> +{
> +	struct child_process config_set = CHILD_PROCESS_INIT;
> +	struct child_process config_get = CHILD_PROCESS_INIT;
> +
> +	/* There is no current repository, so skip registering it */
> +	if (!the_repository || !the_repository->gitdir)
> +		return 0;
> +
> +	config_get.git_cmd = 1;
> +	strvec_pushl(&config_get.args, "config", "--global", "--get", "maintenance.repo",
> +		     the_repository->worktree ? the_repository->worktree
> +					      : the_repository->gitdir,
> +			 NULL);
> +	config_get.out = -1;
> +
> +	if (start_command(&config_get))
> +		return error(_("failed to run 'git config'"));
> +
> +	/* We already have this value in our config! */
> +	if (!finish_command(&config_get))
> +		return 0;
> +
> +	config_set.git_cmd = 1;
> +	strvec_pushl(&config_set.args, "config", "--add", "--global", "maintenance.repo",
> +		     the_repository->worktree ? the_repository->worktree
> +					      : the_repository->gitdir,
> +		     NULL);
> +
> +	return run_command(&config_set);
> +}
> +
> +static int maintenance_unregister(void)
> +{
> +	struct child_process config_unset = CHILD_PROCESS_INIT;
> +
> +	if (!the_repository || !the_repository->gitdir)
> +		return error(_("no current repository to unregister"));
> +
> +	config_unset.git_cmd = 1;
> +	strvec_pushl(&config_unset.args, "config", "--global", "--unset",
> +		     "maintenance.repo",
> +		     the_repository->worktree ? the_repository->worktree
> +					      : the_repository->gitdir,
> +		     NULL);
> +
> +	return run_command(&config_unset);
> +}
> +
> +static const char builtin_maintenance_usage[] =	N_("git maintenance <subcommand> [<options>]");
>  
>  int cmd_maintenance(int argc, const char **argv, const char *prefix)
>  {
> @@ -1417,6 +1466,10 @@ int cmd_maintenance(int argc, const char **argv, const char *prefix)
>  
>  	if (!strcmp(argv[1], "run"))
>  		return maintenance_run(argc - 1, argv + 1, prefix);
> +	if (!strcmp(argv[1], "register"))
> +		return maintenance_register();
> +	if (!strcmp(argv[1], "unregister"))
> +		return maintenance_unregister();
>  
>  	die(_("invalid subcommand: %s"), argv[1]);
>  }
> diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh
> index 328bbaa830..272d1605d2 100755
> --- a/t/t7900-maintenance.sh
> +++ b/t/t7900-maintenance.sh
> @@ -9,7 +9,7 @@ GIT_TEST_MULTI_PACK_INDEX=0
>  
>  test_expect_success 'help text' '
>  	test_expect_code 129 git maintenance -h 2>err &&
> -	test_i18ngrep "usage: git maintenance run" err &&
> +	test_i18ngrep "usage: git maintenance <subcommand>" err &&
>  	test_expect_code 128 git maintenance barf 2>err &&
>  	test_i18ngrep "invalid subcommand: barf" err
>  '
> @@ -304,4 +304,19 @@ test_expect_success '--schedule inheritance weekly -> daily -> hourly' '
>  	test_subcommand git multi-pack-index write --no-progress <weekly.txt
>  '
>  
> +test_expect_success 'register and unregister' '
> +	test_when_finished git config --global --unset-all maintenance.repo &&
> +	git config --global --add maintenance.repo /existing1 &&
> +	git config --global --add maintenance.repo /existing2 &&
> +	git config --global --get-all maintenance.repo >before &&
> +	git maintenance register &&
> +	git config --global --get-all maintenance.repo >actual &&
> +	cp before after &&
> +	pwd >>after &&
> +	test_cmp after actual &&
> +	git maintenance unregister &&
> +	git config --global --get-all maintenance.repo >actual &&
> +	test_cmp before actual
> +'
> +
>  test_done
> -- 
> gitgitgadget
> 

-- 
Danh

  reply	other threads:[~2020-09-17 14:30 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-04 15:41 [PATCH 0/7] Maintenance III: Background maintenance Derrick Stolee via GitGitGadget
2020-09-04 15:42 ` [PATCH 1/7] maintenance: optionally skip --auto process Derrick Stolee via GitGitGadget
2020-09-04 15:42 ` [PATCH 2/7] maintenance: add --schedule option and config Derrick Stolee via GitGitGadget
2020-09-08 13:07   ` Đoàn Trần Công Danh
2020-09-09 12:14     ` Derrick Stolee
2020-09-04 15:42 ` [PATCH 3/7] for-each-repo: run subcommands on configured repos Derrick Stolee via GitGitGadget
2020-09-04 15:42 ` [PATCH 4/7] maintenance: add [un]register subcommands Derrick Stolee via GitGitGadget
2020-09-04 15:42 ` [PATCH 5/7] maintenance: add start/stop subcommands Derrick Stolee via GitGitGadget
2020-09-08  6:29   ` SZEDER Gábor
2020-09-08 12:43     ` Derrick Stolee
2020-09-08 19:31     ` Junio C Hamano
2020-09-04 15:42 ` [PATCH 6/7] maintenance: recommended schedule in register/start Derrick Stolee via GitGitGadget
2020-09-04 15:42 ` [PATCH 7/7] maintenance: add troubleshooting guide to docs Derrick Stolee via GitGitGadget
2020-09-11 17:49 ` [PATCH v2 0/7] Maintenance III: Background maintenance Derrick Stolee via GitGitGadget
2020-09-11 17:49   ` [PATCH v2 1/7] maintenance: optionally skip --auto process Derrick Stolee via GitGitGadget
2020-09-11 17:49   ` [PATCH v2 2/7] maintenance: add --schedule option and config Derrick Stolee via GitGitGadget
2020-09-11 17:49   ` [PATCH v2 3/7] for-each-repo: run subcommands on configured repos Derrick Stolee via GitGitGadget
2020-09-11 17:49   ` [PATCH v2 4/7] maintenance: add [un]register subcommands Derrick Stolee via GitGitGadget
2020-09-17 14:05     ` Đoàn Trần Công Danh [this message]
2020-09-11 17:49   ` [PATCH v2 5/7] maintenance: add start/stop subcommands Derrick Stolee via GitGitGadget
2020-09-11 17:49   ` [PATCH v2 6/7] maintenance: recommended schedule in register/start Derrick Stolee via GitGitGadget
2020-09-29 19:48     ` Martin Ågren
2020-09-30 20:11       ` Derrick Stolee
2020-10-01 20:38         ` Derrick Stolee
2020-10-02  0:38           ` Đoàn Trần Công Danh
2020-10-02  1:55             ` Derrick Stolee
2020-10-05 13:16               ` Đoàn Trần Công Danh
2020-10-05 18:17                 ` Derrick Stolee
2020-09-11 17:49   ` [PATCH v2 7/7] maintenance: add troubleshooting guide to docs Derrick Stolee via GitGitGadget
2020-10-05 12:57   ` [PATCH v3 0/7] Maintenance III: Background maintenance Derrick Stolee via GitGitGadget
2020-10-05 12:57     ` [PATCH v3 1/7] maintenance: optionally skip --auto process Derrick Stolee via GitGitGadget
2020-10-05 12:57     ` [PATCH v3 2/7] maintenance: add --schedule option and config Derrick Stolee via GitGitGadget
2020-10-05 12:57     ` [PATCH v3 3/7] for-each-repo: run subcommands on configured repos Derrick Stolee via GitGitGadget
2020-10-05 12:57     ` [PATCH v3 4/7] maintenance: add [un]register subcommands Derrick Stolee via GitGitGadget
2020-10-05 12:57     ` [PATCH v3 5/7] maintenance: add start/stop subcommands Derrick Stolee via GitGitGadget
2020-10-05 12:57     ` [PATCH v3 6/7] maintenance: use default schedule if not configured Derrick Stolee via GitGitGadget
2020-10-05 19:57       ` Martin Ågren
2020-10-08 13:32         ` Derrick Stolee
2020-10-05 12:57     ` [PATCH v3 7/7] maintenance: add troubleshooting guide to docs Derrick Stolee via GitGitGadget
2020-10-15 17:21     ` [PATCH v4 0/8] Maintenance III: Background maintenance Derrick Stolee via GitGitGadget
2020-10-15 17:21       ` [PATCH v4 1/8] maintenance: optionally skip --auto process Derrick Stolee via GitGitGadget
2020-10-15 17:21       ` [PATCH v4 2/8] maintenance: add --schedule option and config Derrick Stolee via GitGitGadget
2021-02-09 14:06         ` Ævar Arnfjörð Bjarmason
2021-02-09 16:54           ` Derrick Stolee
2021-05-10 12:16             ` Ævar Arnfjörð Bjarmason
2021-05-10 18:42               ` Junio C Hamano
2020-10-15 17:21       ` [PATCH v4 3/8] for-each-repo: run subcommands on configured repos Derrick Stolee via GitGitGadget
2021-05-03 16:10         ` Andrzej Hunt
2021-05-03 17:01           ` Eric Sunshine
2021-05-03 19:26             ` Eric Sunshine
2021-05-03 19:43           ` Derrick Stolee
2020-10-15 17:22       ` [PATCH v4 4/8] maintenance: add [un]register subcommands Derrick Stolee via GitGitGadget
2020-10-15 17:22       ` [PATCH v4 5/8] maintenance: add start/stop subcommands Derrick Stolee via GitGitGadget
2020-12-09 18:51         ` Josh Steadmon
2020-12-09 19:16           ` Josh Steadmon
2020-12-09 21:59             ` Derrick Stolee
2020-12-10  0:13             ` Junio C Hamano
2020-12-10  1:52               ` Derrick Stolee
2020-12-10  6:54                 ` Junio C Hamano
2020-10-15 17:22       ` [PATCH v4 6/8] maintenance: create maintenance.strategy config Derrick Stolee via GitGitGadget
2020-10-15 17:22       ` [PATCH v4 7/8] maintenance: use 'incremental' strategy by default Derrick Stolee via GitGitGadget
2020-10-15 17:22       ` [PATCH v4 8/8] maintenance: add troubleshooting guide to docs Derrick Stolee via GitGitGadget

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200917140543.GC8664@danh.dev \
    --to=congdanhqx@gmail.com \
    --cc=derrickstolee@github.com \
    --cc=dstolee@microsoft.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=jonathantanmy@google.com \
    --cc=jrnieder@gmail.com \
    --cc=sluongng@gmail.com \
    --cc=stolee@gmail.com \
    --cc=szeder.dev@gmail.com \
    --subject='Re: [PATCH v2 4/7] maintenance: add [un]register subcommands' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

git@vger.kernel.org list mirror (unofficial, one of many)

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 git git/ https://public-inbox.org/git \
		git@vger.kernel.org
	public-inbox-index git

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/inbox.comp.version-control.git
	nntp://ie5yzdi7fg72h7s4sdcztq5evakq23rdt33mfyfcddc5u3ndnw24ogqd.onion/inbox.comp.version-control.git
	nntp://4uok3hntl7oi7b4uf4rtfwefqeexfzil2w6kgk2jn5z2f764irre7byd.onion/inbox.comp.version-control.git
	nntp://news.gmane.io/gmane.comp.version-control.git
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git