diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-05-23 21:53:35 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-05-23 21:53:35 +0100 |
| commit | a75a1441b7c1cec93ebc0cb796c21360abbc5573 (patch) | |
| tree | 79242e269749fdca294ace312e259c86595ba072 /src/bin/git_remote_nostr/list.rs | |
| parent | de095c6993ed6e99dd22972519e1cdcf4014f7d0 (diff) | |
feat(push): avoid out of sync issues for ngit relay
we need to be careful with git servers with their own permissions so
a ngit user doesn't inadvertantly push changes on top of a another
user who pushed directly to the git server without using the
force flag.
We dont have this problem with ngit-relay so we can always force
push, even if the user didnt as nostr is the authority of state.
Diffstat (limited to 'src/bin/git_remote_nostr/list.rs')
| -rw-r--r-- | src/bin/git_remote_nostr/list.rs | 30 |
1 files changed, 13 insertions, 17 deletions
diff --git a/src/bin/git_remote_nostr/list.rs b/src/bin/git_remote_nostr/list.rs index bf16f89..ea29531 100644 --- a/src/bin/git_remote_nostr/list.rs +++ b/src/bin/git_remote_nostr/list.rs | |||
| @@ -31,7 +31,7 @@ pub async fn run_list( | |||
| 31 | git_repo: &Repo, | 31 | git_repo: &Repo, |
| 32 | repo_ref: &RepoRef, | 32 | repo_ref: &RepoRef, |
| 33 | for_push: bool, | 33 | for_push: bool, |
| 34 | ) -> Result<HashMap<String, HashMap<String, String>>> { | 34 | ) -> Result<HashMap<String, (HashMap<String, String>, bool)>> { |
| 35 | let nostr_state = (get_state_from_cache(Some(git_repo.get_path()?), repo_ref).await).ok(); | 35 | let nostr_state = (get_state_from_cache(Some(git_repo.get_path()?), repo_ref).await).ok(); |
| 36 | 36 | ||
| 37 | let term = console::Term::stderr(); | 37 | let term = console::Term::stderr(); |
| @@ -46,7 +46,7 @@ pub async fn run_list( | |||
| 46 | 46 | ||
| 47 | let mut state = if let Some(nostr_state) = nostr_state { | 47 | let mut state = if let Some(nostr_state) = nostr_state { |
| 48 | for (name, value) in &nostr_state.state { | 48 | for (name, value) in &nostr_state.state { |
| 49 | for (url, remote_state) in &remote_states { | 49 | for (url, (remote_state, _is_ngit_relay)) in &remote_states { |
| 50 | let remote_name = get_short_git_server_name(git_repo, url); | 50 | let remote_name = get_short_git_server_name(git_repo, url); |
| 51 | if let Some(remote_value) = remote_state.get(name) { | 51 | if let Some(remote_value) = remote_state.get(name) { |
| 52 | if value.ne(remote_value) { | 52 | if value.ne(remote_value) { |
| @@ -74,15 +74,16 @@ pub async fn run_list( | |||
| 74 | } | 74 | } |
| 75 | nostr_state.state | 75 | nostr_state.state |
| 76 | } else { | 76 | } else { |
| 77 | repo_ref | 77 | let (state, _is_ngit_relay) = repo_ref |
| 78 | .git_server | 78 | .git_server |
| 79 | .iter() | 79 | .iter() |
| 80 | .filter_map(|server| remote_states.get(server)) | 80 | .filter_map(|server| remote_states.get(server)) |
| 81 | .cloned() | 81 | .cloned() |
| 82 | .collect::<Vec<HashMap<String, String>>>() | 82 | .collect::<Vec<(HashMap<String, String>, bool)>>() |
| 83 | .first() | 83 | .first() |
| 84 | .context("failed to get refs from git server")? | 84 | .context("failed to get refs from git server")? |
| 85 | .clone() | 85 | .clone(); |
| 86 | state | ||
| 86 | }; | 87 | }; |
| 87 | 88 | ||
| 88 | state.retain(|k, _| !k.starts_with("refs/heads/pr/")); | 89 | state.retain(|k, _| !k.starts_with("refs/heads/pr/")); |
| @@ -112,7 +113,7 @@ async fn get_open_and_draft_proposals_state( | |||
| 112 | term: &console::Term, | 113 | term: &console::Term, |
| 113 | git_repo: &Repo, | 114 | git_repo: &Repo, |
| 114 | repo_ref: &RepoRef, | 115 | repo_ref: &RepoRef, |
| 115 | remote_states: &HashMap<String, HashMap<String, String>>, | 116 | remote_states: &HashMap<String, (HashMap<String, String>, bool)>, |
| 116 | ) -> Result<HashMap<String, String>> { | 117 | ) -> Result<HashMap<String, String>> { |
| 117 | // we cannot use commit_id in the latest patch in a proposal because: | 118 | // we cannot use commit_id in the latest patch in a proposal because: |
| 118 | // 1) the `commit` tag is optional | 119 | // 1) the `commit` tag is optional |
| @@ -121,7 +122,7 @@ async fn get_open_and_draft_proposals_state( | |||
| 121 | 122 | ||
| 122 | // without trusting commit_id we must apply each patch which requires the oid of | 123 | // without trusting commit_id we must apply each patch which requires the oid of |
| 123 | // the parent so we much do a fetch | 124 | // the parent so we much do a fetch |
| 124 | for (git_server_url, oids_from_git_servers) in remote_states { | 125 | for (git_server_url, (oids_from_git_servers, is_ngit_relay)) in remote_states { |
| 125 | if fetch_from_git_server( | 126 | if fetch_from_git_server( |
| 126 | git_repo, | 127 | git_repo, |
| 127 | &oids_from_git_servers | 128 | &oids_from_git_servers |
| @@ -132,7 +133,7 @@ async fn get_open_and_draft_proposals_state( | |||
| 132 | git_server_url, | 133 | git_server_url, |
| 133 | &repo_ref.to_nostr_git_url(&None), | 134 | &repo_ref.to_nostr_git_url(&None), |
| 134 | term, | 135 | term, |
| 135 | is_ngit_relay(git_server_url, &repo_ref.ngit_relays()), | 136 | *is_ngit_relay, |
| 136 | ) | 137 | ) |
| 137 | .is_ok() | 138 | .is_ok() |
| 138 | { | 139 | { |
| @@ -178,22 +179,17 @@ pub fn list_from_remotes( | |||
| 178 | git_servers: &Vec<String>, | 179 | git_servers: &Vec<String>, |
| 179 | decoded_nostr_url: &NostrUrlDecoded, | 180 | decoded_nostr_url: &NostrUrlDecoded, |
| 180 | ngit_relays: &[String], | 181 | ngit_relays: &[String], |
| 181 | ) -> HashMap<String, HashMap<String, String>> { | 182 | ) -> HashMap<String, (HashMap<String, String>, bool)> { |
| 182 | let mut remote_states = HashMap::new(); | 183 | let mut remote_states = HashMap::new(); |
| 183 | let mut errors = HashMap::new(); | 184 | let mut errors = HashMap::new(); |
| 184 | for url in git_servers { | 185 | for url in git_servers { |
| 185 | match list_from_remote( | 186 | let is_ngit_relay = is_ngit_relay(url, ngit_relays); |
| 186 | term, | 187 | match list_from_remote(term, git_repo, url, decoded_nostr_url, is_ngit_relay) { |
| 187 | git_repo, | ||
| 188 | url, | ||
| 189 | decoded_nostr_url, | ||
| 190 | is_ngit_relay(url, ngit_relays), | ||
| 191 | ) { | ||
| 192 | Err(error) => { | 188 | Err(error) => { |
| 193 | errors.insert(url, error); | 189 | errors.insert(url, error); |
| 194 | } | 190 | } |
| 195 | Ok(state) => { | 191 | Ok(state) => { |
| 196 | remote_states.insert(url.to_string(), state); | 192 | remote_states.insert(url.to_string(), (state, is_ngit_relay)); |
| 197 | } | 193 | } |
| 198 | } | 194 | } |
| 199 | } | 195 | } |