3 #include "repository.h"
4 #include "fsmonitor-settings.h"
7 * We keep this structure defintion private and have getters
8 * for all fields so that we can lazy load it as needed.
10 struct fsmonitor_settings
{
11 enum fsmonitor_mode mode
;
15 static void lookup_fsmonitor_settings(struct repository
*r
)
17 struct fsmonitor_settings
*s
;
18 const char *const_str
;
21 if (r
->settings
.fsmonitor
)
25 s
->mode
= FSMONITOR_MODE_DISABLED
;
27 r
->settings
.fsmonitor
= s
;
30 * Overload the existing "core.fsmonitor" config setting (which
31 * has historically been either unset or a hook pathname) to
32 * now allow a boolean value to enable the builtin FSMonitor
33 * or to turn everything off. (This does imply that you can't
34 * use a hook script named "true" or "false", but that's OK.)
36 switch (repo_config_get_maybe_bool(r
, "core.fsmonitor", &bool_value
)) {
38 case 0: /* config value was set to <bool> */
40 fsm_settings__set_ipc(r
);
43 case 1: /* config value was unset */
44 const_str
= getenv("GIT_TEST_FSMONITOR");
47 case -1: /* config value set to an arbitrary string */
48 if (repo_config_get_pathname(r
, "core.fsmonitor", &const_str
))
49 return; /* should not happen */
52 default: /* should not happen */
56 if (!const_str
|| !*const_str
)
59 fsm_settings__set_hook(r
, const_str
);
62 enum fsmonitor_mode
fsm_settings__get_mode(struct repository
*r
)
67 lookup_fsmonitor_settings(r
);
69 return r
->settings
.fsmonitor
->mode
;
72 const char *fsm_settings__get_hook_path(struct repository
*r
)
77 lookup_fsmonitor_settings(r
);
79 return r
->settings
.fsmonitor
->hook_path
;
82 void fsm_settings__set_ipc(struct repository
*r
)
87 lookup_fsmonitor_settings(r
);
89 r
->settings
.fsmonitor
->mode
= FSMONITOR_MODE_IPC
;
90 FREE_AND_NULL(r
->settings
.fsmonitor
->hook_path
);
93 void fsm_settings__set_hook(struct repository
*r
, const char *path
)
98 lookup_fsmonitor_settings(r
);
100 r
->settings
.fsmonitor
->mode
= FSMONITOR_MODE_HOOK
;
101 FREE_AND_NULL(r
->settings
.fsmonitor
->hook_path
);
102 r
->settings
.fsmonitor
->hook_path
= strdup(path
);
105 void fsm_settings__set_disabled(struct repository
*r
)
110 lookup_fsmonitor_settings(r
);
112 r
->settings
.fsmonitor
->mode
= FSMONITOR_MODE_DISABLED
;
113 FREE_AND_NULL(r
->settings
.fsmonitor
->hook_path
);