summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bin/git-autosave-daemon.rs41
-rw-r--r--src/bin/git-restore-autosave.rs3
2 files changed, 20 insertions, 24 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);
diff --git a/src/bin/git-restore-autosave.rs b/src/bin/git-restore-autosave.rs
index b7571fa..b53df76 100644
--- a/src/bin/git-restore-autosave.rs
+++ b/src/bin/git-restore-autosave.rs
@@ -41,6 +41,7 @@ fn main() -> Result<(), anyhow::Error> {
let branch = git_autosave::utils::current_branch(&repository)?;
let earliest_time = repository.head()?.peel_to_commit()?.time();
+ let gitconfig = repository.config()?;
let config: &'static _ = Box::leak(Box::new(Config::load()?));
let auth = GitAuthenticator::new().set_prompter(Inquirer(config));
let mut callbacks = RemoteCallbacks::new();
@@ -62,7 +63,7 @@ fn main() -> Result<(), anyhow::Error> {
})
.filter(|autosave| all_branches || autosave.branch_name == branch)
.filter(|autosave| anytime || autosave.time > earliest_time)
- .filter(|autosave| all_devices || autosave.repo_id.as_bytes() != repo_id.value_bytes())
+ .filter(|autosave| all_devices || autosave.repo_id.as_bytes() != repo_id.as_bytes())
.collect::<Vec<_>>();
if autosaves.is_empty() {