##// END OF EJS Templates
rust-dirstate-status: update bridge for new rust version of `dirstate.status`...
Raphaël Gomès -
r44368:6a88ced3 default
parent child Browse files
Show More
@@ -12,7 +12,7 b' pub use dirstate::{'
12 dirs_multiset::{DirsMultiset, DirsMultisetIter},
12 dirs_multiset::{DirsMultiset, DirsMultisetIter},
13 dirstate_map::DirstateMap,
13 dirstate_map::DirstateMap,
14 parsers::{pack_dirstate, parse_dirstate, PARENT_SIZE},
14 parsers::{pack_dirstate, parse_dirstate, PARENT_SIZE},
15 status::status,
15 status::{status, StatusResult},
16 CopyMap, CopyMapIter, DirstateEntry, DirstateParents, EntryState,
16 CopyMap, CopyMapIter, DirstateEntry, DirstateParents, EntryState,
17 StateMap, StateMapIter,
17 StateMap, StateMapIter,
18 };
18 };
@@ -116,6 +116,7 b' pub fn init_module(py: Python, package: '
116 status_wrapper(
116 status_wrapper(
117 dmap: DirstateMap,
117 dmap: DirstateMap,
118 root_dir: PyObject,
118 root_dir: PyObject,
119 matcher: PyObject,
119 list_clean: bool,
120 list_clean: bool,
120 last_normal_time: i64,
121 last_normal_time: i64,
121 check_exec: bool
122 check_exec: bool
@@ -12,14 +12,17 b''
12 use crate::dirstate::DirstateMap;
12 use crate::dirstate::DirstateMap;
13 use cpython::exc::ValueError;
13 use cpython::exc::ValueError;
14 use cpython::{
14 use cpython::{
15 PyBytes, PyErr, PyList, PyObject, PyResult, Python, PythonObject,
15 ObjectProtocol, PyBytes, PyErr, PyList, PyObject, PyResult, PyTuple,
16 ToPyObject,
16 Python, PythonObject, ToPyObject,
17 };
17 };
18 use hg::utils::files::get_path_from_bytes;
18 use hg::utils::hg_path::HgPathBuf;
19
19 use hg::{
20 use hg::matchers::AlwaysMatcher;
20 matchers::{AlwaysMatcher, FileMatcher},
21 use hg::status;
21 status,
22 use hg::utils::hg_path::HgPath;
22 utils::{files::get_path_from_bytes, hg_path::HgPath},
23 StatusResult,
24 };
25 use std::borrow::Borrow;
23
26
24 /// This will be useless once trait impls for collection are added to `PyBytes`
27 /// This will be useless once trait impls for collection are added to `PyBytes`
25 /// upstream.
28 /// upstream.
@@ -43,6 +46,7 b' fn collect_pybytes_list<P: AsRef<HgPath>'
43 pub fn status_wrapper(
46 pub fn status_wrapper(
44 py: Python,
47 py: Python,
45 dmap: DirstateMap,
48 dmap: DirstateMap,
49 matcher: PyObject,
46 root_dir: PyObject,
50 root_dir: PyObject,
47 list_clean: bool,
51 list_clean: bool,
48 last_normal_time: i64,
52 last_normal_time: i64,
@@ -54,10 +58,9 b' pub fn status_wrapper('
54 let dmap: DirstateMap = dmap.to_py_object(py);
58 let dmap: DirstateMap = dmap.to_py_object(py);
55 let dmap = dmap.get_inner(py);
59 let dmap = dmap.get_inner(py);
56
60
57 // TODO removed in the next patch to get the code to compile. This patch
61 match matcher.get_type(py).name(py).borrow() {
58 // is part of a series and does not make real sense on its own.
62 "alwaysmatcher" => {
59 let matcher = AlwaysMatcher;
63 let matcher = AlwaysMatcher;
60
61 let (lookup, status_res) = status(
64 let (lookup, status_res) = status(
62 &dmap,
65 &dmap,
63 &matcher,
66 &matcher,
@@ -67,7 +70,53 b' pub fn status_wrapper('
67 check_exec,
70 check_exec,
68 )
71 )
69 .map_err(|e| PyErr::new::<ValueError, _>(py, e.to_string()))?;
72 .map_err(|e| PyErr::new::<ValueError, _>(py, e.to_string()))?;
73 build_response(lookup, status_res, py)
74 }
75 "exactmatcher" => {
76 let files = matcher.call_method(
77 py,
78 "files",
79 PyTuple::new(py, &[]),
80 None,
81 )?;
82 let files: PyList = files.cast_into(py)?;
83 let files: PyResult<Vec<HgPathBuf>> = files
84 .iter(py)
85 .map(|f| {
86 Ok(HgPathBuf::from_bytes(
87 f.extract::<PyBytes>(py)?.data(py),
88 ))
89 })
90 .collect();
70
91
92 let files = files?;
93 let matcher = FileMatcher::new(&files)
94 .map_err(|e| PyErr::new::<ValueError, _>(py, e.to_string()))?;
95 let (lookup, status_res) = status(
96 &dmap,
97 &matcher,
98 &root_dir,
99 list_clean,
100 last_normal_time,
101 check_exec,
102 )
103 .map_err(|e| PyErr::new::<ValueError, _>(py, e.to_string()))?;
104 build_response(lookup, status_res, py)
105 }
106 e => {
107 return Err(PyErr::new::<ValueError, _>(
108 py,
109 format!("Unsupported matcher {}", e),
110 ));
111 }
112 }
113 }
114
115 fn build_response(
116 lookup: Vec<&HgPath>,
117 status_res: StatusResult,
118 py: Python,
119 ) -> PyResult<(PyList, PyList, PyList, PyList, PyList, PyList, PyList)> {
71 let modified = collect_pybytes_list(py, status_res.modified.as_ref());
120 let modified = collect_pybytes_list(py, status_res.modified.as_ref());
72 let added = collect_pybytes_list(py, status_res.added.as_ref());
121 let added = collect_pybytes_list(py, status_res.added.as_ref());
73 let removed = collect_pybytes_list(py, status_res.removed.as_ref());
122 let removed = collect_pybytes_list(py, status_res.removed.as_ref());
General Comments 0
You need to be logged in to leave comments. Login now