diff options
-rw-r--r-- | src/cli.rs | 4 | ||||
-rw-r--r-- | src/config.rs | 4 | ||||
-rw-r--r-- | src/features/hyperlinks.rs | 21 | ||||
-rw-r--r-- | src/options/set.rs | 13 |
4 files changed, 26 insertions, 16 deletions
@@ -630,6 +630,9 @@ pub struct Opt { pub computed: ComputedValues, #[structopt(skip)] + pub git_config: Option<GitConfig>, + + #[structopt(skip)] pub git_config_entries: HashMap<String, GitConfigEntry>, } @@ -701,6 +704,7 @@ impl Opt { let mut opt = Opt::from_clap(&arg_matches); options::rewrite::apply_rewrite_rules(&mut opt, &arg_matches); options::set::set_options(&mut opt, &mut git_config, &arg_matches, assets); + opt.git_config = git_config; opt } diff --git a/src/config.rs b/src/config.rs index 1972fa47..b0a8cb3c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -15,7 +15,7 @@ use crate::delta::State; use crate::env; use crate::features::navigate; use crate::features::side_by_side; -use crate::git_config::GitConfigEntry; +use crate::git_config::{GitConfig, GitConfigEntry}; use crate::style::{self, Style}; pub struct Config { @@ -35,6 +35,7 @@ pub struct Config { pub file_renamed_label: String, pub hunk_label: String, pub file_style: Style, + pub git_config: Option<GitConfig>, pub git_config_entries: HashMap<String, GitConfigEntry>, pub hunk_header_file_style: Style, pub hunk_header_line_number_style: Style, @@ -213,6 +214,7 @@ impl From<cli::Opt> for Config { file_renamed_label, hunk_label, file_style, + git_config: opt.git_config, git_config_entries: opt.git_config_entries, hunk_header_file_style, hunk_header_line_number_style, 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( |