Skip to content

Commit 3f1917d

Browse files
mjcheethamgitster
authored andcommitted
scalar: enable built-in FSMonitor on register
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 <[email protected]> Helped-by: Derrick Stolee <[email protected]> Signed-off-by: Matthew John Cheetham <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Victoria Dye <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d934a11 commit 3f1917d

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

contrib/scalar/scalar.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
#include "parse-options.h"
88
#include "config.h"
99
#include "run-command.h"
10+
#include "simple-ipc.h"
11+
#include "fsmonitor-ipc.h"
12+
#include "fsmonitor-settings.h"
1013
#include "refs.h"
1114
#include "dir.h"
1215
#include "packfile.h"
@@ -109,6 +112,12 @@ static int set_scalar_config(const struct scalar_config *config, int reconfigure
109112
return res;
110113
}
111114

115+
static int have_fsmonitor_support(void)
116+
{
117+
return fsmonitor_ipc__is_supported() &&
118+
fsm_settings__get_reason(the_repository) == FSMONITOR_REASON_OK;
119+
}
120+
112121
static int set_recommended_config(int reconfigure)
113122
{
114123
struct scalar_config config[] = {
@@ -170,6 +179,13 @@ static int set_recommended_config(int reconfigure)
170179
config[i].key, config[i].value);
171180
}
172181

182+
if (have_fsmonitor_support()) {
183+
struct scalar_config fsmonitor = { "core.fsmonitor", "true" };
184+
if (set_scalar_config(&fsmonitor, reconfigure))
185+
return error(_("could not configure %s=%s"),
186+
fsmonitor.key, fsmonitor.value);
187+
}
188+
173189
/*
174190
* The `log.excludeDecoration` setting is special because it allows
175191
* for multiple values.
@@ -218,6 +234,16 @@ static int add_or_remove_enlistment(int add)
218234
"scalar.repo", the_repository->worktree, NULL);
219235
}
220236

237+
static int start_fsmonitor_daemon(void)
238+
{
239+
assert(have_fsmonitor_support());
240+
241+
if (fsmonitor_ipc__get_state() != IPC_STATE__LISTENING)
242+
return run_git("fsmonitor--daemon", "start", NULL);
243+
244+
return 0;
245+
}
246+
221247
static int register_dir(void)
222248
{
223249
if (add_or_remove_enlistment(1))
@@ -229,6 +255,10 @@ static int register_dir(void)
229255
if (toggle_maintenance(1))
230256
return error(_("could not turn on maintenance"));
231257

258+
if (have_fsmonitor_support() && start_fsmonitor_daemon()) {
259+
return error(_("could not start the FSMonitor daemon"));
260+
}
261+
232262
return 0;
233263
}
234264

contrib/scalar/t/t9099-scalar.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ test_expect_success 'scalar enlistments need a worktree' '
102102
grep "Scalar enlistments require a worktree" err
103103
'
104104

105+
test_expect_success FSMONITOR_DAEMON 'scalar register starts fsmon daemon' '
106+
git init test/src &&
107+
test_must_fail git -C test/src fsmonitor--daemon status &&
108+
scalar register test/src &&
109+
git -C test/src fsmonitor--daemon status &&
110+
test_cmp_config -C test/src true core.fsmonitor
111+
'
112+
105113
test_expect_success 'scalar unregister' '
106114
git init vanish/src &&
107115
scalar register vanish/src &&

0 commit comments

Comments
 (0)