changeset 49604:086b0c4f8663 stable

matcher: fix the issue with regex inline-flag in rust oo Same problem same solution.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 16 Nov 2022 16:38:42 +0100
parents 3eda36e9b3d6
children b3480822a251
files rust/hg-core/src/filepatterns.rs tests/test-hgignore.t
diffstat 2 files changed, 52 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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()),
+        );
+    }
 }
--- 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