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 <stolee@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed May 7, 2025 at 01:50 UTC c428216d4df289704ad01bb413c177bc0de32e0c
1 file changed +22 -7
scalar.c
+22 -7
@@ -209,6 +209,12 @@ static int set_recommended_config(int reconfigure)
209 return 0;
210 }
211
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 + */
218 static int toggle_maintenance(int enable)
219 {
220 return run_git("maintenance",
@@ -259,7 +265,15 @@ static int stop_fsmonitor_daemon(void)
265 return 0;
266 }
267
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)
277 {
278 if (add_or_remove_enlistment(1))
279 return error(_("could not add enlistment"));
@@ -267,8 +281,9 @@ static int register_dir(void)
281 if (set_recommended_config(0))
282 return error(_("could not set recommended config"));
283
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"));
287
288 if (have_fsmonitor_support() && start_fsmonitor_daemon()) {
289 return error(_("could not start the FSMonitor daemon"));
@@ -550,7 +565,7 @@ static int cmd_clone(int argc, const char **argv)
565 if (res)
566 goto cleanup;
567
553 - res = register_dir();
568 + res = register_dir(1);
569
570 cleanup:
571 free(branch_to_free);
@@ -610,7 +625,7 @@ static int cmd_register(int argc, const char **argv)
625
626 setup_enlistment_directory(argc, argv, usage, options, NULL);
627
613 - return register_dir();
628 + return register_dir(1);
629 }
630
631 static int get_scalar_repos(const char *key, const char *value,
@@ -803,13 +818,13 @@ static int cmd_run(int argc, const char **argv)
818 strbuf_release(&buf);
819
820 if (i == 0)
806 - return register_dir();
821 + return register_dir(1);
822
823 if (i > 0)
824 return run_git("maintenance", "run",
825 "--task", tasks[i].task, NULL);
826
812 - if (register_dir())
827 + if (register_dir(1))
828 return -1;
829 for (i = 1; tasks[i].arg; i++)
830 if (run_git("maintenance", "run",