Skip to content

Commit

Permalink
Merge pull request #3082 from dscho/fsmonitor-gfw
Browse files Browse the repository at this point in the history
Add an experimental built-in FSMonitor
  • Loading branch information
jeffhostetler authored and Git for Windows Build Agent committed May 25, 2021
2 parents 6f037d0 + 6e4ee2f commit 93d2c2c
Show file tree
Hide file tree
Showing 26 changed files with 3,839 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -72,6 +72,7 @@
/git-format-patch
/git-fsck
/git-fsck-objects
/git-fsmonitor--daemon
/git-gc
/git-get-tar-commit-id
/git-grep
Expand Down
45 changes: 35 additions & 10 deletions Documentation/config/core.txt
Expand Up @@ -66,18 +66,43 @@ core.fsmonitor::
will identify all files that may have changed since the
requested date/time. This information is used to speed up git by
avoiding unnecessary processing of files that have not changed.
See the "fsmonitor-watchman" section of linkgit:githooks[5].
+
See the "fsmonitor-watchman" section of linkgit:githooks[5].
+
Note: FSMonitor hooks (and this config setting) are ignored if the
built-in FSMonitor is enabled (see `core.useBuiltinFSMonitor`).

core.fsmonitorHookVersion::
Sets the version of hook that is to be used when calling fsmonitor.
There are currently versions 1 and 2. When this is not set,
version 2 will be tried first and if it fails then version 1
will be tried. Version 1 uses a timestamp as input to determine
which files have changes since that time but some monitors
like watchman have race conditions when used with a timestamp.
Version 2 uses an opaque string so that the monitor can return
something that can be used to determine what files have changed
without race conditions.
Sets the version of hook that is to be used when calling the
FSMonitor hook (as configured via `core.fsmonitor`).
+
There are currently versions 1 and 2. When this is not set,
version 2 will be tried first and if it fails then version 1
will be tried. Version 1 uses a timestamp as input to determine
which files have changes since that time but some monitors
like watchman have race conditions when used with a timestamp.
Version 2 uses an opaque string so that the monitor can return
something that can be used to determine what files have changed
without race conditions.
+
Note: FSMonitor hooks (and this config setting) are ignored if the
built-in FSMonitor is enabled (see `core.useBuiltinFSMonitor`).

core.useBuiltinFSMonitor::
If set to true, enable the built-in filesystem event watcher (for
technical details, see linkgit:git-fsmonitor--daemon[1]).
+
Like external (hook-based) FSMonitors, the built-in FSMonitor can speed up
Git commands that need to refresh the Git index (e.g. `git status`) in a
worktree with many files. The built-in FSMonitor facility eliminates the
need to install and maintain an external third-party monitoring tool.
+
The built-in FSMonitor is currently available only on a limited set of
supported platforms.
+
Note: if this config setting is set to `true`, any FSMonitor hook
configured via `core.fsmonitor` (and possibly `core.fsmonitorHookVersion`)
is ignored.

core.trustctime::
If false, the ctime differences between the index and the
Expand Down
104 changes: 104 additions & 0 deletions Documentation/git-fsmonitor--daemon.txt
@@ -0,0 +1,104 @@
git-fsmonitor--daemon(1)
========================

NAME
----
git-fsmonitor--daemon - Builtin file system monitor daemon

SYNOPSIS
--------
[verse]
'git fsmonitor--daemon' --start
'git fsmonitor--daemon' --run
'git fsmonitor--daemon' --stop
'git fsmonitor--daemon' --is-running
'git fsmonitor--daemon' --is-supported
'git fsmonitor--daemon' --query <token>
'git fsmonitor--daemon' --query-index
'git fsmonitor--daemon' --flush

DESCRIPTION
-----------

Monitors files and directories in the working directory for changes using
platform-specific file system notification facilities.

It communicates directly with commands like `git status` using the
link:technical/api-simple-ipc.html[simple IPC] interface instead of
the slower linkgit:githooks[5] interface.

OPTIONS
-------

--start::
Starts the fsmonitor daemon in the background.

--run::
Runs the fsmonitor daemon in the foreground.

--stop::
Stops the fsmonitor daemon running for the current working
directory, if present.

--is-running::
Exits with zero status if the fsmonitor daemon is watching the
current working directory.

--is-supported::
Exits with zero status if the fsmonitor daemon feature is supported
on this platform.

--query <token>::
Connects to the fsmonitor daemon (starting it if necessary) and
requests the list of changed files and directories since the
given token.
This is intended for testing purposes.

--query-index::
Read the current `<token>` from the File System Monitor index
extension (if present) and use it to query the fsmonitor daemon.
This is intended for testing purposes.

--flush::
Force the fsmonitor daemon to flush its in-memory cache and
re-sync with the file system.
This is intended for testing purposes.

REMARKS
-------
The fsmonitor daemon is a long running process that will watch a single
working directory. Commands, such as `git status`, should automatically
start it (if necessary) when `core.useBuiltinFSMonitor` is set to `true`
(see linkgit:git-config[1]).

Configure the built-in FSMonitor via `core.useBuiltinFSMonitor` in each
working directory separately, or globally via `git config --global
core.useBuiltinFSMonitor true`.

Tokens are opaque strings. They are used by the fsmonitor daemon to
mark a point in time and the associated internal state. Callers should
make no assumptions about the content of the token. In particular,
the should not assume that it is a timestamp.

Query commands send a request-token to the daemon and it responds with
a summary of the changes that have occurred since that token was
created. The daemon also returns a response-token that the client can
use in a future query.

For more information see the "File System Monitor" section in
linkgit:git-update-index[1].

CAVEATS
-------

The fsmonitor daemon does not currently know about submodules and does
not know to filter out file system events that happen within a
submodule. If fsmonitor daemon is watching a super repo and a file is
modified within the working directory of a submodule, it will report
the change (as happening against the super repo). However, the client
should properly ignore these extra events, so performance may be affected
but it should not cause an incorrect result.

GIT
---
Part of the linkgit:git[1] suite
4 changes: 3 additions & 1 deletion Documentation/git-update-index.txt
Expand Up @@ -498,7 +498,9 @@ FILE SYSTEM MONITOR
This feature is intended to speed up git operations for repos that have
large working directories.

It enables git to work together with a file system monitor (see the
It enables git to work together with a file system monitor (see
linkgit:git-fsmonitor--daemon[1]
and the
"fsmonitor-watchman" section of linkgit:githooks[5]) that can
inform it as to what files have been modified. This enables git to avoid
having to lstat() every file to find modified files.
Expand Down
3 changes: 2 additions & 1 deletion Documentation/githooks.txt
Expand Up @@ -593,7 +593,8 @@ fsmonitor-watchman

This hook is invoked when the configuration option `core.fsmonitor` is
set to `.git/hooks/fsmonitor-watchman` or `.git/hooks/fsmonitor-watchmanv2`
depending on the version of the hook to use.
depending on the version of the hook to use, unless overridden via
`core.useBuiltinFSMonitor` (see linkgit:git-config[1]).

Version 1 takes two arguments, a version (1) and the time in elapsed
nanoseconds since midnight, January 1, 1970.
Expand Down
15 changes: 15 additions & 0 deletions Makefile
Expand Up @@ -467,6 +467,11 @@ all::
# directory, and the JSON compilation database 'compile_commands.json' will be
# created at the root of the repository.
#
# If your platform supports an built-in fsmonitor backend, set
# FSMONITOR_DAEMON_BACKEND to the name of the corresponding
# `compat/fsmonitor/fsmonitor-fs-listen-<name>.c` that implements the
# `fsmonitor_fs_listen__*()` routines.
#
# Define DEVELOPER to enable more compiler warnings. Compiler version
# and family are auto detected, but could be overridden by defining
# COMPILER_FEATURES (see config.mak.dev). You can still set
Expand Down Expand Up @@ -893,6 +898,7 @@ LIB_OBJS += fetch-pack.o
LIB_OBJS += fmt-merge-msg.o
LIB_OBJS += fsck.o
LIB_OBJS += fsmonitor.o
LIB_OBJS += fsmonitor-ipc.o
LIB_OBJS += gettext.o
LIB_OBJS += gpg-interface.o
LIB_OBJS += graph.o
Expand Down Expand Up @@ -1096,6 +1102,7 @@ BUILTIN_OBJS += builtin/fmt-merge-msg.o
BUILTIN_OBJS += builtin/for-each-ref.o
BUILTIN_OBJS += builtin/for-each-repo.o
BUILTIN_OBJS += builtin/fsck.o
BUILTIN_OBJS += builtin/fsmonitor--daemon.o
BUILTIN_OBJS += builtin/gc.o
BUILTIN_OBJS += builtin/get-tar-commit-id.o
BUILTIN_OBJS += builtin/grep.o
Expand Down Expand Up @@ -1926,6 +1933,11 @@ ifdef NEED_ACCESS_ROOT_HANDLER
COMPAT_OBJS += compat/access.o
endif

ifdef FSMONITOR_DAEMON_BACKEND
COMPAT_CFLAGS += -DHAVE_FSMONITOR_DAEMON_BACKEND
COMPAT_OBJS += compat/fsmonitor/fsmonitor-fs-listen-$(FSMONITOR_DAEMON_BACKEND).o
endif

ifeq ($(TCLTK_PATH),)
NO_TCLTK = NoThanks
endif
Expand Down Expand Up @@ -2797,6 +2809,9 @@ GIT-BUILD-OPTIONS: FORCE
@echo PAGER_ENV=\''$(subst ','\'',$(subst ','\'',$(PAGER_ENV)))'\' >>$@+
@echo DC_SHA1=\''$(subst ','\'',$(subst ','\'',$(DC_SHA1)))'\' >>$@+
@echo X=\'$(X)\' >>$@+
ifdef FSMONITOR_DAEMON_BACKEND
@echo FSMONITOR_DAEMON_BACKEND=\''$(subst ','\'',$(subst ','\'',$(FSMONITOR_DAEMON_BACKEND)))'\' >>$@+
endif
ifdef TEST_OUTPUT_DIRECTORY
@echo TEST_OUTPUT_DIRECTORY=\''$(subst ','\'',$(subst ','\'',$(TEST_OUTPUT_DIRECTORY)))'\' >>$@+
endif
Expand Down
1 change: 1 addition & 0 deletions builtin.h
Expand Up @@ -159,6 +159,7 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix);
int cmd_for_each_repo(int argc, const char **argv, const char *prefix);
int cmd_format_patch(int argc, const char **argv, const char *prefix);
int cmd_fsck(int argc, const char **argv, const char *prefix);
int cmd_fsmonitor__daemon(int argc, const char **argv, const char *prefix);
int cmd_gc(int argc, const char **argv, const char *prefix);
int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix);
int cmd_grep(int argc, const char **argv, const char *prefix);
Expand Down

0 comments on commit 93d2c2c

Please sign in to comment.