23 DirsMultiset, DirsMultisetIter, DirstateMapError, DirstateParseError, |
23 DirsMultiset, DirsMultisetIter, DirstateMapError, DirstateParseError, |
24 EntryState, |
24 EntryState, |
25 }; |
25 }; |
26 |
26 |
27 py_class!(pub class Dirs |py| { |
27 py_class!(pub class Dirs |py| { |
28 data inner: PySharedRefCell<DirsMultiset>; |
28 data inner_: PySharedRefCell<DirsMultiset>; |
29 |
29 |
30 // `map` is either a `dict` or a flat iterator (usually a `set`, sometimes |
30 // `map` is either a `dict` or a flat iterator (usually a `set`, sometimes |
31 // a `list`) |
31 // a `list`) |
32 def __new__( |
32 def __new__( |
33 _cls, |
33 _cls, |
70 PySharedRefCell::new(inner), |
70 PySharedRefCell::new(inner), |
71 ) |
71 ) |
72 } |
72 } |
73 |
73 |
74 def addpath(&self, path: PyObject) -> PyResult<PyObject> { |
74 def addpath(&self, path: PyObject) -> PyResult<PyObject> { |
75 self.inner_shared(py).borrow_mut().add_path( |
75 self.inner(py).borrow_mut().add_path( |
76 HgPath::new(path.extract::<PyBytes>(py)?.data(py)), |
76 HgPath::new(path.extract::<PyBytes>(py)?.data(py)), |
77 ).and(Ok(py.None())).or_else(|e| { |
77 ).and(Ok(py.None())).or_else(|e| { |
78 match e { |
78 match e { |
79 DirstateMapError::EmptyPath => { |
79 DirstateMapError::EmptyPath => { |
80 Ok(py.None()) |
80 Ok(py.None()) |
107 } |
107 } |
108 } |
108 } |
109 }) |
109 }) |
110 } |
110 } |
111 def __iter__(&self) -> PyResult<DirsMultisetKeysIterator> { |
111 def __iter__(&self) -> PyResult<DirsMultisetKeysIterator> { |
112 let leaked_ref = self.inner_shared(py).leak_immutable(); |
112 let leaked_ref = self.inner(py).leak_immutable(); |
113 DirsMultisetKeysIterator::from_inner( |
113 DirsMultisetKeysIterator::from_inner( |
114 py, |
114 py, |
115 unsafe { leaked_ref.map(py, |o| o.iter()) }, |
115 unsafe { leaked_ref.map(py, |o| o.iter()) }, |
116 ) |
116 ) |
117 } |
117 } |
118 |
118 |
119 def __contains__(&self, item: PyObject) -> PyResult<bool> { |
119 def __contains__(&self, item: PyObject) -> PyResult<bool> { |
120 Ok(self.inner_shared(py).borrow().contains(HgPath::new( |
120 Ok(self.inner(py).borrow().contains(HgPath::new( |
121 item.extract::<PyBytes>(py)?.data(py).as_ref(), |
121 item.extract::<PyBytes>(py)?.data(py).as_ref(), |
122 ))) |
122 ))) |
123 } |
123 } |
124 }); |
124 }); |
125 |
125 |
126 py_shared_ref!(Dirs, DirsMultiset, inner, inner_shared); |
126 py_shared_ref!(Dirs, DirsMultiset, inner_, inner); |
127 |
127 |
128 impl Dirs { |
128 impl Dirs { |
129 pub fn from_inner(py: Python, d: DirsMultiset) -> PyResult<Self> { |
129 pub fn from_inner(py: Python, d: DirsMultiset) -> PyResult<Self> { |
130 Self::create_instance(py, PySharedRefCell::new(d)) |
130 Self::create_instance(py, PySharedRefCell::new(d)) |
131 } |
131 } |