Makefile: sort source files before feeding to xgettext
[git/debian.git] / fsmonitor-settings.c
blob757d230d538056fb88e7ed8d290df3f68c06a78d
1 #include "cache.h"
2 #include "config.h"
3 #include "repository.h"
4 #include "fsmonitor-settings.h"
6 /*
7 * We keep this structure defintion private and have getters
8 * for all fields so that we can lazy load it as needed.
9 */
10 struct fsmonitor_settings {
11 enum fsmonitor_mode mode;
12 char *hook_path;
15 static void lookup_fsmonitor_settings(struct repository *r)
17 struct fsmonitor_settings *s;
18 const char *const_str;
19 int bool_value;
21 if (r->settings.fsmonitor)
22 return;
24 CALLOC_ARRAY(s, 1);
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> */
39 if (bool_value)
40 fsm_settings__set_ipc(r);
41 return;
43 case 1: /* config value was unset */
44 const_str = getenv("GIT_TEST_FSMONITOR");
45 break;
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 */
50 break;
52 default: /* should not happen */
53 return;
56 if (!const_str || !*const_str)
57 return;
59 fsm_settings__set_hook(r, const_str);
62 enum fsmonitor_mode fsm_settings__get_mode(struct repository *r)
64 if (!r)
65 r = the_repository;
67 lookup_fsmonitor_settings(r);
69 return r->settings.fsmonitor->mode;
72 const char *fsm_settings__get_hook_path(struct repository *r)
74 if (!r)
75 r = the_repository;
77 lookup_fsmonitor_settings(r);
79 return r->settings.fsmonitor->hook_path;
82 void fsm_settings__set_ipc(struct repository *r)
84 if (!r)
85 r = the_repository;
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)
95 if (!r)
96 r = the_repository;
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)
107 if (!r)
108 r = the_repository;
110 lookup_fsmonitor_settings(r);
112 r->settings.fsmonitor->mode = FSMONITOR_MODE_DISABLED;
113 FREE_AND_NULL(r->settings.fsmonitor->hook_path);