Skip to content

Commit 2c799a2

Browse files
committed
fsmonitor-settings: remote repos on MacOS are incompatible with FSMonitor
Teach Git to detect remote working directories on MacOS and mark them as incompatible with FSMonitor. With this, `git fsmonitor--daemon run` will error out with a message like it does for bare repos. Client commands, like `git status`, will not attempt to start the daemon. Signed-off-by: Jeff Hostetler <[email protected]>
1 parent d78e513 commit 2c799a2

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

compat/fsmonitor/fsm-settings-darwin.c

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,74 @@
22
#include "config.h"
33
#include "repository.h"
44
#include "fsmonitor-settings.h"
5+
#include "fsmonitor.h"
6+
#include <sys/param.h>
7+
#include <sys/mount.h>
8+
9+
/*
10+
* Remote working directories are problematic for FSMonitor.
11+
*
12+
* The underlying file system on the server machine and/or the remote
13+
* mount type (NFS, SAMBA, etc.) dictates whether notification events
14+
* are available at all to remote client machines.
15+
*
16+
* Kernel differences between the server and client machines also
17+
* dictate the how (buffering, frequency, de-dup) the events are
18+
* delivered to client machine processes.
19+
*
20+
* A client machine (such as a laptop) may choose to suspend/resume
21+
* and it is unclear (without lots of testing) whether the watcher can
22+
* resync after a resume. We might be able to treat this as a normal
23+
* "events were dropped by the kernel" event and do our normal "flush
24+
* and resync" --or-- we might need to close the existing (zombie?)
25+
* notification fd and create a new one.
26+
*
27+
* In theory, the above issues need to be addressed whether we are
28+
* using the Hook or IPC API.
29+
*
30+
* For the builtin FSMonitor, we create the Unix domain socket for the
31+
* IPC in the .git directory. If the working directory is remote,
32+
* then the socket will be created on the remote file system. This
33+
* can fail if the remote file system does not support UDS file types
34+
* (e.g. smbfs to a Windows server) or if the remote kernel does not
35+
* allow a non-local process to bind() the socket. (These problems
36+
* could be fixed by moving the UDS out of the .git directory and to a
37+
* well-known local directory on the client machine, but care should
38+
* be taken to ensure that $HOME is actually local and not a managed
39+
* file share.)
40+
*
41+
* So (for now at least), mark remote working directories as
42+
* incompatible.
43+
*/
44+
static enum fsmonitor_reason is_remote(struct repository *r)
45+
{
46+
struct statfs fs;
47+
48+
if (statfs(r->worktree, &fs) == -1) {
49+
int saved_errno = errno;
50+
trace_printf_key(&trace_fsmonitor, "statfs('%s') failed: %s",
51+
r->worktree, strerror(saved_errno));
52+
errno = saved_errno;
53+
return FSMONITOR_REASON_ZERO;
54+
}
55+
56+
trace_printf_key(&trace_fsmonitor,
57+
"statfs('%s') [type 0x%08x][flags 0x%08x] '%s'",
58+
r->worktree, fs.f_type, fs.f_flags, fs.f_fstypename);
59+
60+
if (!(fs.f_flags & MNT_LOCAL))
61+
return FSMONITOR_REASON_REMOTE;
62+
63+
return FSMONITOR_REASON_ZERO;
64+
}
565

666
enum fsmonitor_reason fsm_os__incompatible(struct repository *r)
767
{
68+
enum fsmonitor_reason reason;
69+
70+
reason = is_remote(r);
71+
if (reason)
72+
return reason;
73+
874
return FSMONITOR_REASON_ZERO;
975
}

fsmonitor-settings.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ static void create_reason_message(struct repository *r,
160160
_("virtual repos are incompatible with fsmonitor"));
161161
return;
162162

163+
case FSMONITOR_REASON_REMOTE:
164+
strbuf_addstr(buf_reason,
165+
_("remote repos are incompatible with fsmonitor"));
166+
return;
167+
163168
default:
164169
BUG("Unhandled case in create_reason_message '%d'", s->reason);
165170
}

fsmonitor-settings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ enum fsmonitor_reason {
1717
FSMONITOR_REASON_ZERO = 0,
1818
FSMONITOR_REASON_BARE = 1,
1919
FSMONITOR_REASON_VIRTUAL = 2,
20+
FSMONITOR_REASON_REMOTE = 3,
2021
};
2122

2223
void fsm_settings__set_ipc(struct repository *r);

0 commit comments

Comments
 (0)