diff --git a/asyncgit/src/push.rs b/asyncgit/src/push.rs index 8fffa137..3404592a 100644 --- a/asyncgit/src/push.rs +++ b/asyncgit/src/push.rs @@ -40,8 +40,8 @@ impl PushProgress { current: usize, total: usize, ) -> Self { - let total = cmp::max(current, total); - let progress = current as f32 / total as f32 * 100.0; + let total = cmp::max(current, total) as f32; + let progress = current as f32 / total * 100.0; let progress = progress as u8; Self { state, progress } } @@ -75,7 +75,7 @@ impl From for PushProgress { current, total, ), - ProgressNotification::Done => { + ProgressNotification::Done | _ => { PushProgress::new(PushProgressState::Pushing, 1, 1) } } @@ -130,7 +130,7 @@ impl AsyncPush { /// pub fn progress(&self) -> Result> { let res = self.progress.lock()?; - Ok(res.map(|progress| progress.into())) + Ok(res.as_ref().map(|progress| progress.clone().into())) } /// @@ -196,7 +196,7 @@ impl AsyncPush { Ok(update) => { Self::set_progress( progress.clone(), - Some(update), + Some(update.clone()), ) .expect("set prgoress failed"); sender @@ -250,7 +250,7 @@ impl AsyncPush { state: Option, ) -> Result<()> { let simple_progress: Option = - state.map(|prog| prog.into()); + state.as_ref().map(|prog| prog.clone().into()); log::info!("push progress: {:?}", simple_progress); let mut progress = progress.lock()?; diff --git a/asyncgit/src/sync/remotes.rs b/asyncgit/src/sync/remotes.rs index dbbc8270..2d07ba51 100644 --- a/asyncgit/src/sync/remotes.rs +++ b/asyncgit/src/sync/remotes.rs @@ -8,9 +8,27 @@ use git2::{ }; use scopetime::scope_time; +use super::CommitId; + /// -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone)] pub enum ProgressNotification { + /// + UpdateTips { + /// + name: String, + /// + a: CommitId, + /// + b: CommitId, + }, + /// + Transfer { + /// + objects: usize, + /// + total_objects: usize, + }, /// PushTransfer { /// @@ -98,19 +116,31 @@ fn remote_callbacks<'a>( log::debug!("progress: {}/{} ({} B)", current, total, bytes,); }); - callbacks.update_tips(|name, a, b| { + + let sender_clone = sender.clone(); + callbacks.update_tips(move |name, a, b| { log::debug!("update: '{}' [{}] [{}]", name, a, b); + sender_clone.clone().map(|sender| { + sender.send(ProgressNotification::UpdateTips { + name: name.to_string(), + a: a.into(), + b: b.into(), + }) + }); true }); - callbacks.transfer_progress(|p| { - log::debug!( - "transfer progress: {} B / {} / {} ", - p.received_bytes(), - p.received_objects(), - p.total_objects() - ); + + let sender_clone = sender.clone(); + callbacks.transfer_progress(move |p| { + sender_clone.clone().map(|sender| { + sender.send(ProgressNotification::Transfer { + objects: p.received_objects(), + total_objects: p.total_objects(), + }) + }); true }); + callbacks.pack_progress(move |stage, current, total| { sender.clone().map(|sender| { sender.send(ProgressNotification::Packing {