Show More
@@ -237,6 +237,25 b' impl DirstateMap {' | |||
|
237 | 237 | ) |
|
238 | 238 | } |
|
239 | 239 | |
|
240 | /// Useful to get immutable references to those sets in contexts where | |
|
241 | /// you only have an immutable reference to the `DirstateMap`, like when | |
|
242 | /// sharing references with Python. | |
|
243 | /// | |
|
244 | /// TODO, get rid of this along with the other "setter/getter" stuff when | |
|
245 | /// a nice typestate plan is defined. | |
|
246 | /// | |
|
247 | /// # Panics | |
|
248 | /// | |
|
249 | /// Will panic if either set is `None`. | |
|
250 | pub fn get_non_normal_other_parent_entries_panic( | |
|
251 | &self, | |
|
252 | ) -> (&HashSet<HgPathBuf>, &HashSet<HgPathBuf>) { | |
|
253 | ( | |
|
254 | self.non_normal_set.as_ref().unwrap(), | |
|
255 | self.other_parent_set.as_ref().unwrap(), | |
|
256 | ) | |
|
257 | } | |
|
258 | ||
|
240 | 259 | pub fn set_non_normal_other_parent_entries(&mut self, force: bool) { |
|
241 | 260 | if !force |
|
242 | 261 | && self.non_normal_set.is_some() |
@@ -20,7 +20,9 b' use cpython::{' | |||
|
20 | 20 | |
|
21 | 21 | use crate::{ |
|
22 | 22 | dirstate::copymap::{CopyMap, CopyMapItemsIterator, CopyMapKeysIterator}, |
|
23 |
dirstate::non_normal_entries:: |
|
|
23 | dirstate::non_normal_entries::{ | |
|
24 | NonNormalEntries, NonNormalEntriesIterator, | |
|
25 | }, | |
|
24 | 26 | dirstate::{dirs_multiset::Dirs, make_dirstate_tuple}, |
|
25 | 27 | }; |
|
26 | 28 | use hg::{ |
@@ -244,6 +246,22 b' py_class!(pub class DirstateMap |py| {' | |||
|
244 | 246 | Ok(ret) |
|
245 | 247 | } |
|
246 | 248 | |
|
249 | def non_normal_entries_iter(&self) -> PyResult<NonNormalEntriesIterator> { | |
|
250 | // Make sure the sets are defined before we no longer have a mutable | |
|
251 | // reference to the dmap. | |
|
252 | self.inner(py) | |
|
253 | .borrow_mut() | |
|
254 | .set_non_normal_other_parent_entries(false); | |
|
255 | ||
|
256 | let leaked_ref = self.inner(py).leak_immutable(); | |
|
257 | ||
|
258 | NonNormalEntriesIterator::from_inner(py, unsafe { | |
|
259 | leaked_ref.map(py, |o| { | |
|
260 | o.get_non_normal_other_parent_entries_panic().0.iter() | |
|
261 | }) | |
|
262 | }) | |
|
263 | } | |
|
264 | ||
|
247 | 265 | def hastrackeddir(&self, d: PyObject) -> PyResult<PyBool> { |
|
248 | 266 | let d = d.extract::<PyBytes>(py)?; |
|
249 | 267 | Ok(self.inner(py).borrow_mut() |
@@ -6,11 +6,15 b'' | |||
|
6 | 6 | // GNU General Public License version 2 or any later version. |
|
7 | 7 | |
|
8 | 8 | use cpython::{ |
|
9 |
exc::NotImplementedError, CompareOp, ObjectProtocol, Py |
|
|
10 |
PyObject, PyResult, PyString, Python, PythonObject, |
|
|
9 | exc::NotImplementedError, CompareOp, ObjectProtocol, PyBytes, PyClone, | |
|
10 | PyErr, PyList, PyObject, PyResult, PyString, Python, PythonObject, | |
|
11 | ToPyObject, UnsafePyLeaked, | |
|
11 | 12 | }; |
|
12 | 13 | |
|
13 | 14 | use crate::dirstate::DirstateMap; |
|
15 | use hg::utils::hg_path::HgPathBuf; | |
|
16 | use std::cell::RefCell; | |
|
17 | use std::collections::hash_set; | |
|
14 | 18 | |
|
15 | 19 | py_class!(pub class NonNormalEntries |py| { |
|
16 | 20 | data dmap: DirstateMap; |
@@ -34,6 +38,10 b' py_class!(pub class NonNormalEntries |py' | |||
|
34 | 38 | def __repr__(&self) -> PyResult<PyString> { |
|
35 | 39 | self.dmap(py).non_normal_entries_display(py) |
|
36 | 40 | } |
|
41 | ||
|
42 | def __iter__(&self) -> PyResult<NonNormalEntriesIterator> { | |
|
43 | self.dmap(py).non_normal_entries_iter(py) | |
|
44 | } | |
|
37 | 45 | }); |
|
38 | 46 | |
|
39 | 47 | impl NonNormalEntries { |
@@ -49,4 +57,20 b' impl NonNormalEntries {' | |||
|
49 | 57 | } |
|
50 | 58 | Ok(true) |
|
51 | 59 | } |
|
60 | ||
|
61 | fn translate_key( | |
|
62 | py: Python, | |
|
63 | key: &HgPathBuf, | |
|
64 | ) -> PyResult<Option<PyBytes>> { | |
|
65 | Ok(Some(PyBytes::new(py, key.as_ref()))) | |
|
52 | 66 | } |
|
67 | } | |
|
68 | ||
|
69 | type NonNormalEntriesIter<'a> = hash_set::Iter<'a, HgPathBuf>; | |
|
70 | ||
|
71 | py_shared_iterator!( | |
|
72 | NonNormalEntriesIterator, | |
|
73 | UnsafePyLeaked<NonNormalEntriesIter<'static>>, | |
|
74 | NonNormalEntries::translate_key, | |
|
75 | Option<PyBytes> | |
|
76 | ); |
General Comments 0
You need to be logged in to leave comments.
Login now