9 //! `hg-core` crate. From Python, this will be seen as |
9 //! `hg-core` crate. From Python, this will be seen as |
10 //! `rustext.dirstate.status`. |
10 //! `rustext.dirstate.status`. |
11 |
11 |
12 use crate::{dirstate::DirstateMap, exceptions::FallbackError}; |
12 use crate::{dirstate::DirstateMap, exceptions::FallbackError}; |
13 use cpython::{ |
13 use cpython::{ |
14 exc::ValueError, ObjectProtocol, PyBytes, PyErr, PyList, PyObject, |
14 exc::ValueError, ObjectProtocol, PyBool, PyBytes, PyErr, PyList, PyObject, |
15 PyResult, PyTuple, Python, PythonObject, ToPyObject, |
15 PyResult, PyTuple, Python, PythonObject, ToPyObject, |
16 }; |
16 }; |
17 use hg::dirstate::status::StatusPath; |
17 use hg::dirstate::status::StatusPath; |
18 use hg::matchers::{ |
18 use hg::matchers::{ |
19 DifferenceMatcher, IntersectionMatcher, Matcher, NeverMatcher, |
19 DifferenceMatcher, IntersectionMatcher, Matcher, NeverMatcher, |
24 parse_pattern_syntax, |
24 parse_pattern_syntax, |
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}, |
28 }, |
28 }, |
29 BadMatch, DirstateStatus, IgnorePattern, PatternFileWarning, StatusError, |
29 BadMatch, DirstateStatus, IgnorePattern, PatternError, PatternFileWarning, |
30 StatusOptions, |
30 StatusError, StatusOptions, |
31 }; |
31 }; |
32 use std::borrow::Borrow; |
32 use std::borrow::Borrow; |
33 |
33 |
34 fn collect_status_path_list(py: Python, paths: &[StatusPath<'_>]) -> PyList { |
34 fn collect_status_path_list(py: Python, paths: &[StatusPath<'_>]) -> PyList { |
35 collect_pybytes_list(py, paths.iter().map(|item| &*item.path)) |
35 collect_pybytes_list(py, paths.iter().map(|item| &*item.path)) |
156 /// Transform a Python matcher into a Rust matcher. |
156 /// Transform a Python matcher into a Rust matcher. |
157 fn extract_matcher( |
157 fn extract_matcher( |
158 py: Python, |
158 py: Python, |
159 matcher: PyObject, |
159 matcher: PyObject, |
160 ) -> PyResult<Box<dyn Matcher + Sync>> { |
160 ) -> PyResult<Box<dyn Matcher + Sync>> { |
|
161 let tampered = matcher |
|
162 .call_method(py, "was_tampered_with", PyTuple::empty(py), None)? |
|
163 .extract::<PyBool>(py)? |
|
164 .is_true(); |
|
165 if tampered { |
|
166 return Err(handle_fallback( |
|
167 py, |
|
168 StatusError::Pattern(PatternError::UnsupportedSyntax( |
|
169 "Pattern matcher was tampered with!".to_string(), |
|
170 )), |
|
171 )); |
|
172 }; |
161 match matcher.get_type(py).name(py).borrow() { |
173 match matcher.get_type(py).name(py).borrow() { |
162 "alwaysmatcher" => Ok(Box::new(AlwaysMatcher)), |
174 "alwaysmatcher" => Ok(Box::new(AlwaysMatcher)), |
163 "nevermatcher" => Ok(Box::new(NeverMatcher)), |
175 "nevermatcher" => Ok(Box::new(NeverMatcher)), |
164 "exactmatcher" => { |
176 "exactmatcher" => { |
165 let files = matcher.call_method( |
177 let files = matcher.call_method( |