Skip to content

Commit

Permalink
Revert "Interpret line-numbers = false in gitconfig as no line numb…
Browse files Browse the repository at this point in the history
…ers at all (#296)"

This reverts commit ecb2da1.
  • Loading branch information
dandavison committed Dec 27, 2020
1 parent 4bb7343 commit 32e068b
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 58 deletions.
14 changes: 0 additions & 14 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,6 @@ pub struct ComputedValues {
pub decorations_width: Width,
pub inspect_raw_lines: InspectRawLines,
pub is_light_mode: bool,
pub line_numbers_mode: LineNumbersMode,
pub paging_mode: PagingMode,
pub syntax_dummy_theme: SyntaxTheme,
pub syntax_set: SyntaxSet,
Expand Down Expand Up @@ -610,19 +609,6 @@ impl Default for InspectRawLines {
}
}

#[derive(Clone, Debug, PartialEq)]
pub enum LineNumbersMode {
None,
First,
Full,
}

impl Default for LineNumbersMode {
fn default() -> Self {
LineNumbersMode::First
}
}

impl Default for PagingMode {
fn default() -> Self {
PagingMode::Never
Expand Down
5 changes: 1 addition & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ pub struct Config {
pub line_numbers_plus_style: Style,
pub line_numbers_right_format: String,
pub line_numbers_right_style: Style,
pub line_numbers_show_first_line_number: bool,
pub line_numbers_zero_style: Style,
pub line_buffer_size: usize,
pub max_line_distance: f64,
Expand Down Expand Up @@ -172,15 +171,13 @@ impl From<cli::Opt> for Config {
hyperlinks_file_link_format: opt.hyperlinks_file_link_format,
inspect_raw_lines: opt.computed.inspect_raw_lines,
keep_plus_minus_markers: opt.keep_plus_minus_markers,
line_numbers: (opt.computed.line_numbers_mode == cli::LineNumbersMode::Full),
line_numbers: opt.line_numbers,
line_numbers_left_format: opt.line_numbers_left_format,
line_numbers_left_style,
line_numbers_minus_style,
line_numbers_plus_style,
line_numbers_right_format: opt.line_numbers_right_format,
line_numbers_right_style,
line_numbers_show_first_line_number: (opt.computed.line_numbers_mode
== cli::LineNumbersMode::First),
line_numbers_zero_style,
line_buffer_size: opt.line_buffer_size,
max_line_distance: opt.max_line_distance,
Expand Down
6 changes: 1 addition & 5 deletions src/hunk_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,7 @@ fn _write_hunk_header(
);
have_hunk_header = true;
};
if !config.line_numbers
&& config.line_numbers_show_first_line_number
&& !config.hunk_header_style.is_raw
&& !config.color_only
{
if !config.line_numbers && !config.hunk_header_style.is_raw && !config.color_only {
if have_hunk_header {
let _ = write!(&mut painter.output_buffer, ":");
}
Expand Down
7 changes: 0 additions & 7 deletions src/options/option_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,6 @@ impl From<OptionValue> for Option<String> {
fn from(value: OptionValue) -> Self {
match value {
OptionValue::OptionString(value) => value,
// HACK: See the comment in options::set::compute_line_numbers_mode(). That function
// deliberately reads what is normally a boolean value ('line-numbers') as a string.
// However options::get::get_option_value() can fall through to obtaining the value
// from builtin_features, in which case an OptionValue::Boolean will be encountered.
// See the comment in options::set::compute_line_numbers_mode() and docstring of
// options::get::get_option_value().
OptionValue::Boolean(_) => None,
_ => delta_unreachable("Error converting OptionValue to Option<String>."),
}
}
Expand Down
29 changes: 1 addition & 28 deletions src/options/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{self, theme};
use crate::options::theme;

macro_rules! set_options {
([$( $field_ident:ident ),* ],
Expand Down Expand Up @@ -186,8 +186,6 @@ 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). side-by-side, and
Expand All @@ -201,31 +199,6 @@ 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,
Expand Down

0 comments on commit 32e068b

Please sign in to comment.