changeset 51605:e4b9f8a74d5f

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.
author Arseniy Alekseyev <aalekseyev@janestreet.com>
date Tue, 16 Apr 2024 17:21:37 +0100
parents 32ba01b5669d
children 55e7784eb3bc
files rust/hg-core/src/filepatterns.rs rust/hg-core/src/lib.rs rust/hg-cpython/src/dirstate/status.rs
diffstat 3 files changed, 16 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- 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)?;