]> git.ipfire.org Git - thirdparty/git.git/blob - fsmonitor.h
git-add.txt: add missing short option -A to synopsis
[thirdparty/git.git] / fsmonitor.h
1 #ifndef FSMONITOR_H
2 #define FSMONITOR_H
3
4 #include "cache.h"
5 #include "dir.h"
6 #include "fsmonitor-settings.h"
7 #include "trace.h"
8
9 extern struct trace_key trace_fsmonitor;
10
11 /*
12 * Read the fsmonitor index extension and (if configured) restore the
13 * CE_FSMONITOR_VALID state.
14 */
15 int read_fsmonitor_extension(struct index_state *istate, const void *data, unsigned long sz);
16
17 /*
18 * Fill the fsmonitor_dirty ewah bits with their state from the index,
19 * before it is split during writing.
20 */
21 void fill_fsmonitor_bitmap(struct index_state *istate);
22
23 /*
24 * Write the CE_FSMONITOR_VALID state into the fsmonitor index
25 * extension. Reads from the fsmonitor_dirty ewah in the index.
26 */
27 void write_fsmonitor_extension(struct strbuf *sb, struct index_state *istate);
28
29 /*
30 * Add/remove the fsmonitor index extension
31 */
32 void add_fsmonitor(struct index_state *istate);
33 void remove_fsmonitor(struct index_state *istate);
34
35 /*
36 * Add/remove the fsmonitor index extension as necessary based on the current
37 * core.fsmonitor setting.
38 */
39 void tweak_fsmonitor(struct index_state *istate);
40
41 /*
42 * Run the configured fsmonitor integration script and clear the
43 * CE_FSMONITOR_VALID bit for any files returned as dirty. Also invalidate
44 * any corresponding untracked cache directory structures. Optimized to only
45 * run the first time it is called.
46 */
47 void refresh_fsmonitor(struct index_state *istate);
48
49 /*
50 * Does the received result contain the "trivial" response?
51 */
52 int fsmonitor_is_trivial_response(const struct strbuf *query_result);
53
54 /*
55 * Check if refresh_fsmonitor has been called at least once.
56 * refresh_fsmonitor is idempotent. Returns true if fsmonitor is
57 * not enabled (since the state will be "fresh" w/ CE_FSMONITOR_VALID unset)
58 * This version is useful for assertions
59 */
60 static inline int is_fsmonitor_refreshed(const struct index_state *istate)
61 {
62 enum fsmonitor_mode fsm_mode = fsm_settings__get_mode(istate->repo);
63
64 return fsm_mode <= FSMONITOR_MODE_DISABLED ||
65 istate->fsmonitor_has_run_once;
66 }
67
68 /*
69 * Set the given cache entries CE_FSMONITOR_VALID bit. This should be
70 * called any time the cache entry has been updated to reflect the
71 * current state of the file on disk.
72 *
73 * However, never mark submodules as valid. When commands like "git
74 * status" run they might need to recurse into the submodule (using a
75 * child process) to get a summary of the submodule state. We don't
76 * have (and don't want to create) the facility to translate every
77 * FS event that we receive and that happens to be deep inside of a
78 * submodule back to the submodule root, so we cannot correctly keep
79 * track of this bit on the gitlink directory. Therefore, we never
80 * set it on submodules.
81 */
82 static inline void mark_fsmonitor_valid(struct index_state *istate, struct cache_entry *ce)
83 {
84 enum fsmonitor_mode fsm_mode = fsm_settings__get_mode(istate->repo);
85
86 if (fsm_mode > FSMONITOR_MODE_DISABLED &&
87 !(ce->ce_flags & CE_FSMONITOR_VALID)) {
88 if (S_ISGITLINK(ce->ce_mode))
89 return;
90 istate->cache_changed |= FSMONITOR_CHANGED;
91 ce->ce_flags |= CE_FSMONITOR_VALID;
92 trace_printf_key(&trace_fsmonitor, "mark_fsmonitor_clean '%s'", ce->name);
93 }
94 }
95
96 /*
97 * Clear the given cache entry's CE_FSMONITOR_VALID bit and invalidate
98 * any corresponding untracked cache directory structures. This should
99 * be called any time git creates or modifies a file that should
100 * trigger an lstat() or invalidate the untracked cache for the
101 * corresponding directory
102 */
103 static inline void mark_fsmonitor_invalid(struct index_state *istate, struct cache_entry *ce)
104 {
105 enum fsmonitor_mode fsm_mode = fsm_settings__get_mode(istate->repo);
106
107 if (fsm_mode > FSMONITOR_MODE_DISABLED) {
108 ce->ce_flags &= ~CE_FSMONITOR_VALID;
109 untracked_cache_invalidate_path(istate, ce->name, 1);
110 trace_printf_key(&trace_fsmonitor, "mark_fsmonitor_invalid '%s'", ce->name);
111 }
112 }
113
114 #endif