Skip to content

diff: add -E/--ignore-tab-expansion support - #423

Open
yunusarda-sudo wants to merge 2 commits into
uutils:mainfrom
yunusarda-sudo:feat/ignore-tab-expansion
Open

yunusarda-sudo wants to merge 2 commits into
uutils:mainfrom
yunusarda-sudo:feat/ignore-tab-expansion

Conversation

@yunusarda-sudo

Copy link
Copy Markdown

GNU diff's -E / --ignore-tab-expansion treats two lines as equal when they match after expanding tabs. Previously, diffutils did not recognize -E and errored with exit code 2.

This PR implements -E / --ignore-tab-expansion:

  1. Adds ignore_tab_expansion: bool to Params and parses -E and --ignore-tab-expansion.
  2. Introduces ComparisonLine in utils.rs which wraps each line and precomputes expanded keys via expand_tabs_to_vec using existing terminal column calculation rules (accounting for custom --tabsize, carriage return, backspace, and wide CJK characters) when ignore_tab_expansion is enabled.
  3. Applies ComparisonLine across normal, unified, context, ed, and side-by-side diff formats.
  4. Adds unit and integration tests covering -E / --ignore-tab-expansion, -s identical files reporting, multiple formats, custom --tabsize, and control/wide character handling.

Fixes #408

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
@github-actions

Copy link
Copy Markdown

GNU diffutils testsuite comparison:

Test results comparison:
  Current:   TOTAL: 33 / PASSED: 21 / FAILED: 8 / SKIPPED: 4
  Reference: TOTAL: 33 / PASSED: 20 / FAILED: 9 / SKIPPED: 4

Changes from main branch:
  TOTAL: +0
  PASSED: +1
  FAILED: -1

Test improvements (1):
  + ignore-tab-expansion

Comment thread src/normal_diff.rs Outdated
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))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)?

Comment thread src/utils.rs Outdated
}
}

impl<'a> AsRef<[u8]> for ComparisonLine<'a> {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this AsRef used anywhere? same for the Clone derive

Comment thread src/utils.rs Outdated
#[derive(Clone, Debug)]
pub struct ComparisonLine<'a> {
pub raw: &'a [u8],
key: std::borrow::Cow<'a, [u8]>,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cow is already imported at the top of the file

Comment thread src/utils.rs Outdated
}

/// 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> {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this need to be pub and a separate function? it is only used in ComparisonLine::new

}

#[test]
fn ignore_tab_expansion() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@sylvestre

Copy link
Copy Markdown
Collaborator

Could you please verify the output of your LLM ?
it isn't great here :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

diff - -E / --ignore-tab-expansion is not implemented

2 participants