Debian Codegraph @

src/handlers/diff_header_diff.rs

raw symbols SCIP
1 use crate::delta::{DiffType, InMergeConflict, MergeParents, State, StateMachine};
2 use crate::handlers::diff_header::{get_repeated_file_path_from_diff_line, FileEvent};
3
4 impl StateMachine<'_> {
5 #[inline]
6 fn test_diff_header_diff_line(&self) -> bool {
7 self.line.starts_with("diff ")
8 }
9
10 #[allow(clippy::unnecessary_wraps)]
11 pub fn handle_diff_header_diff_line(&mut self) -> std::io::Result<bool> {
12 if !self.test_diff_header_diff_line() {
13 return Ok(false);
14 }
15 self.painter.paint_buffered_minus_and_plus_lines();
16 self.painter.emit()?;
17 self.state =
18 if self.line.starts_with("diff --cc ") || self.line.starts_with("diff --combined ") {
19 // We will determine the number of parents when we see the hunk header.
20 State::DiffHeader(DiffType::Combined(
21 MergeParents::Unknown,
22 InMergeConflict::No,
23 ))
24 } else {
25 State::DiffHeader(DiffType::Unified)
26 };
27 self.handle_pending_line_with_diff_name()?;
28 self.handled_diff_header_header_line_file_pair = None;
29 self.diff_line.clone_from(&self.line);
30
31 // Pre-fill header fields from the diff line. For added, removed or renamed files
32 // these are updated precisely on actual header minus and header plus lines.
33 // But for modified binary files which are not added, removed or renamed, there
34 // are no minus and plus lines. Without the code below, in such cases the file names
35 // would remain unchanged from the previous diff, or empty for the very first diff.
36 let name = get_repeated_file_path_from_diff_line(&self.line).unwrap_or_default();
37 self.minus_file.clone_from(&name);
38 self.plus_file.clone_from(&name);
39 self.minus_file_event = FileEvent::Change;
40 self.plus_file_event = FileEvent::Change;
41 self.current_file_pair = Some((self.minus_file.clone(), self.plus_file.clone()));
42
43 if !self.should_skip_line() {
44 self.emit_line_unchanged()?;
45 }
46 Ok(true)
47 }
48 }