Skip to content

diff: add -i/--ignore-case - #413

Open
Xnadir wants to merge 1 commit into
uutils:mainfrom
Xnadir:diff-ignore-case
Open

Xnadir wants to merge 1 commit into
uutils:mainfrom
Xnadir:diff-ignore-case

Conversation

@Xnadir

@Xnadir Xnadir commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Closes #406

diff -i / --ignore-case failed with unrecognized option. It now compares lines with their case folded and prints the original lines.

Rebased on main, it builds on the ComparisonLine comparison key that came with -E: with -i the key is also case folded, so every format (normal, -u, -c, -e, -q, -y) and -i -E together get it without touching the formatters. Folding uses to_lowercase for UTF-8 lines, except in the C/POSIX locale (checked with the existing is_posix_locale("LC_CTYPE")), where only ASCII letters fold, as in GNU diff. -q and the exit status come from the same comparison, so case-only differences count as identical.

Tests: the issue's Funky Stuff / fUNKy stuFf with -i and --ignore-case in the normal, -u, -c, -e and -q formats (and still different without -i), side by side output as one common line, a file that differs in more than case, -i -E together, and the non-ASCII case (AĀΑ-Δ vs aāα-δ), equal under LC_ALL=C.UTF-8 and different under LC_ALL=C. Checked against GNU diff 3.12. cargo test: all pass.

AI disclosure: written with help from Claude Code.

🤖 Generated with Claude Code

Copilot AI balanced review requested due to automatic review settings November 17, 2026 16:11

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

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

GNU diffutils testsuite comparison:

Test results comparison:
  Current:   TOTAL: 33 / PASSED: 22 / FAILED: 7 / SKIPPED: 4
  Reference: TOTAL: 33 / PASSED: 21 / FAILED: 8 / SKIPPED: 4

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

Test improvements (1):
  + ignore-case

Comment thread src/utils.rs Outdated
ignore_case: bool,
) -> Vec<diff::Result<&'a [u8]>> {
if !ignore_case {
return diff::slice(left, right)

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.

do we need to copy the whole result vector when -i isn't passed?
if diff_lines returned diff::Result<&'b &'a [u8]> (&left[i - 1] in the -i branch), this could just be return diff::slice(left, right); and the default path stays as cheap as before


#[rstest]
fn ignore_case(
#[values(&[][..], &["-u"], &["-c"], &["-e"], &["-q"])] format: &[&str],

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 -y too, side_diff.rs is changed as well

Comment thread src/utils.rs Outdated
let posix = is_posix_locale("LC_CTYPE");
let fold = |line: &&[u8]| -> Vec<u8> {
match std::str::from_utf8(line) {
Ok(text) if !posix => 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.

str::to_lowercase applies the final sigma rule (Σ at the end of a word becomes ς), so ΟΔΟΣ and οδοσ differ with -i.
should it fold char by char instead (chars().flat_map(char::to_lowercase))?

@sylvestre

Copy link
Copy Markdown
Collaborator

it has been conflicting for more than 7 days, sorry! please rebase it

Closes uutils#406

Compare lines through ComparisonLine with their case folded (all letters
in a UTF-8 locale, ASCII letters in the POSIX locale, as GNU diff does),
so every output format and -E combine with it.

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

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.

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 - -i / --ignore-case is not implemented

3 participants