log-tree: replace include of revision.h with simple forward declaration
[alt-git.git] / fsmonitor.h
blob7702301d214a413496b298fbbb6e788c108fb5ad
1 #ifndef FSMONITOR_H
2 #define FSMONITOR_H
4 #include "dir.h"
5 #include "fsmonitor-settings.h"
6 #include "object.h"
7 #include "read-cache-ll.h"
8 #include "trace.h"
10 extern struct trace_key trace_fsmonitor;
13 * Read the fsmonitor index extension and (if configured) restore the
14 * CE_FSMONITOR_VALID state.
16 int read_fsmonitor_extension(struct index_state *istate, const void *data, unsigned long sz);
19 * Fill the fsmonitor_dirty ewah bits with their state from the index,
20 * before it is split during writing.
22 void fill_fsmonitor_bitmap(struct index_state *istate);
25 * Write the CE_FSMONITOR_VALID state into the fsmonitor index
26 * extension. Reads from the fsmonitor_dirty ewah in the index.
28 void write_fsmonitor_extension(struct strbuf *sb, struct index_state *istate);
31 * Add/remove the fsmonitor index extension
33 void add_fsmonitor(struct index_state *istate);
34 void remove_fsmonitor(struct index_state *istate);
37 * Add/remove the fsmonitor index extension as necessary based on the current
38 * core.fsmonitor setting.
40 void tweak_fsmonitor(struct index_state *istate);
43 * Run the configured fsmonitor integration script and clear the
44 * CE_FSMONITOR_VALID bit for any files returned as dirty. Also invalidate
45 * any corresponding untracked cache directory structures. Optimized to only
46 * run the first time it is called.
48 void refresh_fsmonitor(struct index_state *istate);
51 * Does the received result contain the "trivial" response?
53 int fsmonitor_is_trivial_response(const struct strbuf *query_result);
56 * Check if refresh_fsmonitor has been called at least once.
57 * refresh_fsmonitor is idempotent. Returns true if fsmonitor is
58 * not enabled (since the state will be "fresh" w/ CE_FSMONITOR_VALID unset)
59 * This version is useful for assertions
61 static inline int is_fsmonitor_refreshed(const struct index_state *istate)
63 enum fsmonitor_mode fsm_mode = fsm_settings__get_mode(istate->repo);
65 return fsm_mode <= FSMONITOR_MODE_DISABLED ||
66 istate->fsmonitor_has_run_once;
70 * Set the given cache entries CE_FSMONITOR_VALID bit. This should be
71 * called any time the cache entry has been updated to reflect the
72 * current state of the file on disk.
74 * However, never mark submodules as valid. When commands like "git
75 * status" run they might need to recurse into the submodule (using a
76 * child process) to get a summary of the submodule state. We don't
77 * have (and don't want to create) the facility to translate every
78 * FS event that we receive and that happens to be deep inside of a
79 * submodule back to the submodule root, so we cannot correctly keep
80 * track of this bit on the gitlink directory. Therefore, we never
81 * set it on submodules.
83 static inline void mark_fsmonitor_valid(struct index_state *istate, struct cache_entry *ce)
85 enum fsmonitor_mode fsm_mode = fsm_settings__get_mode(istate->repo);
87 if (fsm_mode > FSMONITOR_MODE_DISABLED &&
88 !(ce->ce_flags & CE_FSMONITOR_VALID)) {
89 if (S_ISGITLINK(ce->ce_mode))
90 return;
91 istate->cache_changed |= FSMONITOR_CHANGED;
92 ce->ce_flags |= CE_FSMONITOR_VALID;
93 trace_printf_key(&trace_fsmonitor, "mark_fsmonitor_clean '%s'", ce->name);
98 * Clear the given cache entry's CE_FSMONITOR_VALID bit and invalidate
99 * any corresponding untracked cache directory structures. This should
100 * be called any time git creates or modifies a file that should
101 * trigger an lstat() or invalidate the untracked cache for the
102 * corresponding directory
104 static inline void mark_fsmonitor_invalid(struct index_state *istate, struct cache_entry *ce)
106 enum fsmonitor_mode fsm_mode = fsm_settings__get_mode(istate->repo);
108 if (fsm_mode > FSMONITOR_MODE_DISABLED) {
109 ce->ce_flags &= ~CE_FSMONITOR_VALID;
110 untracked_cache_invalidate_path(istate, ce->name, 1);
111 trace_printf_key(&trace_fsmonitor, "mark_fsmonitor_invalid '%s'", ce->name);
115 #endif