From 197fc5a285bb07b7853dd2004bb5666d4527eb11 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Tue, 17 Sep 2024 14:05:59 +0100 Subject: fix(remote): push don't report on writing 0 obj in the TUI as its not useful --- src/bin/git_remote_nostr/push.rs | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'src/bin/git_remote_nostr') 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( bytes: usize, start_time: &Instant, end_time: &Option, -) -> String { +) -> Option { + if total == 0 { + return None; + } let percentage = ((current as f64 / total as f64) * 100.0) // always round down because 100% complete is misleading when its not complete .floor(); @@ -511,10 +514,10 @@ fn report_on_transfer_progress( } }; - format!( + Some(format!( "push: Writing objects: {percentage}% ({current}/{total}) {size:.2} {unit} | {speed:.2} MiB/s{}", if current == total { ", done." } else { "" }, - ) + )) } struct PushReporter<'a> { @@ -590,20 +593,20 @@ impl<'a> PushReporter<'a> { if self.start_time.is_none() { self.start_time = Some(Instant::now()); } - let existing_lines = self.count_all_existing_lines(); - - let report = report_on_transfer_progress( + if let Some(report) = report_on_transfer_progress( current, total, bytes, &self.start_time.unwrap(), &self.end_time, - ); - if report.contains("100%") { - self.end_time = Some(Instant::now()); + ) { + let existing_lines = self.count_all_existing_lines(); + if report.contains("100%") { + self.end_time = Some(Instant::now()); + } + self.transfer_progress_msgs = vec![report]; + self.write_all(existing_lines); } - self.transfer_progress_msgs = vec![report]; - self.write_all(existing_lines); } } -- cgit v1.2.3