upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/git_remote_nostr/fetch.rs3
-rw-r--r--src/bin/git_remote_nostr/list.rs14
-rw-r--r--src/bin/git_remote_nostr/main.rs21
-rw-r--r--src/bin/git_remote_nostr/push.rs109
-rw-r--r--src/bin/ngit/sub_commands/init.rs14
5 files changed, 75 insertions, 86 deletions
diff --git a/src/bin/git_remote_nostr/fetch.rs b/src/bin/git_remote_nostr/fetch.rs
index 7012955..024a923 100644
--- a/src/bin/git_remote_nostr/fetch.rs
+++ b/src/bin/git_remote_nostr/fetch.rs
@@ -32,7 +32,6 @@ use crate::utils::{
32pub async fn run_fetch( 32pub async fn run_fetch(
33 git_repo: &Repo, 33 git_repo: &Repo,
34 repo_ref: &RepoRef, 34 repo_ref: &RepoRef,
35 decoded_nostr_url: &NostrUrlDecoded,
36 stdin: &Stdin, 35 stdin: &Stdin,
37 oid: &str, 36 oid: &str,
38 refstr: &str, 37 refstr: &str,
@@ -54,7 +53,7 @@ pub async fn run_fetch(
54 git_repo, 53 git_repo,
55 &oids_from_git_servers, 54 &oids_from_git_servers,
56 git_server_url, 55 git_server_url,
57 decoded_nostr_url, 56 &repo_ref.to_nostr_git_url(&None),
58 &term, 57 &term,
59 ) { 58 ) {
60 errors.push(error); 59 errors.push(error);
diff --git a/src/bin/git_remote_nostr/list.rs b/src/bin/git_remote_nostr/list.rs
index bba15aa..07c6f59 100644
--- a/src/bin/git_remote_nostr/list.rs
+++ b/src/bin/git_remote_nostr/list.rs
@@ -31,7 +31,6 @@ use crate::{
31pub async fn run_list( 31pub async fn run_list(
32 git_repo: &Repo, 32 git_repo: &Repo,
33 repo_ref: &RepoRef, 33 repo_ref: &RepoRef,
34 decoded_nostr_url: &NostrUrlDecoded,
35 for_push: bool, 34 for_push: bool,
36) -> Result<HashMap<String, HashMap<String, String>>> { 35) -> Result<HashMap<String, HashMap<String, String>>> {
37 let nostr_state = 36 let nostr_state =
@@ -43,7 +42,12 @@ pub async fn run_list(
43 42
44 let term = console::Term::stderr(); 43 let term = console::Term::stderr();
45 44
46 let remote_states = list_from_remotes(&term, git_repo, &repo_ref.git_server, decoded_nostr_url); 45 let remote_states = list_from_remotes(
46 &term,
47 git_repo,
48 &repo_ref.git_server,
49 &repo_ref.to_nostr_git_url(&None),
50 );
47 51
48 let mut state = if let Some(nostr_state) = nostr_state { 52 let mut state = if let Some(nostr_state) = nostr_state {
49 for (name, value) in &nostr_state.state { 53 for (name, value) in &nostr_state.state {
@@ -89,8 +93,7 @@ pub async fn run_list(
89 state.retain(|k, _| !k.starts_with("refs/heads/pr/")); 93 state.retain(|k, _| !k.starts_with("refs/heads/pr/"));
90 94
91 let proposals_state = 95 let proposals_state =
92 get_open_proposals_state(&term, git_repo, repo_ref, decoded_nostr_url, &remote_states) 96 get_open_proposals_state(&term, git_repo, repo_ref, &remote_states).await?;
93 .await?;
94 97
95 state.extend(proposals_state); 98 state.extend(proposals_state);
96 99
@@ -114,7 +117,6 @@ async fn get_open_proposals_state(
114 term: &console::Term, 117 term: &console::Term,
115 git_repo: &Repo, 118 git_repo: &Repo,
116 repo_ref: &RepoRef, 119 repo_ref: &RepoRef,
117 decoded_nostr_url: &NostrUrlDecoded,
118 remote_states: &HashMap<String, HashMap<String, String>>, 120 remote_states: &HashMap<String, HashMap<String, String>>,
119) -> Result<HashMap<String, String>> { 121) -> Result<HashMap<String, String>> {
120 // we cannot use commit_id in the latest patch in a proposal because: 122 // we cannot use commit_id in the latest patch in a proposal because:
@@ -133,7 +135,7 @@ async fn get_open_proposals_state(
133 .cloned() 135 .cloned()
134 .collect::<Vec<String>>(), 136 .collect::<Vec<String>>(),
135 git_server_url, 137 git_server_url,
136 decoded_nostr_url, 138 &repo_ref.to_nostr_git_url(&None),
137 term, 139 term,
138 ) 140 )
139 .is_ok() 141 .is_ok()
diff --git a/src/bin/git_remote_nostr/main.rs b/src/bin/git_remote_nostr/main.rs
index e6f7af3..44359dd 100644
--- a/src/bin/git_remote_nostr/main.rs
+++ b/src/bin/git_remote_nostr/main.rs
@@ -53,9 +53,11 @@ async fn main() -> Result<()> {
53 53
54 fetching_with_report_for_helper(git_repo_path, &client, &decoded_nostr_url.coordinate).await?; 54 fetching_with_report_for_helper(git_repo_path, &client, &decoded_nostr_url.coordinate).await?;
55 55
56 let repo_ref = 56 let mut repo_ref =
57 get_repo_ref_from_cache(Some(git_repo_path), &decoded_nostr_url.coordinate).await?; 57 get_repo_ref_from_cache(Some(git_repo_path), &decoded_nostr_url.coordinate).await?;
58 58
59 repo_ref.set_nostr_git_url(decoded_nostr_url.clone());
60
59 let stdin = io::stdin(); 61 let stdin = io::stdin();
60 let mut line = String::new(); 62 let mut line = String::new();
61 63
@@ -77,21 +79,12 @@ async fn main() -> Result<()> {
77 println!("unsupported"); 79 println!("unsupported");
78 } 80 }
79 ["fetch", oid, refstr] => { 81 ["fetch", oid, refstr] => {
80 fetch::run_fetch( 82 fetch::run_fetch(&git_repo, &repo_ref, &stdin, oid, refstr).await?;
81 &git_repo,
82 &repo_ref,
83 &decoded_nostr_url,
84 &stdin,
85 oid,
86 refstr,
87 )
88 .await?;
89 } 83 }
90 ["push", refspec] => { 84 ["push", refspec] => {
91 push::run_push( 85 push::run_push(
92 &git_repo, 86 &git_repo,
93 &repo_ref, 87 &repo_ref,
94 &decoded_nostr_url,
95 &stdin, 88 &stdin,
96 refspec, 89 refspec,
97 &client, 90 &client,
@@ -100,12 +93,10 @@ async fn main() -> Result<()> {
100 .await?; 93 .await?;
101 } 94 }
102 ["list"] => { 95 ["list"] => {
103 list_outputs = 96 list_outputs = Some(list::run_list(&git_repo, &repo_ref, false).await?);
104 Some(list::run_list(&git_repo, &repo_ref, &decoded_nostr_url, false).await?);
105 } 97 }
106 ["list", "for-push"] => { 98 ["list", "for-push"] => {
107 list_outputs = 99 list_outputs = Some(list::run_list(&git_repo, &repo_ref, true).await?);
108 Some(list::run_list(&git_repo, &repo_ref, &decoded_nostr_url, true).await?);
109 } 100 }
110 [] => { 101 [] => {
111 return Ok(()); 102 return Ok(());
diff --git a/src/bin/git_remote_nostr/push.rs b/src/bin/git_remote_nostr/push.rs
index e8e1587..05c8fc2 100644
--- a/src/bin/git_remote_nostr/push.rs
+++ b/src/bin/git_remote_nostr/push.rs
@@ -53,7 +53,6 @@ use crate::{
53pub async fn run_push( 53pub async fn run_push(
54 git_repo: &Repo, 54 git_repo: &Repo,
55 repo_ref: &RepoRef, 55 repo_ref: &RepoRef,
56 decoded_nostr_url: &NostrUrlDecoded,
57 stdin: &Stdin, 56 stdin: &Stdin,
58 initial_refspec: &str, 57 initial_refspec: &str,
59 client: &Client, 58 client: &Client,
@@ -75,16 +74,18 @@ pub async fn run_push(
75 74
76 let term = console::Term::stderr(); 75 let term = console::Term::stderr();
77 76
78 let list_outputs = match list_outputs { 77 let list_outputs = list_outputs.unwrap_or_else(|| {
79 Some(outputs) => outputs, 78 list_from_remotes(
80 _ => list_from_remotes(&term, git_repo, &repo_ref.git_server, decoded_nostr_url), 79 &term,
81 }; 80 git_repo,
82 81 &repo_ref.git_server,
83 let nostr_state = get_state_from_cache(Some(git_repo.get_path()?), repo_ref).await; 82 &repo_ref.to_nostr_git_url(&None),
83 )
84 });
84 85
85 let existing_state = { 86 let existing_state = {
86 // if no state events - create from first git server listed 87 // if no state events - create from first git server listed
87 if let Ok(nostr_state) = &nostr_state { 88 if let Ok(nostr_state) = &get_state_from_cache(Some(git_repo.get_path()?), repo_ref).await {
88 nostr_state.state.clone() 89 nostr_state.state.clone()
89 } else if let Some(url) = repo_ref 90 } else if let Some(url) = repo_ref
90 .git_server 91 .git_server
@@ -118,55 +119,51 @@ pub async fn run_push(
118 } 119 }
119 }); 120 });
120 121
121 if git_server_refspecs.is_empty() && proposal_refspecs.is_empty() { 122 // all refspecs aren't rejected
122 // all refspecs rejected 123 if !(git_server_refspecs.is_empty() && proposal_refspecs.is_empty()) {
123 println!(); 124 let (rejected_proposal_refspecs, rejected) = create_and_publish_events(
124 return Ok(()); 125 git_repo,
125 } 126 repo_ref,
126 127 &git_server_refspecs,
127 let (rejected_proposal_refspecs, rejected) = create_and_publish_events( 128 &proposal_refspecs,
128 git_repo, 129 client,
129 repo_ref, 130 existing_state,
130 decoded_nostr_url, 131 &term,
131 &git_server_refspecs, 132 )
132 &proposal_refspecs, 133 .await?;
133 client,
134 existing_state,
135 &term,
136 )
137 .await?;
138 134
139 if !rejected { 135 if !rejected {
140 for refspec in &[git_server_refspecs.clone(), proposal_refspecs.clone()].concat() { 136 for refspec in git_server_refspecs.iter().chain(proposal_refspecs.iter()) {
141 if rejected_proposal_refspecs.contains(refspec) { 137 if rejected_proposal_refspecs.contains(refspec) {
142 continue; 138 continue;
139 }
140 let (_, to) = refspec_to_from_to(refspec)?;
141 println!("ok {to}");
142 update_remote_refs_pushed(
143 &git_repo.git_repo,
144 refspec,
145 &repo_ref.to_nostr_git_url(&None).to_string(),
146 )
147 .context("could not update remote_ref locally")?;
143 } 148 }
144 let (_, to) = refspec_to_from_to(refspec)?;
145 println!("ok {to}");
146 update_remote_refs_pushed(
147 &git_repo.git_repo,
148 refspec,
149 &decoded_nostr_url.original_string,
150 )
151 .context("could not update remote_ref locally")?;
152 }
153 149
154 // TODO make async - check gitlib2 callbacks work async 150 // TODO make async - check gitlib2 callbacks work async
155 151
156 for (git_server_url, remote_refspecs) in remote_refspecs { 152 for (git_server_url, remote_refspecs) in remote_refspecs {
157 let remote_refspecs = remote_refspecs 153 let remote_refspecs = remote_refspecs
158 .iter() 154 .iter()
159 .filter(|refspec| git_server_refspecs.contains(refspec)) 155 .filter(|refspec| git_server_refspecs.contains(refspec))
160 .cloned() 156 .cloned()
161 .collect::<Vec<String>>(); 157 .collect::<Vec<String>>();
162 if !refspecs.is_empty() { 158 if !refspecs.is_empty() {
163 let _ = push_to_remote( 159 let _ = push_to_remote(
164 git_repo, 160 git_repo,
165 &git_server_url, 161 &git_server_url,
166 decoded_nostr_url, 162 &repo_ref.to_nostr_git_url(&None),
167 &remote_refspecs, 163 &remote_refspecs,
168 &term, 164 &term,
169 ); 165 );
166 }
170 } 167 }
171 } 168 }
172 } 169 }
@@ -175,11 +172,9 @@ pub async fn run_push(
175 Ok(()) 172 Ok(())
176} 173}
177 174
178#[allow(clippy::too_many_arguments)]
179async fn create_and_publish_events( 175async fn create_and_publish_events(
180 git_repo: &Repo, 176 git_repo: &Repo,
181 repo_ref: &RepoRef, 177 repo_ref: &RepoRef,
182 decoded_nostr_url: &NostrUrlDecoded,
183 git_server_refspecs: &Vec<String>, 178 git_server_refspecs: &Vec<String>,
184 proposal_refspecs: &Vec<String>, 179 proposal_refspecs: &Vec<String>,
185 client: &Client, 180 client: &Client,
@@ -222,7 +217,7 @@ async fn create_and_publish_events(
222 217
223 for event in get_merged_status_events( 218 for event in get_merged_status_events(
224 term, 219 term,
225 decoded_nostr_url, 220 &repo_ref.to_nostr_git_url(&None),
226 repo_ref, 221 repo_ref,
227 git_repo, 222 git_repo,
228 &signer, 223 &signer,
@@ -235,7 +230,7 @@ async fn create_and_publish_events(
235 230
236 if let Ok(Some(repo_ref_event)) = get_maintainers_yaml_update( 231 if let Ok(Some(repo_ref_event)) = get_maintainers_yaml_update(
237 term, 232 term,
238 decoded_nostr_url, 233 &repo_ref.to_nostr_git_url(&None),
239 repo_ref, 234 repo_ref,
240 git_repo, 235 git_repo,
241 &signer, 236 &signer,
diff --git a/src/bin/ngit/sub_commands/init.rs b/src/bin/ngit/sub_commands/init.rs
index f26eea3..4aa7ced 100644
--- a/src/bin/ngit/sub_commands/init.rs
+++ b/src/bin/ngit/sub_commands/init.rs
@@ -596,9 +596,10 @@ fn ask_to_set_origin_remote(repo_ref: &RepoRef, git_repo: &Repo) -> Result<()> {
596 .with_default(true) 596 .with_default(true)
597 .with_prompt("set remote \"origin\" to the nostr url of your repository?"), 597 .with_prompt("set remote \"origin\" to the nostr url of your repository?"),
598 )? { 598 )? {
599 git_repo 599 git_repo.git_repo.remote_set_url(
600 .git_repo 600 "origin",
601 .remote_set_url("origin", &repo_ref.to_nostr_git_url(&Some(git_repo)))?; 601 &repo_ref.to_nostr_git_url(&Some(git_repo)).to_string(),
602 )?;
602 } 603 }
603 Ok(()) 604 Ok(())
604} 605}
@@ -609,9 +610,10 @@ fn ask_to_create_new_origin_remote(repo_ref: &RepoRef, git_repo: &Repo) -> Resul
609 .with_default(true) 610 .with_default(true)
610 .with_prompt("set remote \"origin\" to the nostr url of your repository?"), 611 .with_prompt("set remote \"origin\" to the nostr url of your repository?"),
611 )? { 612 )? {
612 git_repo 613 git_repo.git_repo.remote(
613 .git_repo 614 "origin",
614 .remote("origin", &repo_ref.to_nostr_git_url(&Some(git_repo)))?; 615 &repo_ref.to_nostr_git_url(&Some(git_repo)).to_string(),
616 )?;
615 } 617 }
616 Ok(()) 618 Ok(())
617} 619}