From bc2084a966683db92aedbe0e03e21af045e2b912 Mon Sep 17 00:00:00 2001 From: Dan Davison Date: Sat, 5 Dec 2020 04:45:55 +0000 Subject: [PATCH] Expose max-buffered-lines as a new option Fixes #427 --- src/cli.rs | 9 +++++++++ src/config.rs | 4 ++-- src/delta.rs | 4 ++-- src/options/set.rs | 1 + 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index a366f5294..b6b9b314d 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -509,6 +509,15 @@ pub struct Opt { #[structopt(long = "whitespace-error-style", default_value = "auto auto")] pub whitespace_error_style: String, + #[structopt(long = "line-buffer-size", default_value = "32")] + /// Size of internal line buffer. Delta compares the added and removed versions of nearby lines + /// in order to detect and highlight changes at the level of individual words/tokens. + /// Therefore, nearby lines must be buffered internally before they are painted and emitted. + /// Increasing this value might improve highlighting of some large diff hunks. However, setting + /// this to a high value will adversely affect delta's performance when entire files are + /// added/removed. + pub line_buffer_size: usize, + #[structopt(long = "minus-color")] /// Deprecated: use --minus-style='normal my_background_color'. pub deprecated_minus_background_color: Option, diff --git a/src/config.rs b/src/config.rs index 28983b6da..a8718c519 100644 --- a/src/config.rs +++ b/src/config.rs @@ -43,7 +43,7 @@ pub struct Config { pub line_numbers_right_style: Style, pub line_numbers_show_first_line_number: bool, pub line_numbers_zero_style: Style, - pub max_buffered_lines: usize, + pub line_buffer_size: usize, pub max_line_distance: f64, pub max_line_distance_for_naively_paired_lines: f64, pub max_line_length: usize, @@ -173,7 +173,7 @@ impl From for Config { line_numbers_show_first_line_number: (opt.computed.line_numbers_mode == cli::LineNumbersMode::First), line_numbers_zero_style, - max_buffered_lines: 32, + line_buffer_size: opt.line_buffer_size, max_line_distance: opt.max_line_distance, max_line_distance_for_naively_paired_lines, max_line_length: opt.max_line_length, diff --git a/src/delta.rs b/src/delta.rs index af4106a3c..46eecd6f2 100644 --- a/src/delta.rs +++ b/src/delta.rs @@ -518,8 +518,8 @@ fn handle_hunk_line( // Don't let the line buffers become arbitrarily large -- if we // were to allow that, then for a large deleted/added file we // would process the entire file before painting anything. - if painter.minus_lines.len() > config.max_buffered_lines - || painter.plus_lines.len() > config.max_buffered_lines + if painter.minus_lines.len() > config.line_buffer_size + || painter.plus_lines.len() > config.line_buffer_size { painter.paint_buffered_minus_and_plus_lines(); } diff --git a/src/options/set.rs b/src/options/set.rs index 87eef7d4c..1fc8b4d2e 100644 --- a/src/options/set.rs +++ b/src/options/set.rs @@ -141,6 +141,7 @@ pub fn set_options( hyperlinks_file_link_format, inspect_raw_lines, keep_plus_minus_markers, + line_buffer_size, max_line_distance, max_line_length, // Hack: minus-style must come before minus-*emph-style because the latter default