fsmonitor-settings: stub in Win32-specific incompatibility checking

Extend generic incompatibility checkout with platform-specific mechanism. Stub in Win32 version. In the existing fsmonitor-settings code we have a way to mark types of repos as incompatible with fsmonitor (whether via the hook and IPC APIs). For example, we do this for bare repos, since there are no files to watch. Extend this exclusion mechanism for platform-specific reasons. This commit just creates the framework and adds a stub for Win32. Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff Hostetler committed May 26, 2022 at 21:46 UTC d33c804daec8aaf1e8af187c00166ef4cb017262
6 files changed +52
Makefile
+13
@@ -475,6 +475,11 @@ all::
475 # `compat/fsmonitor/fsm-listen-<name>.c` that implements the
476 # `fsm_listen__*()` routines.
477 #
478 +# If your platform has OS-specific ways to tell if a repo is incompatible with
479 +# fsmonitor (whether the hook or IPC daemon version), set FSMONITOR_OS_SETTINGS
480 +# to the "<name>" of the corresponding `compat/fsmonitor/fsm-settings-<name>.c`
481 +# that implements the `fsm_os_settings__*()` routines.
482 +#
483 # Define DEVELOPER to enable more compiler warnings. Compiler version
484 # and family are auto detected, but could be overridden by defining
485 # COMPILER_FEATURES (see config.mak.dev). You can still set
@@ -1979,6 +1984,11 @@ ifdef FSMONITOR_DAEMON_BACKEND
1984 COMPAT_OBJS += compat/fsmonitor/fsm-listen-$(FSMONITOR_DAEMON_BACKEND).o
1985 endif
1986
1987 +ifdef FSMONITOR_OS_SETTINGS
1988 + COMPAT_CFLAGS += -DHAVE_FSMONITOR_OS_SETTINGS
1989 + COMPAT_OBJS += compat/fsmonitor/fsm-settings-$(FSMONITOR_OS_SETTINGS).o
1990 +endif
1991 +
1992 ifeq ($(TCLTK_PATH),)
1993 NO_TCLTK = NoThanks
1994 endif
@@ -2901,6 +2911,9 @@ GIT-BUILD-OPTIONS: FORCE
2911 ifdef FSMONITOR_DAEMON_BACKEND
2912 @echo FSMONITOR_DAEMON_BACKEND=\''$(subst ','\'',$(subst ','\'',$(FSMONITOR_DAEMON_BACKEND)))'\' >>$@+
2913 endif
2914 +ifdef FSMONITOR_OS_SETTINGS
2915 + @echo FSMONITOR_OS_SETTINGS=\''$(subst ','\'',$(subst ','\'',$(FSMONITOR_OS_SETTINGS)))'\' >>$@+
2916 +endif
2917 ifdef TEST_OUTPUT_DIRECTORY
2918 @echo TEST_OUTPUT_DIRECTORY=\''$(subst ','\'',$(subst ','\'',$(TEST_OUTPUT_DIRECTORY)))'\' >>$@+
2919 endif
compat/fsmonitor/fsm-settings-win32.c new
+9
@@ -0,0 +1,9 @@
1 +#include "cache.h"
2 +#include "config.h"
3 +#include "repository.h"
4 +#include "fsmonitor-settings.h"
5 +
6 +enum fsmonitor_reason fsm_os__incompatible(struct repository *r)
7 +{
8 + return FSMONITOR_REASON_OK;
9 +}
config.mak.uname
+4
@@ -450,6 +450,8 @@ ifeq ($(uname_S),Windows)
450 # These are always available, so we do not have to conditionally
451 # support it.
452 FSMONITOR_DAEMON_BACKEND = win32
453 + FSMONITOR_OS_SETTINGS = win32
454 +
455 NO_SVN_TESTS = YesPlease
456 RUNTIME_PREFIX = YesPlease
457 HAVE_WPGMPTR = YesWeDo
@@ -639,6 +641,8 @@ ifeq ($(uname_S),MINGW)
641 # These are always available, so we do not have to conditionally
642 # support it.
643 FSMONITOR_DAEMON_BACKEND = win32
644 + FSMONITOR_OS_SETTINGS = win32
645 +
646 RUNTIME_PREFIX = YesPlease
647 HAVE_WPGMPTR = YesWeDo
648 NO_ST_BLOCKS_IN_STRUCT_STAT = YesPlease
contrib/buildsystems/CMakeLists.txt
+3
@@ -289,6 +289,9 @@ if(SUPPORTS_SIMPLE_IPC)
289 if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
290 add_compile_definitions(HAVE_FSMONITOR_DAEMON_BACKEND)
291 list(APPEND compat_SOURCES compat/fsmonitor/fsm-listen-win32.c)
292 +
293 + add_compile_definitions(HAVE_FSMONITOR_OS_SETTINGS)
294 + list(APPEND compat_SOURCES compat/fsmonitor/fsm-settings-win32.c)
295 elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
296 add_compile_definitions(HAVE_FSMONITOR_DAEMON_BACKEND)
297 list(APPEND compat_SOURCES compat/fsmonitor/fsm-listen-darwin.c)
fsmonitor-settings.c
+10
@@ -23,6 +23,16 @@ static enum fsmonitor_reason check_for_incompatible(struct repository *r)
23 return FSMONITOR_REASON_BARE;
24 }
25
26 +#ifdef HAVE_FSMONITOR_OS_SETTINGS
27 + {
28 + enum fsmonitor_reason reason;
29 +
30 + reason = fsm_os__incompatible(r);
31 + if (reason != FSMONITOR_REASON_OK)
32 + return reason;
33 + }
34 +#endif
35 +
36 return FSMONITOR_REASON_OK;
37 }
38
fsmonitor-settings.h
+13
@@ -34,4 +34,17 @@ char *fsm_settings__get_incompatible_msg(const struct repository *r,
34
35 struct fsmonitor_settings;
36
37 +#ifdef HAVE_FSMONITOR_OS_SETTINGS
38 +/*
39 + * Ask platform-specific code whether the repository is incompatible
40 + * with fsmonitor (both hook and ipc modes). For example, if the working
41 + * directory is on a remote volume and mounted via a technology that does
42 + * not support notification events, then we should not pretend to watch it.
43 + *
44 + * fsm_os__* routines should considered private to fsm_settings__
45 + * routines.
46 + */
47 +enum fsmonitor_reason fsm_os__incompatible(struct repository *r);
48 +#endif /* HAVE_FSMONITOR_OS_SETTINGS */
49 +
50 #endif /* FSMONITOR_SETTINGS_H */