Mercurial > hg
comparison rust/hg-cpython/src/dirstate/dirstate_map.rs @ 47094:e061a1df32a8
dirstate-tree: Abstract "non-normal" and "other parent" sets
Instead of exposing `HashSet`s directly, have slightly higher-level
methods for the operations that Python bindings need on them.
Differential Revision: https://phab.mercurial-scm.org/D10363
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Thu, 08 Apr 2021 14:58:44 +0200 |
parents | 787ff5d21bcd |
children | 473abf4728bf |
comparison
equal
deleted
inserted
replaced
47093:787ff5d21bcd | 47094:e061a1df32a8 |
---|---|
171 Ok(py.None()) | 171 Ok(py.None()) |
172 } | 172 } |
173 | 173 |
174 def other_parent_entries(&self) -> PyResult<PyObject> { | 174 def other_parent_entries(&self) -> PyResult<PyObject> { |
175 let mut inner_shared = self.inner(py).borrow_mut(); | 175 let mut inner_shared = self.inner(py).borrow_mut(); |
176 let (_, other_parent) = | |
177 inner_shared.get_non_normal_other_parent_entries(); | |
178 | |
179 let set = PySet::empty(py)?; | 176 let set = PySet::empty(py)?; |
180 for path in other_parent.iter() { | 177 for path in inner_shared.iter_other_parent_paths() { |
181 set.add(py, PyBytes::new(py, path.as_bytes()))?; | 178 set.add(py, PyBytes::new(py, path.as_bytes()))?; |
182 } | 179 } |
183 Ok(set.into_object()) | 180 Ok(set.into_object()) |
184 } | 181 } |
185 | 182 |
190 def non_normal_entries_contains(&self, key: PyObject) -> PyResult<bool> { | 187 def non_normal_entries_contains(&self, key: PyObject) -> PyResult<bool> { |
191 let key = key.extract::<PyBytes>(py)?; | 188 let key = key.extract::<PyBytes>(py)?; |
192 Ok(self | 189 Ok(self |
193 .inner(py) | 190 .inner(py) |
194 .borrow_mut() | 191 .borrow_mut() |
195 .get_non_normal_other_parent_entries().0 | 192 .non_normal_entries_contains(HgPath::new(key.data(py)))) |
196 .contains(HgPath::new(key.data(py)))) | |
197 } | 193 } |
198 | 194 |
199 def non_normal_entries_display(&self) -> PyResult<PyString> { | 195 def non_normal_entries_display(&self) -> PyResult<PyString> { |
200 Ok( | 196 Ok( |
201 PyString::new( | 197 PyString::new( |
202 py, | 198 py, |
203 &format!( | 199 &format!( |
204 "NonNormalEntries: {:?}", | 200 "NonNormalEntries: {}", |
205 self | 201 hg::utils::join_display( |
206 .inner(py) | 202 self |
207 .borrow_mut() | 203 .inner(py) |
208 .get_non_normal_other_parent_entries().0 | 204 .borrow_mut() |
209 .iter().map(|o| o)) | 205 .iter_non_normal_paths(), |
206 ", " | |
207 ) | |
210 ) | 208 ) |
211 ) | 209 ) |
210 ) | |
212 } | 211 } |
213 | 212 |
214 def non_normal_entries_remove(&self, key: PyObject) -> PyResult<PyObject> { | 213 def non_normal_entries_remove(&self, key: PyObject) -> PyResult<PyObject> { |
215 let key = key.extract::<PyBytes>(py)?; | 214 let key = key.extract::<PyBytes>(py)?; |
216 self | 215 self |
218 .borrow_mut() | 217 .borrow_mut() |
219 .non_normal_entries_remove(HgPath::new(key.data(py))); | 218 .non_normal_entries_remove(HgPath::new(key.data(py))); |
220 Ok(py.None()) | 219 Ok(py.None()) |
221 } | 220 } |
222 | 221 |
223 def non_normal_entries_union(&self, other: PyObject) -> PyResult<PyList> { | 222 def non_normal_or_other_parent_paths(&self) -> PyResult<PyList> { |
224 let other: PyResult<_> = other.iter(py)? | 223 let mut inner = self.inner(py).borrow_mut(); |
225 .map(|f| { | |
226 Ok(HgPathBuf::from_bytes( | |
227 f?.extract::<PyBytes>(py)?.data(py), | |
228 )) | |
229 }) | |
230 .collect(); | |
231 | |
232 let res = self | |
233 .inner(py) | |
234 .borrow_mut() | |
235 .non_normal_entries_union(other?); | |
236 | 224 |
237 let ret = PyList::new(py, &[]); | 225 let ret = PyList::new(py, &[]); |
238 for filename in res.iter() { | 226 for filename in inner.non_normal_or_other_parent_paths() { |
239 let as_pystring = PyBytes::new(py, filename.as_bytes()); | 227 let as_pystring = PyBytes::new(py, filename.as_bytes()); |
240 ret.append(py, as_pystring.into_object()); | 228 ret.append(py, as_pystring.into_object()); |
241 } | 229 } |
242 Ok(ret) | 230 Ok(ret) |
243 } | 231 } |
251 | 239 |
252 let leaked_ref = self.inner(py).leak_immutable(); | 240 let leaked_ref = self.inner(py).leak_immutable(); |
253 | 241 |
254 NonNormalEntriesIterator::from_inner(py, unsafe { | 242 NonNormalEntriesIterator::from_inner(py, unsafe { |
255 leaked_ref.map(py, |o| { | 243 leaked_ref.map(py, |o| { |
256 o.get_non_normal_other_parent_entries_panic().0.iter() | 244 o.iter_non_normal_paths_panic() |
257 }) | 245 }) |
258 }) | 246 }) |
259 } | 247 } |
260 | 248 |
261 def hastrackeddir(&self, d: PyObject) -> PyResult<PyBool> { | 249 def hastrackeddir(&self, d: PyObject) -> PyResult<PyBool> { |