Remove duplicated definition

pull/70/head
Wilfred Hughes 2021-11-18 23:15:50 +07:00
parent e1ffa2af2a
commit e9792db333
1 changed files with 2 additions and 65 deletions

@ -8,8 +8,8 @@ use std::{
};
use crate::{
context::{add_context, opposite_positions},
hunks::{aligned_lines_from_hunk, extract_lines, Hunk},
context::{opposite_positions},
hunks::{aligned_lines_from_hunk, Hunk},
lines::{codepoint_len, enforce_max_length, format_line_num, LineNumber, MaxLine},
positions::SingleLineSpan,
style::{self, apply_colors, color_positions, split_and_apply, Style},
@ -77,69 +77,6 @@ fn display_single_column(src: &str, color: Color) -> String {
result
}
// TODO: Move to hunks.rs
pub fn merge_adjacent(
hunks: &[Hunk],
lhs_mps: &[MatchedPos],
rhs_mps: &[MatchedPos],
max_lhs_src_line: LineNumber,
max_rhs_src_line: LineNumber,
) -> Vec<Hunk> {
let mut res: Vec<Hunk> = vec![];
let mut prev_hunk: Option<Hunk> = None;
let mut prev_lhs_lines: HashSet<LineNumber> = HashSet::new();
let mut prev_rhs_lines: HashSet<LineNumber> = HashSet::new();
for hunk in hunks {
let mut lhs_lines: HashSet<LineNumber> = HashSet::new();
let mut rhs_lines: HashSet<LineNumber> = HashSet::new();
let lines = extract_lines(hunk);
let contextual_lines =
add_context(&lines, lhs_mps, rhs_mps, max_lhs_src_line, max_rhs_src_line);
for (lhs_line, rhs_line) in contextual_lines {
if let Some(lhs_line) = lhs_line {
lhs_lines.insert(lhs_line);
}
if let Some(rhs_line) = rhs_line {
rhs_lines.insert(rhs_line);
}
}
match prev_hunk {
Some(hunk_so_far) => {
if lhs_lines.is_disjoint(&prev_lhs_lines) && rhs_lines.is_disjoint(&prev_rhs_lines)
{
// No overlaps, start a new hunk.
res.push(hunk_so_far.clone());
prev_hunk = Some(hunk.clone());
prev_lhs_lines = lhs_lines;
prev_rhs_lines = rhs_lines;
} else {
// Adjacent hunks, merge.
prev_hunk = Some(hunk_so_far.merge(hunk));
prev_lhs_lines.extend(lhs_lines.iter());
prev_rhs_lines.extend(rhs_lines.iter());
}
}
None => {
// The very first hunk.
prev_hunk = Some(hunk.clone());
prev_lhs_lines = lhs_lines;
prev_rhs_lines = rhs_lines;
}
}
}
if let Some(current_hunk) = prev_hunk {
res.push(current_hunk);
}
res
}
fn display_line_nums(
lhs_line_num: Option<LineNumber>,
rhs_line_num: Option<LineNumber>,