##// END OF EJS Templates
match: simplify the rust-side file pattern kind parsing...
Arseniy Alekseyev -
r52498:e4b9f8a7 default
parent child Browse files
Show More
@@ -150,21 +150,21 b' fn escape_pattern(pattern: &[u8]) -> Vec'
150 .collect()
150 .collect()
151 }
151 }
152
152
153 pub fn parse_pattern_syntax(
153 pub fn parse_pattern_syntax_kind(
154 kind: &[u8],
154 kind: &[u8],
155 ) -> Result<PatternSyntax, PatternError> {
155 ) -> Result<PatternSyntax, PatternError> {
156 match kind {
156 match kind {
157 b"re:" => Ok(PatternSyntax::Regexp),
157 b"re" => Ok(PatternSyntax::Regexp),
158 b"path:" => Ok(PatternSyntax::Path),
158 b"path" => Ok(PatternSyntax::Path),
159 b"filepath:" => Ok(PatternSyntax::FilePath),
159 b"filepath" => Ok(PatternSyntax::FilePath),
160 b"relpath:" => Ok(PatternSyntax::RelPath),
160 b"relpath" => Ok(PatternSyntax::RelPath),
161 b"rootfilesin:" => Ok(PatternSyntax::RootFilesIn),
161 b"rootfilesin" => Ok(PatternSyntax::RootFilesIn),
162 b"relglob:" => Ok(PatternSyntax::RelGlob),
162 b"relglob" => Ok(PatternSyntax::RelGlob),
163 b"relre:" => Ok(PatternSyntax::RelRegexp),
163 b"relre" => Ok(PatternSyntax::RelRegexp),
164 b"glob:" => Ok(PatternSyntax::Glob),
164 b"glob" => Ok(PatternSyntax::Glob),
165 b"rootglob:" => Ok(PatternSyntax::RootGlob),
165 b"rootglob" => Ok(PatternSyntax::RootGlob),
166 b"include:" => Ok(PatternSyntax::Include),
166 b"include" => Ok(PatternSyntax::Include),
167 b"subinclude:" => Ok(PatternSyntax::SubInclude),
167 b"subinclude" => Ok(PatternSyntax::SubInclude),
168 _ => Err(PatternError::UnsupportedSyntax(
168 _ => Err(PatternError::UnsupportedSyntax(
169 String::from_utf8_lossy(kind).to_string(),
169 String::from_utf8_lossy(kind).to_string(),
170 )),
170 )),
@@ -41,7 +41,7 b' pub mod vfs;'
41
41
42 use crate::utils::hg_path::{HgPathBuf, HgPathError};
42 use crate::utils::hg_path::{HgPathBuf, HgPathError};
43 pub use filepatterns::{
43 pub use filepatterns::{
44 parse_pattern_syntax, read_pattern_file, IgnorePattern,
44 parse_pattern_syntax_kind, read_pattern_file, IgnorePattern,
45 PatternFileWarning, PatternSyntax,
45 PatternFileWarning, PatternSyntax,
46 };
46 };
47 use std::collections::HashMap;
47 use std::collections::HashMap;
@@ -21,7 +21,7 b' use hg::matchers::{'
21 };
21 };
22 use hg::{
22 use hg::{
23 matchers::{AlwaysMatcher, FileMatcher, IncludeMatcher},
23 matchers::{AlwaysMatcher, FileMatcher, IncludeMatcher},
24 parse_pattern_syntax,
24 parse_pattern_syntax_kind,
25 utils::{
25 utils::{
26 files::{get_bytes_from_path, get_path_from_bytes},
26 files::{get_bytes_from_path, get_path_from_bytes},
27 hg_path::{HgPath, HgPathBuf},
27 hg_path::{HgPath, HgPathBuf},
@@ -162,12 +162,8 b' fn collect_kindpats('
162 .iter(py)?
162 .iter(py)?
163 .map(|k| {
163 .map(|k| {
164 let k = k?;
164 let k = k?;
165 let syntax = parse_pattern_syntax(
165 let syntax = parse_pattern_syntax_kind(
166 &[
166 k.get_item(py, 0)?.extract::<PyBytes>(py)?.data(py),
167 k.get_item(py, 0)?.extract::<PyBytes>(py)?.data(py),
168 &b":"[..],
169 ]
170 .concat(),
171 )
167 )
172 .map_err(|e| handle_fallback(py, StatusError::Pattern(e)))?;
168 .map_err(|e| handle_fallback(py, StatusError::Pattern(e)))?;
173 let pattern = k.get_item(py, 1)?.extract::<PyBytes>(py)?;
169 let pattern = k.get_item(py, 1)?.extract::<PyBytes>(py)?;
General Comments 0
You need to be logged in to leave comments. Login now