]>
Commit | Line | Data |
---|---|---|
883e248b BP |
1 | #ifndef FSMONITOR_H |
2 | #define FSMONITOR_H | |
3 | ||
68d68646 | 4 | #include "fsmonitor-ll.h" |
ef3ca954 | 5 | #include "dir.h" |
1e0ea5c4 | 6 | #include "fsmonitor-settings.h" |
08c46a49 EN |
7 | #include "object.h" |
8 | #include "read-cache-ll.h" | |
74ea5c95 | 9 | #include "trace.h" |
ef3ca954 | 10 | |
0ec9949f NK |
11 | /* |
12 | * Check if refresh_fsmonitor has been called at least once. | |
13 | * refresh_fsmonitor is idempotent. Returns true if fsmonitor is | |
14 | * not enabled (since the state will be "fresh" w/ CE_FSMONITOR_VALID unset) | |
15 | * This version is useful for assertions | |
16 | */ | |
17 | static inline int is_fsmonitor_refreshed(const struct index_state *istate) | |
18 | { | |
1e0ea5c4 JH |
19 | enum fsmonitor_mode fsm_mode = fsm_settings__get_mode(istate->repo); |
20 | ||
21 | return fsm_mode <= FSMONITOR_MODE_DISABLED || | |
22 | istate->fsmonitor_has_run_once; | |
0ec9949f NK |
23 | } |
24 | ||
883e248b BP |
25 | /* |
26 | * Set the given cache entries CE_FSMONITOR_VALID bit. This should be | |
27 | * called any time the cache entry has been updated to reflect the | |
28 | * current state of the file on disk. | |
f954c7b8 JH |
29 | * |
30 | * However, never mark submodules as valid. When commands like "git | |
31 | * status" run they might need to recurse into the submodule (using a | |
32 | * child process) to get a summary of the submodule state. We don't | |
33 | * have (and don't want to create) the facility to translate every | |
34 | * FS event that we receive and that happens to be deep inside of a | |
35 | * submodule back to the submodule root, so we cannot correctly keep | |
36 | * track of this bit on the gitlink directory. Therefore, we never | |
37 | * set it on submodules. | |
883e248b | 38 | */ |
b5a81697 | 39 | static inline void mark_fsmonitor_valid(struct index_state *istate, struct cache_entry *ce) |
883e248b | 40 | { |
1e0ea5c4 JH |
41 | enum fsmonitor_mode fsm_mode = fsm_settings__get_mode(istate->repo); |
42 | ||
43 | if (fsm_mode > FSMONITOR_MODE_DISABLED && | |
44 | !(ce->ce_flags & CE_FSMONITOR_VALID)) { | |
f954c7b8 JH |
45 | if (S_ISGITLINK(ce->ce_mode)) |
46 | return; | |
be6b65b9 | 47 | istate->cache_changed |= FSMONITOR_CHANGED; |
883e248b BP |
48 | ce->ce_flags |= CE_FSMONITOR_VALID; |
49 | trace_printf_key(&trace_fsmonitor, "mark_fsmonitor_clean '%s'", ce->name); | |
50 | } | |
51 | } | |
52 | ||
53 | /* | |
54 | * Clear the given cache entry's CE_FSMONITOR_VALID bit and invalidate | |
55 | * any corresponding untracked cache directory structures. This should | |
56 | * be called any time git creates or modifies a file that should | |
57 | * trigger an lstat() or invalidate the untracked cache for the | |
58 | * corresponding directory | |
59 | */ | |
60 | static inline void mark_fsmonitor_invalid(struct index_state *istate, struct cache_entry *ce) | |
61 | { | |
1e0ea5c4 JH |
62 | enum fsmonitor_mode fsm_mode = fsm_settings__get_mode(istate->repo); |
63 | ||
64 | if (fsm_mode > FSMONITOR_MODE_DISABLED) { | |
883e248b | 65 | ce->ce_flags &= ~CE_FSMONITOR_VALID; |
0cacebf0 | 66 | untracked_cache_invalidate_path(istate, ce->name, 1); |
883e248b BP |
67 | trace_printf_key(&trace_fsmonitor, "mark_fsmonitor_invalid '%s'", ce->name); |
68 | } | |
69 | } | |
70 | ||
71 | #endif |