Repository navigation
diff: add -E/--ignore-tab-expansion support - #423
yunusarda-sudo wants to merge 2 commits into
Conversation
GNU diff's -E / --ignore-tab-expansion treats two lines as equal when they match after tab expansion. uutils previously failed with unrecognized option '-E'. Implement -E / --ignore-tab-expansion across all diff formats by wrapping comparison lines in ComparisonLine, expanding tabs using the existing terminal column rules (honoring tabsize, carriage return, backspace, and wide characters) when the flag is enabled. Fixes uutils#408
|
GNU diffutils testsuite comparison: |
| let mut actual_lines: Vec<&[u8]> = actual.split(|&c| c == b'\n').collect(); | ||
| let mut expected_lines: Vec<ComparisonLine> = expected | ||
| .split(|&c| c == b'\n') | ||
| .map(|line| ComparisonLine::new(line, params.ignore_tab_expansion, params.tabsize)) |
There was a problem hiding this comment.
the same split + map block is now copied 10 times across 5 modules.
could you please add a helper in utils.rs, e.g. ComparisonLine::split_lines(text, params)?
| } | ||
| } | ||
|
|
||
| impl<'a> AsRef<[u8]> for ComparisonLine<'a> { |
There was a problem hiding this comment.
is this AsRef used anywhere? same for the Clone derive
| #[derive(Clone, Debug)] | ||
| pub struct ComparisonLine<'a> { | ||
| pub raw: &'a [u8], | ||
| key: std::borrow::Cow<'a, [u8]>, |
There was a problem hiding this comment.
Cow is already imported at the top of the file
| } | ||
|
|
||
| /// Returns the line with tabs expanded according to `tabsize` and terminal column rules. | ||
| pub fn expand_tabs_to_vec(line: &[u8], tabsize: usize) -> Vec<u8> { |
There was a problem hiding this comment.
does this need to be pub and a separate function? it is only used in ComparisonLine::new
| } | ||
|
|
||
| #[test] | ||
| fn ignore_tab_expansion() { |
There was a problem hiding this comment.
please add a test where the files really differ under -E (for example -u with a tab-equivalent context line), checking that the original tabs are what gets printed
|
Could you please verify the output of your LLM ? |
…e, and add differing files test
GNU diff's
-E/--ignore-tab-expansiontreats two lines as equal when they match after expanding tabs. Previously,diffutilsdid not recognize-Eand errored with exit code 2.This PR implements
-E/--ignore-tab-expansion:ignore_tab_expansion: booltoParamsand parses-Eand--ignore-tab-expansion.ComparisonLineinutils.rswhich wraps each line and precomputes expanded keys viaexpand_tabs_to_vecusing existing terminal column calculation rules (accounting for custom--tabsize, carriage return, backspace, and wide CJK characters) whenignore_tab_expansionis enabled.ComparisonLineacross normal, unified, context, ed, and side-by-side diff formats.-E/--ignore-tab-expansion,-sidentical files reporting, multiple formats, custom--tabsize, and control/wide character handling.Fixes #408