scalar: 'unregister' stops background maintenance

Just like `scalar register` starts the scheduled background maintenance,
`scalar unregister` stops it. Note that we use `git maintenance start`
in `scalar register`, but we do not use `git maintenance stop` in
`scalar unregister`: this would stop maintenance for _all_ repositories,
not just for the one we want to unregister.

The `unregister` command also removes the corresponding entry from the
`[scalar]` section in the global Git config.

Co-authored-by: Victoria Dye <vdye@github.com>
Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Derrick Stolee
2021-12-03 13:34:20 +00:00
committed by Junio C Hamano
parent d0feac4e8c
commit c76a53eb71
2 changed files with 50 additions and 8 deletions

View File

@ -198,12 +198,12 @@ static int set_recommended_config(void)
return 0;
}
static int start_maintenance(void)
static int toggle_maintenance(int enable)
{
return run_git("maintenance", "start", NULL);
return run_git("maintenance", enable ? "start" : "unregister", NULL);
}
static int add_enlistment(void)
static int add_or_remove_enlistment(int add)
{
int res;
@ -214,24 +214,39 @@ static int add_enlistment(void)
"scalar.repo", the_repository->worktree, NULL);
/*
* If the setting is already there, then do nothing.
* If we want to add and the setting is already there, then do nothing.
* If we want to remove and the setting is not there, then do nothing.
*/
if (!res)
if ((add && !res) || (!add && res))
return 0;
return run_git("config", "--global", "--add",
return run_git("config", "--global", add ? "--add" : "--unset",
add ? "--no-fixed-value" : "--fixed-value",
"scalar.repo", the_repository->worktree, NULL);
}
static int register_dir(void)
{
int res = add_enlistment();
int res = add_or_remove_enlistment(1);
if (!res)
res = set_recommended_config();
if (!res)
res = start_maintenance();
res = toggle_maintenance(1);
return res;
}
static int unregister_dir(void)
{
int res = 0;
if (toggle_maintenance(0) < 0)
res = -1;
if (add_or_remove_enlistment(0) < 0)
res = -1;
return res;
}
@ -254,11 +269,30 @@ static int cmd_register(int argc, const char **argv)
return register_dir();
}
static int cmd_unregister(int argc, const char **argv)
{
struct option options[] = {
OPT_END(),
};
const char * const usage[] = {
N_("scalar unregister [<enlistment>]"),
NULL
};
argc = parse_options(argc, argv, NULL, options,
usage, 0);
setup_enlistment_directory(argc, argv, usage, options, NULL);
return unregister_dir();
}
static struct {
const char *name;
int (*fn)(int, const char **);
} builtins[] = {
{ "register", cmd_register },
{ "unregister", cmd_unregister },
{ NULL, NULL},
};

View File

@ -9,6 +9,7 @@ SYNOPSIS
--------
[verse]
scalar register [<enlistment>]
scalar unregister [<enlistment>]
DESCRIPTION
-----------
@ -45,6 +46,13 @@ Note: when this subcommand is called in a worktree that is called `src/`, its
parent directory is considered to be the Scalar enlistment. If the worktree is
_not_ called `src/`, it itself will be considered to be the Scalar enlistment.
Unregister
~~~~~~~~~~
unregister [<enlistment>]::
Remove the specified repository from the list of repositories
registered with Scalar and stop the scheduled background maintenance.
SEE ALSO
--------
linkgit:git-maintenance[1].