upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/git_remote_helper.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/git_remote_helper.rs')
-rw-r--r--src/git_remote_helper.rs51
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
434fn fetch(git_repo: &Repository, repo_ref: &RepoRef, stdin: &Stdin, oid: &str) -> Result<()> { 434fn 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
919fn get_oids_from_fetch_batch(stdin: &Stdin, initial_oid: &str) -> Result<Vec<String>> { 943fn 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
937fn get_refspecs_from_push_batch(stdin: &Stdin, initial_refspec: &str) -> Result<Vec<String>> { 966fn get_refspecs_from_push_batch(stdin: &Stdin, initial_refspec: &str) -> Result<Vec<String>> {