Debian Codegraph @

src/handlers/diff_header_misc.rs

raw symbols SCIP
1 use crate::delta::{DiffType, Source, State, StateMachine};
2 use crate::utils::path::relativize_path_maybe;
3
4 impl StateMachine<'_> {
5 #[inline]
6 fn test_diff_file_missing(&self) -> bool {
7 self.source == Source::DiffUnified && self.line.starts_with("Only in ")
8 }
9
10 #[inline]
11 fn test_diff_is_binary(&self) -> bool {
12 self.line.starts_with("Binary files ")
13 }
14
15 pub fn handle_diff_header_misc_line(&mut self) -> std::io::Result<bool> {
16 if !self.test_diff_file_missing() && !self.test_diff_is_binary() {
17 return Ok(false);
18 }
19
20 // Preserve the "Binary files" line when diff lines should be kept unchanged.
21 if !self.config.color_only && self.test_diff_is_binary() {
22 // Print the "Binary files" line verbatim, if there was no "diff" line, or it
23 // listed different files but was not followed by header minus and plus lines.
24 // This can happen in output of standalone diff or git diff --no-index.
25 if self.minus_file.is_empty() && self.plus_file.is_empty() {
26 self.emit_line_unchanged()?;
27 self.handled_diff_header_header_line_file_pair
28 .clone_from(&self.current_file_pair);
29 return Ok(true);
30 }
31
32 if self.minus_file != "/dev/null" {
33 relativize_path_maybe(&mut self.minus_file, self.config);
34 self.minus_file.push_str(" (binary file)");
35 }
36 if self.plus_file != "/dev/null" {
37 relativize_path_maybe(&mut self.plus_file, self.config);
38 self.plus_file.push_str(" (binary file)");
39 }
40 return Ok(true);
41 }
42
43 self.handle_additional_cases(match self.state {
44 State::DiffHeader(_) => self.state.clone(),
45 _ => State::DiffHeader(DiffType::Unified),
46 })
47 }
48 }