Skip to content

Commit 4d4761e

Browse files
author
Stephan Dilly
authored
fix fetch notifications (#555)
* fix fetch notifications * actually show fetch transfer progress * reduce sleep because it significantly slows down fetching
1 parent dfa4d77 commit 4d4761e

File tree

5 files changed

+24
-10
lines changed

5 files changed

+24
-10
lines changed

asyncgit/src/fetch.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ impl AsyncFetch {
8585
let (progress_sender, receiver) = unbounded();
8686

8787
let handle = RemoteProgress::spawn_receiver_thread(
88+
AsyncNotification::Fetch,
8889
sender.clone(),
8990
receiver,
9091
arc_progress,

asyncgit/src/push.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ impl AsyncPush {
8787
let (progress_sender, receiver) = unbounded();
8888

8989
let handle = RemoteProgress::spawn_receiver_thread(
90+
AsyncNotification::Push,
9091
sender.clone(),
9192
receiver,
9293
arc_progress,

asyncgit/src/remote_progress.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ pub enum RemoteProgressState {
2222
PackingDeltafiction,
2323
///
2424
Pushing,
25-
///
25+
/// fetch progress
26+
Transfer,
27+
/// remote progress done
2628
Done,
2729
}
2830

@@ -31,7 +33,7 @@ pub enum RemoteProgressState {
3133
pub struct RemoteProgress {
3234
///
3335
pub state: RemoteProgressState,
34-
///
36+
/// percent 0..100
3537
pub progress: u8,
3638
}
3739

@@ -52,23 +54,20 @@ impl RemoteProgress {
5254
progress: Arc<Mutex<Option<ProgressNotification>>>,
5355
state: Option<ProgressNotification>,
5456
) -> Result<()> {
55-
let simple_progress: Option<RemoteProgress> =
56-
state.as_ref().map(|prog| prog.clone().into());
57-
log::info!("remote progress: {:?}", simple_progress);
5857
let mut progress = progress.lock()?;
5958

6059
*progress = state;
6160

6261
Ok(())
6362
}
6463

64+
/// spawn thread to listen to progress notifcations coming in from blocking remote git method (fetch/push)
6565
pub(crate) fn spawn_receiver_thread(
66+
notification_type: AsyncNotification,
6667
sender: Sender<AsyncNotification>,
6768
receiver: Receiver<ProgressNotification>,
6869
progress: Arc<Mutex<Option<ProgressNotification>>>,
6970
) -> JoinHandle<()> {
70-
log::info!("push progress receiver spawned");
71-
7271
thread::spawn(move || loop {
7372
let incoming = receiver.recv();
7473
match incoming {
@@ -79,11 +78,11 @@ impl RemoteProgress {
7978
)
8079
.expect("set prgoress failed");
8180
sender
82-
.send(AsyncNotification::Push)
83-
.expect("error sending push");
81+
.send(notification_type)
82+
.expect("Notification error");
8483

8584
//NOTE: for better debugging
86-
thread::sleep(Duration::from_millis(100));
85+
thread::sleep(Duration::from_millis(1));
8786

8887
if let ProgressNotification::Done = update {
8988
break;
@@ -133,6 +132,15 @@ impl From<ProgressNotification> for RemoteProgress {
133132
current,
134133
total,
135134
),
135+
ProgressNotification::Transfer {
136+
objects,
137+
total_objects,
138+
..
139+
} => RemoteProgress::new(
140+
RemoteProgressState::Transfer,
141+
objects,
142+
total_objects,
143+
),
136144
_ => RemoteProgress::new(RemoteProgressState::Done, 1, 1),
137145
}
138146
}

src/components/push.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ impl PushComponent {
169169
RemoteProgressState::Pushing => {
170170
strings::PUSH_POPUP_STATES_PUSHING
171171
}
172+
RemoteProgressState::Transfer => {
173+
strings::PUSH_POPUP_STATES_TRANSFER
174+
}
172175
RemoteProgressState::Done => {
173176
strings::PUSH_POPUP_STATES_DONE
174177
}

src/strings.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub static PUSH_POPUP_PROGRESS_NONE: &str = "preparing...";
1111
pub static PUSH_POPUP_STATES_ADDING: &str = "adding objects (1/3)";
1212
pub static PUSH_POPUP_STATES_DELTAS: &str = "deltas (2/3)";
1313
pub static PUSH_POPUP_STATES_PUSHING: &str = "pushing (3/3)";
14+
pub static PUSH_POPUP_STATES_TRANSFER: &str = "transfer";
1415
pub static PUSH_POPUP_STATES_DONE: &str = "done";
1516

1617
pub static SELECT_BRANCH_POPUP_MSG: &str = "Switch Branch";

0 commit comments

Comments
 (0)