Skip to content

diff: add -E/--ignore-tab-expansion - #414

Open
Xnadir wants to merge 2 commits into
uutils:mainfrom
Xnadir:diff-ignore-tab-expansion
Open

Xnadir wants to merge 2 commits into
uutils:mainfrom
Xnadir:diff-ignore-tab-expansion

Conversation

@Xnadir

@Xnadir Xnadir commented Nov 17, 2026

Copy link
Copy Markdown

Refs #408. Stacked on #413 (-i), whose commit this branch includes.

diff -E / --ignore-tab-expansion failed with unrecognized option. It now compares lines after expanding their tabs, so a<TAB>b matches a plus spaces up to the next tab stop and b.

#413's diff_lines helper now takes a small LineCompare (ignore_case, plus the tab size when -E is given) in place of the ignore_case flag. Its key expands tabs with the existing do_expand_tabs, then folds case for -i. So -E honours --tabsize, combines with -i, and counts wide characters the same way -t output does. The backspace and carriage-return column rules mentioned in the issue come from do_expand_tabs too, so -E will follow them once #384 lands. That is why this says "Refs" rather than "Closes".

Tests: the issue's case with -E and --ignore-tab-expansion in the normal, -u, -c, -e and -q formats (and still different without the option), and -E --tabsize=4 -i. They fail without the change. I checked these cases against GNU diff 3.12.

AI disclosure: written with help from Claude Code.

🤖 Generated with Claude Code

Xnadir and others added 2 commits November 17, 2026 21:11
Closes uutils#406

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Refs uutils#408

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 17, 2026 16:16

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@github-actions

Copy link
Copy Markdown

GNU diffutils testsuite comparison:

Test results comparison:
  Current:   TOTAL: 33 / PASSED: 20 / FAILED: 9 / SKIPPED: 4
  Reference: TOTAL: 33 / PASSED: 19 / FAILED: 10 / SKIPPED: 4

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

Test improvements (1):
  + ignore-case

Comment thread src/utils.rs
let mut key = line.to_vec();
if let Some(tabsize) = self.tab_expansion {
let mut expanded = Vec::with_capacity(line.len());
// Writing to a Vec cannot fail, short of an absurd tab size.

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.

with a huge --tabsize (we accept up to isize::MAX - 3), the Vec doesn't return an error, it aborts on allocation
diff -E --tabsize=1000000000000 a b with a tab should crash, no?
could the key store the column reached at each tab instead of materializing the spaces?
please add a test with a huge tabsize too

Comment thread src/utils.rs
}
if self.ignore_case {
key = match std::str::from_utf8(&key) {
Ok(text) if !is_posix_locale("LC_CTYPE") => text.to_lowercase().into_bytes(),

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_posix_locale reads the env for every line, could it be computed once in from_params?

Comment thread src/params.rs
params.ignore_case = true;
continue;
}
if param == "-E" || param == "--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 parse test for -E / --ignore-tab-expansion like the -t one

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.

3 participants