feat: FileWatcher now ignores changes from patterns in .gitignore#360
Conversation
`FileWatcher` will build a gitignore ruleset from all `.gitignore` files in the repo and any global `.gitignore`, and use this to ignore file change events. This prevents a lot of `FileUpdate` events being generated when ignored items like build folders change, which may have been contributing to freezes. If a change is detected involving a `.gitignore` file, the ruleset is rebuilt. Changes are also now no longer watched from a thread, which caused problems with some watcher implementations such as `Fsevents` on macOS.
26bbc63 to
732a5f0
Compare
|
I've removed starting the watcher in a thread because I suspect that the cause was triggering a lot of update events as a result of should-have-been-ignored files changing (such as This is an optmistic change since I am not sure how to reproduce the freezes myself, so I can't say whether this fixes them or not. If there is a repo that will reproduce this, I'm happy to check it myself although I'll be using the If you think it's best to make that change separate to the gitignore changes, or if it's not easy to reproduce the freezing, I'm also happy to remove those changes from this PR. |
|
There are no tests because there are no existing tests for |
|
Nice! I do agree we can drop spawning it in a thread and fixing things properly instead. I believe this approach is missing some of the variants of ignoring stuff though, as seen in https://git-scm.com/docs/gitignore. Did some digging and found this actually: https://git-scm.com/docs/git-check-ignore and https://docs.rs/git2/latest/git2/struct.Repository.html#method.status_should_ignore And in gitu: Works in subdirs: I've disabled ~ ❯ GIT_DIR="$HOME/repos/cfg.git" GIT_WORK_TREE="$HOME" git check-ignore .cache/gnome-calculator/un-daily.xls
~ ❯ echo $status # I'd hope for a 0 (ignored), but seems it doesn't consider showUntrackedFiles
1
~ ❯ GIT_DIR="$HOME/repos/cfg.git" GIT_WORK_TREE="$HOME" git config status.showUntrackedFiles
no |
|
But let's leave the tests aside. I believe it'd be messy, since file update events would come in async. And it'd need to have some sort of sleep duration in hope of catching it. |
`Repository.status_should_ignore` is a compliant way to check if a path should be ignored. This removes the need for the `ignore` lib entirely, and simplifies the file watcher implementation.
Oops, in hindsight this seems like such an obvious thing to have looked for first, good find! If nothing else, this dramatically simplifies the ignore logic, to the point that I don't think the Aside, I noticed (after logging the event type for watch events) that some of these happen multiple times, which probably also creates a lot of churn that have no real effect. It might be worth investigating
Okay. I'll give it some thought, it would be nice to invest in those tests at some stage given the number of issues that have come up in this fairly small set of code. |
| .build() | ||
| .unwrap(); | ||
|
|
||
| let repo = open_repo(repo_dir)?; |
There was a problem hiding this comment.
I recently merged a whole bunch of refactoring, where the creation of the file watcher was moved. Now it'd be real easy to just accept a Repository instead of a Path as argument. Then you'd don't need to call open_repo anymore!
It's created here!
Line 91 in e7b7719
There was a problem hiding this comment.
(I'll test the PR out again soon, but looks promising!)
|
Regading debouncing events. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #360 +/- ##
==========================================
+ Coverage 87.50% 87.56% +0.06%
==========================================
Files 66 66
Lines 6537 6532 -5
==========================================
Hits 5720 5720
+ Misses 817 812 -5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Gj on this! I feel relieved the file watcher is in a better state. |
FileWatcherwill build a gitignore ruleset from all.gitignorefiles in the repo and any global.gitignore, and use this to ignore file change events. This prevents a lot ofFileUpdateevents being generated when ignored items like build folders change, which may have been contributing to freezes.If a change is detected involving a
.gitignorefile, the ruleset is rebuilt.Changes are also now no longer watched from a thread, which caused problems with some watcher implementations such as
Fseventson macOS.Fixes #359
Fixes #358