Skip to content

diff: add -i/--ignore-case support - #421

Open
yunusarda-sudo wants to merge 2 commits into
uutils:mainfrom
yunusarda-sudo:diff-ignore-case
Open

yunusarda-sudo wants to merge 2 commits into
uutils:mainfrom
yunusarda-sudo:diff-ignore-case

Conversation

@yunusarda-sudo

Copy link
Copy Markdown

Implement -i / --ignore-case and --no-ignore-case to ignore letter case during line comparisons, supporting both ASCII and Unicode case folding in UTF-8 locales.

Closes #406

@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

@sylvestre

Copy link
Copy Markdown
Collaborator

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

thanks for working on this!
-i currently pays for a UTF-8 check and lowercasing on every line comparison, and it ignores the locale (see inline).
The format tests only cover identical files; please add one with an actual hunk.

Comment thread src/utils.rs Outdated
if a == b {
return true;
}
if let (Ok(sa), Ok(sb)) = (std::str::from_utf8(a), std::str::from_utf8(b)) {

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.

diff::slice compares lines O(n*m) times, so this runs from_utf8 + to_lowercase on every comparison.
could we fold each line once up front instead?
please check with cargo bench on a large file with -i

Comment thread src/utils.rs Outdated
if a == b {
return true;
}
if let (Ok(sa), Ok(sb)) = (std::str::from_utf8(a), std::str::from_utf8(b)) {

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 LC_ALL=C, GNU only folds ASCII, no?
should this depend on the locale, like is_posix_locale?

Comment thread src/utils.rs Outdated
}
}

impl<'a> AsRef<[u8]> for DiffLineRef<'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?

Comment thread src/unified_diff.rs Outdated

let mut expected_lines: Vec<&[u8]> = expected.split(|&c| c == b'\n').collect();
let mut actual_lines: Vec<&[u8]> = actual.split(|&c| c == b'\n').collect();
let mut expected_lines: Vec<DiffLineRef> = expected

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 copied 8 times across the formats, could be a helper in utils.rs, no?

Comment thread src/unified_diff.rs
mismatch.lines.push(DiffLine::Context(str1.to_vec()));
} else if context_size > 0 {
context_queue.push_back(str);
context_queue.push_back(str1.raw);

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.

context lines are printed from the first file here, does it match GNU output?
please add a test with a real hunk where the context lines differ only in case

.args(&["-i", "-e", "i1", "i2"])
.succeeds()
.stdout_is("");
ts.ucmd().args(&["-i", "-y", "i1", "i2"]).succeeds();

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 check the output too

…X locale, dedup line splitting, and test context lines
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

2 participants