Skip to content

Commit c76a53e

Browse files
derrickstoleevdye
authored andcommitted
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 <[email protected]> Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d0feac4 commit c76a53e

File tree

2 files changed

+50
-8
lines changed

2 files changed

+50
-8
lines changed

contrib/scalar/scalar.c

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,12 @@ static int set_recommended_config(void)
198198
return 0;
199199
}
200200

201-
static int start_maintenance(void)
201+
static int toggle_maintenance(int enable)
202202
{
203-
return run_git("maintenance", "start", NULL);
203+
return run_git("maintenance", enable ? "start" : "unregister", NULL);
204204
}
205205

206-
static int add_enlistment(void)
206+
static int add_or_remove_enlistment(int add)
207207
{
208208
int res;
209209

@@ -214,24 +214,39 @@ static int add_enlistment(void)
214214
"scalar.repo", the_repository->worktree, NULL);
215215

216216
/*
217-
* If the setting is already there, then do nothing.
217+
* If we want to add and the setting is already there, then do nothing.
218+
* If we want to remove and the setting is not there, then do nothing.
218219
*/
219-
if (!res)
220+
if ((add && !res) || (!add && res))
220221
return 0;
221222

222-
return run_git("config", "--global", "--add",
223+
return run_git("config", "--global", add ? "--add" : "--unset",
224+
add ? "--no-fixed-value" : "--fixed-value",
223225
"scalar.repo", the_repository->worktree, NULL);
224226
}
225227

226228
static int register_dir(void)
227229
{
228-
int res = add_enlistment();
230+
int res = add_or_remove_enlistment(1);
229231

230232
if (!res)
231233
res = set_recommended_config();
232234

233235
if (!res)
234-
res = start_maintenance();
236+
res = toggle_maintenance(1);
237+
238+
return res;
239+
}
240+
241+
static int unregister_dir(void)
242+
{
243+
int res = 0;
244+
245+
if (toggle_maintenance(0) < 0)
246+
res = -1;
247+
248+
if (add_or_remove_enlistment(0) < 0)
249+
res = -1;
235250

236251
return res;
237252
}
@@ -254,11 +269,30 @@ static int cmd_register(int argc, const char **argv)
254269
return register_dir();
255270
}
256271

272+
static int cmd_unregister(int argc, const char **argv)
273+
{
274+
struct option options[] = {
275+
OPT_END(),
276+
};
277+
const char * const usage[] = {
278+
N_("scalar unregister [<enlistment>]"),
279+
NULL
280+
};
281+
282+
argc = parse_options(argc, argv, NULL, options,
283+
usage, 0);
284+
285+
setup_enlistment_directory(argc, argv, usage, options, NULL);
286+
287+
return unregister_dir();
288+
}
289+
257290
static struct {
258291
const char *name;
259292
int (*fn)(int, const char **);
260293
} builtins[] = {
261294
{ "register", cmd_register },
295+
{ "unregister", cmd_unregister },
262296
{ NULL, NULL},
263297
};
264298

contrib/scalar/scalar.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ SYNOPSIS
99
--------
1010
[verse]
1111
scalar register [<enlistment>]
12+
scalar unregister [<enlistment>]
1213

1314
DESCRIPTION
1415
-----------
@@ -45,6 +46,13 @@ Note: when this subcommand is called in a worktree that is called `src/`, its
4546
parent directory is considered to be the Scalar enlistment. If the worktree is
4647
_not_ called `src/`, it itself will be considered to be the Scalar enlistment.
4748

49+
Unregister
50+
~~~~~~~~~~
51+
52+
unregister [<enlistment>]::
53+
Remove the specified repository from the list of repositories
54+
registered with Scalar and stop the scheduled background maintenance.
55+
4856
SEE ALSO
4957
--------
5058
linkgit:git-maintenance[1].

0 commit comments

Comments
 (0)