Show More
@@ -0,0 +1,52 | |||||
|
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 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 | |||||
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,13 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 | }; |
|
18 | }; | |
19 |
|
19 | |||
20 | use crate::{ |
|
20 | use crate::{ | |
21 | dirstate::copymap::{CopyMap, CopyMapItemsIterator, CopyMapKeysIterator}, |
|
21 | dirstate::copymap::{CopyMap, CopyMapItemsIterator, CopyMapKeysIterator}, | |
|
22 | dirstate::non_normal_entries::NonNormalEntries, | |||
22 | dirstate::{dirs_multiset::Dirs, make_dirstate_tuple}, |
|
23 | dirstate::{dirs_multiset::Dirs, make_dirstate_tuple}, | |
23 | ref_sharing::{PyLeaked, PySharedRefCell}, |
|
24 | ref_sharing::{PyLeaked, PySharedRefCell}, | |
24 | }; |
|
25 | }; | |
@@ -168,32 +169,86 py_class!(pub class DirstateMap |py| { | |||||
168 | Ok(py.None()) |
|
169 | Ok(py.None()) | |
169 | } |
|
170 | } | |
170 |
|
171 | |||
171 | // TODO share the reference |
|
172 | def other_parent_entries(&self) -> PyResult<PyObject> { | |
172 | def nonnormalentries(&self) -> PyResult<PyObject> { |
|
173 | let mut inner_shared = self.inner_shared(py).borrow_mut()?; | |
173 |
let ( |
|
174 | let (_, other_parent) = | |
174 |
|
|
175 | inner_shared.get_non_normal_other_parent_entries(); | |
175 |
|
176 | |||
176 | let locals = PyDict::new(py); |
|
177 | let locals = PyDict::new(py); | |
177 | locals.set_item( |
|
178 | locals.set_item( | |
178 | py, |
|
179 | py, | |
179 | "non_normal", |
|
|||
180 | non_normal |
|
|||
181 | .iter() |
|
|||
182 | .map(|v| PyBytes::new(py, v.as_ref())) |
|
|||
183 | .collect::<Vec<PyBytes>>() |
|
|||
184 | .to_py_object(py), |
|
|||
185 | )?; |
|
|||
186 | locals.set_item( |
|
|||
187 | py, |
|
|||
188 | "other_parent", |
|
180 | "other_parent", | |
189 | other_parent |
|
181 | other_parent.as_ref() | |
|
182 | .unwrap() | |||
190 | .iter() |
|
183 | .iter() | |
191 | .map(|v| PyBytes::new(py, v.as_ref())) |
|
184 | .map(|v| PyBytes::new(py, v.as_ref())) | |
192 | .collect::<Vec<PyBytes>>() |
|
185 | .collect::<Vec<PyBytes>>() | |
193 | .to_py_object(py), |
|
186 | .to_py_object(py), | |
194 | )?; |
|
187 | )?; | |
195 |
|
188 | |||
196 |
py.eval(" |
|
189 | py.eval("set(other_parent)", None, Some(&locals)) | |
|
190 | } | |||
|
191 | ||||
|
192 | def non_normal_entries(&self) -> PyResult<NonNormalEntries> { | |||
|
193 | NonNormalEntries::from_inner(py, self.clone_ref(py)) | |||
|
194 | } | |||
|
195 | ||||
|
196 | def non_normal_entries_contains(&self, key: PyObject) -> PyResult<bool> { | |||
|
197 | let key = key.extract::<PyBytes>(py)?; | |||
|
198 | Ok(self | |||
|
199 | .inner_shared(py) | |||
|
200 | .borrow_mut()? | |||
|
201 | .get_non_normal_other_parent_entries().0 | |||
|
202 | .as_ref() | |||
|
203 | .unwrap() | |||
|
204 | .contains(HgPath::new(key.data(py)))) | |||
|
205 | } | |||
|
206 | ||||
|
207 | def non_normal_entries_display(&self) -> PyResult<PyString> { | |||
|
208 | Ok( | |||
|
209 | PyString::new( | |||
|
210 | py, | |||
|
211 | &format!( | |||
|
212 | "NonNormalEntries: {:?}", | |||
|
213 | self | |||
|
214 | .inner_shared(py) | |||
|
215 | .borrow_mut()? | |||
|
216 | .get_non_normal_other_parent_entries().0 | |||
|
217 | .as_ref() | |||
|
218 | .unwrap().iter().map(|o| o)) | |||
|
219 | ) | |||
|
220 | ) | |||
|
221 | } | |||
|
222 | ||||
|
223 | def non_normal_entries_remove(&self, key: PyObject) -> PyResult<PyObject> { | |||
|
224 | let key = key.extract::<PyBytes>(py)?; | |||
|
225 | self | |||
|
226 | .inner_shared(py) | |||
|
227 | .borrow_mut()? | |||
|
228 | .non_normal_entries_remove(HgPath::new(key.data(py))); | |||
|
229 | Ok(py.None()) | |||
|
230 | } | |||
|
231 | ||||
|
232 | def non_normal_entries_union(&self, other: PyObject) -> PyResult<PyList> { | |||
|
233 | let other: PyResult<_> = other.iter(py)? | |||
|
234 | .map(|f| { | |||
|
235 | Ok(HgPathBuf::from_bytes( | |||
|
236 | f?.extract::<PyBytes>(py)?.data(py), | |||
|
237 | )) | |||
|
238 | }) | |||
|
239 | .collect(); | |||
|
240 | ||||
|
241 | let res = self | |||
|
242 | .inner_shared(py) | |||
|
243 | .borrow_mut()? | |||
|
244 | .non_normal_entries_union(other?); | |||
|
245 | ||||
|
246 | let ret = PyList::new(py, &[]); | |||
|
247 | for (i, filename) in res.iter().enumerate() { | |||
|
248 | let as_pystring = PyBytes::new(py, filename.as_bytes()); | |||
|
249 | ret.insert_item(py, i, as_pystring.into_object()); | |||
|
250 | } | |||
|
251 | Ok(ret) | |||
197 | } |
|
252 | } | |
198 |
|
253 | |||
199 | def hastrackeddir(&self, d: PyObject) -> PyResult<PyBool> { |
|
254 | def hastrackeddir(&self, d: PyObject) -> PyResult<PyBool> { |
General Comments 0
You need to be logged in to leave comments.
Login now