fsmonitor: deduplicate settings logic for Unix platforms

The macOS fsm-settings-darwin.c is applicable to other Unix variants
as well.  Rename it to fsm-settings-unix.c, using the safer
xstrdup()+dirname() approach and including the "vfat" filesystem check.

Now that both fsm-ipc and fsm-settings use the "unix" variant name,
set FSMONITOR_OS_SETTINGS to "unix" for macOS in config.mak.uname and
remove the if/else conditionals from the build files.

Signed-off-by: Paul Tarjan <github@paulisageek.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Paul Tarjan
2026-02-26 00:27:19 +00:00
committed by Junio C Hamano
parent 72b1daeb13
commit 0e210668c7
5 changed files with 35 additions and 36 deletions

View File

@@ -2323,15 +2323,11 @@ ifdef FSMONITOR_DAEMON_BACKEND
COMPAT_CFLAGS += -DHAVE_FSMONITOR_DAEMON_BACKEND
COMPAT_OBJS += compat/fsmonitor/fsm-listen-$(FSMONITOR_DAEMON_BACKEND).o
COMPAT_OBJS += compat/fsmonitor/fsm-health-$(FSMONITOR_DAEMON_BACKEND).o
ifeq ($(FSMONITOR_DAEMON_BACKEND),win32)
COMPAT_OBJS += compat/fsmonitor/fsm-ipc-win32.o
else
COMPAT_OBJS += compat/fsmonitor/fsm-ipc-unix.o
endif
endif
ifdef FSMONITOR_OS_SETTINGS
COMPAT_CFLAGS += -DHAVE_FSMONITOR_OS_SETTINGS
COMPAT_OBJS += compat/fsmonitor/fsm-ipc-$(FSMONITOR_OS_SETTINGS).o
COMPAT_OBJS += compat/fsmonitor/fsm-settings-$(FSMONITOR_OS_SETTINGS).o
COMPAT_OBJS += compat/fsmonitor/fsm-path-utils-$(FSMONITOR_DAEMON_BACKEND).o
endif

View File

@@ -5,7 +5,7 @@
#include "fsmonitor-settings.h"
#include "fsmonitor-path-utils.h"
/*
/*
* For the builtin FSMonitor, we create the Unix domain socket for the
* IPC in the .git directory. If the working directory is remote,
* then the socket will be created on the remote file system. This
@@ -22,25 +22,31 @@
* The builtin FSMonitor uses a Unix domain socket in the .git
* directory for IPC. These Windows drive formats do not support
* Unix domain sockets, so mark them as incompatible for the daemon.
*
*/
static enum fsmonitor_reason check_uds_volume(struct repository *r)
{
struct fs_info fs;
const char *ipc_path = fsmonitor_ipc__get_path(r);
struct strbuf path = STRBUF_INIT;
strbuf_add(&path, ipc_path, strlen(ipc_path));
char *path;
char *dir;
if (fsmonitor__get_fs_info(dirname(path.buf), &fs) == -1) {
strbuf_release(&path);
/*
* Create a copy for dirname() since it may modify its argument.
*/
path = xstrdup(ipc_path);
dir = dirname(path);
if (fsmonitor__get_fs_info(dir, &fs) == -1) {
free(path);
return FSMONITOR_REASON_ERROR;
}
strbuf_release(&path);
free(path);
if (fs.is_remote ||
!strcmp(fs.typename, "msdos") ||
!strcmp(fs.typename, "ntfs")) {
!strcmp(fs.typename, "msdos") ||
!strcmp(fs.typename, "ntfs") ||
!strcmp(fs.typename, "vfat")) {
free(fs.typename);
return FSMONITOR_REASON_NOSOCKETS;
}

View File

@@ -178,7 +178,7 @@ ifeq ($(uname_S),Darwin)
ifndef NO_PTHREADS
ifndef NO_UNIX_SOCKETS
FSMONITOR_DAEMON_BACKEND = darwin
FSMONITOR_OS_SETTINGS = darwin
FSMONITOR_OS_SETTINGS = unix
endif
endif

View File

@@ -291,23 +291,22 @@ endif()
if(SUPPORTS_SIMPLE_IPC)
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
add_compile_definitions(HAVE_FSMONITOR_DAEMON_BACKEND)
list(APPEND compat_SOURCES compat/fsmonitor/fsm-listen-win32.c)
list(APPEND compat_SOURCES compat/fsmonitor/fsm-health-win32.c)
list(APPEND compat_SOURCES compat/fsmonitor/fsm-ipc-win32.c)
list(APPEND compat_SOURCES compat/fsmonitor/fsm-path-utils-win32.c)
add_compile_definitions(HAVE_FSMONITOR_OS_SETTINGS)
list(APPEND compat_SOURCES compat/fsmonitor/fsm-settings-win32.c)
set(FSMONITOR_DAEMON_BACKEND "win32")
set(FSMONITOR_OS_SETTINGS "win32")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(FSMONITOR_DAEMON_BACKEND "darwin")
set(FSMONITOR_OS_SETTINGS "unix")
endif()
if(FSMONITOR_DAEMON_BACKEND)
add_compile_definitions(HAVE_FSMONITOR_DAEMON_BACKEND)
list(APPEND compat_SOURCES compat/fsmonitor/fsm-listen-darwin.c)
list(APPEND compat_SOURCES compat/fsmonitor/fsm-health-darwin.c)
list(APPEND compat_SOURCES compat/fsmonitor/fsm-ipc-unix.c)
list(APPEND compat_SOURCES compat/fsmonitor/fsm-path-utils-darwin.c)
list(APPEND compat_SOURCES compat/fsmonitor/fsm-listen-${FSMONITOR_DAEMON_BACKEND}.c)
list(APPEND compat_SOURCES compat/fsmonitor/fsm-health-${FSMONITOR_DAEMON_BACKEND}.c)
list(APPEND compat_SOURCES compat/fsmonitor/fsm-path-utils-${FSMONITOR_DAEMON_BACKEND}.c)
list(APPEND compat_SOURCES compat/fsmonitor/fsm-ipc-${FSMONITOR_OS_SETTINGS}.c)
add_compile_definitions(HAVE_FSMONITOR_OS_SETTINGS)
list(APPEND compat_SOURCES compat/fsmonitor/fsm-settings-darwin.c)
list(APPEND compat_SOURCES compat/fsmonitor/fsm-settings-${FSMONITOR_OS_SETTINGS}.c)
endif()
endif()

View File

@@ -1320,10 +1320,13 @@ else
endif
fsmonitor_backend = ''
fsmonitor_os = ''
if host_machine.system() == 'windows'
fsmonitor_backend = 'win32'
fsmonitor_os = 'win32'
elif host_machine.system() == 'darwin'
fsmonitor_backend = 'darwin'
fsmonitor_os = 'unix'
libgit_dependencies += dependency('CoreServices')
endif
if fsmonitor_backend != ''
@@ -1334,17 +1337,12 @@ if fsmonitor_backend != ''
'compat/fsmonitor/fsm-health-' + fsmonitor_backend + '.c',
'compat/fsmonitor/fsm-listen-' + fsmonitor_backend + '.c',
'compat/fsmonitor/fsm-path-utils-' + fsmonitor_backend + '.c',
'compat/fsmonitor/fsm-settings-' + fsmonitor_backend + '.c',
'compat/fsmonitor/fsm-ipc-' + fsmonitor_os + '.c',
'compat/fsmonitor/fsm-settings-' + fsmonitor_os + '.c',
]
if fsmonitor_backend == 'win32'
libgit_sources += 'compat/fsmonitor/fsm-ipc-win32.c'
else
libgit_sources += 'compat/fsmonitor/fsm-ipc-unix.c'
endif
endif
build_options_config.set_quoted('FSMONITOR_DAEMON_BACKEND', fsmonitor_backend)
build_options_config.set_quoted('FSMONITOR_OS_SETTINGS', fsmonitor_backend)
build_options_config.set_quoted('FSMONITOR_OS_SETTINGS', fsmonitor_os)
if not get_option('b_sanitize').contains('address') and get_option('regex').allowed() and compiler.has_header('regex.h') and compiler.get_define('REG_STARTEND', prefix: '#include <regex.h>') != ''
build_options_config.set('NO_REGEX', '')