Show More
@@ -0,0 +1,52 b'' | |||||
|
1 | // non_normal_other_parent_entries.rs | |||
|
2 | // | |||
|
3 | // Copyright 2020 Raphaël Gomès <rgomes@octobus.net> | |||
|
4 | // | |||
|
5 | // This software may be used and distributed according to the terms of the | |||
|
6 | // GNU General Public License version 2 or any later version. | |||
|
7 | ||||
|
8 | use cpython::{ | |||
|
9 | exc::NotImplementedError, CompareOp, ObjectProtocol, PyErr, PyList, | |||
|
10 | PyObject, PyResult, PyString, Python, PythonObject, ToPyObject, | |||
|
11 | }; | |||
|
12 | ||||
|
13 | use crate::dirstate::DirstateMap; | |||
|
14 | ||||
|
15 | py_class!(pub class NonNormalEntries |py| { | |||
|
16 | data dmap: DirstateMap; | |||
|
17 | ||||
|
18 | def __contains__(&self, key: PyObject) -> PyResult<bool> { | |||
|
19 | self.dmap(py).non_normal_entries_contains(py, key) | |||
|
20 | } | |||
|
21 | def remove(&self, key: PyObject) -> PyResult<PyObject> { | |||
|
22 | self.dmap(py).non_normal_entries_remove(py, key) | |||
|
23 | } | |||
|
24 | def union(&self, other: PyObject) -> PyResult<PyList> { | |||
|
25 | self.dmap(py).non_normal_entries_union(py, other) | |||
|
26 | } | |||
|
27 | def __richcmp__(&self, other: PyObject, op: CompareOp) -> PyResult<bool> { | |||
|
28 | match op { | |||
|
29 | CompareOp::Eq => self.is_equal_to(py, other), | |||
|
30 | CompareOp::Ne => Ok(!self.is_equal_to(py, other)?), | |||
|
31 | _ => Err(PyErr::new::<NotImplementedError, _>(py, "")) | |||
|
32 | } | |||
|
33 | } | |||
|
34 | def __repr__(&self) -> PyResult<PyString> { | |||
|
35 | self.dmap(py).non_normal_entries_display(py) | |||
|
36 | } | |||
|
37 | }); | |||
|
38 | ||||
|
39 | impl NonNormalEntries { | |||
|
40 | pub fn from_inner(py: Python, dm: DirstateMap) -> PyResult<Self> { | |||
|
41 | Self::create_instance(py, dm) | |||
|
42 | } | |||
|
43 | ||||
|
44 | fn is_equal_to(&self, py: Python, other: PyObject) -> PyResult<bool> { | |||
|
45 | for item in other.iter(py)? { | |||
|
46 | if !self.dmap(py).non_normal_entries_contains(py, item?)? { | |||
|
47 | return Ok(false); | |||
|
48 | } | |||
|
49 | } | |||
|
50 | Ok(true) | |||
|
51 | } | |||
|
52 | } |
@@ -1846,12 +1846,12 b' if rustmod is not None:' | |||||
1846 |
|
1846 | |||
1847 | @property |
|
1847 | @property | |
1848 | def nonnormalset(self): |
|
1848 | def nonnormalset(self): | |
1849 |
nonnorm |
|
1849 | nonnorm = self._rustmap.non_normal_entries() | |
1850 | return nonnorm |
|
1850 | return nonnorm | |
1851 |
|
1851 | |||
1852 | @propertycache |
|
1852 | @propertycache | |
1853 | def otherparentset(self): |
|
1853 | def otherparentset(self): | |
1854 |
|
|
1854 | otherparents = self._rustmap.other_parent_entries() | |
1855 | return otherparents |
|
1855 | return otherparents | |
1856 |
|
1856 | |||
1857 | @propertycache |
|
1857 | @propertycache |
@@ -12,6 +12,7 b'' | |||||
12 | mod copymap; |
|
12 | mod copymap; | |
13 | mod dirs_multiset; |
|
13 | mod dirs_multiset; | |
14 | mod dirstate_map; |
|
14 | mod dirstate_map; | |
|
15 | mod non_normal_entries; | |||
15 | mod status; |
|
16 | mod status; | |
16 | use crate::dirstate::{ |
|
17 | use crate::dirstate::{ | |
17 | dirs_multiset::Dirs, dirstate_map::DirstateMap, status::status_wrapper, |
|
18 | dirs_multiset::Dirs, dirstate_map::DirstateMap, status::status_wrapper, |
@@ -13,12 +13,14 b' use std::convert::TryInto;' | |||||
13 | use std::time::Duration; |
|
13 | use std::time::Duration; | |
14 |
|
14 | |||
15 | use cpython::{ |
|
15 | use cpython::{ | |
16 |
exc, ObjectProtocol, PyBool, PyBytes, PyClone, PyDict, PyErr, Py |
|
16 | exc, ObjectProtocol, PyBool, PyBytes, PyClone, PyDict, PyErr, PyList, | |
17 |
PyResult, PyTuple, Python, PythonObject, ToPyObject, |
|
17 | PyObject, PyResult, PyString, PyTuple, Python, PythonObject, ToPyObject, | |
|
18 | UnsafePyLeaked, | |||
18 | }; |
|
19 | }; | |
19 |
|
20 | |||
20 | use crate::{ |
|
21 | use crate::{ | |
21 | dirstate::copymap::{CopyMap, CopyMapItemsIterator, CopyMapKeysIterator}, |
|
22 | dirstate::copymap::{CopyMap, CopyMapItemsIterator, CopyMapKeysIterator}, | |
|
23 | dirstate::non_normal_entries::NonNormalEntries, | |||
22 | dirstate::{dirs_multiset::Dirs, make_dirstate_tuple}, |
|
24 | dirstate::{dirs_multiset::Dirs, make_dirstate_tuple}, | |
23 | }; |
|
25 | }; | |
24 | use hg::{ |
|
26 | use hg::{ | |
@@ -164,32 +166,86 b' py_class!(pub class DirstateMap |py| {' | |||||
164 | Ok(py.None()) |
|
166 | Ok(py.None()) | |
165 | } |
|
167 | } | |
166 |
|
168 | |||
167 | // TODO share the reference |
|
169 | def other_parent_entries(&self) -> PyResult<PyObject> { | |
168 | def nonnormalentries(&self) -> PyResult<PyObject> { |
|
170 | let mut inner_shared = self.inner(py).borrow_mut(); | |
169 |
let ( |
|
171 | let (_, other_parent) = | |
170 |
|
|
172 | inner_shared.get_non_normal_other_parent_entries(); | |
171 |
|
173 | |||
172 | let locals = PyDict::new(py); |
|
174 | let locals = PyDict::new(py); | |
173 | locals.set_item( |
|
175 | locals.set_item( | |
174 | py, |
|
176 | py, | |
175 | "non_normal", |
|
|||
176 | non_normal |
|
|||
177 | .iter() |
|
|||
178 | .map(|v| PyBytes::new(py, v.as_ref())) |
|
|||
179 | .collect::<Vec<PyBytes>>() |
|
|||
180 | .to_py_object(py), |
|
|||
181 | )?; |
|
|||
182 | locals.set_item( |
|
|||
183 | py, |
|
|||
184 | "other_parent", |
|
177 | "other_parent", | |
185 | other_parent |
|
178 | other_parent.as_ref() | |
|
179 | .unwrap() | |||
186 | .iter() |
|
180 | .iter() | |
187 | .map(|v| PyBytes::new(py, v.as_ref())) |
|
181 | .map(|v| PyBytes::new(py, v.as_ref())) | |
188 | .collect::<Vec<PyBytes>>() |
|
182 | .collect::<Vec<PyBytes>>() | |
189 | .to_py_object(py), |
|
183 | .to_py_object(py), | |
190 | )?; |
|
184 | )?; | |
191 |
|
185 | |||
192 |
py.eval(" |
|
186 | py.eval("set(other_parent)", None, Some(&locals)) | |
|
187 | } | |||
|
188 | ||||
|
189 | def non_normal_entries(&self) -> PyResult<NonNormalEntries> { | |||
|
190 | NonNormalEntries::from_inner(py, self.clone_ref(py)) | |||
|
191 | } | |||
|
192 | ||||
|
193 | def non_normal_entries_contains(&self, key: PyObject) -> PyResult<bool> { | |||
|
194 | let key = key.extract::<PyBytes>(py)?; | |||
|
195 | Ok(self | |||
|
196 | .inner(py) | |||
|
197 | .borrow_mut() | |||
|
198 | .get_non_normal_other_parent_entries().0 | |||
|
199 | .as_ref() | |||
|
200 | .unwrap() | |||
|
201 | .contains(HgPath::new(key.data(py)))) | |||
|
202 | } | |||
|
203 | ||||
|
204 | def non_normal_entries_display(&self) -> PyResult<PyString> { | |||
|
205 | Ok( | |||
|
206 | PyString::new( | |||
|
207 | py, | |||
|
208 | &format!( | |||
|
209 | "NonNormalEntries: {:?}", | |||
|
210 | self | |||
|
211 | .inner(py) | |||
|
212 | .borrow_mut() | |||
|
213 | .get_non_normal_other_parent_entries().0 | |||
|
214 | .as_ref() | |||
|
215 | .unwrap().iter().map(|o| o)) | |||
|
216 | ) | |||
|
217 | ) | |||
|
218 | } | |||
|
219 | ||||
|
220 | def non_normal_entries_remove(&self, key: PyObject) -> PyResult<PyObject> { | |||
|
221 | let key = key.extract::<PyBytes>(py)?; | |||
|
222 | self | |||
|
223 | .inner(py) | |||
|
224 | .borrow_mut() | |||
|
225 | .non_normal_entries_remove(HgPath::new(key.data(py))); | |||
|
226 | Ok(py.None()) | |||
|
227 | } | |||
|
228 | ||||
|
229 | def non_normal_entries_union(&self, other: PyObject) -> PyResult<PyList> { | |||
|
230 | let other: PyResult<_> = other.iter(py)? | |||
|
231 | .map(|f| { | |||
|
232 | Ok(HgPathBuf::from_bytes( | |||
|
233 | f?.extract::<PyBytes>(py)?.data(py), | |||
|
234 | )) | |||
|
235 | }) | |||
|
236 | .collect(); | |||
|
237 | ||||
|
238 | let res = self | |||
|
239 | .inner(py) | |||
|
240 | .borrow_mut() | |||
|
241 | .non_normal_entries_union(other?); | |||
|
242 | ||||
|
243 | let ret = PyList::new(py, &[]); | |||
|
244 | for filename in res.iter() { | |||
|
245 | let as_pystring = PyBytes::new(py, filename.as_bytes()); | |||
|
246 | ret.append(py, as_pystring.into_object()); | |||
|
247 | } | |||
|
248 | Ok(ret) | |||
193 | } |
|
249 | } | |
194 |
|
250 | |||
195 | def hastrackeddir(&self, d: PyObject) -> PyResult<PyBool> { |
|
251 | def hastrackeddir(&self, d: PyObject) -> PyResult<PyBool> { |
General Comments 0
You need to be logged in to leave comments.
Login now