diff --git a/Makefile b/Makefile index f93c5df1..c25c5e6e 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,7 @@ .PHONY: debug build-release release-linux-musl test clippy clippy-pedantic install install-debug ARGS=-l +# ARGS=-l -d ~/code/extern/kubernetes # ARGS=-l -d ~/code/extern/linux # ARGS=-l -d ~/code/git-bare-test.git -w ~/code/git-bare-test diff --git a/asyncgit/src/asyncjob/mod.rs b/asyncgit/src/asyncjob/mod.rs index d17d2932..d92be0de 100644 --- a/asyncgit/src/asyncjob/mod.rs +++ b/asyncgit/src/asyncjob/mod.rs @@ -7,12 +7,17 @@ use crossbeam_channel::Sender; use std::sync::{Arc, Mutex, RwLock}; /// Passed to `AsyncJob::run` allowing sending intermediate progress notifications -pub struct RunParams { +pub struct RunParams< + T: Copy + Send, + P: Clone + Send + Sync + PartialEq, +> { sender: Sender, progress: Arc>, } -impl RunParams { +impl + RunParams +{ /// send an intermediate update notification. /// do not confuse this with the return value of `run`. /// `send` should only be used about progress notifications @@ -24,9 +29,13 @@ impl RunParams { } /// set the current progress - pub fn set_progress(&self, p: P) -> Result<()> { - *(self.progress.write()?) = p; - Ok(()) + pub fn set_progress(&self, p: P) -> Result { + Ok(if *self.progress.read()? == p { + false + } else { + *(self.progress.write()?) = p; + true + }) } } @@ -35,7 +44,7 @@ pub trait AsyncJob: Send + Sync + Clone { /// defines what notification type is used to communicate outside type Notification: Copy + Send; /// type of progress - type Progress: Clone + Default + Send + Sync; + type Progress: Clone + Default + Send + Sync + PartialEq; /// can run a synchronous time intensive task. /// the returned notification is used to tell interested parties diff --git a/asyncgit/src/filter_commits.rs b/asyncgit/src/filter_commits.rs index 0c28635d..3f5799b0 100644 --- a/asyncgit/src/filter_commits.rs +++ b/asyncgit/src/filter_commits.rs @@ -88,19 +88,14 @@ impl AsyncCommitFilterJob { let total_amount = commits.len(); let start = Instant::now(); - let mut progress = ProgressPercent::new(0, total_amount); - let result = commits .into_iter() .enumerate() .filter_map(|(idx, c)| { - let new_progress = - ProgressPercent::new(idx, total_amount); - - if new_progress != progress { - Self::update_progress(params, new_progress); - progress = new_progress; - } + Self::update_progress( + params, + ProgressPercent::new(idx, total_amount), + ); (*self.filter)(repo, &c) .ok() @@ -115,12 +110,16 @@ impl AsyncCommitFilterJob { params: &RunParams, new_progress: ProgressPercent, ) { - if let Err(e) = params.set_progress(new_progress) { - log::error!("progress error: {e}"); - } else if let Err(e) = - params.send(AsyncGitNotification::CommitFilter) - { - log::error!("send error: {e}"); + match params.set_progress(new_progress) { + Err(e) => log::error!("progress error: {e}"), + Ok(result) if result => { + if let Err(e) = + params.send(AsyncGitNotification::CommitFilter) + { + log::error!("send error: {e}"); + } + } + _ => (), } } }