diff options
author | Dan Davison <dandavison7@gmail.com> | 2020-08-20 20:30:14 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-20 20:30:14 -0400 |
commit | ecb2da1e271aa0daa6dd2ed4c6658d59347020e6 (patch) | |
tree | c8168a1c02a91d65594949bbbe180f27996fe2d5 /src/options/set.rs | |
parent | 98d1da411e185130fe4c167786107cb90725bdef (diff) |
Interpret `line-numbers = false` in gitconfig as no line numbers at all (#296)
Fixes #292
Diffstat (limited to 'src/options/set.rs')
-rw-r--r-- | src/options/set.rs | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/src/options/set.rs b/src/options/set.rs index 150246c9..b8ea10a7 100644 --- a/src/options/set.rs +++ b/src/options/set.rs @@ -16,7 +16,7 @@ use crate::features; use crate::git_config; use crate::git_config_entry::{self, GitConfigEntry}; use crate::options::option_value::{OptionValue, ProvenancedOptionValue}; -use crate::options::theme; +use crate::options::{self, theme}; macro_rules! set_options { ([$( $field_ident:ident ),* ], @@ -183,6 +183,8 @@ pub fn set_options( opt.computed.inspect_raw_lines = cli::InspectRawLines::from_str(&opt.inspect_raw_lines).unwrap(); + opt.computed.line_numbers_mode = + compute_line_numbers_mode(opt, &builtin_features, git_config, &option_names); opt.computed.paging_mode = parse_paging_mode(&opt.paging_mode); // --color-only is used for interactive.diffFilter (git add -p) and side-by-side cannot be used @@ -192,6 +194,31 @@ pub fn set_options( } } +fn compute_line_numbers_mode( + opt: &cli::Opt, + builtin_features: &HashMap<String, features::BuiltinFeature>, + git_config: &mut Option<git_config::GitConfig>, + option_names: &HashMap<&str, &str>, +) -> cli::LineNumbersMode { + // line-numbers is in general treated as a boolean value. We read it as a string here in order + // to interpret an explicit "false" (as opposed to merely absence) as meaning "Do not show any + // line numbers; not even the first line number of the hunk". + let line_numbers_string_value: Option<Option<String>> = options::get::get_option_value( + option_names["line-numbers"], + builtin_features, + opt, + git_config, + ); + match ( + line_numbers_string_value.as_ref().map(|val| val.as_deref()), + opt.line_numbers, + ) { + (Some(Some("false")), _) => cli::LineNumbersMode::None, + (_, true) => cli::LineNumbersMode::Full, + (_, false) => cli::LineNumbersMode::First, + } +} + #[allow(non_snake_case)] fn set__light__dark__syntax_theme__options( opt: &mut cli::Opt, |