3
#include "dir.h"
4
#include "ewah/ewok.h"
5
#include "fsmonitor.h"
6
+#include "fsmonitor-ipc.h"
7
#include "run-command.h"
8
#include "strbuf.h"
9
149
/*
150
* Call the query-fsmonitor hook passing the last update token of the saved results.
151
*/
151
-static int query_fsmonitor(int version, const char *last_update, struct strbuf *query_result)
152
+static int query_fsmonitor_hook(struct repository *r,
153
+ int version,
154
+ const char *last_update,
155
+ struct strbuf *query_result)
156
{
157
struct child_process cp = CHILD_PROCESS_INIT;
158
int result;
159
156
- if (!core_fsmonitor)
160
+ if (fsm_settings__get_mode(r) != FSMONITOR_MODE_HOOK)
161
return -1;
162
159
- strvec_push(&cp.args, core_fsmonitor);
163
+ strvec_push(&cp.args, fsm_settings__get_hook_path(r));
164
strvec_pushf(&cp.args, "%d", version);
165
strvec_pushf(&cp.args, "%s", last_update);
166
cp.use_shell = 1;
229
char *buf;
230
unsigned int i;
231
int is_trivial = 0;
232
+ struct repository *r = istate->repo ? istate->repo : the_repository;
233
+ enum fsmonitor_mode fsm_mode = fsm_settings__get_mode(r);
234
229
- if (!core_fsmonitor || istate->fsmonitor_has_run_once)
235
+ if (fsm_mode <= FSMONITOR_MODE_DISABLED ||
236
+ istate->fsmonitor_has_run_once)
237
return;
238
232
- hook_version = fsmonitor_hook_version();
233
-
239
istate->fsmonitor_has_run_once = 1;
240
241
trace_printf_key(&trace_fsmonitor, "refresh fsmonitor");
242
+
243
+ if (fsm_mode == FSMONITOR_MODE_IPC) {
244
+ /* TODO */
245
+ return;
246
+ }
247
+
248
+ assert(fsm_mode == FSMONITOR_MODE_HOOK);
249
+
250
+ hook_version = fsmonitor_hook_version();
251
+
252
/*
238
- * This could be racy so save the date/time now and query_fsmonitor
253
+ * This could be racy so save the date/time now and query_fsmonitor_hook
254
* should be inclusive to ensure we don't miss potential changes.
255
*/
256
last_update = getnanotime();
258
strbuf_addf(&last_update_token, "%"PRIu64"", last_update);
259
260
/*
246
- * If we have a last update token, call query_fsmonitor for the set of
261
+ * If we have a last update token, call query_fsmonitor_hook for the set of
262
* changes since that token, else assume everything is possibly dirty
263
* and check it all.
264
*/
265
if (istate->fsmonitor_last_update) {
266
if (hook_version == -1 || hook_version == HOOK_INTERFACE_VERSION2) {
252
- query_success = !query_fsmonitor(HOOK_INTERFACE_VERSION2,
267
+ query_success = !query_fsmonitor_hook(
268
+ r, HOOK_INTERFACE_VERSION2,
269
istate->fsmonitor_last_update, &query_result);
270
271
if (query_success) {
296
}
297
298
if (hook_version == HOOK_INTERFACE_VERSION1) {
283
- query_success = !query_fsmonitor(HOOK_INTERFACE_VERSION1,
299
+ query_success = !query_fsmonitor_hook(
300
+ r, HOOK_INTERFACE_VERSION1,
301
istate->fsmonitor_last_update, &query_result);
302
if (query_success)
303
is_trivial = query_result.buf[0] == '/';
307
trace2_data_intmax("fsm_hook", NULL,
308
"query/trivial-response", 1);
309
293
- trace_performance_since(last_update, "fsmonitor process '%s'", core_fsmonitor);
294
- trace_printf_key(&trace_fsmonitor, "fsmonitor process '%s' returned %s",
295
- core_fsmonitor, query_success ? "success" : "failure");
310
+ trace_performance_since(last_update, "fsmonitor process '%s'",
311
+ fsm_settings__get_hook_path(r));
312
+ trace_printf_key(&trace_fsmonitor,
313
+ "fsmonitor process '%s' returned %s",
314
+ fsm_settings__get_hook_path(r),
315
+ query_success ? "success" : "failure");
316
}
317
318
/*
449
void tweak_fsmonitor(struct index_state *istate)
450
{
451
unsigned int i;
432
- int fsmonitor_enabled = git_config_get_fsmonitor();
452
+ int fsmonitor_enabled = (fsm_settings__get_mode(istate->repo)
453
+ > FSMONITOR_MODE_DISABLED);
454
455
if (istate->fsmonitor_dirty) {
456
if (fsmonitor_enabled) {
470
istate->fsmonitor_dirty = NULL;
471
}
472
452
- switch (fsmonitor_enabled) {
453
- case -1: /* keep: do nothing */
454
- break;
455
- case 0: /* false */
456
- remove_fsmonitor(istate);
457
- break;
458
- case 1: /* true */
473
+ if (fsmonitor_enabled)
474
add_fsmonitor(istate);
460
- break;
461
- default: /* unknown value: do nothing */
462
- break;
463
- }
475
+ else
476
+ remove_fsmonitor(istate);
477
}