Update fsmonitor to utilize the new fsexcludes based logic for excluding paths that do not need to be scaned for new or modified files. Remove the old logic in dir.c that utilized the untracked cache (if enabled) to accomplish the same goal. Signed-off-by: Ben Peart <benpeart@xxxxxxxxxxxxx> --- dir.c | 10 +++------- dir.h | 2 -- fsmonitor.c | 21 ++------------------- fsmonitor.h | 10 +++------- t/t7519-status-fsmonitor.sh | 14 +++----------- 5 files changed, 11 insertions(+), 46 deletions(-) diff --git a/dir.c b/dir.c index 1aa639b9f4..28c2c83f76 100644 --- a/dir.c +++ b/dir.c @@ -19,7 +19,6 @@ #include "varint.h" #include "ewah/ewok.h" #include "fsexcludes.h" -#include "fsmonitor.h" /* * Tells read_directory_recursive how a file or directory should be treated. @@ -1827,12 +1826,9 @@ static int valid_cached_dir(struct dir_struct *dir, if (!untracked) return 0; - /* - * With fsmonitor, we can trust the untracked cache's valid field. - */ - refresh_fsmonitor(istate); - if (!(dir->untracked->use_fsmonitor && untracked->valid)) { - if (lstat(path->len ? path->buf : ".", &st)) { + if (!untracked->valid) { + if (stat(path->len ? path->buf : ".", &st)) { + invalidate_directory(dir->untracked, untracked); memset(&untracked->stat_data, 0, sizeof(untracked->stat_data)); return 0; } diff --git a/dir.h b/dir.h index b0758b82a2..e67ccfbb29 100644 --- a/dir.h +++ b/dir.h @@ -139,8 +139,6 @@ struct untracked_cache { int gitignore_invalidated; int dir_invalidated; int dir_opened; - /* fsmonitor invalidation data */ - unsigned int use_fsmonitor : 1; }; struct dir_struct { diff --git a/fsmonitor.c b/fsmonitor.c index 6d7bcd5d0e..dd67eef851 100644 --- a/fsmonitor.c +++ b/fsmonitor.c @@ -2,6 +2,7 @@ #include "config.h" #include "dir.h" #include "ewah/ewok.h" +#include "fsexcludes.h" #include "fsmonitor.h" #include "run-command.h" #include "strbuf.h" @@ -125,12 +126,7 @@ static void fsmonitor_refresh_callback(struct index_state *istate, const char *n ce->ce_flags &= ~CE_FSMONITOR_VALID; } - /* - * Mark the untracked cache dirty even if it wasn't found in the index - * as it could be a new untracked file. - */ trace_printf_key(&trace_fsmonitor, "fsmonitor_refresh_callback '%s'", name); - untracked_cache_invalidate_path(istate, name, 0); } void refresh_fsmonitor(struct index_state *istate) @@ -184,11 +180,8 @@ void refresh_fsmonitor(struct index_state *istate) /* Mark all entries invalid */ for (i = 0; i < istate->cache_nr; i++) istate->cache[i]->ce_flags &= ~CE_FSMONITOR_VALID; - - if (istate->untracked) - istate->untracked->use_fsmonitor = 0; } - strbuf_release(&query_result); + fsexcludes_init(&query_result); /* Now that we've updated istate, save the last_update time */ istate->fsmonitor_last_update = last_update; @@ -207,12 +200,6 @@ void add_fsmonitor(struct index_state *istate) for (i = 0; i < istate->cache_nr; i++) istate->cache[i]->ce_flags &= ~CE_FSMONITOR_VALID; - /* reset the untracked cache */ - if (istate->untracked) { - add_untracked_cache(istate); - istate->untracked->use_fsmonitor = 1; - } - /* Update the fsmonitor state */ refresh_fsmonitor(istate); } @@ -241,10 +228,6 @@ void tweak_fsmonitor(struct index_state *istate) /* Mark all previously saved entries as dirty */ ewah_each_bit(istate->fsmonitor_dirty, fsmonitor_ewah_callback, istate); - - /* Now mark the untracked cache for fsmonitor usage */ - if (istate->untracked) - istate->untracked->use_fsmonitor = 1; } ewah_free(istate->fsmonitor_dirty); diff --git a/fsmonitor.h b/fsmonitor.h index 65f3743636..f7adfc1f7c 100644 --- a/fsmonitor.h +++ b/fsmonitor.h @@ -35,8 +35,7 @@ extern void tweak_fsmonitor(struct index_state *istate); /* * Run the configured fsmonitor integration script and clear the - * CE_FSMONITOR_VALID bit for any files returned as dirty. Also invalidate - * any corresponding untracked cache directory structures. Optimized to only + * CE_FSMONITOR_VALID bit for any files returned as dirty. Optimized to only * run the first time it is called. */ extern void refresh_fsmonitor(struct index_state *istate); @@ -55,17 +54,14 @@ static inline void mark_fsmonitor_valid(struct cache_entry *ce) } /* - * Clear the given cache entry's CE_FSMONITOR_VALID bit and invalidate - * any corresponding untracked cache directory structures. This should + * Clear the given cache entry's CE_FSMONITOR_VALID bit. This should * be called any time git creates or modifies a file that should - * trigger an lstat() or invalidate the untracked cache for the - * corresponding directory + * trigger an lstat() for the corresponding directory */ static inline void mark_fsmonitor_invalid(struct index_state *istate, struct cache_entry *ce) { if (core_fsmonitor) { ce->ce_flags &= ~CE_FSMONITOR_VALID; - untracked_cache_invalidate_path(istate, ce->name, 1); trace_printf_key(&trace_fsmonitor, "mark_fsmonitor_invalid '%s'", ce->name); } } diff --git a/t/t7519-status-fsmonitor.sh b/t/t7519-status-fsmonitor.sh index 756beb0d8e..d6a1da5a0a 100755 --- a/t/t7519-status-fsmonitor.sh +++ b/t/t7519-status-fsmonitor.sh @@ -225,8 +225,7 @@ test_expect_success '*only* files returned by the integration script get flagged # Ensure commands that call refresh_index() to move the index back in time # properly invalidate the fsmonitor cache test_expect_success 'refresh_index() invalidates fsmonitor cache' ' - write_script .git/hooks/fsmonitor-test<<-\EOF && - EOF + write_integration_script && clean_repo && dirty_repo && git add . && @@ -275,7 +274,7 @@ do ' # Make sure it's actually skipping the check for modified and untracked - # (if enabled) files unless it is told about them. + # files unless it is told about them. test_expect_success "status doesn't detect unreported modifications" ' write_script .git/hooks/fsmonitor-test<<-\EOF && :>marker @@ -288,14 +287,7 @@ do git status >actual && test_path_is_file marker && test_i18ngrep ! "Changes not staged for commit:" actual && - if test $uc_val = true - then - test_i18ngrep ! "Untracked files:" actual - fi && - if test $uc_val = false - then - test_i18ngrep "Untracked files:" actual - fi && + test_i18ngrep ! "Untracked files:" actual && rm -f marker ' done -- 2.17.0.windows.1