]> git.ipfire.org Git - thirdparty/git.git/commitdiff
scalar: 'unregister' stops background maintenance
authorDerrick Stolee <dstolee@microsoft.com>
Fri, 3 Dec 2021 13:34:20 +0000 (13:34 +0000)
committerJunio C Hamano <gitster@pobox.com>
Sun, 5 Dec 2021 05:52:23 +0000 (21:52 -0800)
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>
contrib/scalar/scalar.c
contrib/scalar/scalar.txt

index 55a304442d48066b41333051c912c5e812a9c085..9ab9dffe3ac4f540677752ce31cd3f3c1145f3dc 100644 (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},
 };
 
index 568987064b228644ce146bb1b9ec1261f04009f7..d9a79984492a8e40bdae51dc0f7aa112a6bae123 100644 (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].