diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-09-12 16:54:52 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-09-12 16:54:52 +0100 |
| commit | 5e958f48e58712736e6394f15b91997ba5231e01 (patch) | |
| tree | 3eb7393eb4c4fcacfe7ca9791c7499cca1b36aa9 /src/bin/git_remote_nostr/utils.rs | |
| parent | ca33d4d2effff63986038c94e69a7484ddfa1839 (diff) | |
fix(remote): `push` status updates
push needs to use push_transfer_progress rather than transfer_progress
Diffstat (limited to 'src/bin/git_remote_nostr/utils.rs')
| -rw-r--r-- | src/bin/git_remote_nostr/utils.rs | 63 |
1 files changed, 0 insertions, 63 deletions
diff --git a/src/bin/git_remote_nostr/utils.rs b/src/bin/git_remote_nostr/utils.rs index 6e09851..15a0d76 100644 --- a/src/bin/git_remote_nostr/utils.rs +++ b/src/bin/git_remote_nostr/utils.rs | |||
| @@ -310,69 +310,6 @@ pub fn error_might_be_authentication_related(error: &anyhow::Error) -> bool { | |||
| 310 | false | 310 | false |
| 311 | } | 311 | } |
| 312 | 312 | ||
| 313 | pub enum TransferDirection { | ||
| 314 | Fetch, | ||
| 315 | Push, | ||
| 316 | } | ||
| 317 | |||
| 318 | pub enum ProgressStatus { | ||
| 319 | InProgress, | ||
| 320 | Complete, | ||
| 321 | } | ||
| 322 | |||
| 323 | #[allow(clippy::cast_precision_loss)] | ||
| 324 | #[allow(clippy::float_cmp)] | ||
| 325 | #[allow(clippy::needless_pass_by_value)] | ||
| 326 | pub fn report_on_transfer_progress( | ||
| 327 | progress_stats: &git2::Progress<'_>, | ||
| 328 | term: &console::Term, | ||
| 329 | direction: TransferDirection, | ||
| 330 | status: ProgressStatus, | ||
| 331 | ) { | ||
| 332 | let total = progress_stats.total_objects() as f64; | ||
| 333 | if total == 0.0 { | ||
| 334 | return; | ||
| 335 | } | ||
| 336 | let received = progress_stats.received_objects() as f64; | ||
| 337 | let percentage = (received / total) * 100.0; | ||
| 338 | |||
| 339 | // Get the total received bytes | ||
| 340 | let received_bytes = progress_stats.received_bytes() as f64; | ||
| 341 | |||
| 342 | // Determine whether to use KiB or MiB | ||
| 343 | let (size, unit) = if received_bytes >= (1024.0 * 1024.0) { | ||
| 344 | // Convert to MiB | ||
| 345 | (received_bytes / (1024.0 * 1024.0), "MiB") | ||
| 346 | } else { | ||
| 347 | // Convert to KiB | ||
| 348 | (received_bytes / 1024.0, "KiB") | ||
| 349 | }; | ||
| 350 | |||
| 351 | // Format the output for receiving objects | ||
| 352 | if received < total || matches!(status, ProgressStatus::Complete) { | ||
| 353 | let _ = term.write_line( | ||
| 354 | format!( | ||
| 355 | "{} objects: {percentage:.0}% ({received}/{total}) {size:.2} {unit}, done.\r", | ||
| 356 | if matches!(direction, TransferDirection::Fetch) { | ||
| 357 | "Receiving" | ||
| 358 | } else { | ||
| 359 | "Writing" | ||
| 360 | }, | ||
| 361 | ) | ||
| 362 | .as_str(), | ||
| 363 | ); | ||
| 364 | } | ||
| 365 | if received == total || matches!(status, ProgressStatus::Complete) { | ||
| 366 | let indexed_deltas = progress_stats.indexed_deltas() as f64; | ||
| 367 | let total_deltas = progress_stats.total_deltas() as f64; | ||
| 368 | let percentage = (indexed_deltas / total_deltas) * 100.0; | ||
| 369 | let _ = term.write_line( | ||
| 370 | format!("Resolving deltas: {percentage:.0}% ({indexed_deltas}/{total_deltas}) done.\r") | ||
| 371 | .as_str(), | ||
| 372 | ); | ||
| 373 | } | ||
| 374 | } | ||
| 375 | |||
| 376 | pub fn report_on_sideband_progress(data: &[u8], term: &console::Term) { | 313 | pub fn report_on_sideband_progress(data: &[u8], term: &console::Term) { |
| 377 | if let Ok(data) = str::from_utf8(data) { | 314 | if let Ok(data) = str::from_utf8(data) { |
| 378 | let data = data | 315 | let data = data |