Repository navigation
Conversation
4becade to
571d3a2
Compare
Merging this PR will improve performance by 57.88%Warning uutils has exceeded the Hobby plan limit of 5 active contributors. Upgrade your plan or apply to the open source program by December 8, 2026 to keep using CodSpeed. 2 warnings
Performance Changes
Tip Curious why performance improved? Comment Comparing |
Oh no... |
| fancy-regex = { version = "0.19.2", default-features = false, features = ["std", "unicode"] } | ||
| regex = "1.12" | ||
| uucore = { version = "0.10.0", features = ["entries", "fs", "fsext", "mode"] } | ||
| uucore = { git = "https://github.com/wtcpython/coreutils.git", branch = "uucore-regex", features = ["entries", "fs", "fsext", "mode", "regex"] } |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
70d7f30 to
671b7ca
Compare
|
Commit 70d7f30 has test result changes: bfs testsuite: |
|
the ci is red :) |
| RegexType::PosixBasic => Syntax::posix_basic(), | ||
| RegexType::PosixExtended => Syntax::posix_extended(), | ||
| // GNU find's -regex does full-path matching, so anchor the pattern. | ||
| let anchored = if pattern.starts_with('^') && pattern.ends_with('$') { |
There was a problem hiding this comment.
anchoring by concatenation breaks alternation: a|b becomes ^a|b$, which means ^a or b$. please wrap it instead, something like ^(?:{pattern})$
| } else if pattern.ends_with('$') { | ||
| format!("^{pattern}") | ||
| } else { | ||
| format!("^{pattern}$") |
There was a problem hiding this comment.
this changes -regex/-name matching semantics, please add tests in tests/test_find.rs (alternation, ^/$ in the middle, -iregex, each -regextype)
| fn matches(&self, file_info: &WalkEntry, _: &mut MatcherIO) -> bool { | ||
| self.regex | ||
| .is_match(file_info.path().to_string_lossy().as_ref()) | ||
| .unwrap_or(false) |
There was a problem hiding this comment.
unwrap_or(false) silently turns a backtrack-limit error into "no match", is that what we want?
| } | ||
|
|
||
| match chars.next() { | ||
| Some(c) if "(){}|+?".contains(c) => output.push(c), |
There was a problem hiding this comment.
in emacs syntax a bare | is a literal and only \| is alternation, so | needs to be escaped in the other branch. the doc comment above says the opposite
| // so anchor the regex to prevent partial matches. | ||
| let anchored = format!("^{r}$"); | ||
| regex_transpile::compile(&anchored, super::regex::RegexType::PosixBasic, caseless) | ||
| .unwrap() |
There was a problem hiding this comment.
unwrap() on a user-supplied pattern, could you please propagate the error? the "should never fail" comment was true for parse_bre, not for the new transpiler
671b7ca to
097a4d1
Compare
097a4d1 to
6e93bd7
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #864 +/- ##
==========================================
+ Coverage 92.29% 92.42% +0.12%
==========================================
Files 38 40 +2
Lines 8714 9223 +509
Branches 429 480 +51
==========================================
+ Hits 8043 8524 +481
- Misses 532 543 +11
- Partials 139 156 +17 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
6e93bd7 to
0695864
Compare
| // For the full copyright and license information, please view the LICENSE | ||
| // file that was distributed with this source code. | ||
|
|
||
| //! Unified regular expression infrastructure for uutils. |
There was a problem hiding this comment.
this module doc does not match this crate, please make it shorter
| @@ -23,7 +23,7 @@ chrono = "0.4.45" | |||
| clap = { version = "4.6", features = ["env"] } | |||
| faccess = "0.2.4" | |||
| nix = { version = "0.31", features = ["fs", "user"] } | |||
There was a problem hiding this comment.
codspeed shows about 30% slower, which is way above what we accept.
do you know where it comes from? leftmost_longest?
There was a problem hiding this comment.
N.B. fancy-regex 0.20.0 was just released which contains a performance improvement for leftmost longest among a few others, in case it helps
| } | ||
|
|
||
| if parse_bre(&expr, RegexOptions::REGEX_OPTION_NONE).is_ok() { | ||
| if bre_to_ere(&expr, false).is_ok_and(|re| Regex::new(&re).is_ok()) { |
There was a problem hiding this comment.
why not regex_transpile::compile(&expr, RegexType::PosixBasic, false).is_ok()? here it is built without the same builder options
| self.regex.as_ref().is_some_and(|r| r.is_match(string)) | ||
| self.regex | ||
| .as_ref() | ||
| .is_some_and(|r| r.is_match(string).unwrap_or(false)) |
There was a problem hiding this comment.
same question as for -regex: the error is silently turned into "no match" here
| let anchored = match regex_type { | ||
| RegexType::PosixExtended => format!("^(?:{pattern})$"), | ||
| RegexType::Emacs | RegexType::PosixBasic | RegexType::Grep => { | ||
| format!(r"^\({pattern}\)$") |
There was a problem hiding this comment.
this adds a capture group, so backrefs are shifted: \(a\)\1 becomes ^\(\(a\)\1\)$ and \1 now points to the outer group.
could you please anchor after transpiling instead, with ^(?:...)$ in compile()? glob.rs could use it too.
and please add a test with a backref
0695864 to
add13e3
Compare
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
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.
add13e3 to
c67cfd3
Compare
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
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.
|
Commit c67cfd3 has test result changes: bfs testsuite: |
|
hi, this one can't be merged as it is:
|
c67cfd3 to
4647195
Compare
This comment was marked as resolved.
This comment was marked as resolved.
4647195 to
e5f8fe1
Compare
|
thanks for tackling this! |
e5f8fe1 to
675538c
Compare
675538c to
d3c0604
Compare
| /// | ||
| /// If `anchored` is `true`, the pattern is implicitly anchored at the start (`^`), as required by POSIX `expr`. | ||
| /// Otherwise, standard unanchored BRE transpilation is performed (e.g. for `grep` and `sed`). | ||
| pub fn bre_to_ere(pattern_str: &str, anchored: bool) -> Result<String, RegexError> { |
There was a problem hiding this comment.
anchored is always false in this crate, do we need it?
the doc here (and on check_posix_regex_errors) still talks about expr, grep, sed and GNU coreutils
| { | ||
| Ok(matched) => matched, | ||
| Err(e) => { | ||
| let _ = writeln!(&mut stderr(), "find: {e}"); |
There was a problem hiding this comment.
please use program_name() instead of a hardcoded find:, same in glob.rs
| } else if "(){}|".contains(ch) { | ||
| output.push('\\'); | ||
| } | ||
| output.push(ch); |
There was a problem hiding this comment.
what happens with -regex '*foo' in emacs syntax (the default)? bre_to_ere escapes a leading *, this doesn't
same question for emacs \`` and '`
please add a test
d3c0604 to
a6ded96
Compare
|
Commit a6ded96 has test result changes: bfs testsuite: |
|
i guess you saw - gnu/regextype_emacs |
|
thanks for picking this up! |
|
|
||
| while let Some(ch) = chars.next() { | ||
| if in_bracket { | ||
| if ch == ']' && !output.ends_with(['[', '^']) { |
There was a problem hiding this comment.
in emacs syntax a backslash is literal inside brackets, so [\] should match a \. here it goes through as is and fancy-regex reads it as an escape (unclosed class)
also ends_with(['[', '^']) looks at the output, so [a^] or [[] never close the bracket and the rest is left untranspiled
please add tests, could it be what breaks gnu/regextype_emacs?
| prev_is_escaped = false; | ||
| continue; | ||
| } | ||
| if curr == ']' && !curr_is_escaped && re_string != "[" && re_string != "[^" { |
There was a problem hiding this comment.
this keeps the backslash as an escape inside brackets. glob needs that but -regex does not: -regextype posix-basic -regex '.*[\]' used to match a trailing \ and now fails to compile.
onig only enabled it for globs (SYNTAX_BEHAVIOR_BACKSLASH_ESCAPE_IN_CC), could you please make it an option of compile()?
| let transpiled = match regex_type { | ||
| RegexType::PosixBasic | RegexType::Grep => bre_to_ere(pattern)?, | ||
| RegexType::Emacs => transpile_emacs(pattern), | ||
| RegexType::PosixExtended => pattern.to_owned(), |
There was a problem hiding this comment.
posix-extended is passed as is, so it has the same [\] problem, and fancy-regex extensions like (?=...) are accepted too. is that ok?
| patterns.iter().any(|s| entry.contains(s.as_str())) | ||
| } | ||
| Self::Regex(v) => v.iter().any(|r| r.find(entry).is_some()), | ||
| Self::Regex(v) => v.iter().any(|r| r.is_match(entry).unwrap_or(false)), |
There was a problem hiding this comment.
same as for find: a matching error silently becomes "no match" here (and in all() below)
Closes #212