upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/bin/git_remote_nostr
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/git_remote_nostr')
-rw-r--r--src/bin/git_remote_nostr/push.rs25
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
520struct PushReporter<'a> { 523struct 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