diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-09-17 14:05:59 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-09-17 14:05:59 +0100 |
| commit | 197fc5a285bb07b7853dd2004bb5666d4527eb11 (patch) | |
| tree | efc5851342f34f582ad7dcd394c3e25680a33504 /src/bin/git_remote_nostr/push.rs | |
| parent | 2163e0a01f934692c8967a11eb9828fd70f7d03d (diff) | |
fix(remote): push don't report on writing 0 obj
in the TUI as its not useful
Diffstat (limited to 'src/bin/git_remote_nostr/push.rs')
| -rw-r--r-- | src/bin/git_remote_nostr/push.rs | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/bin/git_remote_nostr/push.rs b/src/bin/git_remote_nostr/push.rs index b038d19..dab0103 100644 --- a/src/bin/git_remote_nostr/push.rs +++ b/src/bin/git_remote_nostr/push.rs | |||
| @@ -488,7 +488,10 @@ fn report_on_transfer_progress( | |||
| 488 | bytes: usize, | 488 | bytes: usize, |
| 489 | start_time: &Instant, | 489 | start_time: &Instant, |
| 490 | end_time: &Option<Instant>, | 490 | end_time: &Option<Instant>, |
| 491 | ) -> String { | 491 | ) -> Option<String> { |
| 492 | if total == 0 { | ||
| 493 | return None; | ||
| 494 | } | ||
| 492 | let percentage = ((current as f64 / total as f64) * 100.0) | 495 | let percentage = ((current as f64 / total as f64) * 100.0) |
| 493 | // always round down because 100% complete is misleading when its not complete | 496 | // always round down because 100% complete is misleading when its not complete |
| 494 | .floor(); | 497 | .floor(); |
| @@ -511,10 +514,10 @@ fn report_on_transfer_progress( | |||
| 511 | } | 514 | } |
| 512 | }; | 515 | }; |
| 513 | 516 | ||
| 514 | format!( | 517 | Some(format!( |
| 515 | "push: Writing objects: {percentage}% ({current}/{total}) {size:.2} {unit} | {speed:.2} MiB/s{}", | 518 | "push: Writing objects: {percentage}% ({current}/{total}) {size:.2} {unit} | {speed:.2} MiB/s{}", |
| 516 | if current == total { ", done." } else { "" }, | 519 | if current == total { ", done." } else { "" }, |
| 517 | ) | 520 | )) |
| 518 | } | 521 | } |
| 519 | 522 | ||
| 520 | struct PushReporter<'a> { | 523 | struct PushReporter<'a> { |
| @@ -590,20 +593,20 @@ impl<'a> PushReporter<'a> { | |||
| 590 | if self.start_time.is_none() { | 593 | if self.start_time.is_none() { |
| 591 | self.start_time = Some(Instant::now()); | 594 | self.start_time = Some(Instant::now()); |
| 592 | } | 595 | } |
| 593 | let existing_lines = self.count_all_existing_lines(); | 596 | if let Some(report) = report_on_transfer_progress( |
| 594 | |||
| 595 | let report = report_on_transfer_progress( | ||
| 596 | current, | 597 | current, |
| 597 | total, | 598 | total, |
| 598 | bytes, | 599 | bytes, |
| 599 | &self.start_time.unwrap(), | 600 | &self.start_time.unwrap(), |
| 600 | &self.end_time, | 601 | &self.end_time, |
| 601 | ); | 602 | ) { |
| 602 | if report.contains("100%") { | 603 | let existing_lines = self.count_all_existing_lines(); |
| 603 | self.end_time = Some(Instant::now()); | 604 | if report.contains("100%") { |
| 605 | self.end_time = Some(Instant::now()); | ||
| 606 | } | ||
| 607 | self.transfer_progress_msgs = vec![report]; | ||
| 608 | self.write_all(existing_lines); | ||
| 604 | } | 609 | } |
| 605 | self.transfer_progress_msgs = vec![report]; | ||
| 606 | self.write_all(existing_lines); | ||
| 607 | } | 610 | } |
| 608 | } | 611 | } |
| 609 | 612 | ||