diff --git a/Cargo.lock b/Cargo.lock index fca96937d6..ce31c89448 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -686,7 +686,6 @@ dependencies = [ "figment", "git-version", "git2", - "ignore", "insta", "itertools 0.14.0", "log", @@ -733,19 +732,6 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" -[[package]] -name = "globset" -version = "0.4.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15f1ce686646e7f1e19bf7d5533fe443a45dbfb990e00629110797578b42fb19" -dependencies = [ - "aho-corasick", - "bstr", - "log", - "regex-automata", - "regex-syntax", -] - [[package]] name = "half" version = "2.4.1" @@ -956,22 +942,6 @@ dependencies = [ "icu_properties", ] -[[package]] -name = "ignore" -version = "0.4.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d89fd380afde86567dfba715db065673989d6253f42b88179abd3eae47bda4b" -dependencies = [ - "crossbeam-deque", - "globset", - "log", - "memchr", - "regex-automata", - "same-file", - "walkdir", - "winapi-util", -] - [[package]] name = "indexmap" version = "2.6.0" diff --git a/Cargo.toml b/Cargo.toml index 1abeb44bf1..760900e848 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,7 +30,6 @@ etcetera = "0.10.0" figment = { version = "0.10.19", features = ["toml"] } git-version = "0.3.9" git2 = { version = "0.20.1", default-features = false } -ignore = "0.4.23" itertools = "0.14.0" log = "0.4.27" nom = "7.1.3" diff --git a/src/error.rs b/src/error.rs index 83f3d6058b..044864a596 100644 --- a/src/error.rs +++ b/src/error.rs @@ -9,7 +9,6 @@ pub enum Error { Term(io::Error), GitDirUtf8(string::FromUtf8Error), Config(figment::Error), - FileWatcherGitignore(ignore::Error), FileWatcher(notify::Error), ReadRebaseStatusFile(io::Error), ReadBranchName(io::Error), @@ -64,9 +63,6 @@ impl Display for Error { Error::Term(e) => f.write_fmt(format_args!("Terminal error: {}", e)), Error::GitDirUtf8(_e) => f.write_str("Git directory not valid UTF-8"), Error::Config(e) => f.write_fmt(format_args!("Configuration error: {}", e)), - Error::FileWatcherGitignore(e) => { - f.write_fmt(format_args!("File watcher gitignore error: {}", e)) - } Error::FileWatcher(e) => f.write_fmt(format_args!("File watcher error: {}", e)), Error::ReadRebaseStatusFile(e) => { f.write_fmt(format_args!("Couldn't read rebase status file: {}", e)) diff --git a/src/file_watcher.rs b/src/file_watcher.rs index 27dd9c3a14..191e2af4c4 100644 --- a/src/file_watcher.rs +++ b/src/file_watcher.rs @@ -1,30 +1,24 @@ -use crate::{error::Error, Res}; -use ignore::gitignore::GitignoreBuilder; -use notify::{Event, EventKind, RecursiveMode, Watcher}; +use crate::{error::Error, open_repo, Res}; +use notify::{Event, EventKind, RecommendedWatcher, RecursiveMode, Watcher}; use std::{ path::Path, sync::{ atomic::{AtomicBool, Ordering}, Arc, }, - thread, }; pub struct FileWatcher { + _watcher: RecommendedWatcher, pending_updates: Arc, } impl FileWatcher { - pub fn new(path: &Path) -> Res { + pub fn new(repo_dir: &Path) -> Res { let pending_updates = Arc::new(AtomicBool::new(false)); let pending_updates_w = pending_updates.clone(); - let gitignore = GitignoreBuilder::new(path) - .add_line(None, super::LOG_FILE_NAME) - .map_err(Error::FileWatcherGitignore)? - .build() - .unwrap(); - + let repo = open_repo(repo_dir)?; let mut watcher = notify::recommended_watcher(move |res: Result| { if let Ok(event) = res { if !is_changed(&event) { @@ -32,8 +26,8 @@ impl FileWatcher { } for path in event.paths { - if !gitignore.matched(&path, path.is_dir()).is_ignore() { - log::info!("File changed: {:?}", path); + if !repo.status_should_ignore(&path).unwrap_or(false) { + log::info!("File changed: {:?} ({:?})", path, event.kind); pending_updates_w.store(true, Ordering::Relaxed); break; } @@ -42,17 +36,19 @@ impl FileWatcher { }) .map_err(Error::FileWatcher)?; - let path_buf = path.to_owned(); - thread::spawn(move || { - if let Err(err) = watcher - .watch(path_buf.as_ref(), RecursiveMode::Recursive) - .map_err(Error::FileWatcher) - { - log::error!("Couldn't start file-watcher due to: {}", err); - } - }); + let path_buf = repo_dir.to_owned(); + watcher + .watch(&path_buf, RecursiveMode::Recursive) + .map_err(Error::FileWatcher)?; + log::info!( + "File watcher started (kind: {:?})", + RecommendedWatcher::kind() + ); - Ok(Self { pending_updates }) + Ok(Self { + _watcher: watcher, + pending_updates, + }) } pub fn pending_updates(&self) -> bool {