Skip to content

Commit feea1cb

Browse files
jeffhostetlerdscho
authored andcommitted
fixup! fsmonitor: config settings are repository-specific
This reverts commit 81f7337. Signed-off-by: Jeff Hostetler <[email protected]>
1 parent c6e29c2 commit feea1cb

13 files changed

+51
-194
lines changed

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,6 @@ LIB_OBJS += fmt-merge-msg.o
904904
LIB_OBJS += fsck.o
905905
LIB_OBJS += fsmonitor.o
906906
LIB_OBJS += fsmonitor-ipc.o
907-
LIB_OBJS += fsmonitor-settings.o
908907
LIB_OBJS += gettext.o
909908
LIB_OBJS += gpg-interface.o
910909
LIB_OBJS += graph.o

builtin/update-index.c

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,25 +1216,14 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
12161216
}
12171217

12181218
if (fsmonitor > 0) {
1219-
enum fsmonitor_mode fsm_mode = fsm_settings__get_mode(r);
1220-
1221-
if (fsm_mode == FSMONITOR_MODE_DISABLED) {
1222-
warning(_("core.useBuiltinFSMonitor is unset; "
1223-
"set it if you really want to enable the "
1224-
"builtin fsmonitor"));
1219+
if (git_config_get_fsmonitor() == 0)
12251220
warning(_("core.fsmonitor is unset; "
1226-
"set it if you really want to enable the "
1227-
"hook-based fsmonitor"));
1228-
}
1221+
"set it if you really want to "
1222+
"enable fsmonitor"));
12291223
add_fsmonitor(&the_index);
12301224
report(_("fsmonitor enabled"));
12311225
} else if (!fsmonitor) {
1232-
enum fsmonitor_mode fsm_mode = fsm_settings__get_mode(r);
1233-
if (fsm_mode == FSMONITOR_MODE_IPC)
1234-
warning(_("core.useBuiltinFSMonitor is set; "
1235-
"remove it if you really want to "
1236-
"disable fsmonitor"));
1237-
if (fsm_mode == FSMONITOR_MODE_HOOK)
1226+
if (git_config_get_fsmonitor() == 1)
12381227
warning(_("core.fsmonitor is set; "
12391228
"remove it if you really want to "
12401229
"disable fsmonitor"));

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,7 @@ extern int core_preload_index;
990990
extern int precomposed_unicode;
991991
extern int protect_hfs;
992992
extern int protect_ntfs;
993+
extern const char *core_fsmonitor;
993994

994995
extern int core_apply_sparse_checkout;
995996
extern int core_sparse_checkout_cone;

config.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2517,6 +2517,20 @@ int git_config_get_max_percent_split_change(void)
25172517
return -1; /* default value */
25182518
}
25192519

2520+
int git_config_get_fsmonitor(void)
2521+
{
2522+
if (git_config_get_pathname("core.fsmonitor", &core_fsmonitor))
2523+
core_fsmonitor = getenv("GIT_TEST_FSMONITOR");
2524+
2525+
if (core_fsmonitor && !*core_fsmonitor)
2526+
core_fsmonitor = NULL;
2527+
2528+
if (core_fsmonitor)
2529+
return 1;
2530+
2531+
return 0;
2532+
}
2533+
25202534
int git_config_get_index_threads(int *dest)
25212535
{
25222536
int is_bool, val;

config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,7 @@ int git_config_get_index_threads(int *dest);
609609
int git_config_get_untracked_cache(void);
610610
int git_config_get_split_index(void);
611611
int git_config_get_max_percent_split_change(void);
612+
int git_config_get_fsmonitor(void);
612613

613614
/* This dies if the configured or default date is in the future */
614615
int git_config_get_expiry(const char *key, const char **output);

environment.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ int protect_hfs = PROTECT_HFS_DEFAULT;
8484
#define PROTECT_NTFS_DEFAULT 1
8585
#endif
8686
int protect_ntfs = PROTECT_NTFS_DEFAULT;
87+
const char *core_fsmonitor;
8788

8889
/*
8990
* The character that begins a commented line in user-editable file

fsmonitor-settings.c

Lines changed: 0 additions & 97 deletions
This file was deleted.

fsmonitor-settings.h

Lines changed: 0 additions & 21 deletions
This file was deleted.

fsmonitor.c

Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include "dir.h"
44
#include "ewah/ewok.h"
55
#include "fsmonitor.h"
6-
#include "fsmonitor-ipc.h"
76
#include "run-command.h"
87
#include "strbuf.h"
98

@@ -149,18 +148,15 @@ void write_fsmonitor_extension(struct strbuf *sb, struct index_state *istate)
149148
/*
150149
* Call the query-fsmonitor hook passing the last update token of the saved results.
151150
*/
152-
static int query_fsmonitor_hook(struct repository *r,
153-
int version,
154-
const char *last_update,
155-
struct strbuf *query_result)
151+
static int query_fsmonitor(int version, const char *last_update, struct strbuf *query_result)
156152
{
157153
struct child_process cp = CHILD_PROCESS_INIT;
158154
int result;
159155

160-
if (fsm_settings__get_mode(r) != FSMONITOR_MODE_HOOK)
156+
if (!core_fsmonitor)
161157
return -1;
162158

163-
strvec_push(&cp.args, fsm_settings__get_hook_path(r));
159+
strvec_push(&cp.args, core_fsmonitor);
164160
strvec_pushf(&cp.args, "%d", version);
165161
strvec_pushf(&cp.args, "%s", last_update);
166162
cp.use_shell = 1;
@@ -242,43 +238,31 @@ void refresh_fsmonitor(struct index_state *istate)
242238
struct strbuf last_update_token = STRBUF_INIT;
243239
char *buf;
244240
unsigned int i;
245-
struct repository *r = istate->repo ? istate->repo : the_repository;
246-
enum fsmonitor_mode fsm_mode = fsm_settings__get_mode(r);
247241

248-
if (fsm_mode <= FSMONITOR_MODE_DISABLED ||
249-
istate->fsmonitor_has_run_once)
242+
if (!core_fsmonitor || istate->fsmonitor_has_run_once)
250243
return;
251244

245+
hook_version = fsmonitor_hook_version();
246+
252247
istate->fsmonitor_has_run_once = 1;
253248

254249
trace_printf_key(&trace_fsmonitor, "refresh fsmonitor");
255-
256-
if (fsm_mode == FSMONITOR_MODE_IPC) {
257-
/* TODO */
258-
return;
259-
}
260-
261-
assert(fsm_mode == FSMONITOR_MODE_HOOK);
262-
263-
hook_version = fsmonitor_hook_version();
264-
265250
/*
266-
* This could be racy so save the date/time now and query_fsmonitor_hook
251+
* This could be racy so save the date/time now and query_fsmonitor
267252
* should be inclusive to ensure we don't miss potential changes.
268253
*/
269254
last_update = getnanotime();
270255
if (hook_version == HOOK_INTERFACE_VERSION1)
271256
strbuf_addf(&last_update_token, "%"PRIu64"", last_update);
272257

273258
/*
274-
* If we have a last update token, call query_fsmonitor_hook for the set of
259+
* If we have a last update token, call query_fsmonitor for the set of
275260
* changes since that token, else assume everything is possibly dirty
276261
* and check it all.
277262
*/
278263
if (istate->fsmonitor_last_update) {
279264
if (hook_version == -1 || hook_version == HOOK_INTERFACE_VERSION2) {
280-
query_success = !query_fsmonitor_hook(
281-
r, HOOK_INTERFACE_VERSION2,
265+
query_success = !query_fsmonitor(HOOK_INTERFACE_VERSION2,
282266
istate->fsmonitor_last_update, &query_result);
283267

284268
if (query_success) {
@@ -308,17 +292,13 @@ void refresh_fsmonitor(struct index_state *istate)
308292
}
309293

310294
if (hook_version == HOOK_INTERFACE_VERSION1) {
311-
query_success = !query_fsmonitor_hook(
312-
r, HOOK_INTERFACE_VERSION1,
295+
query_success = !query_fsmonitor(HOOK_INTERFACE_VERSION1,
313296
istate->fsmonitor_last_update, &query_result);
314297
}
315298

316-
trace_performance_since(last_update, "fsmonitor process '%s'",
317-
fsm_settings__get_hook_path(r));
318-
trace_printf_key(&trace_fsmonitor,
319-
"fsmonitor process '%s' returned %s",
320-
fsm_settings__get_hook_path(r),
321-
query_success ? "success" : "failure");
299+
trace_performance_since(last_update, "fsmonitor process '%s'", core_fsmonitor);
300+
trace_printf_key(&trace_fsmonitor, "fsmonitor process '%s' returned %s",
301+
core_fsmonitor, query_success ? "success" : "failure");
322302
}
323303

324304
/* a fsmonitor process can return '/' to indicate all entries are invalid */
@@ -431,8 +411,7 @@ void remove_fsmonitor(struct index_state *istate)
431411
void tweak_fsmonitor(struct index_state *istate)
432412
{
433413
unsigned int i;
434-
struct repository *r = istate->repo ? istate->repo : the_repository;
435-
int fsmonitor_enabled = (fsm_settings__get_mode(r) > FSMONITOR_MODE_DISABLED);
414+
int fsmonitor_enabled = git_config_get_fsmonitor();
436415

437416
if (istate->fsmonitor_dirty) {
438417
if (fsmonitor_enabled) {
@@ -452,8 +431,16 @@ void tweak_fsmonitor(struct index_state *istate)
452431
istate->fsmonitor_dirty = NULL;
453432
}
454433

455-
if (fsmonitor_enabled)
456-
add_fsmonitor(istate);
457-
else
434+
switch (fsmonitor_enabled) {
435+
case -1: /* keep: do nothing */
436+
break;
437+
case 0: /* false */
458438
remove_fsmonitor(istate);
439+
break;
440+
case 1: /* true */
441+
add_fsmonitor(istate);
442+
break;
443+
default: /* unknown value: do nothing */
444+
break;
445+
}
459446
}

fsmonitor.h

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
#include "cache.h"
55
#include "dir.h"
6-
#include "fsmonitor-settings.h"
76

87
extern struct trace_key trace_fsmonitor;
98

@@ -58,11 +57,7 @@ int fsmonitor_is_trivial_response(const struct strbuf *query_result);
5857
*/
5958
static inline int is_fsmonitor_refreshed(const struct index_state *istate)
6059
{
61-
struct repository *r = istate->repo ? istate->repo : the_repository;
62-
enum fsmonitor_mode fsm_mode = fsm_settings__get_mode(r);
63-
64-
return fsm_mode <= FSMONITOR_MODE_DISABLED ||
65-
istate->fsmonitor_has_run_once;
60+
return !core_fsmonitor || istate->fsmonitor_has_run_once;
6661
}
6762

6863
/*
@@ -72,11 +67,7 @@ static inline int is_fsmonitor_refreshed(const struct index_state *istate)
7267
*/
7368
static inline void mark_fsmonitor_valid(struct index_state *istate, struct cache_entry *ce)
7469
{
75-
struct repository *r = istate->repo ? istate->repo : the_repository;
76-
enum fsmonitor_mode fsm_mode = fsm_settings__get_mode(r);
77-
78-
if (fsm_mode > FSMONITOR_MODE_DISABLED &&
79-
!(ce->ce_flags & CE_FSMONITOR_VALID)) {
70+
if (core_fsmonitor && !(ce->ce_flags & CE_FSMONITOR_VALID)) {
8071
istate->cache_changed = 1;
8172
ce->ce_flags |= CE_FSMONITOR_VALID;
8273
trace_printf_key(&trace_fsmonitor, "mark_fsmonitor_clean '%s'", ce->name);
@@ -92,10 +83,7 @@ static inline void mark_fsmonitor_valid(struct index_state *istate, struct cache
9283
*/
9384
static inline void mark_fsmonitor_invalid(struct index_state *istate, struct cache_entry *ce)
9485
{
95-
struct repository *r = istate->repo ? istate->repo : the_repository;
96-
enum fsmonitor_mode fsm_mode = fsm_settings__get_mode(r);
97-
98-
if (fsm_mode > FSMONITOR_MODE_DISABLED) {
86+
if (core_fsmonitor) {
9987
ce->ce_flags &= ~CE_FSMONITOR_VALID;
10088
untracked_cache_invalidate_path(istate, ce->name, 1);
10189
trace_printf_key(&trace_fsmonitor, "mark_fsmonitor_invalid '%s'", ce->name);

0 commit comments

Comments
 (0)