summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Davison <dandavison7@gmail.com>2020-12-05 02:05:27 -0500
committerGitHub <noreply@github.com>2020-12-05 02:05:27 -0500
commit4b99d7c994343347215a3a7d6e7f95eedbc06603 (patch)
tree91f8ea7329897ed58ed92bc005ca614ecd92f316
parent73571485466055335401990d8c47b8621f3f4f7e (diff)
Expose line-buffer-size as a new option (#429)
Fixes #427
-rw-r--r--src/cli.rs9
-rw-r--r--src/config.rs4
-rw-r--r--src/delta.rs4
-rw-r--r--src/options/set.rs1
4 files changed, 14 insertions, 4 deletions
diff --git a/src/cli.rs b/src/cli.rs
index a366f529..b6b9b314 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<String>,
diff --git a/src/config.rs b/src/config.rs
index 28983b6d..a8718c51 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<cli::Opt> 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 af4106a3..46eecd6f 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 87eef7d4..1fc8b4d2 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