Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 8 additions & 38 deletions text/diff_util/file_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,6 @@ pub struct FileDiff<'a> {
}

impl<'a> FileDiff<'a> {
pub fn are_different(&self) -> bool {
self.are_different
}

pub fn set_different(&mut self, are_different: bool) {
self.are_different = are_different;
}

fn new(
file1: &'a mut FileData<'a>,
file2: &'a mut FileData<'a>,
Expand All @@ -44,7 +36,7 @@ impl<'a> FileDiff<'a> {
Self {
file1,
file2,
hunks: Hunks::new(),
hunks: Default::default(),
format_options,
are_different: false,
}
Expand Down Expand Up @@ -105,10 +97,10 @@ impl<'a> FileDiff<'a> {
.create_hunks_from_lcs(&lcs_indices, num_lines1, num_lines2);

if diff.hunks.hunk_count() > 0 {
diff.set_different(true);
diff.are_different = true;
}

if diff.are_different() {
if diff.are_different {
if let Some(show_if_different) = show_if_different {
println!("{}", show_if_different);
}
Expand Down Expand Up @@ -216,7 +208,7 @@ impl<'a> FileDiff<'a> {
}
}

if self.are_different() {
if self.are_different {
Ok(DiffExitStatus::Different)
} else {
Ok(DiffExitStatus::NotDifferent)
Expand Down Expand Up @@ -331,7 +323,7 @@ impl<'a> FileDiff<'a> {
Self::get_header(self.file2, self.format_options.label2())
);

let mut diff_disp = ContextDiffDisplay::new();
let mut diff_disp = ContextDiffDisplay::default();

for hunk in self.hunks.hunks() {
// move cursor to the start of context for first hunk
Expand Down Expand Up @@ -458,7 +450,7 @@ impl<'a> FileDiff<'a> {
Self::get_header(self.file2, self.format_options.label2())
);

let mut diff_disp = UnifiedDiffDisplay::new();
let mut diff_disp = UnifiedDiffDisplay::default();

for hunk in self.hunks.hunks() {
// move cursor to the start of context for first hunk
Expand Down Expand Up @@ -526,6 +518,7 @@ impl<'a> FileDiff<'a> {
}
}

#[derive(Default)]
pub struct UnifiedDiffDisplay {
curr_pos1: usize,
curr_pos2: usize,
Expand All @@ -540,18 +533,6 @@ pub struct UnifiedDiffDisplay {
}

impl UnifiedDiffDisplay {
pub fn new() -> Self {
Self {
curr_pos1: 0,
curr_pos2: 0,
context_start1: 0,
context_start2: 0,
hunk1_len: 0,
hunk2_len: 0,
hunk_lines: String::new(),
}
}

pub fn write_line(
&mut self,
file: &FileData,
Expand Down Expand Up @@ -607,6 +588,7 @@ impl UnifiedDiffDisplay {
}
}

#[derive(Default)]
pub struct ContextDiffDisplay {
curr_pos1: usize,
curr_pos2: usize,
Expand All @@ -621,18 +603,6 @@ pub struct ContextDiffDisplay {
}

impl ContextDiffDisplay {
pub fn new() -> Self {
Self {
curr_pos1: 0,
curr_pos2: 0,
context_start1: 0,
context_start2: 0,
hunk1_len: 0,
hunk2_len: 0,
hunk_lines: [String::new(), String::new()],
}
}

pub fn set_context_start(&mut self) {
self.context_start1 = self.curr_pos1 + 1;
self.context_start2 = self.curr_pos2 + 1;
Expand Down
14 changes: 1 addition & 13 deletions text/diff_util/hunks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ impl Default for Hunk {
}

impl Hunk {
pub fn new() -> Self {
Self::default()
}

pub fn f1_range(&self, is_ed: bool) -> String {
if self.ln1_start == self.ln1_end {
format!("{}", self.ln1_start)
Expand Down Expand Up @@ -193,20 +189,12 @@ impl Hunk {
}
}

#[derive(Default)]
pub struct Hunks {
hunks: Vec<Hunk>,
}

impl Hunks {
pub fn new() -> Self {
Self {
hunks: {
Hunk::new();
vec![] as Vec<Hunk>
},
}
}

pub fn hunks(&self) -> &Vec<Hunk> {
&self.hunks
}
Expand Down