diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-12-20 08:07:22 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-12-20 08:07:22 +0000 |
| commit | 8cc4a21061433c9a29e36c4f33e4d84bea1defee (patch) | |
| tree | 2bb56276d12612585da5f0bd0e7246a5b6b1c535 /src/lib | |
| parent | cc87576cdfdd3aa18df6e94fbfa079d9e4f0241a (diff) | |
refactor: use nostr url from repo_ref
simplify to allow the removal of warning:
`#[allow(clippy::too_many_arguments)]`
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/git/nostr_url.rs | 3 | ||||
| -rw-r--r-- | src/lib/repo_ref.rs | 16 |
2 files changed, 9 insertions, 10 deletions
diff --git a/src/lib/git/nostr_url.rs b/src/lib/git/nostr_url.rs index de7953f..ae0ac5f 100644 --- a/src/lib/git/nostr_url.rs +++ b/src/lib/git/nostr_url.rs | |||
| @@ -66,6 +66,9 @@ pub struct NostrUrlDecoded { | |||
| 66 | 66 | ||
| 67 | impl fmt::Display for NostrUrlDecoded { | 67 | impl fmt::Display for NostrUrlDecoded { |
| 68 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | 68 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 69 | if !self.original_string.is_empty() { | ||
| 70 | return write!(f, "{}", self.original_string); | ||
| 71 | } | ||
| 69 | write!(f, "nostr://")?; | 72 | write!(f, "nostr://")?; |
| 70 | if let Some(user) = &self.user { | 73 | if let Some(user) = &self.user { |
| 71 | write!(f, "{}@", user)?; | 74 | write!(f, "{}@", user)?; |
diff --git a/src/lib/repo_ref.rs b/src/lib/repo_ref.rs index 8705597..38f6774 100644 --- a/src/lib/repo_ref.rs +++ b/src/lib/repo_ref.rs | |||
| @@ -241,12 +241,12 @@ impl RepoRef { | |||
| 241 | self.nostr_git_url = Some(nostr_git_url) | 241 | self.nostr_git_url = Some(nostr_git_url) |
| 242 | } | 242 | } |
| 243 | 243 | ||
| 244 | pub fn to_nostr_git_url(&self, git_repo: &Option<&Repo>) -> String { | 244 | pub fn to_nostr_git_url(&self, git_repo: &Option<&Repo>) -> NostrUrlDecoded { |
| 245 | if let Some(nostr_git_url) = &self.nostr_git_url { | 245 | if let Some(nostr_git_url) = &self.nostr_git_url { |
| 246 | return nostr_git_url.original_string.clone(); | 246 | return nostr_git_url.clone(); |
| 247 | } | 247 | } |
| 248 | let c = self.coordinate_with_hint(); | 248 | let c = self.coordinate_with_hint(); |
| 249 | format!("{}", NostrUrlDecoded { | 249 | NostrUrlDecoded { |
| 250 | original_string: String::new(), | 250 | original_string: String::new(), |
| 251 | nip05: use_nip05_git_config_cache_to_find_nip05_from_public_key( | 251 | nip05: use_nip05_git_config_cache_to_find_nip05_from_public_key( |
| 252 | &c.public_key, | 252 | &c.public_key, |
| @@ -256,7 +256,7 @@ impl RepoRef { | |||
| 256 | coordinate: c, | 256 | coordinate: c, |
| 257 | protocol: None, | 257 | protocol: None, |
| 258 | user: None, | 258 | user: None, |
| 259 | }) | 259 | } |
| 260 | } | 260 | } |
| 261 | } | 261 | } |
| 262 | 262 | ||
| @@ -460,12 +460,8 @@ fn set_or_create_git_remote_with_nostr_url( | |||
| 460 | repo_ref: &RepoRef, | 460 | repo_ref: &RepoRef, |
| 461 | git_repo: &Repo, | 461 | git_repo: &Repo, |
| 462 | ) -> Result<()> { | 462 | ) -> Result<()> { |
| 463 | let url = repo_ref.to_nostr_git_url(&Some(git_repo)); | 463 | let url = repo_ref.to_nostr_git_url(&Some(git_repo)).to_string(); |
| 464 | if git_repo | 464 | if git_repo.git_repo.remote_set_url(name, &url).is_err() { |
| 465 | .git_repo | ||
| 466 | .remote_set_url(name, &repo_ref.to_nostr_git_url(&Some(git_repo))) | ||
| 467 | .is_err() | ||
| 468 | { | ||
| 469 | git_repo.git_repo.remote(name, &url)?; | 465 | git_repo.git_repo.remote(name, &url)?; |
| 470 | } | 466 | } |
| 471 | eprintln!("set git remote \"{name}\" to {url}"); | 467 | eprintln!("set git remote \"{name}\" to {url}"); |