mirror of
https://github.com/dandavison/delta.git
synced 2024-10-04 20:07:18 +03:00
Remove unnecessary borrows (#692)
This commit is contained in:
parent
2de7b51cc9
commit
ea3417abe4
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@ -107,7 +107,7 @@ jobs:
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: clippy
|
||||
args: -- -D warnings --allow clippy::needless_borrow
|
||||
args: -- -D warnings
|
||||
|
||||
coverage:
|
||||
name: Code coverage
|
||||
|
@ -90,7 +90,7 @@ pub fn ansi_16_color_name_to_number(name: &str) -> Option<u8> {
|
||||
fn ansi_16_color_number_to_name(n: u8) -> Option<&'static str> {
|
||||
for (k, _n) in &*ANSI_16_COLORS {
|
||||
if *_n == n {
|
||||
return Some(&*k);
|
||||
return Some(*k);
|
||||
}
|
||||
}
|
||||
None
|
||||
|
@ -112,7 +112,7 @@ impl<'a> StateMachine<'a> {
|
||||
let line = &self.line;
|
||||
|
||||
if self.source == Source::Unknown {
|
||||
self.source = detect_source(&line);
|
||||
self.source = detect_source(line);
|
||||
}
|
||||
|
||||
let mut handled_line = if self.config.commit_regex.is_match(line) {
|
||||
@ -174,7 +174,7 @@ impl<'a> StateMachine<'a> {
|
||||
|
||||
fn ingest_line(&mut self, raw_line_bytes: &[u8]) {
|
||||
// TODO: retain raw_line as Cow
|
||||
self.raw_line = String::from_utf8_lossy(&raw_line_bytes).to_string();
|
||||
self.raw_line = String::from_utf8_lossy(raw_line_bytes).to_string();
|
||||
if self.config.max_line_length > 0 && self.raw_line.len() > self.config.max_line_length {
|
||||
self.raw_line = ansi::truncate_str(
|
||||
&self.raw_line,
|
||||
|
@ -190,8 +190,8 @@ fn paint_left_panel_minus_line<'a>(
|
||||
) -> String {
|
||||
let (mut panel_line, panel_line_is_empty) = paint_minus_or_plus_panel_line(
|
||||
line_index,
|
||||
&syntax_style_sections,
|
||||
&diff_style_sections,
|
||||
syntax_style_sections,
|
||||
diff_style_sections,
|
||||
state,
|
||||
line_numbers_data,
|
||||
PanelSide::Left,
|
||||
@ -224,8 +224,8 @@ fn paint_right_panel_plus_line<'a>(
|
||||
) -> String {
|
||||
let (mut panel_line, panel_line_is_empty) = paint_minus_or_plus_panel_line(
|
||||
line_index,
|
||||
&syntax_style_sections,
|
||||
&diff_style_sections,
|
||||
syntax_style_sections,
|
||||
diff_style_sections,
|
||||
state,
|
||||
line_numbers_data,
|
||||
PanelSide::Right,
|
||||
@ -384,13 +384,13 @@ fn right_pad_left_panel_line(
|
||||
};
|
||||
};
|
||||
// Pad with (maybe painted) spaces to the panel width.
|
||||
let text_width = ansi::measure_text_width(&panel_line);
|
||||
let text_width = ansi::measure_text_width(panel_line);
|
||||
let panel_width = config.side_by_side_data.left_panel.width;
|
||||
if text_width < panel_width {
|
||||
let fill_style = get_right_fill_style_for_left_panel(
|
||||
panel_line_is_empty,
|
||||
line_index,
|
||||
&diff_style_sections,
|
||||
diff_style_sections,
|
||||
state,
|
||||
background_color_extends_to_terminal_width,
|
||||
config,
|
||||
@ -420,7 +420,7 @@ fn right_fill_right_panel_line(
|
||||
config: &Config,
|
||||
) {
|
||||
*panel_line = ansi::truncate_str(
|
||||
&panel_line,
|
||||
panel_line,
|
||||
config.side_by_side_data.right_panel.width,
|
||||
&config.truncation_symbol,
|
||||
)
|
||||
|
@ -148,7 +148,7 @@ fn write_to_output_buffer(
|
||||
&lines,
|
||||
&delta::State::HunkHeader,
|
||||
&mut painter.highlighter,
|
||||
&painter.config,
|
||||
painter.config,
|
||||
);
|
||||
Painter::paint_lines(
|
||||
syntax_style_sections,
|
||||
|
@ -173,7 +173,7 @@ You can also use delta to diff two files: `delta file_A file_B`."
|
||||
if let Err(error) = delta(
|
||||
BufReader::new(diff_process.stdout.unwrap()).byte_lines(),
|
||||
writer,
|
||||
&config,
|
||||
config,
|
||||
) {
|
||||
match error.kind() {
|
||||
ErrorKind::BrokenPipe => return 0,
|
||||
@ -363,7 +363,7 @@ fn show_themes(dark: bool, light: bool, computed_theme_is_light: bool) -> std::i
|
||||
|
||||
for theme in &get_themes(git_config::GitConfig::try_create()) {
|
||||
let opt =
|
||||
cli::Opt::from_iter_and_git_config(&["", "", "--features", &theme], &mut git_config);
|
||||
cli::Opt::from_iter_and_git_config(&["", "", "--features", theme], &mut git_config);
|
||||
let is_dark_theme = opt.dark;
|
||||
let is_light_theme = opt.light;
|
||||
let config = config::Config::from(opt);
|
||||
|
@ -82,8 +82,8 @@ pub trait GetOptionValue {
|
||||
for feature in opt.features.to_lowercase().split_whitespace().rev() {
|
||||
match Self::get_provenanced_value_for_feature(
|
||||
option_name,
|
||||
&feature,
|
||||
&builtin_features,
|
||||
feature,
|
||||
builtin_features,
|
||||
opt,
|
||||
git_config,
|
||||
) {
|
||||
@ -120,7 +120,7 @@ pub trait GetOptionValue {
|
||||
}
|
||||
if let Some(builtin_feature) = builtin_features.get(feature) {
|
||||
if let Some(value_function) = builtin_feature.get(option_name) {
|
||||
return Some(value_function(opt, &git_config));
|
||||
return Some(value_function(opt, git_config));
|
||||
}
|
||||
}
|
||||
None
|
||||
|
@ -221,7 +221,7 @@ fn set__light__dark__syntax_theme__options(
|
||||
}
|
||||
};
|
||||
let empty_builtin_features = HashMap::new();
|
||||
validate_light_and_dark(&opt);
|
||||
validate_light_and_dark(opt);
|
||||
if !(opt.light || opt.dark) {
|
||||
set_options!(
|
||||
[dark, light],
|
||||
@ -233,7 +233,7 @@ fn set__light__dark__syntax_theme__options(
|
||||
false
|
||||
);
|
||||
}
|
||||
validate_light_and_dark(&opt);
|
||||
validate_light_and_dark(opt);
|
||||
set_options!(
|
||||
[syntax_theme],
|
||||
opt,
|
||||
@ -304,7 +304,7 @@ fn gather_features(
|
||||
// Gather features from command line.
|
||||
if let Some(git_config) = git_config {
|
||||
for feature in split_feature_string(&opt.features.to_lowercase()) {
|
||||
gather_features_recursively(feature, &mut features, &builtin_features, opt, git_config);
|
||||
gather_features_recursively(feature, &mut features, builtin_features, opt, git_config);
|
||||
}
|
||||
} else {
|
||||
for feature in split_feature_string(&opt.features.to_lowercase()) {
|
||||
@ -315,33 +315,28 @@ fn gather_features(
|
||||
// Gather builtin feature flags supplied on command line.
|
||||
// TODO: Iterate over programatically-obtained names of builtin features.
|
||||
if opt.raw {
|
||||
gather_builtin_features_recursively("raw", &mut features, &builtin_features, opt);
|
||||
gather_builtin_features_recursively("raw", &mut features, builtin_features, opt);
|
||||
}
|
||||
if opt.color_only {
|
||||
gather_builtin_features_recursively("color-only", &mut features, &builtin_features, opt);
|
||||
gather_builtin_features_recursively("color-only", &mut features, builtin_features, opt);
|
||||
}
|
||||
if opt.diff_highlight {
|
||||
gather_builtin_features_recursively(
|
||||
"diff-highlight",
|
||||
&mut features,
|
||||
&builtin_features,
|
||||
opt,
|
||||
);
|
||||
gather_builtin_features_recursively("diff-highlight", &mut features, builtin_features, opt);
|
||||
}
|
||||
if opt.diff_so_fancy {
|
||||
gather_builtin_features_recursively("diff-so-fancy", &mut features, &builtin_features, opt);
|
||||
gather_builtin_features_recursively("diff-so-fancy", &mut features, builtin_features, opt);
|
||||
}
|
||||
if opt.hyperlinks {
|
||||
gather_builtin_features_recursively("hyperlinks", &mut features, &builtin_features, opt);
|
||||
gather_builtin_features_recursively("hyperlinks", &mut features, builtin_features, opt);
|
||||
}
|
||||
if opt.line_numbers {
|
||||
gather_builtin_features_recursively("line-numbers", &mut features, &builtin_features, opt);
|
||||
gather_builtin_features_recursively("line-numbers", &mut features, builtin_features, opt);
|
||||
}
|
||||
if opt.navigate {
|
||||
gather_builtin_features_recursively("navigate", &mut features, &builtin_features, opt);
|
||||
gather_builtin_features_recursively("navigate", &mut features, builtin_features, opt);
|
||||
}
|
||||
if opt.side_by_side {
|
||||
gather_builtin_features_recursively("side-by-side", &mut features, &builtin_features, opt);
|
||||
gather_builtin_features_recursively("side-by-side", &mut features, builtin_features, opt);
|
||||
}
|
||||
|
||||
if let Some(git_config) = git_config {
|
||||
@ -352,7 +347,7 @@ fn gather_features(
|
||||
gather_features_recursively(
|
||||
feature,
|
||||
&mut features,
|
||||
&builtin_features,
|
||||
builtin_features,
|
||||
opt,
|
||||
git_config,
|
||||
)
|
||||
@ -363,7 +358,7 @@ fn gather_features(
|
||||
gather_builtin_features_from_flags_in_gitconfig(
|
||||
"delta",
|
||||
&mut features,
|
||||
&builtin_features,
|
||||
builtin_features,
|
||||
opt,
|
||||
git_config,
|
||||
);
|
||||
|
@ -69,7 +69,7 @@ impl<'a> Painter<'a> {
|
||||
|
||||
pub fn set_highlighter(&mut self) {
|
||||
if let Some(ref syntax_theme) = self.config.syntax_theme {
|
||||
self.highlighter = HighlightLines::new(self.syntax, &syntax_theme)
|
||||
self.highlighter = HighlightLines::new(self.syntax, syntax_theme)
|
||||
};
|
||||
}
|
||||
|
||||
@ -205,7 +205,7 @@ impl<'a> Painter<'a> {
|
||||
&lines,
|
||||
&state,
|
||||
&mut self.highlighter,
|
||||
&self.config,
|
||||
self.config,
|
||||
);
|
||||
let diff_style_sections = vec![(self.config.zero_style, lines[0].0.as_str())]; // TODO: compute style from state
|
||||
|
||||
@ -496,11 +496,11 @@ impl<'a> Painter<'a> {
|
||||
) {
|
||||
let (minus_lines, minus_styles): (Vec<&str>, Vec<Style>) = minus_lines
|
||||
.iter()
|
||||
.map(|(s, t)| (s.as_str(), *config.get_style(&t)))
|
||||
.map(|(s, t)| (s.as_str(), *config.get_style(t)))
|
||||
.unzip();
|
||||
let (plus_lines, plus_styles): (Vec<&str>, Vec<Style>) = plus_lines
|
||||
.iter()
|
||||
.map(|(s, t)| (s.as_str(), *config.get_style(&t)))
|
||||
.map(|(s, t)| (s.as_str(), *config.get_style(t)))
|
||||
.unzip();
|
||||
let mut diff_sections = edits::infer_edits(
|
||||
minus_lines,
|
||||
|
@ -102,7 +102,7 @@ fn _parse_file_path(s: &str, git_diff_name: bool) -> String {
|
||||
match s.strip_suffix('\t').unwrap_or(s) {
|
||||
path if path == "/dev/null" => "/dev/null",
|
||||
path if git_diff_name && DIFF_PREFIXES.iter().any(|s| path.starts_with(s)) => &path[2..],
|
||||
path if git_diff_name => &path,
|
||||
path if git_diff_name => path,
|
||||
path => path.split('\t').next().unwrap_or(""),
|
||||
}
|
||||
.to_string()
|
||||
@ -142,7 +142,7 @@ pub fn get_file_extension_from_file_meta_line_file_path(path: &str) -> Option<&s
|
||||
if path.is_empty() || path == "/dev/null" {
|
||||
None
|
||||
} else {
|
||||
get_extension(&path).map(|ex| ex.trim())
|
||||
get_extension(path).map(|ex| ex.trim())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ impl Style {
|
||||
is_emph: bool,
|
||||
) -> Self {
|
||||
let (ansi_term_style, is_omitted, is_raw, is_syntax_highlighted) =
|
||||
parse_ansi_term_style(&style_string, default, true_color);
|
||||
parse_ansi_term_style(style_string, default, true_color);
|
||||
let decoration_style =
|
||||
DecorationStyle::from_str(decoration_style_string.unwrap_or(""), true_color);
|
||||
Self {
|
||||
@ -132,7 +132,7 @@ bitflags! {
|
||||
impl DecorationStyle {
|
||||
pub fn from_str(style_string: &str, true_color: bool) -> Self {
|
||||
let (special_attributes, style_string) =
|
||||
extract_special_decoration_attributes(&style_string);
|
||||
extract_special_decoration_attributes(style_string);
|
||||
let (style, is_omitted, is_raw, is_syntax_highlighted) =
|
||||
parse_ansi_term_style(&style_string, None, true_color);
|
||||
if is_raw {
|
||||
|
Loading…
Reference in New Issue
Block a user