diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-08-07 10:20:48 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-08-07 12:13:29 +0100 |
| commit | 843a3c2dfebf661bd47f0a0faf2849cc660b7349 (patch) | |
| tree | 97f59116114b3372e7a504526577e8d9f20cbf0b /src/git_remote_helper.rs | |
| parent | 406f6d70f6a71cbd8796268f6c36711e893ab9d5 (diff) | |
feat(remote): `fetch` applies proposal commits
that have been proposal tips returned by `list` can be found
Diffstat (limited to 'src/git_remote_helper.rs')
| -rw-r--r-- | src/git_remote_helper.rs | 73 |
1 files changed, 59 insertions, 14 deletions
diff --git a/src/git_remote_helper.rs b/src/git_remote_helper.rs index d7363cf..4cafba1 100644 --- a/src/git_remote_helper.rs +++ b/src/git_remote_helper.rs | |||
| @@ -31,6 +31,7 @@ use sub_commands::{ | |||
| 31 | list::{ | 31 | list::{ |
| 32 | get_all_proposal_patch_events_from_cache, get_commit_id_from_patch, | 32 | get_all_proposal_patch_events_from_cache, get_commit_id_from_patch, |
| 33 | get_most_recent_patch_with_ancestors, get_proposals_and_revisions_from_cache, status_kinds, | 33 | get_most_recent_patch_with_ancestors, get_proposals_and_revisions_from_cache, status_kinds, |
| 34 | tag_value, | ||
| 34 | }, | 35 | }, |
| 35 | send::{event_is_revision_root, event_to_cover_letter, send_events}, | 36 | send::{event_is_revision_root, event_to_cover_letter, send_events}, |
| 36 | }; | 37 | }; |
| @@ -104,7 +105,7 @@ async fn main() -> Result<()> { | |||
| 104 | println!("unsupported"); | 105 | println!("unsupported"); |
| 105 | } | 106 | } |
| 106 | ["fetch", oid, refstr] => { | 107 | ["fetch", oid, refstr] => { |
| 107 | fetch(&git_repo, &repo_ref, &stdin, oid, refstr)?; | 108 | fetch(&git_repo, &repo_ref, &stdin, oid, refstr).await?; |
| 108 | } | 109 | } |
| 109 | ["push", refspec] => { | 110 | ["push", refspec] => { |
| 110 | push( | 111 | push( |
| @@ -431,14 +432,14 @@ async fn get_open_proposals( | |||
| 431 | Ok(open_proposals) | 432 | Ok(open_proposals) |
| 432 | } | 433 | } |
| 433 | 434 | ||
| 434 | fn fetch( | 435 | async fn fetch( |
| 435 | git_repo: &Repo, | 436 | git_repo: &Repo, |
| 436 | repo_ref: &RepoRef, | 437 | repo_ref: &RepoRef, |
| 437 | stdin: &Stdin, | 438 | stdin: &Stdin, |
| 438 | oid: &str, | 439 | oid: &str, |
| 439 | refstr: &str, | 440 | refstr: &str, |
| 440 | ) -> Result<()> { | 441 | ) -> Result<()> { |
| 441 | let fetch_batch = get_oids_from_fetch_batch(stdin, oid, refstr)?; | 442 | let mut fetch_batch = get_oids_from_fetch_batch(stdin, oid, refstr)?; |
| 442 | 443 | ||
| 443 | let oids_from_git_servers = fetch_batch | 444 | let oids_from_git_servers = fetch_batch |
| 444 | .iter() | 445 | .iter() |
| @@ -465,20 +466,64 @@ fn fetch( | |||
| 465 | )?; | 466 | )?; |
| 466 | errors.insert(short_name.to_string(), e); | 467 | errors.insert(short_name.to_string(), e); |
| 467 | } else { | 468 | } else { |
| 468 | term.flush()?; | 469 | break; |
| 469 | println!(); | ||
| 470 | return Ok(()); | ||
| 471 | } | 470 | } |
| 472 | } | 471 | } |
| 472 | |||
| 473 | if oids_from_git_servers | ||
| 474 | .iter() | ||
| 475 | .any(|oid| !git_repo.does_commit_exist(oid).unwrap()) | ||
| 476 | { | ||
| 477 | bail!( | ||
| 478 | "failed to fetch objects in nostr state event from:\r\n{}", | ||
| 479 | errors | ||
| 480 | .iter() | ||
| 481 | .map(|(url, error)| format!("{url}: {error}")) | ||
| 482 | .collect::<Vec<String>>() | ||
| 483 | .join("\r\n") | ||
| 484 | ); | ||
| 485 | } | ||
| 486 | |||
| 487 | let open_proposals = get_open_proposals(git_repo, repo_ref).await?; | ||
| 488 | |||
| 489 | fetch_batch.retain(|refstr, _| refstr.contains("refs/heads/prs/")); | ||
| 490 | |||
| 491 | for (refstr, oid) in fetch_batch { | ||
| 492 | if let Some((_, (_, patches))) = open_proposals.iter().find(|(_, (proposal, _))| { | ||
| 493 | if let Ok(cl) = event_to_cover_letter(proposal) { | ||
| 494 | if let Ok(branch_name) = cl.get_branch_name() { | ||
| 495 | branch_name.eq(&refstr.replace("refs/heads/", "")) | ||
| 496 | } else { | ||
| 497 | false | ||
| 498 | } | ||
| 499 | } else { | ||
| 500 | false | ||
| 501 | } | ||
| 502 | }) { | ||
| 503 | if !git_repo.does_commit_exist(&oid)? { | ||
| 504 | let mut patches_ancestor_first = patches.clone(); | ||
| 505 | patches_ancestor_first.reverse(); | ||
| 506 | if git_repo.does_commit_exist(&tag_value( | ||
| 507 | patches_ancestor_first.first().unwrap(), | ||
| 508 | "parent-commit", | ||
| 509 | )?)? { | ||
| 510 | for patch in &patches_ancestor_first { | ||
| 511 | git_repo.create_commit_from_patch(patch)?; | ||
| 512 | } | ||
| 513 | } else { | ||
| 514 | term.write_line( | ||
| 515 | format!("WARNING: cannot find parent commit for {refstr}").as_str(), | ||
| 516 | )?; | ||
| 517 | } | ||
| 518 | } | ||
| 519 | } else { | ||
| 520 | term.write_line(format!("WARNING: cannot find proposal for {refstr}").as_str())?; | ||
| 521 | } | ||
| 522 | } | ||
| 523 | |||
| 473 | term.flush()?; | 524 | term.flush()?; |
| 474 | bail!( | 525 | println!(); |
| 475 | "failed to fetch objects in nostr state event from:\r\n{}", | 526 | Ok(()) |
| 476 | errors | ||
| 477 | .iter() | ||
| 478 | .map(|(url, error)| format!("{url}: {error}")) | ||
| 479 | .collect::<Vec<String>>() | ||
| 480 | .join("\r\n") | ||
| 481 | ); | ||
| 482 | } | 527 | } |
| 483 | 528 | ||
| 484 | fn fetch_from_git_server( | 529 | fn fetch_from_git_server( |