Skip to content

Commit

Permalink
Expose max-buffered-lines as a new option
Browse files Browse the repository at this point in the history
Fixes #427
  • Loading branch information
dandavison committed Dec 5, 2020
1 parent beb700f commit bc2084a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down
4 changes: 2 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/delta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
1 change: 1 addition & 0 deletions src/options/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bc2084a

Please sign in to comment.