Repository navigation
diff: add -B/--ignore-blank-lines - #419
yunusarda-sudo wants to merge 2 commits into
Conversation
| /// Returns true if a line contains only ASCII spaces, tabs or carriage returns, or is empty. | ||
| #[inline] | ||
| pub fn is_blank_line(line: &[u8]) -> bool { | ||
| line.iter().all(|&c| c == b' ' || c == b'\t' || c == b'\r') |
There was a problem hiding this comment.
GNU -B only ignores empty lines, unless -b or -w is given too (see info diff, "Blank Lines").
with this, a\n \nb\n vs a\nb\n exits 0, GNU exits 1.
please add a test for it
| .lines | ||
| .iter() | ||
| .any(|l| matches!(l, DiffLine::MissingNL)); | ||
| if has_missing_nl { |
There was a problem hiding this comment.
this also matches the MissingNL after a common last context line.
printf 'a\n\nb' vs printf 'a\nb' with -u -B prints a hunk, but the normal format prints nothing.
same in context_diff.rs. please add a test
| let expected_blank = mismatch.expected.iter().all(|l| is_blank_line(l)); | ||
| let actual_blank = mismatch.actual.iter().all(|l| is_blank_line(l)); | ||
| let missing_nl = mismatch.expected_missing_nl || mismatch.actual_missing_nl; | ||
| !(expected_blank && actual_blank && !missing_nl) |
There was a problem hiding this comment.
once blank means empty, can this missing_nl case still happen?
it isn't checked in ed_diff.rs either
| DiffLine::Context(_) => false, | ||
| }); | ||
| expected_has_non_blank || actual_has_non_blank | ||
| }); |
There was a problem hiding this comment.
almost the same filter 4 times, could it be a shared helper in utils.rs?
| at.write("a", "a\n\nb\n"); | ||
| at.write("b", "a\nb\n"); | ||
| for option in ["-B", "--ignore-blank-lines"] { | ||
| for format in [&[][..], &["-u"], &["-c"], &["-e"], &["-q"]] { |
There was a problem hiding this comment.
what about -y? -B is silently ignored there.
please also add a test where a blank change and a real change are in the same hunk
- restrict is_blank_line to empty lines matching GNU diff behavior
- extract has_non_blank_lines shared helper in utils.rs, deduplicating filter across normal, unified, context, and ed diffs
- fix missing newline handling at EOF for common context lines under -u and -c
- support -B in side-by-side (-y) diff format with '(' and ')' gutter markers
- add regression tests for whitespace lines, trailing missing-newline context, mixed blank/real changes, and side-by-side format
Add
-B/--ignore-blank-linesto ignore changes that consist entirely of inserted or deleted blank lines across normal, unified, context, and ed output formats.Closes #407