forked from msysgit/git
/
fsmonitor-settings.c
97 lines (73 loc) · 1.84 KB
/
fsmonitor-settings.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "cache.h"
#include "config.h"
#include "repository.h"
#include "fsmonitor-settings.h"
/*
* We keep this structure defintion private and have getters
* for all fields so that we can lazy load it as needed.
*/
struct fsmonitor_settings {
enum fsmonitor_mode mode;
char *hook_path;
};
void fsm_settings__set_ipc(struct repository *r)
{
struct fsmonitor_settings *s = r->settings.fsmonitor;
s->mode = FSMONITOR_MODE_IPC;
}
void fsm_settings__set_hook(struct repository *r, const char *path)
{
struct fsmonitor_settings *s = r->settings.fsmonitor;
s->mode = FSMONITOR_MODE_HOOK;
s->hook_path = strdup(path);
}
void fsm_settings__set_disabled(struct repository *r)
{
struct fsmonitor_settings *s = r->settings.fsmonitor;
s->mode = FSMONITOR_MODE_DISABLED;
FREE_AND_NULL(s->hook_path);
}
static int check_for_ipc(struct repository *r)
{
int value;
if (!repo_config_get_bool(r, "core.usebuiltinfsmonitor", &value) &&
value) {
fsm_settings__set_ipc(r);
return 1;
}
return 0;
}
static int check_for_hook(struct repository *r)
{
const char *const_str;
if (repo_config_get_pathname(r, "core.fsmonitor", &const_str))
const_str = getenv("GIT_TEST_FSMONITOR");
if (const_str && *const_str) {
fsm_settings__set_hook(r, const_str);
return 1;
}
return 0;
}
static void lookup_fsmonitor_settings(struct repository *r)
{
struct fsmonitor_settings *s;
CALLOC_ARRAY(s, 1);
r->settings.fsmonitor = s;
if (check_for_ipc(r))
return;
if (check_for_hook(r))
return;
fsm_settings__set_disabled(r);
}
enum fsmonitor_mode fsm_settings__get_mode(struct repository *r)
{
if (!r->settings.fsmonitor)
lookup_fsmonitor_settings(r);
return r->settings.fsmonitor->mode;
}
const char *fsm_settings__get_hook_path(struct repository *r)
{
if (!r->settings.fsmonitor)
lookup_fsmonitor_settings(r);
return r->settings.fsmonitor->hook_path;
}