diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-08-06 11:49:28 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-08-06 13:09:49 +0100 |
| commit | 47271a823485c002ab6c3f304b86dbba2d7594dd (patch) | |
| tree | 75d06b6e6c4c3f3b82baf3b5565b8471243b85e6 /src/git_remote_helper.rs | |
| parent | f1aa1be738af0dc80eb3b5827249bb537de1e0cd (diff) | |
feat(remote): `fetch` report on progress
so that user knows what step we are on
Diffstat (limited to 'src/git_remote_helper.rs')
| -rw-r--r-- | src/git_remote_helper.rs | 51 |
1 files changed, 40 insertions, 11 deletions
diff --git a/src/git_remote_helper.rs b/src/git_remote_helper.rs index f851c90..0cfd268 100644 --- a/src/git_remote_helper.rs +++ b/src/git_remote_helper.rs | |||
| @@ -103,8 +103,8 @@ async fn main() -> Result<()> { | |||
| 103 | ["option", ..] => { | 103 | ["option", ..] => { |
| 104 | println!("unsupported"); | 104 | println!("unsupported"); |
| 105 | } | 105 | } |
| 106 | ["fetch", oid, _refstr] => { | 106 | ["fetch", oid, refstr] => { |
| 107 | fetch(&git_repo.git_repo, &repo_ref, &stdin, oid)?; | 107 | fetch(&git_repo, &repo_ref, &stdin, oid, refstr)?; |
| 108 | } | 108 | } |
| 109 | ["push", refspec] => { | 109 | ["push", refspec] => { |
| 110 | push( | 110 | push( |
| @@ -431,18 +431,42 @@ async fn get_open_proposals( | |||
| 431 | Ok(open_proposals) | 431 | Ok(open_proposals) |
| 432 | } | 432 | } |
| 433 | 433 | ||
| 434 | fn fetch(git_repo: &Repository, repo_ref: &RepoRef, stdin: &Stdin, oid: &str) -> Result<()> { | 434 | fn fetch( |
| 435 | let oids = get_oids_from_fetch_batch(stdin, oid)?; | 435 | git_repo: &Repo, |
| 436 | repo_ref: &RepoRef, | ||
| 437 | stdin: &Stdin, | ||
| 438 | oid: &str, | ||
| 439 | refstr: &str, | ||
| 440 | ) -> Result<()> { | ||
| 441 | let fetch_batch = get_oids_from_fetch_batch(stdin, oid, refstr)?; | ||
| 442 | |||
| 443 | let oids_from_git_servers = fetch_batch.values().cloned().collect::<Vec<String>>(); | ||
| 436 | 444 | ||
| 437 | let mut errors = HashMap::new(); | 445 | let mut errors = HashMap::new(); |
| 446 | let term = console::Term::stderr(); | ||
| 447 | |||
| 438 | for git_server_url in &repo_ref.git_server { | 448 | for git_server_url in &repo_ref.git_server { |
| 439 | if let Err(e) = fetch_from_git_server(git_repo, &oids, git_server_url) { | 449 | let term = console::Term::stderr(); |
| 440 | errors.insert(git_server_url.to_string(), e); | 450 | let short_name = get_short_git_server_name(git_repo, git_server_url); |
| 451 | term.write_line(format!("fetching from {short_name}...").as_str())?; | ||
| 452 | let res = fetch_from_git_server(&git_repo.git_repo, &oids_from_git_servers, git_server_url); | ||
| 453 | term.clear_last_lines(1)?; | ||
| 454 | if let Err(e) = res { | ||
| 455 | term.write_line( | ||
| 456 | format!( | ||
| 457 | "WARNING: failed to fetch from {short_name} error: | ||
| 458 | {e}" | ||
| 459 | ) | ||
| 460 | .as_str(), | ||
| 461 | )?; | ||
| 462 | errors.insert(short_name.to_string(), e); | ||
| 441 | } else { | 463 | } else { |
| 464 | term.flush()?; | ||
| 442 | println!(); | 465 | println!(); |
| 443 | return Ok(()); | 466 | return Ok(()); |
| 444 | } | 467 | } |
| 445 | } | 468 | } |
| 469 | term.flush()?; | ||
| 446 | bail!( | 470 | bail!( |
| 447 | "failed to fetch objects in nostr state event from:\r\n{}", | 471 | "failed to fetch objects in nostr state event from:\r\n{}", |
| 448 | errors | 472 | errors |
| @@ -916,14 +940,19 @@ fn get_short_git_server_name(git_repo: &Repo, url: &str) -> std::string::String | |||
| 916 | url.to_string() | 940 | url.to_string() |
| 917 | } | 941 | } |
| 918 | 942 | ||
| 919 | fn get_oids_from_fetch_batch(stdin: &Stdin, initial_oid: &str) -> Result<Vec<String>> { | 943 | fn get_oids_from_fetch_batch( |
| 944 | stdin: &Stdin, | ||
| 945 | initial_oid: &str, | ||
| 946 | initial_refstr: &str, | ||
| 947 | ) -> Result<HashMap<String, String>> { | ||
| 920 | let mut line = String::new(); | 948 | let mut line = String::new(); |
| 921 | let mut oids = vec![initial_oid.to_string()]; | 949 | let mut batch = HashMap::new(); |
| 950 | batch.insert(initial_refstr.to_string(), initial_oid.to_string()); | ||
| 922 | loop { | 951 | loop { |
| 923 | let tokens = read_line(stdin, &mut line)?; | 952 | let tokens = read_line(stdin, &mut line)?; |
| 924 | match tokens.as_slice() { | 953 | match tokens.as_slice() { |
| 925 | ["fetch", oid, _refstr] => { | 954 | ["fetch", oid, refstr] => { |
| 926 | oids.push((*oid).to_string()); | 955 | batch.insert((*refstr).to_string(), (*oid).to_string()); |
| 927 | } | 956 | } |
| 928 | [] => break, | 957 | [] => break, |
| 929 | _ => bail!( | 958 | _ => bail!( |
| @@ -931,7 +960,7 @@ fn get_oids_from_fetch_batch(stdin: &Stdin, initial_oid: &str) -> Result<Vec<Str | |||
| 931 | ), | 960 | ), |
| 932 | } | 961 | } |
| 933 | } | 962 | } |
| 934 | Ok(oids) | 963 | Ok(batch) |
| 935 | } | 964 | } |
| 936 | 965 | ||
| 937 | fn get_refspecs_from_push_batch(stdin: &Stdin, initial_refspec: &str) -> Result<Vec<String>> { | 966 | fn get_refspecs_from_push_batch(stdin: &Stdin, initial_refspec: &str) -> Result<Vec<String>> { |