diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-08-01 09:49:04 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-08-01 10:19:34 +0100 |
| commit | 1f38d2a97e4c8b1d814c414343d1e118ce119f70 (patch) | |
| tree | ed2ae5d043b308045c9901a1debfb2ad71190cf6 | |
| parent | c494242fbf7308e50e38ed7b4750a4fe2638ed18 (diff) | |
fix(remote): download oids not refstr
so that if the git server is ahead of the state announcement,
only the commits in the state annoucement will be downloaded
| -rw-r--r-- | src/git_remote_helper.rs | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/git_remote_helper.rs b/src/git_remote_helper.rs index 38a0aa5..de49275 100644 --- a/src/git_remote_helper.rs +++ b/src/git_remote_helper.rs | |||
| @@ -93,8 +93,8 @@ async fn main() -> Result<()> { | |||
| 93 | ["option", ..] => { | 93 | ["option", ..] => { |
| 94 | println!("unsupported"); | 94 | println!("unsupported"); |
| 95 | } | 95 | } |
| 96 | ["fetch", _oid, refstr] => { | 96 | ["fetch", oid, _refstr] => { |
| 97 | fetch(&git_repo.git_repo, &repo_ref, &stdin, refstr)?; | 97 | fetch(&git_repo.git_repo, &repo_ref, &stdin, oid)?; |
| 98 | } | 98 | } |
| 99 | ["push", refspec] => { | 99 | ["push", refspec] => { |
| 100 | push( | 100 | push( |
| @@ -182,14 +182,14 @@ async fn list(git_repo: &Repo, repo_ref: &RepoRef, for_push: bool) -> Result<()> | |||
| 182 | Ok(()) | 182 | Ok(()) |
| 183 | } | 183 | } |
| 184 | 184 | ||
| 185 | fn fetch(git_repo: &Repository, repo_ref: &RepoRef, stdin: &Stdin, refstr: &str) -> Result<()> { | 185 | fn fetch(git_repo: &Repository, repo_ref: &RepoRef, stdin: &Stdin, oid: &str) -> Result<()> { |
| 186 | let git_server_remote_url = repo_ref | 186 | let git_server_remote_url = repo_ref |
| 187 | .git_server | 187 | .git_server |
| 188 | .first() | 188 | .first() |
| 189 | .context("no git server listed in nostr repository announcement")?; | 189 | .context("no git server listed in nostr repository announcement")?; |
| 190 | let mut git_server_remote = git_repo.remote_anonymous(git_server_remote_url)?; | 190 | let mut git_server_remote = git_repo.remote_anonymous(git_server_remote_url)?; |
| 191 | git_server_remote.connect(git2::Direction::Fetch)?; | 191 | git_server_remote.connect(git2::Direction::Fetch)?; |
| 192 | git_server_remote.download(&get_refstrs_from_fetch_batch(stdin, refstr)?, None)?; | 192 | git_server_remote.download(&get_oids_from_fetch_batch(stdin, oid)?, None)?; |
| 193 | git_server_remote.disconnect()?; | 193 | git_server_remote.disconnect()?; |
| 194 | println!(); | 194 | println!(); |
| 195 | Ok(()) | 195 | Ok(()) |
| @@ -422,14 +422,14 @@ fn get_remote_name_by_url(git_repo: &Repository, url: &str) -> Result<String> { | |||
| 422 | .to_string()) | 422 | .to_string()) |
| 423 | } | 423 | } |
| 424 | 424 | ||
| 425 | fn get_refstrs_from_fetch_batch(stdin: &Stdin, initial_refstr: &str) -> Result<Vec<String>> { | 425 | fn get_oids_from_fetch_batch(stdin: &Stdin, initial_oid: &str) -> Result<Vec<String>> { |
| 426 | let mut line = String::new(); | 426 | let mut line = String::new(); |
| 427 | let mut refstrs = vec![initial_refstr.to_string()]; | 427 | let mut oids = vec![initial_oid.to_string()]; |
| 428 | loop { | 428 | loop { |
| 429 | let tokens = read_line(stdin, &mut line)?; | 429 | let tokens = read_line(stdin, &mut line)?; |
| 430 | match tokens.as_slice() { | 430 | match tokens.as_slice() { |
| 431 | ["fetch", _oid, refstr] => { | 431 | ["fetch", oid, _refstr] => { |
| 432 | refstrs.push((*refstr).to_string()); | 432 | oids.push((*oid).to_string()); |
| 433 | } | 433 | } |
| 434 | [] => break, | 434 | [] => break, |
| 435 | _ => bail!( | 435 | _ => bail!( |
| @@ -437,7 +437,7 @@ fn get_refstrs_from_fetch_batch(stdin: &Stdin, initial_refstr: &str) -> Result<V | |||
| 437 | ), | 437 | ), |
| 438 | } | 438 | } |
| 439 | } | 439 | } |
| 440 | Ok(refstrs) | 440 | Ok(oids) |
| 441 | } | 441 | } |
| 442 | 442 | ||
| 443 | fn get_refspecs_from_push_batch(stdin: &Stdin, initial_refspec: &str) -> Result<Vec<String>> { | 443 | fn get_refspecs_from_push_batch(stdin: &Stdin, initial_refspec: &str) -> Result<Vec<String>> { |