From 8cc4a21061433c9a29e36c4f33e4d84bea1defee Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Fri, 20 Dec 2024 08:07:22 +0000 Subject: refactor: use nostr url from repo_ref simplify to allow the removal of warning: `#[allow(clippy::too_many_arguments)]` --- src/lib/git/nostr_url.rs | 3 +++ src/lib/repo_ref.rs | 16 ++++++---------- 2 files changed, 9 insertions(+), 10 deletions(-) (limited to 'src/lib') 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 { impl fmt::Display for NostrUrlDecoded { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + if !self.original_string.is_empty() { + return write!(f, "{}", self.original_string); + } write!(f, "nostr://")?; if let Some(user) = &self.user { 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 { self.nostr_git_url = Some(nostr_git_url) } - pub fn to_nostr_git_url(&self, git_repo: &Option<&Repo>) -> String { + pub fn to_nostr_git_url(&self, git_repo: &Option<&Repo>) -> NostrUrlDecoded { if let Some(nostr_git_url) = &self.nostr_git_url { - return nostr_git_url.original_string.clone(); + return nostr_git_url.clone(); } let c = self.coordinate_with_hint(); - format!("{}", NostrUrlDecoded { + NostrUrlDecoded { original_string: String::new(), nip05: use_nip05_git_config_cache_to_find_nip05_from_public_key( &c.public_key, @@ -256,7 +256,7 @@ impl RepoRef { coordinate: c, protocol: None, user: None, - }) + } } } @@ -460,12 +460,8 @@ fn set_or_create_git_remote_with_nostr_url( repo_ref: &RepoRef, git_repo: &Repo, ) -> Result<()> { - let url = repo_ref.to_nostr_git_url(&Some(git_repo)); - if git_repo - .git_repo - .remote_set_url(name, &repo_ref.to_nostr_git_url(&Some(git_repo))) - .is_err() - { + let url = repo_ref.to_nostr_git_url(&Some(git_repo)).to_string(); + if git_repo.git_repo.remote_set_url(name, &url).is_err() { git_repo.git_repo.remote(name, &url)?; } eprintln!("set git remote \"{name}\" to {url}"); -- cgit v1.2.3