diff options
Diffstat (limited to 'src/bin/git-autosave-daemon.rs')
| -rw-r--r-- | src/bin/git-autosave-daemon.rs | 41 |
1 files changed, 18 insertions, 23 deletions
diff --git a/src/bin/git-autosave-daemon.rs b/src/bin/git-autosave-daemon.rs index 2c27ab2..80edb34 100644 --- a/src/bin/git-autosave-daemon.rs +++ b/src/bin/git-autosave-daemon.rs @@ -5,9 +5,7 @@ use git_autosave::{Config, authenticate::Inquirer, commit_autosave, push_autosav use git2::{RemoteCallbacks, Repository, StatusOptions}; use happylock::{Mutex, ThreadKey}; use notify::{EventKind, INotifyWatcher, RecursiveMode}; -use notify_debouncer_full::{ - DebounceEventHandler, DebounceEventResult, DebouncedEvent, Debouncer, FileIdCache, -}; +use notify_debouncer_full::{DebounceEventHandler, DebounceEventResult, Debouncer, FileIdCache}; struct ConfigWatcher<Cache: FileIdCache + 'static> { config: &'static Mutex<Config>, @@ -16,14 +14,6 @@ struct ConfigWatcher<Cache: FileIdCache + 'static> { struct Watcher(&'static Mutex<Config>); -fn is_event_useful(events: &[DebouncedEvent]) -> bool { - events.iter().all(|event| { - event.kind == EventKind::Any - || event.kind == EventKind::Other - || matches!(event.kind, EventKind::Access(_)) - }) -} - impl<Cache: FileIdCache + Send + 'static> DebounceEventHandler for ConfigWatcher<Cache> { fn handle_event(&mut self, events: DebounceEventResult) { let events = match events { @@ -35,7 +25,10 @@ impl<Cache: FileIdCache + Send + 'static> DebounceEventHandler for ConfigWatcher return; } }; - if !is_event_useful(&events) { + if events + .iter() + .all(|event| matches!(event.kind, EventKind::Access(_))) + { return; } @@ -90,13 +83,14 @@ impl DebounceEventHandler for Watcher { return; } }; - if !is_event_useful(&events) { - return; - } let mut workdirs_to_autosave = HashSet::new(); let mut repositories_to_autosave = Vec::new(); - for path in events.iter().flat_map(|event| &event.paths) { + for (event, path) in events + .iter() + .filter(|event| !matches!(event.kind, EventKind::Access(_))) + .flat_map(|event| event.paths.iter().map(move |path| (event, path))) + { if path .components() .any(|component| component.as_os_str() == ".git") @@ -109,6 +103,13 @@ impl DebounceEventHandler for Watcher { log::warn!("Skipping non-repository: {:?}", &path); continue; }; + let Some(workdir) = repository.workdir() else { + log::warn!("Skipping bare repository: {:?}", &path); + continue; + }; + if workdirs_to_autosave.contains(workdir) { + continue; + } match repository.is_path_ignored(path) { Ok(true) => { log::trace!("Skipping event for ignored path: {:?}", path); @@ -119,13 +120,6 @@ impl DebounceEventHandler for Watcher { log::error!("Failed to determine if path is ignore: {e}"); } } - let Some(workdir) = repository.workdir() else { - log::warn!("Skipping bare repository: {:?}", &path); - continue; - }; - if workdirs_to_autosave.contains(workdir) { - continue; - } if let Ok(status) = repository.statuses(Some( StatusOptions::new() .include_untracked(true) @@ -135,6 +129,7 @@ impl DebounceEventHandler for Watcher { continue; } + log::info!("Event: {:?}", event); log::info!("Updated path: {:?}", &path); workdirs_to_autosave.insert(workdir.to_path_buf()); repositories_to_autosave.push(repository); |
