diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/bin/git_remote_nostr/fetch.rs | 10 | ||||
| -rw-r--r-- | src/bin/git_remote_nostr/list.rs | 163 | ||||
| -rw-r--r-- | src/bin/git_remote_nostr/main.rs | 3 | ||||
| -rw-r--r-- | src/bin/git_remote_nostr/push.rs | 17 | ||||
| -rw-r--r-- | src/bin/ngit/cli.rs | 3 | ||||
| -rw-r--r-- | src/lib/list.rs | 159 | ||||
| -rw-r--r-- | src/lib/mod.rs | 2 | ||||
| -rw-r--r-- | src/lib/utils.rs (renamed from src/bin/git_remote_nostr/utils.rs) | 5 |
8 files changed, 185 insertions, 177 deletions
diff --git a/src/bin/git_remote_nostr/fetch.rs b/src/bin/git_remote_nostr/fetch.rs index f3d4362..221d964 100644 --- a/src/bin/git_remote_nostr/fetch.rs +++ b/src/bin/git_remote_nostr/fetch.rs | |||
| @@ -19,15 +19,15 @@ use ngit::{ | |||
| 19 | git_events::{KIND_PULL_REQUEST, KIND_PULL_REQUEST_UPDATE, tag_value}, | 19 | git_events::{KIND_PULL_REQUEST, KIND_PULL_REQUEST_UPDATE, tag_value}, |
| 20 | login::get_curent_user, | 20 | login::get_curent_user, |
| 21 | repo_ref::{RepoRef, is_grasp_server}, | 21 | repo_ref::{RepoRef, is_grasp_server}, |
| 22 | utils::{ | ||
| 23 | Direction, find_proposal_and_patches_by_branch_name, get_oids_from_fetch_batch, | ||
| 24 | get_open_or_draft_proposals, get_read_protocols_to_try, join_with_and, | ||
| 25 | set_protocol_preference, | ||
| 26 | }, | ||
| 22 | }; | 27 | }; |
| 23 | use nostr::nips::nip19; | 28 | use nostr::nips::nip19; |
| 24 | use nostr_sdk::{Event, ToBech32}; | 29 | use nostr_sdk::{Event, ToBech32}; |
| 25 | 30 | ||
| 26 | use crate::utils::{ | ||
| 27 | Direction, find_proposal_and_patches_by_branch_name, get_oids_from_fetch_batch, | ||
| 28 | get_open_or_draft_proposals, get_read_protocols_to_try, join_with_and, set_protocol_preference, | ||
| 29 | }; | ||
| 30 | |||
| 31 | pub async fn run_fetch( | 31 | pub async fn run_fetch( |
| 32 | git_repo: &Repo, | 32 | git_repo: &Repo, |
| 33 | repo_ref: &RepoRef, | 33 | repo_ref: &RepoRef, |
diff --git a/src/bin/git_remote_nostr/list.rs b/src/bin/git_remote_nostr/list.rs index 7bdf170..df98c12 100644 --- a/src/bin/git_remote_nostr/list.rs +++ b/src/bin/git_remote_nostr/list.rs | |||
| @@ -1,30 +1,22 @@ | |||
| 1 | use core::str; | ||
| 2 | use std::collections::HashMap; | 1 | use std::collections::HashMap; |
| 3 | 2 | ||
| 4 | use anyhow::{Context, Result, anyhow}; | 3 | use anyhow::{Context, Result}; |
| 5 | use auth_git2::GitAuthenticator; | ||
| 6 | use client::get_state_from_cache; | 4 | use client::get_state_from_cache; |
| 7 | use git::RepoActions; | 5 | use git::RepoActions; |
| 8 | use ngit::{ | 6 | use ngit::{ |
| 9 | client, | 7 | client, |
| 10 | git::{ | 8 | git::{self}, |
| 11 | self, | ||
| 12 | nostr_url::{CloneUrl, NostrUrlDecoded, ServerProtocol}, | ||
| 13 | }, | ||
| 14 | git_events::{KIND_PULL_REQUEST, KIND_PULL_REQUEST_UPDATE, event_to_cover_letter, tag_value}, | 9 | git_events::{KIND_PULL_REQUEST, KIND_PULL_REQUEST_UPDATE, event_to_cover_letter, tag_value}, |
| 10 | list::{get_ahead_behind, list_from_remotes}, | ||
| 15 | login::get_curent_user, | 11 | login::get_curent_user, |
| 16 | repo_ref::{self, is_grasp_server}, | 12 | repo_ref::{self}, |
| 13 | utils::{get_open_or_draft_proposals, get_short_git_server_name}, | ||
| 17 | }; | 14 | }; |
| 18 | use nostr_sdk::hashes::sha1::Hash as Sha1Hash; | ||
| 19 | use repo_ref::RepoRef; | 15 | use repo_ref::RepoRef; |
| 20 | 16 | ||
| 21 | use crate::{ | 17 | use crate::{ |
| 22 | fetch::{fetch_from_git_server, make_commits_for_proposal}, | 18 | fetch::{fetch_from_git_server, make_commits_for_proposal}, |
| 23 | git::Repo, | 19 | git::Repo, |
| 24 | utils::{ | ||
| 25 | Direction, get_open_or_draft_proposals, get_read_protocols_to_try, | ||
| 26 | get_short_git_server_name, join_with_and, set_protocol_preference, | ||
| 27 | }, | ||
| 28 | }; | 20 | }; |
| 29 | 21 | ||
| 30 | pub async fn run_list( | 22 | pub async fn run_list( |
| @@ -210,148 +202,3 @@ async fn get_open_and_draft_proposals_state( | |||
| 210 | } | 202 | } |
| 211 | Ok(state) | 203 | Ok(state) |
| 212 | } | 204 | } |
| 213 | |||
| 214 | pub fn list_from_remotes( | ||
| 215 | term: &console::Term, | ||
| 216 | git_repo: &Repo, | ||
| 217 | git_servers: &Vec<String>, | ||
| 218 | decoded_nostr_url: &NostrUrlDecoded, | ||
| 219 | grasp_servers: &[String], | ||
| 220 | ) -> HashMap<String, (HashMap<String, String>, bool)> { | ||
| 221 | let mut remote_states = HashMap::new(); | ||
| 222 | let mut errors = HashMap::new(); | ||
| 223 | for url in git_servers { | ||
| 224 | let is_grasp_server = is_grasp_server(url, grasp_servers); | ||
| 225 | match list_from_remote(term, git_repo, url, decoded_nostr_url, is_grasp_server) { | ||
| 226 | Err(error) => { | ||
| 227 | errors.insert(url, error); | ||
| 228 | } | ||
| 229 | Ok(state) => { | ||
| 230 | remote_states.insert(url.to_string(), (state, is_grasp_server)); | ||
| 231 | } | ||
| 232 | } | ||
| 233 | } | ||
| 234 | remote_states | ||
| 235 | } | ||
| 236 | |||
| 237 | pub fn list_from_remote( | ||
| 238 | term: &console::Term, | ||
| 239 | git_repo: &Repo, | ||
| 240 | git_server_url: &str, | ||
| 241 | decoded_nostr_url: &NostrUrlDecoded, | ||
| 242 | is_grasp_server: bool, | ||
| 243 | ) -> Result<HashMap<String, String>> { | ||
| 244 | let server_url = git_server_url.parse::<CloneUrl>()?; | ||
| 245 | let protocols_to_attempt = | ||
| 246 | get_read_protocols_to_try(git_repo, &server_url, decoded_nostr_url, is_grasp_server); | ||
| 247 | |||
| 248 | let mut failed_protocols = vec![]; | ||
| 249 | let mut remote_state: Option<HashMap<String, String>> = None; | ||
| 250 | |||
| 251 | for protocol in &protocols_to_attempt { | ||
| 252 | term.write_line( | ||
| 253 | format!( | ||
| 254 | "fetching {} ref list over {protocol}...", | ||
| 255 | server_url.short_name(), | ||
| 256 | ) | ||
| 257 | .as_str(), | ||
| 258 | )?; | ||
| 259 | |||
| 260 | let formatted_url = server_url.format_as(protocol, &decoded_nostr_url.user)?; | ||
| 261 | let res = list_from_remote_url( | ||
| 262 | git_repo, | ||
| 263 | &formatted_url, | ||
| 264 | [ServerProtocol::UnauthHttps, ServerProtocol::UnauthHttp].contains(protocol), | ||
| 265 | term, | ||
| 266 | ); | ||
| 267 | |||
| 268 | match res { | ||
| 269 | Ok(state) => { | ||
| 270 | remote_state = Some(state); | ||
| 271 | term.clear_last_lines(1)?; | ||
| 272 | if !failed_protocols.is_empty() { | ||
| 273 | term.write_line( | ||
| 274 | format!( | ||
| 275 | "list: succeeded over {protocol} from {}", | ||
| 276 | server_url.short_name(), | ||
| 277 | ) | ||
| 278 | .as_str(), | ||
| 279 | )?; | ||
| 280 | let _ = | ||
| 281 | set_protocol_preference(git_repo, protocol, &server_url, &Direction::Fetch); | ||
| 282 | } | ||
| 283 | break; | ||
| 284 | } | ||
| 285 | Err(error) => { | ||
| 286 | term.clear_last_lines(1)?; | ||
| 287 | term.write_line( | ||
| 288 | format!("list: {formatted_url} failed over {protocol}: {error}").as_str(), | ||
| 289 | )?; | ||
| 290 | failed_protocols.push(protocol); | ||
| 291 | } | ||
| 292 | } | ||
| 293 | } | ||
| 294 | if let Some(remote_state) = remote_state { | ||
| 295 | if failed_protocols.is_empty() { | ||
| 296 | term.clear_last_lines(1)?; | ||
| 297 | } | ||
| 298 | Ok(remote_state) | ||
| 299 | } else { | ||
| 300 | let error = anyhow!( | ||
| 301 | "{} failed over {}{}", | ||
| 302 | server_url.short_name(), | ||
| 303 | join_with_and(&failed_protocols), | ||
| 304 | if decoded_nostr_url.protocol.is_some() { | ||
| 305 | " and nostr url contains protocol override so no other protocols were attempted" | ||
| 306 | } else { | ||
| 307 | "" | ||
| 308 | }, | ||
| 309 | ); | ||
| 310 | term.write_line(format!("list: {error}").as_str())?; | ||
| 311 | Err(error) | ||
| 312 | } | ||
| 313 | } | ||
| 314 | |||
| 315 | fn list_from_remote_url( | ||
| 316 | git_repo: &Repo, | ||
| 317 | git_server_remote_url: &str, | ||
| 318 | dont_authenticate: bool, | ||
| 319 | term: &console::Term, | ||
| 320 | ) -> Result<HashMap<String, String>> { | ||
| 321 | let git_config = git_repo.git_repo.config()?; | ||
| 322 | |||
| 323 | let mut git_server_remote = git_repo.git_repo.remote_anonymous(git_server_remote_url)?; | ||
| 324 | // authentication may be required | ||
| 325 | let auth = GitAuthenticator::default(); | ||
| 326 | let mut remote_callbacks = git2::RemoteCallbacks::new(); | ||
| 327 | if !dont_authenticate { | ||
| 328 | remote_callbacks.credentials(auth.credentials(&git_config)); | ||
| 329 | } | ||
| 330 | term.write_line("list: connecting...")?; | ||
| 331 | git_server_remote.connect_auth(git2::Direction::Fetch, Some(remote_callbacks), None)?; | ||
| 332 | term.clear_last_lines(1)?; | ||
| 333 | let mut state = HashMap::new(); | ||
| 334 | for head in git_server_remote.list()? { | ||
| 335 | if let Some(symbolic_reference) = head.symref_target() { | ||
| 336 | state.insert( | ||
| 337 | head.name().to_string(), | ||
| 338 | format!("ref: {symbolic_reference}"), | ||
| 339 | ); | ||
| 340 | // ignore dereferenced tags | ||
| 341 | } else if !head.name().to_string().ends_with("^{}") { | ||
| 342 | state.insert(head.name().to_string(), head.oid().to_string()); | ||
| 343 | } | ||
| 344 | } | ||
| 345 | git_server_remote.disconnect()?; | ||
| 346 | Ok(state) | ||
| 347 | } | ||
| 348 | |||
| 349 | fn get_ahead_behind( | ||
| 350 | git_repo: &Repo, | ||
| 351 | base_ref_or_oid: &str, | ||
| 352 | latest_ref_or_oid: &str, | ||
| 353 | ) -> Result<(Vec<Sha1Hash>, Vec<Sha1Hash>)> { | ||
| 354 | let base = git_repo.get_commit_or_tip_of_reference(base_ref_or_oid)?; | ||
| 355 | let latest = git_repo.get_commit_or_tip_of_reference(latest_ref_or_oid)?; | ||
| 356 | git_repo.get_commits_ahead_behind(&base, &latest) | ||
| 357 | } | ||
diff --git a/src/bin/git_remote_nostr/main.rs b/src/bin/git_remote_nostr/main.rs index cf47a30..aac626b 100644 --- a/src/bin/git_remote_nostr/main.rs +++ b/src/bin/git_remote_nostr/main.rs | |||
| @@ -18,16 +18,15 @@ use ngit::{ | |||
| 18 | client::{self, Params}, | 18 | client::{self, Params}, |
| 19 | git::{self, utils::set_git_timeout}, | 19 | git::{self, utils::set_git_timeout}, |
| 20 | login::existing::load_existing_login, | 20 | login::existing::load_existing_login, |
| 21 | utils::read_line, | ||
| 21 | }; | 22 | }; |
| 22 | use nostr::nips::nip19::Nip19Coordinate; | 23 | use nostr::nips::nip19::Nip19Coordinate; |
| 23 | use utils::read_line; | ||
| 24 | 24 | ||
| 25 | use crate::{client::Client, git::Repo}; | 25 | use crate::{client::Client, git::Repo}; |
| 26 | 26 | ||
| 27 | mod fetch; | 27 | mod fetch; |
| 28 | mod list; | 28 | mod list; |
| 29 | mod push; | 29 | mod push; |
| 30 | mod utils; | ||
| 31 | 30 | ||
| 32 | #[tokio::main] | 31 | #[tokio::main] |
| 33 | async fn main() -> Result<()> { | 32 | async fn main() -> Result<()> { |
diff --git a/src/bin/git_remote_nostr/push.rs b/src/bin/git_remote_nostr/push.rs index 909a0ab..74e98f9 100644 --- a/src/bin/git_remote_nostr/push.rs +++ b/src/bin/git_remote_nostr/push.rs | |||
| @@ -25,9 +25,15 @@ use ngit::{ | |||
| 25 | oid_to_shorthand_string, | 25 | oid_to_shorthand_string, |
| 26 | }, | 26 | }, |
| 27 | git_events::{self, KIND_PULL_REQUEST, event_to_cover_letter, get_event_root}, | 27 | git_events::{self, KIND_PULL_REQUEST, event_to_cover_letter, get_event_root}, |
| 28 | list::list_from_remotes, | ||
| 28 | login::{self, user::UserRef}, | 29 | login::{self, user::UserRef}, |
| 29 | repo_ref::{self, get_repo_config_from_yaml, is_grasp_server, normalize_grasp_server_url}, | 30 | repo_ref::{self, get_repo_config_from_yaml, is_grasp_server, normalize_grasp_server_url}, |
| 30 | repo_state, | 31 | repo_state, |
| 32 | utils::{ | ||
| 33 | Direction, find_proposal_and_patches_by_branch_name, get_all_proposals, | ||
| 34 | get_remote_name_by_url, get_short_git_server_name, get_write_protocols_to_try, | ||
| 35 | join_with_and, read_line, set_protocol_preference, | ||
| 36 | }, | ||
| 31 | }; | 37 | }; |
| 32 | use nostr::{event::UnsignedEvent, nips::nip10::Marker}; | 38 | use nostr::{event::UnsignedEvent, nips::nip10::Marker}; |
| 33 | use nostr_sdk::{ | 39 | use nostr_sdk::{ |
| @@ -37,16 +43,7 @@ use nostr_sdk::{ | |||
| 37 | use repo_ref::RepoRef; | 43 | use repo_ref::RepoRef; |
| 38 | use repo_state::RepoState; | 44 | use repo_state::RepoState; |
| 39 | 45 | ||
| 40 | use crate::{ | 46 | use crate::{client::Client, git::Repo}; |
| 41 | client::Client, | ||
| 42 | git::Repo, | ||
| 43 | list::list_from_remotes, | ||
| 44 | utils::{ | ||
| 45 | Direction, find_proposal_and_patches_by_branch_name, get_all_proposals, | ||
| 46 | get_remote_name_by_url, get_short_git_server_name, get_write_protocols_to_try, | ||
| 47 | join_with_and, read_line, set_protocol_preference, | ||
| 48 | }, | ||
| 49 | }; | ||
| 50 | 47 | ||
| 51 | #[allow(clippy::too_many_lines)] | 48 | #[allow(clippy::too_many_lines)] |
| 52 | #[allow(clippy::type_complexity)] | 49 | #[allow(clippy::type_complexity)] |
diff --git a/src/bin/ngit/cli.rs b/src/bin/ngit/cli.rs index 843c904..1507f71 100644 --- a/src/bin/ngit/cli.rs +++ b/src/bin/ngit/cli.rs | |||
| @@ -96,6 +96,9 @@ pub enum Commands { | |||
| 96 | Send(sub_commands::send::SubCommandArgs), | 96 | Send(sub_commands::send::SubCommandArgs), |
| 97 | /// list PRs; checkout, apply or download selected | 97 | /// list PRs; checkout, apply or download selected |
| 98 | List, | 98 | List, |
| 99 | /// update repo git servers to reflect nostr state (add, update or delete | ||
| 100 | /// remote refs) | ||
| 101 | Sync, | ||
| 99 | /// login, logout or export keys | 102 | /// login, logout or export keys |
| 100 | Account(AccountSubCommandArgs), | 103 | Account(AccountSubCommandArgs), |
| 101 | } | 104 | } |
diff --git a/src/lib/list.rs b/src/lib/list.rs new file mode 100644 index 0000000..b940546 --- /dev/null +++ b/src/lib/list.rs | |||
| @@ -0,0 +1,159 @@ | |||
| 1 | use std::collections::HashMap; | ||
| 2 | |||
| 3 | use anyhow::{Result, anyhow}; | ||
| 4 | use auth_git2::GitAuthenticator; | ||
| 5 | use nostr::hashes::sha1::Hash as Sha1Hash; | ||
| 6 | |||
| 7 | use crate::{ | ||
| 8 | git::{ | ||
| 9 | Repo, RepoActions, | ||
| 10 | nostr_url::{CloneUrl, NostrUrlDecoded, ServerProtocol}, | ||
| 11 | }, | ||
| 12 | repo_ref::is_grasp_server, | ||
| 13 | utils::{Direction, get_read_protocols_to_try, join_with_and, set_protocol_preference}, | ||
| 14 | }; | ||
| 15 | |||
| 16 | pub fn list_from_remotes( | ||
| 17 | term: &console::Term, | ||
| 18 | git_repo: &Repo, | ||
| 19 | git_servers: &Vec<String>, | ||
| 20 | decoded_nostr_url: &NostrUrlDecoded, | ||
| 21 | grasp_servers: &[String], | ||
| 22 | ) -> HashMap<String, (HashMap<String, String>, bool)> { | ||
| 23 | let mut remote_states = HashMap::new(); | ||
| 24 | let mut errors = HashMap::new(); | ||
| 25 | for url in git_servers { | ||
| 26 | let is_grasp_server = is_grasp_server(url, grasp_servers); | ||
| 27 | match list_from_remote(term, git_repo, url, decoded_nostr_url, is_grasp_server) { | ||
| 28 | Err(error) => { | ||
| 29 | errors.insert(url, error); | ||
| 30 | } | ||
| 31 | Ok(state) => { | ||
| 32 | remote_states.insert(url.to_string(), (state, is_grasp_server)); | ||
| 33 | } | ||
| 34 | } | ||
| 35 | } | ||
| 36 | remote_states | ||
| 37 | } | ||
| 38 | |||
| 39 | pub fn list_from_remote( | ||
| 40 | term: &console::Term, | ||
| 41 | git_repo: &Repo, | ||
| 42 | git_server_url: &str, | ||
| 43 | decoded_nostr_url: &NostrUrlDecoded, | ||
| 44 | is_grasp_server: bool, | ||
| 45 | ) -> Result<HashMap<String, String>> { | ||
| 46 | let server_url = git_server_url.parse::<CloneUrl>()?; | ||
| 47 | let protocols_to_attempt = | ||
| 48 | get_read_protocols_to_try(git_repo, &server_url, decoded_nostr_url, is_grasp_server); | ||
| 49 | |||
| 50 | let mut failed_protocols = vec![]; | ||
| 51 | let mut remote_state: Option<HashMap<String, String>> = None; | ||
| 52 | |||
| 53 | for protocol in &protocols_to_attempt { | ||
| 54 | term.write_line( | ||
| 55 | format!( | ||
| 56 | "fetching {} ref list over {protocol}...", | ||
| 57 | server_url.short_name(), | ||
| 58 | ) | ||
| 59 | .as_str(), | ||
| 60 | )?; | ||
| 61 | |||
| 62 | let formatted_url = server_url.format_as(protocol, &decoded_nostr_url.user)?; | ||
| 63 | let res = list_from_remote_url( | ||
| 64 | git_repo, | ||
| 65 | &formatted_url, | ||
| 66 | [ServerProtocol::UnauthHttps, ServerProtocol::UnauthHttp].contains(protocol), | ||
| 67 | term, | ||
| 68 | ); | ||
| 69 | |||
| 70 | match res { | ||
| 71 | Ok(state) => { | ||
| 72 | remote_state = Some(state); | ||
| 73 | term.clear_last_lines(1)?; | ||
| 74 | if !failed_protocols.is_empty() { | ||
| 75 | term.write_line( | ||
| 76 | format!( | ||
| 77 | "list: succeeded over {protocol} from {}", | ||
| 78 | server_url.short_name(), | ||
| 79 | ) | ||
| 80 | .as_str(), | ||
| 81 | )?; | ||
| 82 | let _ = | ||
| 83 | set_protocol_preference(git_repo, protocol, &server_url, &Direction::Fetch); | ||
| 84 | } | ||
| 85 | break; | ||
| 86 | } | ||
| 87 | Err(error) => { | ||
| 88 | term.clear_last_lines(1)?; | ||
| 89 | term.write_line( | ||
| 90 | format!("list: {formatted_url} failed over {protocol}: {error}").as_str(), | ||
| 91 | )?; | ||
| 92 | failed_protocols.push(protocol); | ||
| 93 | } | ||
| 94 | } | ||
| 95 | } | ||
| 96 | if let Some(remote_state) = remote_state { | ||
| 97 | if failed_protocols.is_empty() { | ||
| 98 | term.clear_last_lines(1)?; | ||
| 99 | } | ||
| 100 | Ok(remote_state) | ||
| 101 | } else { | ||
| 102 | let error = anyhow!( | ||
| 103 | "{} failed over {}{}", | ||
| 104 | server_url.short_name(), | ||
| 105 | join_with_and(&failed_protocols), | ||
| 106 | if decoded_nostr_url.protocol.is_some() { | ||
| 107 | " and nostr url contains protocol override so no other protocols were attempted" | ||
| 108 | } else { | ||
| 109 | "" | ||
| 110 | }, | ||
| 111 | ); | ||
| 112 | term.write_line(format!("list: {error}").as_str())?; | ||
| 113 | Err(error) | ||
| 114 | } | ||
| 115 | } | ||
| 116 | |||
| 117 | fn list_from_remote_url( | ||
| 118 | git_repo: &Repo, | ||
| 119 | git_server_remote_url: &str, | ||
| 120 | dont_authenticate: bool, | ||
| 121 | term: &console::Term, | ||
| 122 | ) -> Result<HashMap<String, String>> { | ||
| 123 | let git_config = git_repo.git_repo.config()?; | ||
| 124 | |||
| 125 | let mut git_server_remote = git_repo.git_repo.remote_anonymous(git_server_remote_url)?; | ||
| 126 | // authentication may be required | ||
| 127 | let auth = GitAuthenticator::default(); | ||
| 128 | let mut remote_callbacks = git2::RemoteCallbacks::new(); | ||
| 129 | if !dont_authenticate { | ||
| 130 | remote_callbacks.credentials(auth.credentials(&git_config)); | ||
| 131 | } | ||
| 132 | term.write_line("list: connecting...")?; | ||
| 133 | git_server_remote.connect_auth(git2::Direction::Fetch, Some(remote_callbacks), None)?; | ||
| 134 | term.clear_last_lines(1)?; | ||
| 135 | let mut state = HashMap::new(); | ||
| 136 | for head in git_server_remote.list()? { | ||
| 137 | if let Some(symbolic_reference) = head.symref_target() { | ||
| 138 | state.insert( | ||
| 139 | head.name().to_string(), | ||
| 140 | format!("ref: {symbolic_reference}"), | ||
| 141 | ); | ||
| 142 | // ignore dereferenced tags | ||
| 143 | } else if !head.name().to_string().ends_with("^{}") { | ||
| 144 | state.insert(head.name().to_string(), head.oid().to_string()); | ||
| 145 | } | ||
| 146 | } | ||
| 147 | git_server_remote.disconnect()?; | ||
| 148 | Ok(state) | ||
| 149 | } | ||
| 150 | |||
| 151 | pub fn get_ahead_behind( | ||
| 152 | git_repo: &Repo, | ||
| 153 | base_ref_or_oid: &str, | ||
| 154 | latest_ref_or_oid: &str, | ||
| 155 | ) -> Result<(Vec<Sha1Hash>, Vec<Sha1Hash>)> { | ||
| 156 | let base = git_repo.get_commit_or_tip_of_reference(base_ref_or_oid)?; | ||
| 157 | let latest = git_repo.get_commit_or_tip_of_reference(latest_ref_or_oid)?; | ||
| 158 | git_repo.get_commits_ahead_behind(&base, &latest) | ||
| 159 | } | ||
diff --git a/src/lib/mod.rs b/src/lib/mod.rs index 7c7bd6a..076c2d2 100644 --- a/src/lib/mod.rs +++ b/src/lib/mod.rs | |||
| @@ -2,9 +2,11 @@ pub mod cli_interactor; | |||
| 2 | pub mod client; | 2 | pub mod client; |
| 3 | pub mod git; | 3 | pub mod git; |
| 4 | pub mod git_events; | 4 | pub mod git_events; |
| 5 | pub mod list; | ||
| 5 | pub mod login; | 6 | pub mod login; |
| 6 | pub mod repo_ref; | 7 | pub mod repo_ref; |
| 7 | pub mod repo_state; | 8 | pub mod repo_state; |
| 9 | pub mod utils; | ||
| 8 | 10 | ||
| 9 | use anyhow::{Result, anyhow}; | 11 | use anyhow::{Result, anyhow}; |
| 10 | use directories::ProjectDirs; | 12 | use directories::ProjectDirs; |
diff --git a/src/bin/git_remote_nostr/utils.rs b/src/lib/utils.rs index 2cb85bf..431757f 100644 --- a/src/bin/git_remote_nostr/utils.rs +++ b/src/lib/utils.rs | |||
| @@ -8,7 +8,9 @@ use std::{ | |||
| 8 | 8 | ||
| 9 | use anyhow::{Context, Result, bail}; | 9 | use anyhow::{Context, Result, bail}; |
| 10 | use git2::Repository; | 10 | use git2::Repository; |
| 11 | use ngit::{ | 11 | use nostr_sdk::{Event, EventId, Kind, PublicKey, Url}; |
| 12 | |||
| 13 | use crate::{ | ||
| 12 | client::{ | 14 | client::{ |
| 13 | get_all_proposal_patch_pr_pr_update_events_from_cache, get_events_from_local_cache, | 15 | get_all_proposal_patch_pr_pr_update_events_from_cache, get_events_from_local_cache, |
| 14 | get_proposals_and_revisions_from_cache, | 16 | get_proposals_and_revisions_from_cache, |
| @@ -23,7 +25,6 @@ use ngit::{ | |||
| 23 | }, | 25 | }, |
| 24 | repo_ref::RepoRef, | 26 | repo_ref::RepoRef, |
| 25 | }; | 27 | }; |
| 26 | use nostr_sdk::{Event, EventId, Kind, PublicKey, Url}; | ||
| 27 | 28 | ||
| 28 | pub fn get_short_git_server_name(git_repo: &Repo, url: &str) -> std::string::String { | 29 | pub fn get_short_git_server_name(git_repo: &Repo, url: &str) -> std::string::String { |
| 29 | if let Ok(name) = get_remote_name_by_url(&git_repo.git_repo, url) { | 30 | if let Ok(name) = get_remote_name_by_url(&git_repo.git_repo, url) { |