Skip to content
Snippets Groups Projects
Commit 75119bbe authored by Raphaël Gomès's avatar Raphaël Gomès
Browse files

hg-cpython: refactor matcher transformation logic

This reduces duplication and will allow for recursive transformation in
UnionMatcher.
parent 137d6bb7
No related branches found
No related tags found
2 merge requests!168branching: merge default into stable,!155Rust Matcher support improvement
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
PyResult, PyTuple, Python, PythonObject, ToPyObject, PyResult, PyTuple, Python, PythonObject, ToPyObject,
}; };
use hg::dirstate::status::StatusPath; use hg::dirstate::status::StatusPath;
use hg::matchers::Matcher;
use hg::{ use hg::{
matchers::{AlwaysMatcher, FileMatcher, IncludeMatcher}, matchers::{AlwaysMatcher, FileMatcher, IncludeMatcher},
parse_pattern_syntax, parse_pattern_syntax,
...@@ -133,4 +134,26 @@ ...@@ -133,4 +134,26 @@
build_response(py, status_res, warnings) build_response(py, status_res, warnings)
}; };
let matcher = extract_matcher(py, matcher)?;
dmap.with_status(
&*matcher,
root_dir.to_path_buf(),
ignore_files,
StatusOptions {
check_exec,
list_clean,
list_ignored,
list_unknown,
list_copies,
collect_traversed_dirs,
},
after_status,
)
}
/// Transform a Python matcher into a Rust matcher.
fn extract_matcher(
py: Python,
matcher: PyObject,
) -> PyResult<Box<dyn Matcher + Sync>> {
match matcher.get_type(py).name(py).borrow() { match matcher.get_type(py).name(py).borrow() {
...@@ -136,21 +159,5 @@ ...@@ -136,21 +159,5 @@
match matcher.get_type(py).name(py).borrow() { match matcher.get_type(py).name(py).borrow() {
"alwaysmatcher" => { "alwaysmatcher" => Ok(Box::new(AlwaysMatcher)),
let matcher = AlwaysMatcher;
dmap.with_status(
&matcher,
root_dir.to_path_buf(),
ignore_files,
StatusOptions {
check_exec,
list_clean,
list_ignored,
list_unknown,
list_copies,
collect_traversed_dirs,
},
after_status,
)
}
"exactmatcher" => { "exactmatcher" => {
let files = matcher.call_method( let files = matcher.call_method(
py, py,
...@@ -169,5 +176,5 @@ ...@@ -169,5 +176,5 @@
.collect(); .collect();
let files = files?; let files = files?;
let matcher = FileMatcher::new(files) let file_matcher = FileMatcher::new(files)
.map_err(|e| PyErr::new::<ValueError, _>(py, e.to_string()))?; .map_err(|e| PyErr::new::<ValueError, _>(py, e.to_string()))?;
...@@ -173,18 +180,5 @@ ...@@ -173,18 +180,5 @@
.map_err(|e| PyErr::new::<ValueError, _>(py, e.to_string()))?; .map_err(|e| PyErr::new::<ValueError, _>(py, e.to_string()))?;
dmap.with_status( Ok(Box::new(file_matcher))
&matcher,
root_dir.to_path_buf(),
ignore_files,
StatusOptions {
check_exec,
list_clean,
list_ignored,
list_unknown,
list_copies,
collect_traversed_dirs,
},
after_status,
)
} }
"includematcher" => { "includematcher" => {
// Get the patterns from Python even though most of them are // Get the patterns from Python even though most of them are
...@@ -221,20 +215,7 @@ ...@@ -221,20 +215,7 @@
let matcher = IncludeMatcher::new(ignore_patterns) let matcher = IncludeMatcher::new(ignore_patterns)
.map_err(|e| handle_fallback(py, e.into()))?; .map_err(|e| handle_fallback(py, e.into()))?;
dmap.with_status( Ok(Box::new(matcher))
&matcher,
root_dir.to_path_buf(),
ignore_files,
StatusOptions {
check_exec,
list_clean,
list_ignored,
list_unknown,
list_copies,
collect_traversed_dirs,
},
after_status,
)
} }
e => Err(PyErr::new::<FallbackError, _>( e => Err(PyErr::new::<FallbackError, _>(
py, py,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment