forked from git/git
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fsmonitor: config settings are repository-specific
Move FSMonitor config settings to a new `struct fsmonitor_settings` structure. Add a lazily-loaded pointer to `struct repo_settings`. Create `fsm_settings__get_*()` getters to lazily look up fsmonitor- related config settings. Get rid of the `core_fsmonitor` global variable, and add support for the new `core.useBuiltinFSMonitor` config setting. Move config code to lookup the existing `core.fsmonitor` value to `fsmonitor-settings.[ch]`. The `core_fsmonitor` global variable was used to store the pathname to the FSMonitor hook and it was used as a boolean to see if FSMonitor was enabled. This dual usage will lead to confusion when we add support for a builtin FSMonitor based on IPC, since the builtin FSMonitor doesn't need the hook pathname. Replace the boolean usage with an `enum fsmonitor_mode` to represent the state of FSMonitor. And only set the pathname when in HOOK mode. Signed-off-by: Jeff Hostetler <[email protected]>
- Loading branch information
1 parent
0aaca2f
commit 0a756b2
Showing
13 changed files
with
194 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#ifndef FSMONITOR_SETTINGS_H | ||
#define FSMONITOR_SETTINGS_H | ||
|
||
struct repository; | ||
|
||
enum fsmonitor_mode { | ||
FSMONITOR_MODE_DISABLED = 0, | ||
FSMONITOR_MODE_HOOK = 1, /* core.fsmonitor */ | ||
FSMONITOR_MODE_IPC = 2, /* core.useBuiltinFSMonitor */ | ||
}; | ||
|
||
void fsm_settings__set_ipc(struct repository *r); | ||
void fsm_settings__set_hook(struct repository *r, const char *path); | ||
void fsm_settings__set_disabled(struct repository *r); | ||
|
||
enum fsmonitor_mode fsm_settings__get_mode(struct repository *r); | ||
const char *fsm_settings__get_hook_path(struct repository *r); | ||
|
||
struct fsmonitor_settings; | ||
|
||
#endif /* FSMONITOR_SETTINGS_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.