|
|
|
|
@ -407,6 +407,11 @@ fn diff_file(
|
|
|
|
|
guess_content(&rhs_bytes, rhs_path, binary_overrides),
|
|
|
|
|
) {
|
|
|
|
|
(ProbableFileKind::Binary, _) | (_, ProbableFileKind::Binary) => {
|
|
|
|
|
let has_byte_changes = if lhs_bytes == rhs_bytes {
|
|
|
|
|
None
|
|
|
|
|
} else {
|
|
|
|
|
Some((lhs_bytes.len(), rhs_bytes.len()))
|
|
|
|
|
};
|
|
|
|
|
return DiffResult {
|
|
|
|
|
extra_info: renamed,
|
|
|
|
|
display_path: display_path.to_owned(),
|
|
|
|
|
@ -416,7 +421,7 @@ fn diff_file(
|
|
|
|
|
lhs_positions: vec![],
|
|
|
|
|
rhs_positions: vec![],
|
|
|
|
|
hunks: vec![],
|
|
|
|
|
has_byte_changes: lhs_bytes != rhs_bytes,
|
|
|
|
|
has_byte_changes,
|
|
|
|
|
has_syntactic_changes: false,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
@ -549,7 +554,11 @@ fn check_only_text(
|
|
|
|
|
lhs_src: &str,
|
|
|
|
|
rhs_src: &str,
|
|
|
|
|
) -> DiffResult {
|
|
|
|
|
let has_changes = lhs_src != rhs_src;
|
|
|
|
|
let has_byte_changes = if lhs_src == rhs_src {
|
|
|
|
|
None
|
|
|
|
|
} else {
|
|
|
|
|
Some((lhs_src.as_bytes().len(), rhs_src.as_bytes().len()))
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
DiffResult {
|
|
|
|
|
display_path: display_path.to_owned(),
|
|
|
|
|
@ -560,8 +569,8 @@ fn check_only_text(
|
|
|
|
|
lhs_positions: vec![],
|
|
|
|
|
rhs_positions: vec![],
|
|
|
|
|
hunks: vec![],
|
|
|
|
|
has_byte_changes: has_changes,
|
|
|
|
|
has_syntactic_changes: has_changes,
|
|
|
|
|
has_byte_changes,
|
|
|
|
|
has_syntactic_changes: lhs_src != rhs_src,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -601,7 +610,7 @@ fn diff_file_content(
|
|
|
|
|
lhs_positions: vec![],
|
|
|
|
|
rhs_positions: vec![],
|
|
|
|
|
hunks: vec![],
|
|
|
|
|
has_byte_changes: false,
|
|
|
|
|
has_byte_changes: None,
|
|
|
|
|
has_syntactic_changes: false,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
@ -633,6 +642,13 @@ fn diff_file_content(
|
|
|
|
|
Ok((lhs, rhs)) => {
|
|
|
|
|
if diff_options.check_only {
|
|
|
|
|
let has_syntactic_changes = lhs != rhs;
|
|
|
|
|
|
|
|
|
|
let has_byte_changes = if lhs_src == rhs_src {
|
|
|
|
|
None
|
|
|
|
|
} else {
|
|
|
|
|
Some((lhs_src.as_bytes().len(), rhs_src.as_bytes().len()))
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return DiffResult {
|
|
|
|
|
extra_info,
|
|
|
|
|
display_path: display_path.to_owned(),
|
|
|
|
|
@ -642,7 +658,7 @@ fn diff_file_content(
|
|
|
|
|
lhs_positions: vec![],
|
|
|
|
|
rhs_positions: vec![],
|
|
|
|
|
hunks: vec![],
|
|
|
|
|
has_byte_changes: true,
|
|
|
|
|
has_byte_changes,
|
|
|
|
|
has_syntactic_changes,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
@ -775,6 +791,12 @@ fn diff_file_content(
|
|
|
|
|
);
|
|
|
|
|
let has_syntactic_changes = !hunks.is_empty();
|
|
|
|
|
|
|
|
|
|
let has_byte_changes = if lhs_src == rhs_src {
|
|
|
|
|
None
|
|
|
|
|
} else {
|
|
|
|
|
Some((lhs_src.as_bytes().len(), rhs_src.as_bytes().len()))
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
DiffResult {
|
|
|
|
|
extra_info,
|
|
|
|
|
display_path: display_path.to_owned(),
|
|
|
|
|
@ -784,7 +806,7 @@ fn diff_file_content(
|
|
|
|
|
lhs_positions,
|
|
|
|
|
rhs_positions,
|
|
|
|
|
hunks,
|
|
|
|
|
has_byte_changes: true,
|
|
|
|
|
has_byte_changes,
|
|
|
|
|
has_syntactic_changes,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -923,7 +945,7 @@ fn print_diff_result(display_options: &DisplayOptions, summary: &DiffResult) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
(FileContent::Binary, FileContent::Binary) => {
|
|
|
|
|
if display_options.print_unchanged || summary.has_byte_changes {
|
|
|
|
|
if display_options.print_unchanged || summary.has_byte_changes.is_some() {
|
|
|
|
|
println!(
|
|
|
|
|
"{}",
|
|
|
|
|
display::style::header(
|
|
|
|
|
@ -935,10 +957,17 @@ fn print_diff_result(display_options: &DisplayOptions, summary: &DiffResult) {
|
|
|
|
|
display_options
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
if summary.has_byte_changes {
|
|
|
|
|
println!("Binary contents changed.\n");
|
|
|
|
|
} else {
|
|
|
|
|
println!("No changes.\n");
|
|
|
|
|
|
|
|
|
|
match summary.has_byte_changes {
|
|
|
|
|
Some((lhs_len, rhs_len)) => {
|
|
|
|
|
let format_options = FormatSizeOptions::from(BINARY).decimal_places(1);
|
|
|
|
|
println!(
|
|
|
|
|
"Binary contents changed (old: {}, new: {}).\n",
|
|
|
|
|
&format_size(lhs_len, format_options),
|
|
|
|
|
&format_size(rhs_len, format_options),
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
None => println!("No changes.\n"),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|