# HG changeset patch # User Arseniy Alekseyev # Date 2024-04-16 16:21:37 # Node ID e4b9f8a74d5fd3832ecf984c3bcd79d6e481c0d1 # Parent 32ba01b5669d33b3d8b144df751aee3b58b486ab 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. diff --git a/rust/hg-core/src/filepatterns.rs b/rust/hg-core/src/filepatterns.rs --- a/rust/hg-core/src/filepatterns.rs +++ b/rust/hg-core/src/filepatterns.rs @@ -150,21 +150,21 @@ fn escape_pattern(pattern: &[u8]) -> Vec .collect() } -pub fn parse_pattern_syntax( +pub fn parse_pattern_syntax_kind( kind: &[u8], ) -> Result { 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(), )), diff --git a/rust/hg-core/src/lib.rs b/rust/hg-core/src/lib.rs --- a/rust/hg-core/src/lib.rs +++ b/rust/hg-core/src/lib.rs @@ -41,7 +41,7 @@ pub mod vfs; 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; diff --git a/rust/hg-cpython/src/dirstate/status.rs b/rust/hg-cpython/src/dirstate/status.rs --- a/rust/hg-cpython/src/dirstate/status.rs +++ b/rust/hg-cpython/src/dirstate/status.rs @@ -21,7 +21,7 @@ use hg::matchers::{ }; 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 @@ fn collect_kindpats( .iter(py)? .map(|k| { let k = k?; - let syntax = parse_pattern_syntax( - &[ - k.get_item(py, 0)?.extract::(py)?.data(py), - &b":"[..], - ] - .concat(), + let syntax = parse_pattern_syntax_kind( + k.get_item(py, 0)?.extract::(py)?.data(py), ) .map_err(|e| handle_fallback(py, StatusError::Pattern(e)))?; let pattern = k.get_item(py, 1)?.extract::(py)?;