fsmonitor: check for compatability before communicating with fsmonitor

If fsmonitor is not in a compatible state, warn with an appropriate message. Signed-off-by: Eric DeCosta <edecosta@mathworks.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Eric DeCosta committed Oct 4, 2022 at 17:32 UTC 25c2cab08f90b6251b1ace91e37f05d4cb8fcd0c
3 files changed +15 -4
fsmonitor-settings.c
+7 -3
@@ -1,6 +1,7 @@
1 #include "cache.h"
2 #include "config.h"
3 #include "repository.h"
4 +#include "fsmonitor-ipc.h"
5 #include "fsmonitor-settings.h"
6 #include "fsmonitor-path-utils.h"
7
@@ -242,10 +243,11 @@ enum fsmonitor_reason fsm_settings__get_reason(struct repository *r)
243 return r->settings.fsmonitor->reason;
244 }
245
245 -char *fsm_settings__get_incompatible_msg(const struct repository *r,
246 +char *fsm_settings__get_incompatible_msg(struct repository *r,
247 enum fsmonitor_reason reason)
248 {
249 struct strbuf msg = STRBUF_INIT;
250 + const char *socket_dir;
251
252 switch (reason) {
253 case FSMONITOR_REASON_UNTESTED:
@@ -281,9 +283,11 @@ char *fsm_settings__get_incompatible_msg(const struct repository *r,
283 goto done;
284
285 case FSMONITOR_REASON_NOSOCKETS:
286 + socket_dir = dirname((char *)fsmonitor_ipc__get_path(r));
287 strbuf_addf(&msg,
285 - _("repository '%s' is incompatible with fsmonitor due to lack of Unix sockets"),
286 - r->worktree);
288 + _("socket directory '%s' is incompatible with fsmonitor due"
289 + " to lack of Unix sockets support"),
290 + socket_dir);
291 goto done;
292 }
293
fsmonitor-settings.h
+1 -1
@@ -33,7 +33,7 @@ enum fsmonitor_mode fsm_settings__get_mode(struct repository *r);
33 const char *fsm_settings__get_hook_path(struct repository *r);
34
35 enum fsmonitor_reason fsm_settings__get_reason(struct repository *r);
36 -char *fsm_settings__get_incompatible_msg(const struct repository *r,
36 +char *fsm_settings__get_incompatible_msg(struct repository *r,
37 enum fsmonitor_reason reason);
38
39 struct fsmonitor_settings;
fsmonitor.c
+7
@@ -295,6 +295,7 @@ static int fsmonitor_force_update_threshold = 100;
295
296 void refresh_fsmonitor(struct index_state *istate)
297 {
298 + static int warn_once = 0;
299 struct strbuf query_result = STRBUF_INIT;
300 int query_success = 0, hook_version = -1;
301 size_t bol = 0; /* beginning of line */
@@ -305,6 +306,12 @@ void refresh_fsmonitor(struct index_state *istate)
306 int is_trivial = 0;
307 struct repository *r = istate->repo ? istate->repo : the_repository;
308 enum fsmonitor_mode fsm_mode = fsm_settings__get_mode(r);
309 + enum fsmonitor_reason reason = fsm_settings__get_reason(r);
310 +
311 + if (!warn_once && reason > FSMONITOR_REASON_OK) {
312 + warn_once = 1;
313 + warning("%s", fsm_settings__get_incompatible_msg(r, reason));
314 + }
315
316 if (fsm_mode <= FSMONITOR_MODE_DISABLED ||
317 istate->fsmonitor_has_run_once)