Skip to content

Commit 0e21066

Browse files
ptarjangitster
authored andcommitted
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>
1 parent 72b1dae commit 0e21066

5 files changed

Lines changed: 35 additions & 36 deletions

File tree

Makefile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2323,15 +2323,11 @@ ifdef FSMONITOR_DAEMON_BACKEND
23232323
COMPAT_CFLAGS += -DHAVE_FSMONITOR_DAEMON_BACKEND
23242324
COMPAT_OBJS += compat/fsmonitor/fsm-listen-$(FSMONITOR_DAEMON_BACKEND).o
23252325
COMPAT_OBJS += compat/fsmonitor/fsm-health-$(FSMONITOR_DAEMON_BACKEND).o
2326-
ifeq ($(FSMONITOR_DAEMON_BACKEND),win32)
2327-
COMPAT_OBJS += compat/fsmonitor/fsm-ipc-win32.o
2328-
else
2329-
COMPAT_OBJS += compat/fsmonitor/fsm-ipc-unix.o
2330-
endif
23312326
endif
23322327

23332328
ifdef FSMONITOR_OS_SETTINGS
23342329
COMPAT_CFLAGS += -DHAVE_FSMONITOR_OS_SETTINGS
2330+
COMPAT_OBJS += compat/fsmonitor/fsm-ipc-$(FSMONITOR_OS_SETTINGS).o
23352331
COMPAT_OBJS += compat/fsmonitor/fsm-settings-$(FSMONITOR_OS_SETTINGS).o
23362332
COMPAT_OBJS += compat/fsmonitor/fsm-path-utils-$(FSMONITOR_DAEMON_BACKEND).o
23372333
endif
Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "fsmonitor-settings.h"
66
#include "fsmonitor-path-utils.h"
77

8-
/*
8+
/*
99
* For the builtin FSMonitor, we create the Unix domain socket for the
1010
* IPC in the .git directory. If the working directory is remote,
1111
* then the socket will be created on the remote file system. This
@@ -22,25 +22,31 @@
2222
* The builtin FSMonitor uses a Unix domain socket in the .git
2323
* directory for IPC. These Windows drive formats do not support
2424
* Unix domain sockets, so mark them as incompatible for the daemon.
25-
*
2625
*/
2726
static enum fsmonitor_reason check_uds_volume(struct repository *r)
2827
{
2928
struct fs_info fs;
3029
const char *ipc_path = fsmonitor_ipc__get_path(r);
31-
struct strbuf path = STRBUF_INIT;
32-
strbuf_add(&path, ipc_path, strlen(ipc_path));
30+
char *path;
31+
char *dir;
32+
33+
/*
34+
* Create a copy for dirname() since it may modify its argument.
35+
*/
36+
path = xstrdup(ipc_path);
37+
dir = dirname(path);
3338

34-
if (fsmonitor__get_fs_info(dirname(path.buf), &fs) == -1) {
35-
strbuf_release(&path);
39+
if (fsmonitor__get_fs_info(dir, &fs) == -1) {
40+
free(path);
3641
return FSMONITOR_REASON_ERROR;
3742
}
3843

39-
strbuf_release(&path);
44+
free(path);
4045

4146
if (fs.is_remote ||
42-
!strcmp(fs.typename, "msdos") ||
43-
!strcmp(fs.typename, "ntfs")) {
47+
!strcmp(fs.typename, "msdos") ||
48+
!strcmp(fs.typename, "ntfs") ||
49+
!strcmp(fs.typename, "vfat")) {
4450
free(fs.typename);
4551
return FSMONITOR_REASON_NOSOCKETS;
4652
}

config.mak.uname

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ ifeq ($(uname_S),Darwin)
178178
ifndef NO_PTHREADS
179179
ifndef NO_UNIX_SOCKETS
180180
FSMONITOR_DAEMON_BACKEND = darwin
181-
FSMONITOR_OS_SETTINGS = darwin
181+
FSMONITOR_OS_SETTINGS = unix
182182
endif
183183
endif
184184

contrib/buildsystems/CMakeLists.txt

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -291,23 +291,22 @@ endif()
291291

292292
if(SUPPORTS_SIMPLE_IPC)
293293
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
294-
add_compile_definitions(HAVE_FSMONITOR_DAEMON_BACKEND)
295-
list(APPEND compat_SOURCES compat/fsmonitor/fsm-listen-win32.c)
296-
list(APPEND compat_SOURCES compat/fsmonitor/fsm-health-win32.c)
297-
list(APPEND compat_SOURCES compat/fsmonitor/fsm-ipc-win32.c)
298-
list(APPEND compat_SOURCES compat/fsmonitor/fsm-path-utils-win32.c)
299-
300-
add_compile_definitions(HAVE_FSMONITOR_OS_SETTINGS)
301-
list(APPEND compat_SOURCES compat/fsmonitor/fsm-settings-win32.c)
294+
set(FSMONITOR_DAEMON_BACKEND "win32")
295+
set(FSMONITOR_OS_SETTINGS "win32")
302296
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
297+
set(FSMONITOR_DAEMON_BACKEND "darwin")
298+
set(FSMONITOR_OS_SETTINGS "unix")
299+
endif()
300+
301+
if(FSMONITOR_DAEMON_BACKEND)
303302
add_compile_definitions(HAVE_FSMONITOR_DAEMON_BACKEND)
304-
list(APPEND compat_SOURCES compat/fsmonitor/fsm-listen-darwin.c)
305-
list(APPEND compat_SOURCES compat/fsmonitor/fsm-health-darwin.c)
306-
list(APPEND compat_SOURCES compat/fsmonitor/fsm-ipc-unix.c)
307-
list(APPEND compat_SOURCES compat/fsmonitor/fsm-path-utils-darwin.c)
303+
list(APPEND compat_SOURCES compat/fsmonitor/fsm-listen-${FSMONITOR_DAEMON_BACKEND}.c)
304+
list(APPEND compat_SOURCES compat/fsmonitor/fsm-health-${FSMONITOR_DAEMON_BACKEND}.c)
305+
list(APPEND compat_SOURCES compat/fsmonitor/fsm-path-utils-${FSMONITOR_DAEMON_BACKEND}.c)
306+
list(APPEND compat_SOURCES compat/fsmonitor/fsm-ipc-${FSMONITOR_OS_SETTINGS}.c)
308307

309308
add_compile_definitions(HAVE_FSMONITOR_OS_SETTINGS)
310-
list(APPEND compat_SOURCES compat/fsmonitor/fsm-settings-darwin.c)
309+
list(APPEND compat_SOURCES compat/fsmonitor/fsm-settings-${FSMONITOR_OS_SETTINGS}.c)
311310
endif()
312311
endif()
313312

meson.build

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,10 +1320,13 @@ else
13201320
endif
13211321

13221322
fsmonitor_backend = ''
1323+
fsmonitor_os = ''
13231324
if host_machine.system() == 'windows'
13241325
fsmonitor_backend = 'win32'
1326+
fsmonitor_os = 'win32'
13251327
elif host_machine.system() == 'darwin'
13261328
fsmonitor_backend = 'darwin'
1329+
fsmonitor_os = 'unix'
13271330
libgit_dependencies += dependency('CoreServices')
13281331
endif
13291332
if fsmonitor_backend != ''
@@ -1334,17 +1337,12 @@ if fsmonitor_backend != ''
13341337
'compat/fsmonitor/fsm-health-' + fsmonitor_backend + '.c',
13351338
'compat/fsmonitor/fsm-listen-' + fsmonitor_backend + '.c',
13361339
'compat/fsmonitor/fsm-path-utils-' + fsmonitor_backend + '.c',
1337-
'compat/fsmonitor/fsm-settings-' + fsmonitor_backend + '.c',
1340+
'compat/fsmonitor/fsm-ipc-' + fsmonitor_os + '.c',
1341+
'compat/fsmonitor/fsm-settings-' + fsmonitor_os + '.c',
13381342
]
1339-
1340-
if fsmonitor_backend == 'win32'
1341-
libgit_sources += 'compat/fsmonitor/fsm-ipc-win32.c'
1342-
else
1343-
libgit_sources += 'compat/fsmonitor/fsm-ipc-unix.c'
1344-
endif
13451343
endif
13461344
build_options_config.set_quoted('FSMONITOR_DAEMON_BACKEND', fsmonitor_backend)
1347-
build_options_config.set_quoted('FSMONITOR_OS_SETTINGS', fsmonitor_backend)
1345+
build_options_config.set_quoted('FSMONITOR_OS_SETTINGS', fsmonitor_os)
13481346

13491347
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>') != ''
13501348
build_options_config.set('NO_REGEX', '')

0 commit comments

Comments
 (0)