Skip to content

Commit

Permalink
Return the GitRemoteRepo type directly (#1328)
Browse files Browse the repository at this point in the history
The type is unnecessarily wrapped and it's the only use for
`GitConfigEntry::GitRemote` enum variant.
  • Loading branch information
nickelc committed Mar 5, 2023
1 parent a8446c5 commit 5e4faab
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/features/hyperlinks.rs
Expand Up @@ -6,7 +6,7 @@ use regex::{Captures, Regex};

use crate::config::Config;
use crate::features::OptionValueFunction;
use crate::git_config::{GitConfig, GitConfigEntry, GitRemoteRepo};
use crate::git_config::{GitConfig, GitRemoteRepo};

pub fn make_feature() -> Vec<(String, OptionValueFunction)> {
builtin_feature!([
Expand All @@ -32,7 +32,7 @@ pub fn format_commit_line_with_osc8_commit_hyperlink<'a>(
format_osc8_hyperlink(&commit_link_format.replace("{commit}", commit), commit);
format!("{prefix}{formatted_commit}{suffix}")
})
} else if let Some(GitConfigEntry::GitRemote(repo)) = config
} else if let Some(repo) = config
.git_config
.as_ref()
.and_then(GitConfig::get_remote_url)
Expand Down
1 change: 0 additions & 1 deletion src/git_config/git_config_entry.rs
Expand Up @@ -9,7 +9,6 @@ use crate::errors::*;
#[derive(Clone, Debug)]
pub enum GitConfigEntry {
Style(String),
GitRemote(GitRemoteRepo),
}

#[derive(Clone, Debug, PartialEq, Eq)]
Expand Down
8 changes: 2 additions & 6 deletions src/git_config/mod.rs
Expand Up @@ -96,17 +96,13 @@ impl GitConfig {
}
}

pub fn get_remote_url(&self) -> Option<GitConfigEntry> {
pub fn get_remote_url(&self) -> Option<GitRemoteRepo> {
self.repo
.as_ref()?
.find_remote("origin")
.ok()?
.url()
.and_then(|url| {
GitRemoteRepo::from_str(url)
.ok()
.map(GitConfigEntry::GitRemote)
})
.and_then(|url| GitRemoteRepo::from_str(url).ok())
}

pub fn for_each<F>(&self, regex: &str, mut f: F)
Expand Down

0 comments on commit 5e4faab

Please sign in to comment.