]>
Commit | Line | Data |
---|---|---|
883e248b BP |
1 | #ifndef FSMONITOR_H |
2 | #define FSMONITOR_H | |
3 | ||
ef3ca954 EN |
4 | #include "cache.h" |
5 | #include "dir.h" | |
1e0ea5c4 | 6 | #include "fsmonitor-settings.h" |
74ea5c95 | 7 | #include "trace.h" |
ef3ca954 | 8 | |
883e248b BP |
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 | */ | |
55454427 | 15 | int read_fsmonitor_extension(struct index_state *istate, const void *data, unsigned long sz); |
883e248b BP |
16 | |
17 | /* | |
3bd28eb2 AV |
18 | * Fill the fsmonitor_dirty ewah bits with their state from the index, |
19 | * before it is split during writing. | |
20 | */ | |
55454427 | 21 | void fill_fsmonitor_bitmap(struct index_state *istate); |
3bd28eb2 AV |
22 | |
23 | /* | |
24 | * Write the CE_FSMONITOR_VALID state into the fsmonitor index | |
25 | * extension. Reads from the fsmonitor_dirty ewah in the index. | |
883e248b | 26 | */ |
55454427 | 27 | void write_fsmonitor_extension(struct strbuf *sb, struct index_state *istate); |
883e248b BP |
28 | |
29 | /* | |
30 | * Add/remove the fsmonitor index extension | |
31 | */ | |
55454427 DL |
32 | void add_fsmonitor(struct index_state *istate); |
33 | void remove_fsmonitor(struct index_state *istate); | |
883e248b BP |
34 | |
35 | /* | |
36 | * Add/remove the fsmonitor index extension as necessary based on the current | |
37 | * core.fsmonitor setting. | |
38 | */ | |
55454427 | 39 | void tweak_fsmonitor(struct index_state *istate); |
883e248b BP |
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 | */ | |
55454427 | 47 | void refresh_fsmonitor(struct index_state *istate); |
883e248b | 48 | |
940b94f3 JH |
49 | /* |
50 | * Does the received result contain the "trivial" response? | |
51 | */ | |
52 | int fsmonitor_is_trivial_response(const struct strbuf *query_result); | |
53 | ||
0ec9949f NK |
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 | { | |
1e0ea5c4 JH |
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; | |
0ec9949f NK |
66 | } |
67 | ||
883e248b BP |
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. | |
f954c7b8 JH |
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. | |
883e248b | 81 | */ |
b5a81697 | 82 | static inline void mark_fsmonitor_valid(struct index_state *istate, struct cache_entry *ce) |
883e248b | 83 | { |
1e0ea5c4 JH |
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)) { | |
f954c7b8 JH |
88 | if (S_ISGITLINK(ce->ce_mode)) |
89 | return; | |
b5a81697 | 90 | istate->cache_changed = 1; |
883e248b BP |
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 | { | |
1e0ea5c4 JH |
105 | enum fsmonitor_mode fsm_mode = fsm_settings__get_mode(istate->repo); |
106 | ||
107 | if (fsm_mode > FSMONITOR_MODE_DISABLED) { | |
883e248b | 108 | ce->ce_flags &= ~CE_FSMONITOR_VALID; |
0cacebf0 | 109 | untracked_cache_invalidate_path(istate, ce->name, 1); |
883e248b BP |
110 | trace_printf_key(&trace_fsmonitor, "mark_fsmonitor_invalid '%s'", ce->name); |
111 | } | |
112 | } | |
113 | ||
114 | #endif |