# HG changeset patch # User Pierre-Yves David # Date 1668613122 -3600 # Node ID 086b0c4f86632ff0ff355dad24f83cf968fddeaf # Parent 3eda36e9b3d6fa45b458f9a20448980d491dc342 matcher: fix the issue with regex inline-flag in rust oo Same problem same solution. diff -r 3eda36e9b3d6 -r 086b0c4f8663 rust/hg-core/src/filepatterns.rs --- a/rust/hg-core/src/filepatterns.rs Wed Nov 16 13:05:01 2022 +0100 +++ b/rust/hg-core/src/filepatterns.rs Wed Nov 16 16:38:42 2022 +0100 @@ -171,6 +171,10 @@ } } +lazy_static! { + static ref FLAG_RE: Regex = Regex::new(r"^\(\?[aiLmsux]+\)").unwrap(); +} + /// Builds the regex that corresponds to the given pattern. /// If within a `syntax: regexp` context, returns the pattern, /// otherwise, returns the corresponding regex. @@ -193,7 +197,22 @@ { return pattern.to_owned(); } - [&b".*"[..], pattern].concat() + match FLAG_RE.find(pattern) { + Some(mat) => { + let s = mat.start(); + let e = mat.end(); + [ + &b"(?"[..], + &pattern[s + 2..e - 1], + &b":"[..], + &b".*"[..], + &pattern[e..], + &b")"[..], + ] + .concat() + } + None => [&b".*"[..], pattern].concat(), + } } PatternSyntax::Path | PatternSyntax::RelPath => { if pattern == b"." { @@ -703,4 +722,35 @@ Some(br"[^/]*\.o(?:/|$)".to_vec()), ); } + + #[test] + fn test_build_single_relregex() { + assert_eq!( + build_single_regex(&IgnorePattern::new( + PatternSyntax::RelRegexp, + b"^ba{2}r", + Path::new("") + )) + .unwrap(), + Some(b"^ba{2}r".to_vec()), + ); + assert_eq!( + build_single_regex(&IgnorePattern::new( + PatternSyntax::RelRegexp, + b"ba{2}r", + Path::new("") + )) + .unwrap(), + Some(b".*ba{2}r".to_vec()), + ); + assert_eq!( + build_single_regex(&IgnorePattern::new( + PatternSyntax::RelRegexp, + b"(?ia)ba{2}r", + Path::new("") + )) + .unwrap(), + Some(b"(?ia:.*ba{2}r)".to_vec()), + ); + } } diff -r 3eda36e9b3d6 -r 086b0c4f8663 tests/test-hgignore.t --- a/tests/test-hgignore.t Wed Nov 16 13:05:01 2022 +0100 +++ b/tests/test-hgignore.t Wed Nov 16 16:38:42 2022 +0100 @@ -90,8 +90,7 @@ $ echo 're:.HGIGNORE' >> .hgignore $ hg status A dir/b.o - ? .hgignore (no-rust !) - ? .hgignore (rust missing-correct-output !) + ? .hgignore ? a.c ? syntax