Ben Peart | 883e248 | 2017-09-22 12:35:40 -0400 | [diff] [blame] | 1 | #ifndef FSMONITOR_H |
| 2 | #define FSMONITOR_H |
| 3 | |
Elijah Newren | ef3ca95 | 2018-08-15 10:54:05 -0700 | [diff] [blame] | 4 | #include "cache.h" |
| 5 | #include "dir.h" |
Jeff Hostetler | 1e0ea5c | 2022-03-25 18:02:46 +0000 | [diff] [blame] | 6 | #include "fsmonitor-settings.h" |
Elijah Newren | 74ea5c9 | 2023-04-11 03:00:38 +0000 | [diff] [blame] | 7 | #include "trace.h" |
Elijah Newren | ef3ca95 | 2018-08-15 10:54:05 -0700 | [diff] [blame] | 8 | |
Ben Peart | 883e248 | 2017-09-22 12:35:40 -0400 | [diff] [blame] | 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 | */ |
Denton Liu | 5545442 | 2019-04-29 04:28:14 -0400 | [diff] [blame] | 15 | int read_fsmonitor_extension(struct index_state *istate, const void *data, unsigned long sz); |
Ben Peart | 883e248 | 2017-09-22 12:35:40 -0400 | [diff] [blame] | 16 | |
| 17 | /* |
Alex Vandiver | 3bd28eb | 2017-11-09 11:58:10 -0800 | [diff] [blame] | 18 | * Fill the fsmonitor_dirty ewah bits with their state from the index, |
| 19 | * before it is split during writing. |
| 20 | */ |
Denton Liu | 5545442 | 2019-04-29 04:28:14 -0400 | [diff] [blame] | 21 | void fill_fsmonitor_bitmap(struct index_state *istate); |
Alex Vandiver | 3bd28eb | 2017-11-09 11:58:10 -0800 | [diff] [blame] | 22 | |
| 23 | /* |
| 24 | * Write the CE_FSMONITOR_VALID state into the fsmonitor index |
| 25 | * extension. Reads from the fsmonitor_dirty ewah in the index. |
Ben Peart | 883e248 | 2017-09-22 12:35:40 -0400 | [diff] [blame] | 26 | */ |
Denton Liu | 5545442 | 2019-04-29 04:28:14 -0400 | [diff] [blame] | 27 | void write_fsmonitor_extension(struct strbuf *sb, struct index_state *istate); |
Ben Peart | 883e248 | 2017-09-22 12:35:40 -0400 | [diff] [blame] | 28 | |
| 29 | /* |
| 30 | * Add/remove the fsmonitor index extension |
| 31 | */ |
Denton Liu | 5545442 | 2019-04-29 04:28:14 -0400 | [diff] [blame] | 32 | void add_fsmonitor(struct index_state *istate); |
| 33 | void remove_fsmonitor(struct index_state *istate); |
Ben Peart | 883e248 | 2017-09-22 12:35:40 -0400 | [diff] [blame] | 34 | |
| 35 | /* |
| 36 | * Add/remove the fsmonitor index extension as necessary based on the current |
| 37 | * core.fsmonitor setting. |
| 38 | */ |
Denton Liu | 5545442 | 2019-04-29 04:28:14 -0400 | [diff] [blame] | 39 | void tweak_fsmonitor(struct index_state *istate); |
Ben Peart | 883e248 | 2017-09-22 12:35:40 -0400 | [diff] [blame] | 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 | */ |
Denton Liu | 5545442 | 2019-04-29 04:28:14 -0400 | [diff] [blame] | 47 | void refresh_fsmonitor(struct index_state *istate); |
Ben Peart | 883e248 | 2017-09-22 12:35:40 -0400 | [diff] [blame] | 48 | |
| 49 | /* |
Jeff Hostetler | 940b94f | 2021-02-03 15:34:47 +0000 | [diff] [blame] | 50 | * Does the received result contain the "trivial" response? |
| 51 | */ |
| 52 | int fsmonitor_is_trivial_response(const struct strbuf *query_result); |
| 53 | |
| 54 | /* |
Nipunn Koorapati | 0ec9949 | 2021-03-17 21:22:22 +0000 | [diff] [blame] | 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 | { |
Jeff Hostetler | 1e0ea5c | 2022-03-25 18:02:46 +0000 | [diff] [blame] | 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; |
Nipunn Koorapati | 0ec9949 | 2021-03-17 21:22:22 +0000 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | /* |
Ben Peart | 883e248 | 2017-09-22 12:35:40 -0400 | [diff] [blame] | 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. |
Jeff Hostetler | f954c7b | 2022-05-26 21:47:17 +0000 | [diff] [blame] | 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. |
Ben Peart | 883e248 | 2017-09-22 12:35:40 -0400 | [diff] [blame] | 81 | */ |
Johannes Schindelin | b5a8169 | 2019-05-24 05:23:48 -0700 | [diff] [blame] | 82 | static inline void mark_fsmonitor_valid(struct index_state *istate, struct cache_entry *ce) |
Ben Peart | 883e248 | 2017-09-22 12:35:40 -0400 | [diff] [blame] | 83 | { |
Jeff Hostetler | 1e0ea5c | 2022-03-25 18:02:46 +0000 | [diff] [blame] | 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)) { |
Jeff Hostetler | f954c7b | 2022-05-26 21:47:17 +0000 | [diff] [blame] | 88 | if (S_ISGITLINK(ce->ce_mode)) |
| 89 | return; |
Johannes Schindelin | b5a8169 | 2019-05-24 05:23:48 -0700 | [diff] [blame] | 90 | istate->cache_changed = 1; |
Ben Peart | 883e248 | 2017-09-22 12:35:40 -0400 | [diff] [blame] | 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 | { |
Jeff Hostetler | 1e0ea5c | 2022-03-25 18:02:46 +0000 | [diff] [blame] | 105 | enum fsmonitor_mode fsm_mode = fsm_settings__get_mode(istate->repo); |
| 106 | |
| 107 | if (fsm_mode > FSMONITOR_MODE_DISABLED) { |
Ben Peart | 883e248 | 2017-09-22 12:35:40 -0400 | [diff] [blame] | 108 | ce->ce_flags &= ~CE_FSMONITOR_VALID; |
Nguyễn Thái Ngọc Duy | 0cacebf | 2018-02-07 16:21:40 +0700 | [diff] [blame] | 109 | untracked_cache_invalidate_path(istate, ce->name, 1); |
Ben Peart | 883e248 | 2017-09-22 12:35:40 -0400 | [diff] [blame] | 110 | trace_printf_key(&trace_fsmonitor, "mark_fsmonitor_invalid '%s'", ce->name); |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | #endif |