match: simplify the rust-side file pattern kind parsing
authorArseniy Alekseyev <aalekseyev@janestreet.com>
Tue, 16 Apr 2024 17:21:37 +0100
changeset 51605 e4b9f8a74d5f
parent 51604 32ba01b5669d
child 51606 55e7784eb3bc
match: simplify the rust-side file pattern kind parsing There's no need to add the ':' characters if we're simply pattern matching against constants next.
rust/hg-core/src/filepatterns.rs
rust/hg-core/src/lib.rs
rust/hg-cpython/src/dirstate/status.rs
--- a/rust/hg-core/src/filepatterns.rs	Tue Apr 16 13:51:45 2024 +0100
+++ b/rust/hg-core/src/filepatterns.rs	Tue Apr 16 17:21:37 2024 +0100
@@ -150,21 +150,21 @@
         .collect()
 }
 
-pub fn parse_pattern_syntax(
+pub fn parse_pattern_syntax_kind(
     kind: &[u8],
 ) -> Result<PatternSyntax, PatternError> {
     match kind {
-        b"re:" => Ok(PatternSyntax::Regexp),
-        b"path:" => Ok(PatternSyntax::Path),
-        b"filepath:" => Ok(PatternSyntax::FilePath),
-        b"relpath:" => Ok(PatternSyntax::RelPath),
-        b"rootfilesin:" => Ok(PatternSyntax::RootFilesIn),
-        b"relglob:" => Ok(PatternSyntax::RelGlob),
-        b"relre:" => Ok(PatternSyntax::RelRegexp),
-        b"glob:" => Ok(PatternSyntax::Glob),
-        b"rootglob:" => Ok(PatternSyntax::RootGlob),
-        b"include:" => Ok(PatternSyntax::Include),
-        b"subinclude:" => Ok(PatternSyntax::SubInclude),
+        b"re" => Ok(PatternSyntax::Regexp),
+        b"path" => Ok(PatternSyntax::Path),
+        b"filepath" => Ok(PatternSyntax::FilePath),
+        b"relpath" => Ok(PatternSyntax::RelPath),
+        b"rootfilesin" => Ok(PatternSyntax::RootFilesIn),
+        b"relglob" => Ok(PatternSyntax::RelGlob),
+        b"relre" => Ok(PatternSyntax::RelRegexp),
+        b"glob" => Ok(PatternSyntax::Glob),
+        b"rootglob" => Ok(PatternSyntax::RootGlob),
+        b"include" => Ok(PatternSyntax::Include),
+        b"subinclude" => Ok(PatternSyntax::SubInclude),
         _ => Err(PatternError::UnsupportedSyntax(
             String::from_utf8_lossy(kind).to_string(),
         )),
--- a/rust/hg-core/src/lib.rs	Tue Apr 16 13:51:45 2024 +0100
+++ b/rust/hg-core/src/lib.rs	Tue Apr 16 17:21:37 2024 +0100
@@ -41,7 +41,7 @@
 
 use crate::utils::hg_path::{HgPathBuf, HgPathError};
 pub use filepatterns::{
-    parse_pattern_syntax, read_pattern_file, IgnorePattern,
+    parse_pattern_syntax_kind, read_pattern_file, IgnorePattern,
     PatternFileWarning, PatternSyntax,
 };
 use std::collections::HashMap;
--- a/rust/hg-cpython/src/dirstate/status.rs	Tue Apr 16 13:51:45 2024 +0100
+++ b/rust/hg-cpython/src/dirstate/status.rs	Tue Apr 16 17:21:37 2024 +0100
@@ -21,7 +21,7 @@
 };
 use hg::{
     matchers::{AlwaysMatcher, FileMatcher, IncludeMatcher},
-    parse_pattern_syntax,
+    parse_pattern_syntax_kind,
     utils::{
         files::{get_bytes_from_path, get_path_from_bytes},
         hg_path::{HgPath, HgPathBuf},
@@ -162,12 +162,8 @@
         .iter(py)?
         .map(|k| {
             let k = k?;
-            let syntax = parse_pattern_syntax(
-                &[
-                    k.get_item(py, 0)?.extract::<PyBytes>(py)?.data(py),
-                    &b":"[..],
-                ]
-                .concat(),
+            let syntax = parse_pattern_syntax_kind(
+                k.get_item(py, 0)?.extract::<PyBytes>(py)?.data(py),
             )
             .map_err(|e| handle_fallback(py, StatusError::Pattern(e)))?;
             let pattern = k.get_item(py, 1)?.extract::<PyBytes>(py)?;