ci: fix code style
[git/debian.git] / fsmonitor--daemon.h
blobbd09fffc1767a36282ca8f01381acf969ab159d6
1 #ifndef FSMONITOR_DAEMON_H
2 #define FSMONITOR_DAEMON_H
4 #ifdef HAVE_FSMONITOR_DAEMON_BACKEND
6 #include "cache.h"
7 #include "dir.h"
8 #include "run-command.h"
9 #include "simple-ipc.h"
10 #include "thread-utils.h"
12 struct fsmonitor_batch;
13 struct fsmonitor_token_data;
16 * Create a new batch of path(s). The returned batch is considered
17 * private and not linked into the fsmonitor daemon state. The caller
18 * should fill this batch with one or more paths and then publish it.
20 struct fsmonitor_batch *fsmonitor_batch__new(void);
23 * Free the list of batches starting with this one.
25 void fsmonitor_batch__free_list(struct fsmonitor_batch *batch);
28 * Add this path to this batch of modified files.
30 * The batch should be private and NOT (yet) linked into the fsmonitor
31 * daemon state and therefore not yet visible to worker threads and so
32 * no locking is required.
34 void fsmonitor_batch__add_path(struct fsmonitor_batch *batch, const char *path);
36 struct fsmonitor_daemon_backend_data; /* opaque platform-specific data */
38 struct fsmonitor_daemon_state {
39 pthread_t listener_thread;
40 pthread_mutex_t main_lock;
42 struct strbuf path_worktree_watch;
43 struct strbuf path_gitdir_watch;
44 int nr_paths_watching;
46 struct fsmonitor_token_data *current_token_data;
48 struct strbuf path_cookie_prefix;
49 pthread_cond_t cookies_cond;
50 int cookie_seq;
51 struct hashmap cookies;
53 int error_code;
54 struct fsmonitor_daemon_backend_data *backend_data;
56 struct ipc_server_data *ipc_server_data;
60 * Pathname classifications.
62 * The daemon classifies the pathnames that it receives from file
63 * system notification events into the following categories and uses
64 * that to decide whether clients are told about them. (And to watch
65 * for file system synchronization events.)
67 * The daemon only collects and reports on the set of modified paths
68 * within the working directory (proper).
70 * The client should only care about paths within the working
71 * directory proper (inside the working directory and not ".git" nor
72 * inside of ".git/"). That is, the client has read the index and is
73 * asking for a list of any paths in the working directory that have
74 * been modified since the last token. The client does not care about
75 * file system changes within the ".git/" directory (such as new loose
76 * objects or packfiles). So the client will only receive paths that
77 * are classified as IS_WORKDIR_PATH.
79 * Note that ".git" is usually a directory and is therefore inside
80 * the cone of the FS watch that we have on the working directory root,
81 * so we will also get FS events for disk activity on and within ".git/"
82 * that we need to respond to or filter from the client.
84 * But Git also allows ".git" to be a *file* that points to a GITDIR
85 * outside of the working directory. When this happens, we need to
86 * create FS watches on both the working directory root *and* on the
87 * (external) GITDIR root. (The latter is required because we put
88 * cookie files inside it and use them to sync with the FS event
89 * stream.)
91 * Note that in the context of this discussion, I'm using "GITDIR"
92 * to only mean an external GITDIR referenced by a ".git" file.
94 * The platform FS event backends will receive watch-specific
95 * relative paths (except for those OS's that always emit absolute
96 * paths). We use the following enum and routines to classify each
97 * path so that we know how to handle it. There is a slight asymmetry
98 * here because ".git/" is inside the working directory and the
99 * (external) GITDIR is not, and therefore how we handle events may
100 * vary slightly, so I have different enums for "IS...DOT_GIT..." and
101 * "IS...GITDIR...".
103 * The daemon uses the IS_DOT_GIT and IS_GITDIR internally to mean the
104 * exact ".git" file/directory or GITDIR directory. If the daemon
105 * receives a delete event for either of these paths, it will
106 * automatically shutdown, for example.
108 * Note that the daemon DOES NOT explicitly watch nor special case the
109 * index. The daemon does not read the index nor have any internal
110 * index-relative state, so there are no "IS...INDEX..." enum values.
112 enum fsmonitor_path_type {
113 IS_WORKDIR_PATH = 0,
115 IS_DOT_GIT,
116 IS_INSIDE_DOT_GIT,
117 IS_INSIDE_DOT_GIT_WITH_COOKIE_PREFIX,
119 IS_GITDIR,
120 IS_INSIDE_GITDIR,
121 IS_INSIDE_GITDIR_WITH_COOKIE_PREFIX,
123 IS_OUTSIDE_CONE,
127 * Classify a pathname relative to the root of the working directory.
129 enum fsmonitor_path_type fsmonitor_classify_path_workdir_relative(
130 const char *relative_path);
133 * Classify a pathname relative to a <gitdir> that is external to the
134 * worktree directory.
136 enum fsmonitor_path_type fsmonitor_classify_path_gitdir_relative(
137 const char *relative_path);
140 * Classify an absolute pathname received from a filesystem event.
142 enum fsmonitor_path_type fsmonitor_classify_path_absolute(
143 struct fsmonitor_daemon_state *state,
144 const char *path);
147 * Prepend the this batch of path(s) onto the list of batches associated
148 * with the current token. This makes the batch visible to worker threads.
150 * The caller no longer owns the batch and must not free it.
152 * Wake up the client threads waiting on these cookies.
154 void fsmonitor_publish(struct fsmonitor_daemon_state *state,
155 struct fsmonitor_batch *batch,
156 const struct string_list *cookie_names);
159 * If the platform-specific layer loses sync with the filesystem,
160 * it should call this to invalidate cached data and abort waiting
161 * threads.
163 void fsmonitor_force_resync(struct fsmonitor_daemon_state *state);
165 #endif /* HAVE_FSMONITOR_DAEMON_BACKEND */
166 #endif /* FSMONITOR_DAEMON_H */