From: Matthew John Cheetham <mjcheetham@xxxxxxxxxxx> Using the built-in FSMonitor makes many common commands quite a bit faster. So let's teach the `scalar register` command to enable the built-in FSMonitor and kick-start the fsmonitor--daemon process (for convenience). For simplicity, we only support the built-in FSMonitor (and no external file system monitor such as e.g. Watchman). Helped-by: Junio C Hamano <gitster@xxxxxxxxx> Signed-off-by: Matthew John Cheetham <mjcheetham@xxxxxxxxxxx> Signed-off-by: Johannes Schindelin <johannes.schindelin@xxxxxx> Signed-off-by: Victoria Dye <vdye@xxxxxxxxxx> --- contrib/scalar/scalar.c | 21 +++++++++++++++++++++ contrib/scalar/t/t9099-scalar.sh | 11 +++++++++++ 2 files changed, 32 insertions(+) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index 6025cd71604..28d915ec006 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -7,6 +7,8 @@ #include "parse-options.h" #include "config.h" #include "run-command.h" +#include "simple-ipc.h" +#include "fsmonitor-ipc.h" #include "refs.h" #include "dir.h" #include "packfile.h" @@ -169,6 +171,12 @@ static int set_recommended_config(int reconfigure) { "core.autoCRLF", "false" }, { "core.safeCRLF", "false" }, { "fetch.showForcedUpdates", "false" }, +#ifdef HAVE_FSMONITOR_DAEMON_BACKEND + /* + * Enable the built-in FSMonitor on supported platforms. + */ + { "core.fsmonitor", "true" }, +#endif { NULL, NULL }, }; int i; @@ -236,6 +244,16 @@ static int add_or_remove_enlistment(int add) "scalar.repo", the_repository->worktree, NULL); } +static int start_fsmonitor_daemon(void) +{ + assert(fsmonitor_ipc__is_supported()); + + if (fsmonitor_ipc__get_state() != IPC_STATE__LISTENING) + return run_git("fsmonitor--daemon", "start", NULL); + + return 0; +} + static int register_dir(void) { if (add_or_remove_enlistment(1)) @@ -247,6 +265,9 @@ static int register_dir(void) if (toggle_maintenance(1)) return error(_("could not turn on maintenance")); + if (fsmonitor_ipc__is_supported() && start_fsmonitor_daemon()) + return error(_("could not start the FSMonitor daemon")); + return 0; } diff --git a/contrib/scalar/t/t9099-scalar.sh b/contrib/scalar/t/t9099-scalar.sh index 10b1172a8aa..526f64d001c 100755 --- a/contrib/scalar/t/t9099-scalar.sh +++ b/contrib/scalar/t/t9099-scalar.sh @@ -13,10 +13,21 @@ PATH=$PWD/..:$PATH GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab ../cron.txt,launchctl:true,schtasks:true" export GIT_TEST_MAINT_SCHEDULER +test_lazy_prereq BUILTIN_FSMONITOR ' + git version --build-options | grep -q "feature:.*fsmonitor--daemon" +' + test_expect_success 'scalar shows a usage' ' test_expect_code 129 scalar -h ' +test_expect_success BUILTIN_FSMONITOR 'scalar register starts fsmon daemon' ' + git init test/src && + test_must_fail git -C test/src fsmonitor--daemon status && + scalar register test/src && + git -C test/src fsmonitor--daemon status +' + test_expect_success 'scalar unregister' ' git init vanish/src && scalar register vanish/src && -- gitgitgadget