]> git.ipfire.org Git - thirdparty/git.git/blobdiff - fsmonitor.c
fsmonitor: config settings are repository-specific
[thirdparty/git.git] / fsmonitor.c
index 448d0ee33f5a79eef0addb102f4871c0ea841eaa..0e961b74d82684b551a84f93e9354d422342b2b7 100644 (file)
@@ -3,6 +3,7 @@
 #include "dir.h"
 #include "ewah/ewok.h"
 #include "fsmonitor.h"
+#include "fsmonitor-ipc.h"
 #include "run-command.h"
 #include "strbuf.h"
 
@@ -148,15 +149,18 @@ void write_fsmonitor_extension(struct strbuf *sb, struct index_state *istate)
 /*
  * Call the query-fsmonitor hook passing the last update token of the saved results.
  */
-static int query_fsmonitor(int version, const char *last_update, struct strbuf *query_result)
+static int query_fsmonitor_hook(struct repository *r,
+                               int version,
+                               const char *last_update,
+                               struct strbuf *query_result)
 {
        struct child_process cp = CHILD_PROCESS_INIT;
        int result;
 
-       if (!core_fsmonitor)
+       if (fsm_settings__get_mode(r) != FSMONITOR_MODE_HOOK)
                return -1;
 
-       strvec_push(&cp.args, core_fsmonitor);
+       strvec_push(&cp.args, fsm_settings__get_hook_path(r));
        strvec_pushf(&cp.args, "%d", version);
        strvec_pushf(&cp.args, "%s", last_update);
        cp.use_shell = 1;
@@ -225,17 +229,28 @@ void refresh_fsmonitor(struct index_state *istate)
        char *buf;
        unsigned int i;
        int is_trivial = 0;
+       struct repository *r = istate->repo ? istate->repo : the_repository;
+       enum fsmonitor_mode fsm_mode = fsm_settings__get_mode(r);
 
-       if (!core_fsmonitor || istate->fsmonitor_has_run_once)
+       if (fsm_mode <= FSMONITOR_MODE_DISABLED ||
+           istate->fsmonitor_has_run_once)
                return;
 
-       hook_version = fsmonitor_hook_version();
-
        istate->fsmonitor_has_run_once = 1;
 
        trace_printf_key(&trace_fsmonitor, "refresh fsmonitor");
+
+       if (fsm_mode == FSMONITOR_MODE_IPC) {
+               /* TODO */
+               return;
+       }
+
+       assert(fsm_mode == FSMONITOR_MODE_HOOK);
+
+       hook_version = fsmonitor_hook_version();
+
        /*
-        * This could be racy so save the date/time now and query_fsmonitor
+        * This could be racy so save the date/time now and query_fsmonitor_hook
         * should be inclusive to ensure we don't miss potential changes.
         */
        last_update = getnanotime();
@@ -243,13 +258,14 @@ void refresh_fsmonitor(struct index_state *istate)
                strbuf_addf(&last_update_token, "%"PRIu64"", last_update);
 
        /*
-        * If we have a last update token, call query_fsmonitor for the set of
+        * If we have a last update token, call query_fsmonitor_hook for the set of
         * changes since that token, else assume everything is possibly dirty
         * and check it all.
         */
        if (istate->fsmonitor_last_update) {
                if (hook_version == -1 || hook_version == HOOK_INTERFACE_VERSION2) {
-                       query_success = !query_fsmonitor(HOOK_INTERFACE_VERSION2,
+                       query_success = !query_fsmonitor_hook(
+                               r, HOOK_INTERFACE_VERSION2,
                                istate->fsmonitor_last_update, &query_result);
 
                        if (query_success) {
@@ -280,7 +296,8 @@ void refresh_fsmonitor(struct index_state *istate)
                }
 
                if (hook_version == HOOK_INTERFACE_VERSION1) {
-                       query_success = !query_fsmonitor(HOOK_INTERFACE_VERSION1,
+                       query_success = !query_fsmonitor_hook(
+                               r, HOOK_INTERFACE_VERSION1,
                                istate->fsmonitor_last_update, &query_result);
                        if (query_success)
                                is_trivial = query_result.buf[0] == '/';
@@ -290,9 +307,12 @@ void refresh_fsmonitor(struct index_state *istate)
                        trace2_data_intmax("fsm_hook", NULL,
                                           "query/trivial-response", 1);
 
-               trace_performance_since(last_update, "fsmonitor process '%s'", core_fsmonitor);
-               trace_printf_key(&trace_fsmonitor, "fsmonitor process '%s' returned %s",
-                       core_fsmonitor, query_success ? "success" : "failure");
+               trace_performance_since(last_update, "fsmonitor process '%s'",
+                                       fsm_settings__get_hook_path(r));
+               trace_printf_key(&trace_fsmonitor,
+                                "fsmonitor process '%s' returned %s",
+                                fsm_settings__get_hook_path(r),
+                                query_success ? "success" : "failure");
        }
 
        /*
@@ -429,7 +449,8 @@ void remove_fsmonitor(struct index_state *istate)
 void tweak_fsmonitor(struct index_state *istate)
 {
        unsigned int i;
-       int fsmonitor_enabled = git_config_get_fsmonitor();
+       int fsmonitor_enabled = (fsm_settings__get_mode(istate->repo)
+                                > FSMONITOR_MODE_DISABLED);
 
        if (istate->fsmonitor_dirty) {
                if (fsmonitor_enabled) {
@@ -449,16 +470,8 @@ void tweak_fsmonitor(struct index_state *istate)
                istate->fsmonitor_dirty = NULL;
        }
 
-       switch (fsmonitor_enabled) {
-       case -1: /* keep: do nothing */
-               break;
-       case 0: /* false */
-               remove_fsmonitor(istate);
-               break;
-       case 1: /* true */
+       if (fsmonitor_enabled)
                add_fsmonitor(istate);
-               break;
-       default: /* unknown value: do nothing */
-               break;
-       }
+       else
+               remove_fsmonitor(istate);
 }