]> git.ipfire.org Git - thirdparty/git.git/blob - fsmonitor-settings.c
rev-parse: documentation adjustment - mention remote tracking with @{u}
[thirdparty/git.git] / fsmonitor-settings.c
1 #include "cache.h"
2 #include "config.h"
3 #include "repository.h"
4 #include "fsmonitor-settings.h"
5
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;
13 };
14
15 static void lookup_fsmonitor_settings(struct repository *r)
16 {
17 struct fsmonitor_settings *s;
18 const char *const_str;
19 int bool_value;
20
21 if (r->settings.fsmonitor)
22 return;
23
24 CALLOC_ARRAY(s, 1);
25 s->mode = FSMONITOR_MODE_DISABLED;
26
27 r->settings.fsmonitor = s;
28
29 /*
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.)
35 */
36 switch (repo_config_get_maybe_bool(r, "core.fsmonitor", &bool_value)) {
37
38 case 0: /* config value was set to <bool> */
39 if (bool_value)
40 fsm_settings__set_ipc(r);
41 return;
42
43 case 1: /* config value was unset */
44 const_str = getenv("GIT_TEST_FSMONITOR");
45 break;
46
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;
51
52 default: /* should not happen */
53 return;
54 }
55
56 if (!const_str || !*const_str)
57 return;
58
59 fsm_settings__set_hook(r, const_str);
60 }
61
62 enum fsmonitor_mode fsm_settings__get_mode(struct repository *r)
63 {
64 if (!r)
65 r = the_repository;
66
67 lookup_fsmonitor_settings(r);
68
69 return r->settings.fsmonitor->mode;
70 }
71
72 const char *fsm_settings__get_hook_path(struct repository *r)
73 {
74 if (!r)
75 r = the_repository;
76
77 lookup_fsmonitor_settings(r);
78
79 return r->settings.fsmonitor->hook_path;
80 }
81
82 void fsm_settings__set_ipc(struct repository *r)
83 {
84 if (!r)
85 r = the_repository;
86
87 lookup_fsmonitor_settings(r);
88
89 r->settings.fsmonitor->mode = FSMONITOR_MODE_IPC;
90 FREE_AND_NULL(r->settings.fsmonitor->hook_path);
91 }
92
93 void fsm_settings__set_hook(struct repository *r, const char *path)
94 {
95 if (!r)
96 r = the_repository;
97
98 lookup_fsmonitor_settings(r);
99
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);
103 }
104
105 void fsm_settings__set_disabled(struct repository *r)
106 {
107 if (!r)
108 r = the_repository;
109
110 lookup_fsmonitor_settings(r);
111
112 r->settings.fsmonitor->mode = FSMONITOR_MODE_DISABLED;
113 FREE_AND_NULL(r->settings.fsmonitor->hook_path);
114 }