summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDerrick Stolee <dstolee@microsoft.com>2021-12-03 13:34:20 +0000
committerJunio C Hamano <gitster@pobox.com>2021-12-04 21:52:23 -0800
commitc76a53eb71c5d0d931b1f95a9933913ecef9e4ad (patch)
tree82a54b67c682533892444740e11ac421bbced9e4
parentd0feac4e8c0b60b16c06363f9feb3e2d0ecf00f1 (diff)
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>
-rw-r--r--contrib/scalar/scalar.c50
-rw-r--r--contrib/scalar/scalar.txt8
2 files changed, 50 insertions, 8 deletions
diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c
index 55a304442d..9ab9dffe3a 100644
--- a/contrib/scalar/scalar.c
+++ b/contrib/scalar/scalar.c
@@ -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},
};
diff --git a/contrib/scalar/scalar.txt b/contrib/scalar/scalar.txt
index 568987064b..d9a7998449 100644
--- a/contrib/scalar/scalar.txt
+++ b/contrib/scalar/scalar.txt
@@ -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].