diff options
author | Dan Davison <dandavison7@gmail.com> | 2021-12-04 15:11:51 -0500 |
---|---|---|
committer | Dan Davison <dandavison7@gmail.com> | 2021-12-04 18:01:30 -0500 |
commit | 3b7fcc66a674bdbf2c58187d2e5bfb7d3b5f1133 (patch) | |
tree | 613ce26e2dbcefb3b32e6d6ed1f4763f7c1090b1 /src | |
parent | 580a1e88ad9f305aa2d1292b4c1cc5b5b7b7b087 (diff) |
Fix weird but correct line handling
This handler function was returning `false`, thus signaling that it
had not handled the line, when it was not the responsibility of any
other handler to handle the line. It was doing this to rely on the
fall-through handlers determining whether to emit the line or skip it.
But this risks another handler handling it and is a violation of the
contract. It is much more appropriate to make the determination in the
handler itself, emit it if appropriate, and signal that it has been
handled.
Diffstat (limited to 'src')
-rw-r--r-- | src/delta.rs | 4 | ||||
-rw-r--r-- | src/handlers/diff_header_diff.rs | 5 |
2 files changed, 6 insertions, 3 deletions
diff --git a/src/delta.rs b/src/delta.rs index c2e48ba0..bbbce519 100644 --- a/src/delta.rs +++ b/src/delta.rs @@ -170,12 +170,12 @@ impl<'a> StateMachine<'a> { } /// Skip file metadata lines unless a raw diff style has been requested. - fn should_skip_line(&self) -> bool { + pub fn should_skip_line(&self) -> bool { self.state == State::DiffHeader && self.should_handle() && !self.config.color_only } /// Emit unchanged any line that delta does not handle. - fn emit_line_unchanged(&mut self) -> std::io::Result<bool> { + pub fn emit_line_unchanged(&mut self) -> std::io::Result<bool> { self.painter.emit()?; writeln!( self.painter.writer, diff --git a/src/handlers/diff_header_diff.rs b/src/handlers/diff_header_diff.rs index 161f666b..78ec2a98 100644 --- a/src/handlers/diff_header_diff.rs +++ b/src/handlers/diff_header_diff.rs @@ -15,6 +15,9 @@ impl<'a> StateMachine<'a> { self.state = State::DiffHeader; self.handled_diff_header_header_line_file_pair = None; self.diff_line = self.line.clone(); - Ok(false) + if !self.should_skip_line() { + self.emit_line_unchanged()?; + } + Ok(true) } } |