diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/features/hyperlinks.rs | 21 | ||||
-rw-r--r-- | src/options/set.rs | 13 |
2 files changed, 19 insertions, 15 deletions
diff --git a/src/features/hyperlinks.rs b/src/features/hyperlinks.rs index bf0c2354..2d3ad3b0 100644 --- a/src/features/hyperlinks.rs +++ b/src/features/hyperlinks.rs @@ -1,11 +1,12 @@ use std::borrow::Cow; +use std::str::FromStr; use lazy_static::lazy_static; use regex::{Captures, Regex}; use crate::config::Config; use crate::features::OptionValueFunction; -use crate::git_config::{GitConfigEntry, GitRemoteRepo}; +use crate::git_config::{GitConfig, GitConfigEntry, GitRemoteRepo}; pub fn make_feature() -> Vec<(String, OptionValueFunction)> { builtin_feature!([ @@ -28,16 +29,30 @@ pub fn format_commit_line_with_osc8_commit_hyperlink<'a>( format_osc8_hyperlink(&commit_link_format.replace("{commit}", commit), commit) }) } else if let Some(GitConfigEntry::GitRemote(GitRemoteRepo::GitHubRepo(repo))) = - config.git_config_entries.get("remote.origin.url") + config.git_config.as_ref().and_then(get_remote_url) { COMMIT_LINE_REGEX.replace(line, |captures: &Captures| { - format_commit_line_captures_with_osc8_commit_hyperlink(captures, repo) + format_commit_line_captures_with_osc8_commit_hyperlink(captures, &repo) }) } else { Cow::from(line) } } +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 to `path`, displaying `text`. pub fn format_osc8_file_hyperlink<'a>( relative_path: &'a str, diff --git a/src/options/set.rs b/src/options/set.rs index 4fc0a1fd..53240fce 100644 --- a/src/options/set.rs +++ b/src/options/set.rs @@ -13,7 +13,7 @@ use crate::config; use crate::env; use crate::errors::*; use crate::features; -use crate::git_config::{GitConfig, GitConfigEntry, GitRemoteRepo}; +use crate::git_config::{GitConfig, GitConfigEntry}; use crate::options::option_value::{OptionValue, ProvenancedOptionValue}; use crate::options::theme; @@ -564,7 +564,6 @@ fn is_truecolor_terminal() -> bool { } fn set_git_config_entries(opt: &mut cli::Opt, git_config: &mut GitConfig) { - // Styles for key in &["color.diff.old", "color.diff.new"] { if let Some(style_string) = git_config.get::<String>(key) { opt.git_config_entries @@ -572,16 +571,6 @@ fn set_git_config_entries(opt: &mut cli::Opt, git_config: &mut GitConfig) { } } - // Strings - for key in &["remote.origin.url"] { - if let Some(string) = git_config.get::<String>(key) { - if let Ok(repo) = GitRemoteRepo::from_str(&string) { - opt.git_config_entries - .insert(key.to_string(), GitConfigEntry::GitRemote(repo)); - } - } - } - if let Some(repo) = &git_config.repo { if let Some(workdir) = repo.workdir() { opt.git_config_entries.insert( |