Skip to content

Commit

Permalink
scalar: enable built-in FSMonitor on register
Browse files Browse the repository at this point in the history
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).

Signed-off-by: Matthew John Cheetham <mjcheetham@outlook.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
  • Loading branch information
mjcheetham authored and dscho committed Jun 7, 2021
1 parent b2c2c95 commit 4f2e092
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
36 changes: 36 additions & 0 deletions contrib/scalar/scalar.c
Expand Up @@ -10,6 +10,8 @@
#include "refs.h"
#include "help.h"
#include "dir.h"
#include "simple-ipc.h"
#include "fsmonitor-ipc.h"

static void setup_enlistment_directory(int argc, const char **argv,
const char * const *usagestr,
Expand Down Expand Up @@ -150,6 +152,12 @@ static int set_recommended_config(int reconfigure)
{ "maintenance.incremental-repack.enabled", "true" },
{ "maintenance.incremental-repack.auto", "0" },
{ "maintenance.incremental-repack.schedule", "daily" },
#ifdef HAVE_FSMONITOR_DAEMON_BACKEND
/*
* Enable the built-in FSMonitor on supported platforms.
*/
{ "core.useBuiltinFSMonitor", "true" },
#endif
{ NULL, NULL },
};
int i;
Expand Down Expand Up @@ -220,6 +228,31 @@ static int add_or_remove_enlistment(int add)
"scalar.repo", the_repository->worktree, NULL);
}

static int start_fsmonitor_daemon(void)
{
#ifdef HAVE_FSMONITOR_DAEMON_BACKEND
struct strbuf err = STRBUF_INIT;
struct child_process cp = CHILD_PROCESS_INIT;

cp.git_cmd = 1;
strvec_pushl(&cp.args, "fsmonitor--daemon", "start", NULL);
if (!pipe_command(&cp, NULL, 0, NULL, 0, &err, 0)) {
strbuf_release(&err);
return 0;
}

if (fsmonitor_ipc__get_state() != IPC_STATE__LISTENING) {
write_in_full(2, err.buf, err.len);
strbuf_release(&err);
return error(_("could not start the FSMonitor daemon"));
}

strbuf_release(&err);
#endif

return 0;
}

static int register_dir(void)
{
int res = add_or_remove_enlistment(1);
Expand All @@ -230,6 +263,9 @@ static int register_dir(void)
if (!res)
res = toggle_maintenance(1);

if (!res)
res = start_fsmonitor_daemon();

return res;
}

Expand Down
11 changes: 11 additions & 0 deletions contrib/scalar/t/t9099-scalar.sh
Expand Up @@ -13,10 +13,21 @@ PATH=$(pwd)/..:$PATH
GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab ../cron.txt"
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 &&
Expand Down

0 comments on commit 4f2e092

Please sign in to comment.