diff options
author | nickelc <constantin.nickel@gmail.com> | 2023-03-05 20:59:30 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-05 14:59:30 -0500 |
commit | a30aa5f88fb707953e2c78e9f888d147d03a3fe3 (patch) | |
tree | 3afd0a3ea1b362e2111624c0e2736423c8f28302 /src/features | |
parent | 420b1acea1f977aa45712ca22309fad20a5a6018 (diff) |
Encapsulate `git2` types (#1326)
* Move theme iteration logic to `GitConfig`
The `git2::Config` type is now encapsulated and the regex is given to
`libgit2` to filter the config entries.
* Move remote url getter to `GitConfig`
Diffstat (limited to 'src/features')
-rw-r--r-- | src/features/hyperlinks.rs | 21 |
1 files changed, 4 insertions, 17 deletions
diff --git a/src/features/hyperlinks.rs b/src/features/hyperlinks.rs index aac32210..118d8355 100644 --- a/src/features/hyperlinks.rs +++ b/src/features/hyperlinks.rs @@ -1,6 +1,5 @@ use std::borrow::Cow; use std::path::Path; -use std::str::FromStr; use lazy_static::lazy_static; use regex::{Captures, Regex}; @@ -33,8 +32,10 @@ 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.git_config.as_ref().and_then(get_remote_url) + } else if let Some(GitConfigEntry::GitRemote(repo)) = config + .git_config + .as_ref() + .and_then(GitConfig::get_remote_url) { COMMIT_LINE_REGEX.replace(line, |captures: &Captures| { format_commit_line_captures_with_osc8_commit_hyperlink(captures, &repo) @@ -44,20 +45,6 @@ pub fn format_commit_line_with_osc8_commit_hyperlink<'a>( } } -fn get_remote_url(git_config: &GitConfig) -> Option<GitConfigEntry> { - git_config - .repo - .as_ref()? - .find_remote("origin") - .ok()? - .url() - .and_then(|url| { - GitRemoteRepo::from_str(url) - .ok() - .map(GitConfigEntry::GitRemote) - }) -} - /// Create a file hyperlink, displaying `text`. pub fn format_osc8_file_hyperlink<'a, P>( absolute_path: P, |