diff options
Diffstat (limited to 'src/bin/git_remote_nostr/push.rs')
| -rw-r--r-- | src/bin/git_remote_nostr/push.rs | 62 |
1 files changed, 45 insertions, 17 deletions
diff --git a/src/bin/git_remote_nostr/push.rs b/src/bin/git_remote_nostr/push.rs index 5a19bb0..0a7f1a6 100644 --- a/src/bin/git_remote_nostr/push.rs +++ b/src/bin/git_remote_nostr/push.rs | |||
| @@ -18,6 +18,7 @@ use ngit::{ | |||
| 18 | git::{ | 18 | git::{ |
| 19 | self, | 19 | self, |
| 20 | nostr_url::{CloneUrl, NostrUrlDecoded}, | 20 | nostr_url::{CloneUrl, NostrUrlDecoded}, |
| 21 | oid_to_shorthand_string, | ||
| 21 | }, | 22 | }, |
| 22 | git_events::{self, get_event_root}, | 23 | git_events::{self, get_event_root}, |
| 23 | login::{self, get_curent_user}, | 24 | login::{self, get_curent_user}, |
| @@ -39,7 +40,6 @@ use crate::{ | |||
| 39 | find_proposal_and_patches_by_branch_name, get_all_proposals, get_remote_name_by_url, | 40 | find_proposal_and_patches_by_branch_name, get_all_proposals, get_remote_name_by_url, |
| 40 | get_short_git_server_name, get_write_protocols_to_try, join_with_and, | 41 | get_short_git_server_name, get_write_protocols_to_try, join_with_and, |
| 41 | push_error_is_not_authentication_failure, read_line, report_on_sideband_progress, | 42 | push_error_is_not_authentication_failure, read_line, report_on_sideband_progress, |
| 42 | report_on_transfer_progress, ProgressStatus, TransferDirection, | ||
| 43 | }, | 43 | }, |
| 44 | }; | 44 | }; |
| 45 | 45 | ||
| @@ -355,13 +355,7 @@ fn push_to_remote( | |||
| 355 | let mut success = false; | 355 | let mut success = false; |
| 356 | 356 | ||
| 357 | for protocol in &protocols_to_attempt { | 357 | for protocol in &protocols_to_attempt { |
| 358 | term.write_line( | 358 | term.write_line(format!("push: {} over {protocol}...", server_url.short_name(),).as_str())?; |
| 359 | format!( | ||
| 360 | "fetching {} ref list over {protocol}...", | ||
| 361 | server_url.short_name(), | ||
| 362 | ) | ||
| 363 | .as_str(), | ||
| 364 | )?; | ||
| 365 | 359 | ||
| 366 | let formatted_url = server_url.format_as(protocol, &decoded_nostr_url.user)?; | 360 | let formatted_url = server_url.format_as(protocol, &decoded_nostr_url.user)?; |
| 367 | 361 | ||
| @@ -424,16 +418,50 @@ fn push_to_remote_url( | |||
| 424 | } | 418 | } |
| 425 | Ok(()) | 419 | Ok(()) |
| 426 | }); | 420 | }); |
| 427 | remote_callbacks.transfer_progress(|stats| { | 421 | remote_callbacks.push_negotiation(|updates| { |
| 428 | let _ = term.clear_last_lines(1); | 422 | for update in updates { |
| 429 | report_on_transfer_progress( | 423 | let _ = term.write_line( |
| 430 | &stats, | 424 | format!( |
| 431 | term, | 425 | " {}..{} {} -> {}", |
| 432 | TransferDirection::Push, | 426 | oid_to_shorthand_string(update.dst()).unwrap(), |
| 433 | ProgressStatus::InProgress, | 427 | oid_to_shorthand_string(update.src()).unwrap(), |
| 434 | ); | 428 | update |
| 435 | true | 429 | .src_refname() |
| 430 | .unwrap_or("") | ||
| 431 | .replace("refs/heads/", "") | ||
| 432 | .replace("refs/tags/", "tags/"), | ||
| 433 | update | ||
| 434 | .dst_refname() | ||
| 435 | .unwrap_or("") | ||
| 436 | .replace("refs/heads/", "") | ||
| 437 | .replace("refs/tags/", "tags/"), | ||
| 438 | ) | ||
| 439 | .as_str(), | ||
| 440 | ); | ||
| 441 | // now a blank line for transfer progress to delete | ||
| 442 | let _ = term.write_line(""); | ||
| 443 | } | ||
| 444 | Ok(()) | ||
| 436 | }); | 445 | }); |
| 446 | remote_callbacks.push_transfer_progress( | ||
| 447 | #[allow(clippy::cast_precision_loss)] | ||
| 448 | |current, total, bytes| { | ||
| 449 | let _ = term.clear_last_lines(1); | ||
| 450 | let percentage = (current as f64 / total as f64) * 100.0; | ||
| 451 | let (size, unit) = if bytes >= (1024 * 1024) { | ||
| 452 | (bytes as f64 / (1024.0 * 1024.0), "MiB") | ||
| 453 | } else { | ||
| 454 | (bytes as f64 / 1024.0, "KiB") | ||
| 455 | }; | ||
| 456 | let _ = term.write_line( | ||
| 457 | format!( | ||
| 458 | "Writing objects: {percentage:.0}% ({current}/{total}) {size:.2} {unit}, done." | ||
| 459 | ) | ||
| 460 | .as_str(), | ||
| 461 | ); | ||
| 462 | }, | ||
| 463 | ); | ||
| 464 | |||
| 437 | remote_callbacks.sideband_progress(|data| { | 465 | remote_callbacks.sideband_progress(|data| { |
| 438 | report_on_sideband_progress(data, term); | 466 | report_on_sideband_progress(data, term); |
| 439 | true | 467 | true |