Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flush line buffers in additional locations #1003

Merged
merged 2 commits into from
Mar 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/handlers/diff_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ impl<'a> StateMachine<'a> {
));
}

self.painter.paint_buffered_minus_and_plus_lines();
// In color_only mode, raw_line's structure shouldn't be changed.
// So it needs to avoid fn _handle_diff_header_header_line
// (it connects the plus_file and minus_file),
Expand Down Expand Up @@ -127,6 +128,7 @@ impl<'a> StateMachine<'a> {
));
self.current_file_pair = Some((self.minus_file.clone(), self.plus_file.clone()));

self.painter.paint_buffered_minus_and_plus_lines();
// In color_only mode, raw_line's structure shouldn't be changed.
// So it needs to avoid fn _handle_diff_header_header_line
// (it connects the plus_file and minus_file),
Expand Down
3 changes: 3 additions & 0 deletions src/paint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ impl<'p> Painter<'p> {
}

pub fn paint_buffered_minus_and_plus_lines(&mut self) {
if self.minus_lines.is_empty() && self.plus_lines.is_empty() {
return;
}
paint_minus_and_plus_lines(
MinusPlus::new(&self.minus_lines, &self.plus_lines),
&mut self.line_numbers_data,
Expand Down
30 changes: 30 additions & 0 deletions src/tests/test_example_diffs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,15 @@ mod tests {
);
}

#[test]
fn test_diff_unified_concatenated() {
// See #1002. Line buffers were not being flushed correctly, leading to material from first
// file last hunk appearing at beginning of second file first hunk.
DeltaTest::with_args(&[])
.with_input(DIFF_UNIFIED_CONCATENATED)
.expect_contains("\nLINES.\n\n1/y 2022-03-06");
}

#[test]
#[ignore] // Ideally, delta would make this test pass. See #121.
fn test_delta_ignores_non_diff_input() {
Expand Down Expand Up @@ -1875,6 +1884,27 @@ Only in b/: just_b
+This is different from a
";

const DIFF_UNIFIED_CONCATENATED: &str = "\
--- 1/x 2022-03-06 11:16:06.313403500 -0800
+++ 2/x 2022-03-06 11:18:14.083403500 -0800
@@ -1,5 +1,5 @@
This
-is
+IS
a
few
-lines.
+LINES.
--- 1/y 2022-03-06 11:16:44.483403500 -0800
+++ 2/y 2022-03-06 11:16:55.213403500 -0800
@@ -1,4 +1,4 @@
This
is
-another
+ANOTHER
test.
";

const NOT_A_DIFF_OUTPUT: &str = "\
Hello world
This is a regular file that contains:
Expand Down