[PATCH v6 05/10] fsmonitor: deduplicate IPC path logic for Unix platforms
- From
- Paul Tarjan via GitGitGadget <gitgitgadget@gmail.com>
- Date
- Feb 25, 2026, 20:17 UTC
- Message-ID
- <ff31e359a7070c8d410518da0230ad0ecae7d771.1772050636.git.gitgitgadget@gmail.com>
- In-Reply-To
- <pull.2147.v6.git.git.1772050636.gitgitgadget@gmail.com>
From: Paul Tarjan <github@paulisageek.com>
The IPC path logic for determining the Unix domain socket location is nearly identical between macOS and Linux. Both need to check whether the .git directory is on a remote filesystem and, if so, fall back to a socket path under $HOME or a user-configured directory.
Merge the two implementations into a single fsm-ipc-unix.c that is shared by both platforms. The unified version includes the worktree NULL check (BUG guard) from the Linux implementation, which was missing in the macOS version.
Update Makefile, meson.build, and CMakeLists.txt to use the new shared file for non-Windows platforms.
Signed-off-by: Paul Tarjan <github@paulisageek.com>
---
Makefile | 6 +++++-
compat/fsmonitor/{fsm-ipc-darwin.c => fsm-ipc-unix.c} | 4 +++-
contrib/buildsystems/CMakeLists.txt | 2 +-
meson.build | 7 ++++++-
4 files changed, 15 insertions(+), 4 deletions(-)
rename compat/fsmonitor/{fsm-ipc-darwin.c => fsm-ipc-unix.c} (96%)diff --git a/Makefile b/Makefile index 8aa489f3b6..2157bbf173 100644 --- a/Makefile +++ b/Makefile @@ -2365,7 +2365,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 - COMPAT_OBJS += compat/fsmonitor/fsm-ipc-$(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 diff --git a/compat/fsmonitor/fsm-ipc-darwin.c b/compat/fsmonitor/fsm-ipc-unix.c similarity index 96% rename from compat/fsmonitor/fsm-ipc-darwin.c rename to compat/fsmonitor/fsm-ipc-unix.c index fe149a1b37..d34a6419bc 100644 --- a/compat/fsmonitor/fsm-ipc-darwin.c +++ b/compat/fsmonitor/fsm-ipc-unix.c @@ -27,13 +27,15 @@ const char *fsmonitor_ipc__get_path(struct repository *r) if (ipc_path) return ipc_path; - /* By default the socket file is created in the .git directory */ if (fsmonitor__is_fs_remote(r->gitdir) < 1) { ipc_path = fsmonitor_ipc__get_default_path(); return ipc_path; } + if (!r->worktree) + BUG("repository has no worktree"); + git_SHA1_Init(&sha1ctx); git_SHA1_Update(&sha1ctx, r->worktree, strlen(r->worktree)); git_SHA1_Final(hash, &sha1ctx); diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt index 28877feb9d..32ef6ebe1b 100644 --- a/contrib/buildsystems/CMakeLists.txt +++ b/contrib/buildsystems/CMakeLists.txt @@ -303,7 +303,7 @@ if(SUPPORTS_SIMPLE_IPC) 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-darwin.c) + list(APPEND compat_SOURCES compat/fsmonitor/fsm-ipc-unix.c) list(APPEND compat_SOURCES compat/fsmonitor/fsm-path-utils-darwin.c) add_compile_definitions(HAVE_FSMONITOR_OS_SETTINGS) diff --git a/meson.build b/meson.build index dd52efd1c8..8de795f9d4 100644 --- a/meson.build +++ b/meson.build @@ -1332,11 +1332,16 @@ if fsmonitor_backend != '' libgit_sources += [ 'compat/fsmonitor/fsm-health-' + fsmonitor_backend + '.c', - 'compat/fsmonitor/fsm-ipc-' + 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', ] + + 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)
-- gitgitgadget