fix fetch notifications (#555)

* fix fetch notifications
* actually show fetch transfer progress
* reduce sleep because it significantly slows down fetching
This commit is contained in:
Stephan Dilly 2021-03-01 12:32:39 +01:00 committed by GitHub
parent dfa4d7789d
commit 4d4761ed21
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 10 deletions

View file

@ -85,6 +85,7 @@ impl AsyncFetch {
let (progress_sender, receiver) = unbounded();
let handle = RemoteProgress::spawn_receiver_thread(
AsyncNotification::Fetch,
sender.clone(),
receiver,
arc_progress,

View file

@ -87,6 +87,7 @@ impl AsyncPush {
let (progress_sender, receiver) = unbounded();
let handle = RemoteProgress::spawn_receiver_thread(
AsyncNotification::Push,
sender.clone(),
receiver,
arc_progress,

View file

@ -22,7 +22,9 @@ pub enum RemoteProgressState {
PackingDeltafiction,
///
Pushing,
///
/// fetch progress
Transfer,
/// remote progress done
Done,
}
@ -31,7 +33,7 @@ pub enum RemoteProgressState {
pub struct RemoteProgress {
///
pub state: RemoteProgressState,
///
/// percent 0..100
pub progress: u8,
}
@ -52,9 +54,6 @@ impl RemoteProgress {
progress: Arc<Mutex<Option<ProgressNotification>>>,
state: Option<ProgressNotification>,
) -> Result<()> {
let simple_progress: Option<RemoteProgress> =
state.as_ref().map(|prog| prog.clone().into());
log::info!("remote progress: {:?}", simple_progress);
let mut progress = progress.lock()?;
*progress = state;
@ -62,13 +61,13 @@ impl RemoteProgress {
Ok(())
}
/// spawn thread to listen to progress notifcations coming in from blocking remote git method (fetch/push)
pub(crate) fn spawn_receiver_thread(
notification_type: AsyncNotification,
sender: Sender<AsyncNotification>,
receiver: Receiver<ProgressNotification>,
progress: Arc<Mutex<Option<ProgressNotification>>>,
) -> JoinHandle<()> {
log::info!("push progress receiver spawned");
thread::spawn(move || loop {
let incoming = receiver.recv();
match incoming {
@ -79,11 +78,11 @@ impl RemoteProgress {
)
.expect("set prgoress failed");
sender
.send(AsyncNotification::Push)
.expect("error sending push");
.send(notification_type)
.expect("Notification error");
//NOTE: for better debugging
thread::sleep(Duration::from_millis(100));
thread::sleep(Duration::from_millis(1));
if let ProgressNotification::Done = update {
break;
@ -133,6 +132,15 @@ impl From<ProgressNotification> for RemoteProgress {
current,
total,
),
ProgressNotification::Transfer {
objects,
total_objects,
..
} => RemoteProgress::new(
RemoteProgressState::Transfer,
objects,
total_objects,
),
_ => RemoteProgress::new(RemoteProgressState::Done, 1, 1),
}
}

View file

@ -169,6 +169,9 @@ impl PushComponent {
RemoteProgressState::Pushing => {
strings::PUSH_POPUP_STATES_PUSHING
}
RemoteProgressState::Transfer => {
strings::PUSH_POPUP_STATES_TRANSFER
}
RemoteProgressState::Done => {
strings::PUSH_POPUP_STATES_DONE
}

View file

@ -11,6 +11,7 @@ pub static PUSH_POPUP_PROGRESS_NONE: &str = "preparing...";
pub static PUSH_POPUP_STATES_ADDING: &str = "adding objects (1/3)";
pub static PUSH_POPUP_STATES_DELTAS: &str = "deltas (2/3)";
pub static PUSH_POPUP_STATES_PUSHING: &str = "pushing (3/3)";
pub static PUSH_POPUP_STATES_TRANSFER: &str = "transfer";
pub static PUSH_POPUP_STATES_DONE: &str = "done";
pub static SELECT_BRANCH_POPUP_MSG: &str = "Switch Branch";