]>
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" |
ef3ca954 | 7 | |
883e248b BP |
8 | extern struct trace_key trace_fsmonitor; |
9 | ||
10 | /* | |
11 | * Read the fsmonitor index extension and (if configured) restore the | |
12 | * CE_FSMONITOR_VALID state. | |
13 | */ | |
55454427 | 14 | int read_fsmonitor_extension(struct index_state *istate, const void *data, unsigned long sz); |
883e248b BP |
15 | |
16 | /* | |
3bd28eb2 AV |
17 | * Fill the fsmonitor_dirty ewah bits with their state from the index, |
18 | * before it is split during writing. | |
19 | */ | |
55454427 | 20 | void fill_fsmonitor_bitmap(struct index_state *istate); |
3bd28eb2 AV |
21 | |
22 | /* | |
23 | * Write the CE_FSMONITOR_VALID state into the fsmonitor index | |
24 | * extension. Reads from the fsmonitor_dirty ewah in the index. | |
883e248b | 25 | */ |
55454427 | 26 | void write_fsmonitor_extension(struct strbuf *sb, struct index_state *istate); |
883e248b BP |
27 | |
28 | /* | |
29 | * Add/remove the fsmonitor index extension | |
30 | */ | |
55454427 DL |
31 | void add_fsmonitor(struct index_state *istate); |
32 | void remove_fsmonitor(struct index_state *istate); | |
883e248b BP |
33 | |
34 | /* | |
35 | * Add/remove the fsmonitor index extension as necessary based on the current | |
36 | * core.fsmonitor setting. | |
37 | */ | |
55454427 | 38 | void tweak_fsmonitor(struct index_state *istate); |
883e248b BP |
39 | |
40 | /* | |
41 | * Run the configured fsmonitor integration script and clear the | |
42 | * CE_FSMONITOR_VALID bit for any files returned as dirty. Also invalidate | |
43 | * any corresponding untracked cache directory structures. Optimized to only | |
44 | * run the first time it is called. | |
45 | */ | |
55454427 | 46 | void refresh_fsmonitor(struct index_state *istate); |
883e248b | 47 | |
940b94f3 JH |
48 | /* |
49 | * Does the received result contain the "trivial" response? | |
50 | */ | |
51 | int fsmonitor_is_trivial_response(const struct strbuf *query_result); | |
52 | ||
0ec9949f NK |
53 | /* |
54 | * Check if refresh_fsmonitor has been called at least once. | |
55 | * refresh_fsmonitor is idempotent. Returns true if fsmonitor is | |
56 | * not enabled (since the state will be "fresh" w/ CE_FSMONITOR_VALID unset) | |
57 | * This version is useful for assertions | |
58 | */ | |
59 | static inline int is_fsmonitor_refreshed(const struct index_state *istate) | |
60 | { | |
1e0ea5c4 JH |
61 | enum fsmonitor_mode fsm_mode = fsm_settings__get_mode(istate->repo); |
62 | ||
63 | return fsm_mode <= FSMONITOR_MODE_DISABLED || | |
64 | istate->fsmonitor_has_run_once; | |
0ec9949f NK |
65 | } |
66 | ||
883e248b BP |
67 | /* |
68 | * Set the given cache entries CE_FSMONITOR_VALID bit. This should be | |
69 | * called any time the cache entry has been updated to reflect the | |
70 | * current state of the file on disk. | |
71 | */ | |
b5a81697 | 72 | static inline void mark_fsmonitor_valid(struct index_state *istate, struct cache_entry *ce) |
883e248b | 73 | { |
1e0ea5c4 JH |
74 | enum fsmonitor_mode fsm_mode = fsm_settings__get_mode(istate->repo); |
75 | ||
76 | if (fsm_mode > FSMONITOR_MODE_DISABLED && | |
77 | !(ce->ce_flags & CE_FSMONITOR_VALID)) { | |
b5a81697 | 78 | istate->cache_changed = 1; |
883e248b BP |
79 | ce->ce_flags |= CE_FSMONITOR_VALID; |
80 | trace_printf_key(&trace_fsmonitor, "mark_fsmonitor_clean '%s'", ce->name); | |
81 | } | |
82 | } | |
83 | ||
84 | /* | |
85 | * Clear the given cache entry's CE_FSMONITOR_VALID bit and invalidate | |
86 | * any corresponding untracked cache directory structures. This should | |
87 | * be called any time git creates or modifies a file that should | |
88 | * trigger an lstat() or invalidate the untracked cache for the | |
89 | * corresponding directory | |
90 | */ | |
91 | static inline void mark_fsmonitor_invalid(struct index_state *istate, struct cache_entry *ce) | |
92 | { | |
1e0ea5c4 JH |
93 | enum fsmonitor_mode fsm_mode = fsm_settings__get_mode(istate->repo); |
94 | ||
95 | if (fsm_mode > FSMONITOR_MODE_DISABLED) { | |
883e248b | 96 | ce->ce_flags &= ~CE_FSMONITOR_VALID; |
0cacebf0 | 97 | untracked_cache_invalidate_path(istate, ce->name, 1); |
883e248b BP |
98 | trace_printf_key(&trace_fsmonitor, "mark_fsmonitor_invalid '%s'", ce->name); |
99 | } | |
100 | } | |
101 | ||
102 | #endif |