Skip to content

Commit

Permalink
Experimental: assume naive line pairings are homologous
Browse files Browse the repository at this point in the history
Experimental feature controlled by environment variable
DELTA_EXPERIMENTAL_MAX_LINE_DISTANCE_FOR_NAIVELY_PAIRED_LINES.
  • Loading branch information
dandavison committed May 1, 2020
1 parent 703c6a7 commit 5162437
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub struct Config<'a> {
pub theme: Option<&'a Theme>,
pub theme_name: String,
pub max_line_distance: f64,
pub max_line_distance_for_naively_paired_lines: f64,
pub minus_style_modifier: StyleModifier,
pub minus_emph_style_modifier: StyleModifier,
pub plus_style_modifier: StyleModifier,
Expand Down Expand Up @@ -130,10 +131,16 @@ pub fn get_config<'a>(
let minus_line_marker = if keep_plus_minus_markers { "-" } else { " " };
let plus_line_marker = if keep_plus_minus_markers { "+" } else { " " };

let max_line_distance_for_naively_paired_lines =
env::get_env_var("DELTA_EXPERIMENTAL_MAX_LINE_DISTANCE_FOR_NAIVELY_PAIRED_LINES")
.map(|s| s.parse::<f64>().unwrap_or(0.0))
.unwrap_or(0.0);

Config {
theme,
theme_name,
max_line_distance: opt.max_line_distance,
max_line_distance_for_naively_paired_lines,
minus_style_modifier,
minus_emph_style_modifier,
plus_style_modifier,
Expand Down
7 changes: 6 additions & 1 deletion src/edits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub fn infer_edits<'a, EditOperation>(
noop_insertion: EditOperation,
insertion: EditOperation,
max_line_distance: f64,
max_line_distance_for_naively_paired_lines: f64,
) -> (
Vec<Vec<(EditOperation, &'a str)>>, // annotated minus lines
Vec<Vec<(EditOperation, &'a str)>>, // annotated plus lines
Expand All @@ -42,7 +43,10 @@ where
minus_line,
plus_line,
);
if distance <= max_line_distance {
if minus_lines.len() == plus_lines.len()
&& distance <= max_line_distance_for_naively_paired_lines
|| distance <= max_line_distance
{
// minus_line and plus_line are inferred to be a homologous pair.

// Emit as unpaired the plus lines already considered and rejected
Expand Down Expand Up @@ -597,6 +601,7 @@ mod tests {
PlusNoop,
Insertion,
max_line_distance,
0.0,
);
assert_eq!(actual_edits, expected_edits);
}
Expand Down
1 change: 1 addition & 0 deletions src/paint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ impl<'a> Painter<'a> {
config.plus_style_modifier,
config.plus_emph_style_modifier,
config.max_line_distance,
config.max_line_distance_for_naively_paired_lines,
)
}
}
Expand Down

0 comments on commit 5162437

Please sign in to comment.