Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • mercurial/mercurial-devel
1 result
Show changes
Commits on Source (2)
  • Georges Racinet's avatar
    rust-filepatterns: export glob_to_re function · 406b413e3cf2
    Georges Racinet authored
    Making this function public should not risk freezing the internal API,
    and it can be useful for all downstream code that needs to perform
    glob matching against byte strings, such as RHGitaly where it will
    be useful to match on branches and tags.
    406b413e3cf2
  • Georges Racinet's avatar
    rust-matchers: raw regular expression builder · 5633de951d34
    Georges Racinet authored
    Extracting this `re_builder()` from `re_matcher()` makes it reusable
    in more general cases than matching `HgPath` instances and would
    help reducing code duplication in RHGitaly.
    5633de951d34
...@@ -73,7 +73,7 @@ ...@@ -73,7 +73,7 @@
} }
/// Transforms a glob pattern into a regex /// Transforms a glob pattern into a regex
fn glob_to_re(pat: &[u8]) -> Vec<u8> { pub fn glob_to_re(pat: &[u8]) -> Vec<u8> {
let mut input = pat; let mut input = pat;
let mut res: Vec<u8> = vec![]; let mut res: Vec<u8> = vec![];
let mut group_depth = 0; let mut group_depth = 0;
......
...@@ -737,6 +737,5 @@ ...@@ -737,6 +737,5 @@
} }
} }
/// Returns a function that matches an `HgPath` against the given regex /// Return a `RegexBuilder` from a bytes pattern
/// pattern.
/// ///
...@@ -742,9 +741,7 @@ ...@@ -742,9 +741,7 @@
/// ///
/// This can fail when the pattern is invalid or not supported by the /// This works around the fact that even if it works on byte haysacks,
/// underlying engine (the `regex` crate), for instance anything with /// [`regex::bytes::Regex`] still uses UTF-8 patterns.
/// back-references. pub fn re_bytes_builder(pattern: &[u8]) -> regex::bytes::RegexBuilder {
#[logging_timer::time("trace")]
fn re_matcher(pattern: &[u8]) -> PatternResult<RegexMatcher> {
use std::io::Write; use std::io::Write;
// The `regex` crate adds `.*` to the start and end of expressions if there // The `regex` crate adds `.*` to the start and end of expressions if there
...@@ -764,7 +761,18 @@ ...@@ -764,7 +761,18 @@
// # Safety // # Safety
// This is safe because we escaped all non-ASCII bytes. // This is safe because we escaped all non-ASCII bytes.
let pattern_string = unsafe { String::from_utf8_unchecked(escaped_bytes) }; let pattern_string = unsafe { String::from_utf8_unchecked(escaped_bytes) };
let re = regex::bytes::RegexBuilder::new(&pattern_string) regex::bytes::RegexBuilder::new(&pattern_string)
}
/// Returns a function that matches an `HgPath` against the given regex
/// pattern.
///
/// This can fail when the pattern is invalid or not supported by the
/// underlying engine (the `regex` crate), for instance anything with
/// back-references.
#[logging_timer::time("trace")]
fn re_matcher(pattern: &[u8]) -> PatternResult<RegexMatcher> {
let re = re_bytes_builder(pattern)
.unicode(false) .unicode(false)
// Big repos with big `.hgignore` will hit the default limit and // Big repos with big `.hgignore` will hit the default limit and
// incur a significant performance hit. One repo's `hg status` hit // incur a significant performance hit. One repo's `hg status` hit
......