##// 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 12 dirs_multiset::{DirsMultiset, DirsMultisetIter},
13 13 dirstate_map::DirstateMap,
14 14 parsers::{pack_dirstate, parse_dirstate, PARENT_SIZE},
15 status::status,
15 status::{status, StatusResult},
16 16 CopyMap, CopyMapIter, DirstateEntry, DirstateParents, EntryState,
17 17 StateMap, StateMapIter,
18 18 };
@@ -116,6 +116,7 b' pub fn init_module(py: Python, package: '
116 116 status_wrapper(
117 117 dmap: DirstateMap,
118 118 root_dir: PyObject,
119 matcher: PyObject,
119 120 list_clean: bool,
120 121 last_normal_time: i64,
121 122 check_exec: bool
@@ -12,14 +12,17 b''
12 12 use crate::dirstate::DirstateMap;
13 13 use cpython::exc::ValueError;
14 14 use cpython::{
15 PyBytes, PyErr, PyList, PyObject, PyResult, Python, PythonObject,
16 ToPyObject,
15 ObjectProtocol, PyBytes, PyErr, PyList, PyObject, PyResult, PyTuple,
16 Python, PythonObject, ToPyObject,
17 17 };
18 use hg::utils::files::get_path_from_bytes;
19
20 use hg::matchers::AlwaysMatcher;
21 use hg::status;
22 use hg::utils::hg_path::HgPath;
18 use hg::utils::hg_path::HgPathBuf;
19 use hg::{
20 matchers::{AlwaysMatcher, FileMatcher},
21 status,
22 utils::{files::get_path_from_bytes, hg_path::HgPath},
23 StatusResult,
24 };
25 use std::borrow::Borrow;
23 26
24 27 /// This will be useless once trait impls for collection are added to `PyBytes`
25 28 /// upstream.
@@ -43,6 +46,7 b' fn collect_pybytes_list<P: AsRef<HgPath>'
43 46 pub fn status_wrapper(
44 47 py: Python,
45 48 dmap: DirstateMap,
49 matcher: PyObject,
46 50 root_dir: PyObject,
47 51 list_clean: bool,
48 52 last_normal_time: i64,
@@ -54,20 +58,65 b' pub fn status_wrapper('
54 58 let dmap: DirstateMap = dmap.to_py_object(py);
55 59 let dmap = dmap.get_inner(py);
56 60
57 // TODO removed in the next patch to get the code to compile. This patch
58 // is part of a series and does not make real sense on its own.
59 let matcher = AlwaysMatcher;
61 match matcher.get_type(py).name(py).borrow() {
62 "alwaysmatcher" => {
63 let matcher = AlwaysMatcher;
64 let (lookup, status_res) = status(
65 &dmap,
66 &matcher,
67 &root_dir,
68 list_clean,
69 last_normal_time,
70 check_exec,
71 )
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();
60 91
61 let (lookup, status_res) = status(
62 &dmap,
63 &matcher,
64 &root_dir,
65 list_clean,
66 last_normal_time,
67 check_exec,
68 )
69 .map_err(|e| PyErr::new::<ValueError, _>(py, e.to_string()))?;
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 }
70 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 120 let modified = collect_pybytes_list(py, status_res.modified.as_ref());
72 121 let added = collect_pybytes_list(py, status_res.added.as_ref());
73 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