mirror of
https://github.com/gitui-org/gitui
synced 2026-05-23 17:08:21 +00:00
support more remote callbacks
This commit is contained in:
parent
4e0ca3259e
commit
d9e20c802d
2 changed files with 45 additions and 15 deletions
|
|
@ -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<ProgressNotification> 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<Option<PushProgress>> {
|
||||
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<ProgressNotification>,
|
||||
) -> Result<()> {
|
||||
let simple_progress: Option<PushProgress> =
|
||||
state.map(|prog| prog.into());
|
||||
state.as_ref().map(|prog| prog.clone().into());
|
||||
log::info!("push progress: {:?}", simple_progress);
|
||||
let mut progress = progress.lock()?;
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue