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" |
| 6 | |
Ben Peart | 883e248 | 2017-09-22 12:35:40 -0400 | [diff] [blame] | 7 | extern struct trace_key trace_fsmonitor; |
| 8 | |
| 9 | /* |
| 10 | * Read the fsmonitor index extension and (if configured) restore the |
| 11 | * CE_FSMONITOR_VALID state. |
| 12 | */ |
Denton Liu | 5545442 | 2019-04-29 04:28:14 -0400 | [diff] [blame] | 13 | 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] | 14 | |
| 15 | /* |
Alex Vandiver | 3bd28eb | 2017-11-09 11:58:10 -0800 | [diff] [blame] | 16 | * Fill the fsmonitor_dirty ewah bits with their state from the index, |
| 17 | * before it is split during writing. |
| 18 | */ |
Denton Liu | 5545442 | 2019-04-29 04:28:14 -0400 | [diff] [blame] | 19 | void fill_fsmonitor_bitmap(struct index_state *istate); |
Alex Vandiver | 3bd28eb | 2017-11-09 11:58:10 -0800 | [diff] [blame] | 20 | |
| 21 | /* |
| 22 | * Write the CE_FSMONITOR_VALID state into the fsmonitor index |
| 23 | * extension. Reads from the fsmonitor_dirty ewah in the index. |
Ben Peart | 883e248 | 2017-09-22 12:35:40 -0400 | [diff] [blame] | 24 | */ |
Denton Liu | 5545442 | 2019-04-29 04:28:14 -0400 | [diff] [blame] | 25 | void write_fsmonitor_extension(struct strbuf *sb, struct index_state *istate); |
Ben Peart | 883e248 | 2017-09-22 12:35:40 -0400 | [diff] [blame] | 26 | |
| 27 | /* |
| 28 | * Add/remove the fsmonitor index extension |
| 29 | */ |
Denton Liu | 5545442 | 2019-04-29 04:28:14 -0400 | [diff] [blame] | 30 | void add_fsmonitor(struct index_state *istate); |
| 31 | void remove_fsmonitor(struct index_state *istate); |
Ben Peart | 883e248 | 2017-09-22 12:35:40 -0400 | [diff] [blame] | 32 | |
| 33 | /* |
| 34 | * Add/remove the fsmonitor index extension as necessary based on the current |
| 35 | * core.fsmonitor setting. |
| 36 | */ |
Denton Liu | 5545442 | 2019-04-29 04:28:14 -0400 | [diff] [blame] | 37 | void tweak_fsmonitor(struct index_state *istate); |
Ben Peart | 883e248 | 2017-09-22 12:35:40 -0400 | [diff] [blame] | 38 | |
| 39 | /* |
| 40 | * Run the configured fsmonitor integration script and clear the |
| 41 | * CE_FSMONITOR_VALID bit for any files returned as dirty. Also invalidate |
| 42 | * any corresponding untracked cache directory structures. Optimized to only |
| 43 | * run the first time it is called. |
| 44 | */ |
Denton Liu | 5545442 | 2019-04-29 04:28:14 -0400 | [diff] [blame] | 45 | void refresh_fsmonitor(struct index_state *istate); |
Ben Peart | 883e248 | 2017-09-22 12:35:40 -0400 | [diff] [blame] | 46 | |
| 47 | /* |
| 48 | * Set the given cache entries CE_FSMONITOR_VALID bit. This should be |
| 49 | * called any time the cache entry has been updated to reflect the |
| 50 | * current state of the file on disk. |
| 51 | */ |
Johannes Schindelin | b5a8169 | 2019-05-24 05:23:48 -0700 | [diff] [blame] | 52 | 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] | 53 | { |
Johannes Schindelin | b5a8169 | 2019-05-24 05:23:48 -0700 | [diff] [blame] | 54 | if (core_fsmonitor && !(ce->ce_flags & CE_FSMONITOR_VALID)) { |
| 55 | istate->cache_changed = 1; |
Ben Peart | 883e248 | 2017-09-22 12:35:40 -0400 | [diff] [blame] | 56 | ce->ce_flags |= CE_FSMONITOR_VALID; |
| 57 | trace_printf_key(&trace_fsmonitor, "mark_fsmonitor_clean '%s'", ce->name); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | /* |
| 62 | * Clear the given cache entry's CE_FSMONITOR_VALID bit and invalidate |
| 63 | * any corresponding untracked cache directory structures. This should |
| 64 | * be called any time git creates or modifies a file that should |
| 65 | * trigger an lstat() or invalidate the untracked cache for the |
| 66 | * corresponding directory |
| 67 | */ |
| 68 | static inline void mark_fsmonitor_invalid(struct index_state *istate, struct cache_entry *ce) |
| 69 | { |
| 70 | if (core_fsmonitor) { |
| 71 | ce->ce_flags &= ~CE_FSMONITOR_VALID; |
Nguyễn Thái Ngọc Duy | 0cacebf | 2018-02-07 16:21:40 +0700 | [diff] [blame] | 72 | untracked_cache_invalidate_path(istate, ce->name, 1); |
Ben Peart | 883e248 | 2017-09-22 12:35:40 -0400 | [diff] [blame] | 73 | trace_printf_key(&trace_fsmonitor, "mark_fsmonitor_invalid '%s'", ce->name); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | #endif |