Skip to content

Commit c428216

Browse files
derrickstoleegitster
authored andcommitted
scalar: customize register_dir()'s behavior
In advance of adding a --[no-]maintenance option to several 'scalar' subcommands, extend the register_dir() method to include an option for how it should handle background maintenance. It's important that we understand the context of toggle_maintenance() that will enable _or disable_ maintenance depending on its input value. Add a doc comment with this information. Similarly, update register_dir() to either enable maintenance or leave it alone. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6c0bd1f commit c428216

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

scalar.c

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,12 @@ static int set_recommended_config(int reconfigure)
209209
return 0;
210210
}
211211

212+
/**
213+
* Enable or disable the maintenance mode for the current repository:
214+
*
215+
* * If 'enable' is nonzero, run 'git maintenance start'.
216+
* * If 'enable' is zero, run 'git maintenance unregister --force'.
217+
*/
212218
static int toggle_maintenance(int enable)
213219
{
214220
return run_git("maintenance",
@@ -259,16 +265,25 @@ static int stop_fsmonitor_daemon(void)
259265
return 0;
260266
}
261267

262-
static int register_dir(void)
268+
/**
269+
* Register the current directory as a Scalar enlistment, and set the
270+
* recommended configuration.
271+
*
272+
* * If 'maintenance' is non-zero, then enable background maintenance.
273+
* * If 'maintenance' is zero, then leave background maintenance as it is
274+
* currently configured.
275+
*/
276+
static int register_dir(int maintenance)
263277
{
264278
if (add_or_remove_enlistment(1))
265279
return error(_("could not add enlistment"));
266280

267281
if (set_recommended_config(0))
268282
return error(_("could not set recommended config"));
269283

270-
if (toggle_maintenance(1))
271-
warning(_("could not turn on maintenance"));
284+
if (maintenance &&
285+
toggle_maintenance(maintenance))
286+
warning(_("could not toggle maintenance"));
272287

273288
if (have_fsmonitor_support() && start_fsmonitor_daemon()) {
274289
return error(_("could not start the FSMonitor daemon"));
@@ -550,7 +565,7 @@ static int cmd_clone(int argc, const char **argv)
550565
if (res)
551566
goto cleanup;
552567

553-
res = register_dir();
568+
res = register_dir(1);
554569

555570
cleanup:
556571
free(branch_to_free);
@@ -610,7 +625,7 @@ static int cmd_register(int argc, const char **argv)
610625

611626
setup_enlistment_directory(argc, argv, usage, options, NULL);
612627

613-
return register_dir();
628+
return register_dir(1);
614629
}
615630

616631
static int get_scalar_repos(const char *key, const char *value,
@@ -803,13 +818,13 @@ static int cmd_run(int argc, const char **argv)
803818
strbuf_release(&buf);
804819

805820
if (i == 0)
806-
return register_dir();
821+
return register_dir(1);
807822

808823
if (i > 0)
809824
return run_git("maintenance", "run",
810825
"--task", tasks[i].task, NULL);
811826

812-
if (register_dir())
827+
if (register_dir(1))
813828
return -1;
814829
for (i = 1; tasks[i].arg; i++)
815830
if (run_git("maintenance", "run",

0 commit comments

Comments
 (0)