Don't bother storing bytes of binary files

pull/454/head
Wilfred Hughes 2022-12-17 23:44:39 +07:00
parent 4b2e601de1
commit aa067e636b
2 changed files with 10 additions and 11 deletions

@ -284,9 +284,8 @@ fn diff_file_content(
rhs_display_path: rhs_display_path.into(),
language: None,
detected_language: None,
// TODO: do we need to store the actual bytes?
lhs_src: FileContent::Binary(lhs_bytes.to_vec()),
rhs_src: FileContent::Binary(rhs_bytes.to_vec()),
lhs_src: FileContent::Binary,
rhs_src: FileContent::Binary,
lhs_positions: vec![],
rhs_positions: vec![],
hunks: vec![],
@ -539,9 +538,8 @@ fn print_diff_result(display_options: &DisplayOptions, summary: &DiffResult) {
}
}
}
(FileContent::Binary(lhs_bytes), FileContent::Binary(rhs_bytes)) => {
let changed = lhs_bytes != rhs_bytes;
if display_options.print_unchanged || changed {
(FileContent::Binary, FileContent::Binary) => {
if display_options.print_unchanged || !summary.has_same_bytes {
println!(
"{}",
display::style::header(
@ -553,14 +551,15 @@ fn print_diff_result(display_options: &DisplayOptions, summary: &DiffResult) {
display_options
)
);
if changed {
println!("Binary contents changed.");
} else {
if summary.has_same_bytes {
println!("No changes.");
} else {
println!("Binary contents changed.");
}
}
}
(_, FileContent::Binary(_)) | (FileContent::Binary(_), _) => {
(FileContent::Text(_), FileContent::Binary)
| (FileContent::Binary, FileContent::Text(_)) => {
// We're diffing a binary file against a text file.
println!(
"{}",

@ -5,7 +5,7 @@ use crate::{display::hunks::Hunk, parse::syntax::MatchedPos};
#[derive(Debug, PartialEq, Eq)]
pub enum FileContent {
Text(String),
Binary(Vec<u8>),
Binary,
}
#[derive(Debug)]