Mercurial > hg
comparison rust/hg-cpython/src/dirstate/dirstate_map.rs @ 44233:281642cd1d04
rust-cpython: rename inner_shared() to inner()
The "shared" accessor will be automatically generated, and will have the
same name as the data itself.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 25 Jan 2020 17:21:06 +0900 |
parents | 2a24ead003f0 |
children | bad4e7b361d2 |
comparison
equal
deleted
inserted
replaced
44232:06df075b8925 | 44233:281642cd1d04 |
---|---|
40 // `py_class!` is already implemented and does not mention | 40 // `py_class!` is already implemented and does not mention |
41 // `RustDirstateMap`, rightfully so. | 41 // `RustDirstateMap`, rightfully so. |
42 // All attributes also have to have a separate refcount data attribute for | 42 // All attributes also have to have a separate refcount data attribute for |
43 // leaks, with all methods that go along for reference sharing. | 43 // leaks, with all methods that go along for reference sharing. |
44 py_class!(pub class DirstateMap |py| { | 44 py_class!(pub class DirstateMap |py| { |
45 data inner: PySharedRefCell<RustDirstateMap>; | 45 data inner_: PySharedRefCell<RustDirstateMap>; |
46 | 46 |
47 def __new__(_cls, _root: PyObject) -> PyResult<Self> { | 47 def __new__(_cls, _root: PyObject) -> PyResult<Self> { |
48 let inner = RustDirstateMap::default(); | 48 let inner = RustDirstateMap::default(); |
49 Self::create_instance( | 49 Self::create_instance( |
50 py, | 50 py, |
51 PySharedRefCell::new(inner), | 51 PySharedRefCell::new(inner), |
52 ) | 52 ) |
53 } | 53 } |
54 | 54 |
55 def clear(&self) -> PyResult<PyObject> { | 55 def clear(&self) -> PyResult<PyObject> { |
56 self.inner_shared(py).borrow_mut().clear(); | 56 self.inner(py).borrow_mut().clear(); |
57 Ok(py.None()) | 57 Ok(py.None()) |
58 } | 58 } |
59 | 59 |
60 def get( | 60 def get( |
61 &self, | 61 &self, |
62 key: PyObject, | 62 key: PyObject, |
63 default: Option<PyObject> = None | 63 default: Option<PyObject> = None |
64 ) -> PyResult<Option<PyObject>> { | 64 ) -> PyResult<Option<PyObject>> { |
65 let key = key.extract::<PyBytes>(py)?; | 65 let key = key.extract::<PyBytes>(py)?; |
66 match self.inner_shared(py).borrow().get(HgPath::new(key.data(py))) { | 66 match self.inner(py).borrow().get(HgPath::new(key.data(py))) { |
67 Some(entry) => { | 67 Some(entry) => { |
68 Ok(Some(make_dirstate_tuple(py, entry)?)) | 68 Ok(Some(make_dirstate_tuple(py, entry)?)) |
69 }, | 69 }, |
70 None => Ok(default) | 70 None => Ok(default) |
71 } | 71 } |
78 state: PyObject, | 78 state: PyObject, |
79 mode: PyObject, | 79 mode: PyObject, |
80 size: PyObject, | 80 size: PyObject, |
81 mtime: PyObject | 81 mtime: PyObject |
82 ) -> PyResult<PyObject> { | 82 ) -> PyResult<PyObject> { |
83 self.inner_shared(py).borrow_mut().add_file( | 83 self.inner(py).borrow_mut().add_file( |
84 HgPath::new(f.extract::<PyBytes>(py)?.data(py)), | 84 HgPath::new(f.extract::<PyBytes>(py)?.data(py)), |
85 oldstate.extract::<PyBytes>(py)?.data(py)[0] | 85 oldstate.extract::<PyBytes>(py)?.data(py)[0] |
86 .try_into() | 86 .try_into() |
87 .map_err(|e: DirstateParseError| { | 87 .map_err(|e: DirstateParseError| { |
88 PyErr::new::<exc::ValueError, _>(py, e.to_string()) | 88 PyErr::new::<exc::ValueError, _>(py, e.to_string()) |
106 &self, | 106 &self, |
107 f: PyObject, | 107 f: PyObject, |
108 oldstate: PyObject, | 108 oldstate: PyObject, |
109 size: PyObject | 109 size: PyObject |
110 ) -> PyResult<PyObject> { | 110 ) -> PyResult<PyObject> { |
111 self.inner_shared(py).borrow_mut() | 111 self.inner(py).borrow_mut() |
112 .remove_file( | 112 .remove_file( |
113 HgPath::new(f.extract::<PyBytes>(py)?.data(py)), | 113 HgPath::new(f.extract::<PyBytes>(py)?.data(py)), |
114 oldstate.extract::<PyBytes>(py)?.data(py)[0] | 114 oldstate.extract::<PyBytes>(py)?.data(py)[0] |
115 .try_into() | 115 .try_into() |
116 .map_err(|e: DirstateParseError| { | 116 .map_err(|e: DirstateParseError| { |
130 def dropfile( | 130 def dropfile( |
131 &self, | 131 &self, |
132 f: PyObject, | 132 f: PyObject, |
133 oldstate: PyObject | 133 oldstate: PyObject |
134 ) -> PyResult<PyBool> { | 134 ) -> PyResult<PyBool> { |
135 self.inner_shared(py).borrow_mut() | 135 self.inner(py).borrow_mut() |
136 .drop_file( | 136 .drop_file( |
137 HgPath::new(f.extract::<PyBytes>(py)?.data(py)), | 137 HgPath::new(f.extract::<PyBytes>(py)?.data(py)), |
138 oldstate.extract::<PyBytes>(py)?.data(py)[0] | 138 oldstate.extract::<PyBytes>(py)?.data(py)[0] |
139 .try_into() | 139 .try_into() |
140 .map_err(|e: DirstateParseError| { | 140 .map_err(|e: DirstateParseError| { |
161 Ok(HgPathBuf::from_bytes( | 161 Ok(HgPathBuf::from_bytes( |
162 filename?.extract::<PyBytes>(py)?.data(py), | 162 filename?.extract::<PyBytes>(py)?.data(py), |
163 )) | 163 )) |
164 }) | 164 }) |
165 .collect(); | 165 .collect(); |
166 self.inner_shared(py).borrow_mut() | 166 self.inner(py).borrow_mut() |
167 .clear_ambiguous_times(files?, now.extract(py)?); | 167 .clear_ambiguous_times(files?, now.extract(py)?); |
168 Ok(py.None()) | 168 Ok(py.None()) |
169 } | 169 } |
170 | 170 |
171 // TODO share the reference | 171 // TODO share the reference |
172 def nonnormalentries(&self) -> PyResult<PyObject> { | 172 def nonnormalentries(&self) -> PyResult<PyObject> { |
173 let (non_normal, other_parent) = | 173 let (non_normal, other_parent) = |
174 self.inner_shared(py).borrow().non_normal_other_parent_entries(); | 174 self.inner(py).borrow().non_normal_other_parent_entries(); |
175 | 175 |
176 let locals = PyDict::new(py); | 176 let locals = PyDict::new(py); |
177 locals.set_item( | 177 locals.set_item( |
178 py, | 178 py, |
179 "non_normal", | 179 "non_normal", |
196 py.eval("set(non_normal), set(other_parent)", None, Some(&locals)) | 196 py.eval("set(non_normal), set(other_parent)", None, Some(&locals)) |
197 } | 197 } |
198 | 198 |
199 def hastrackeddir(&self, d: PyObject) -> PyResult<PyBool> { | 199 def hastrackeddir(&self, d: PyObject) -> PyResult<PyBool> { |
200 let d = d.extract::<PyBytes>(py)?; | 200 let d = d.extract::<PyBytes>(py)?; |
201 Ok(self.inner_shared(py).borrow_mut() | 201 Ok(self.inner(py).borrow_mut() |
202 .has_tracked_dir(HgPath::new(d.data(py))) | 202 .has_tracked_dir(HgPath::new(d.data(py))) |
203 .map_err(|e| { | 203 .map_err(|e| { |
204 PyErr::new::<exc::ValueError, _>(py, e.to_string()) | 204 PyErr::new::<exc::ValueError, _>(py, e.to_string()) |
205 })? | 205 })? |
206 .to_py_object(py)) | 206 .to_py_object(py)) |
207 } | 207 } |
208 | 208 |
209 def hasdir(&self, d: PyObject) -> PyResult<PyBool> { | 209 def hasdir(&self, d: PyObject) -> PyResult<PyBool> { |
210 let d = d.extract::<PyBytes>(py)?; | 210 let d = d.extract::<PyBytes>(py)?; |
211 Ok(self.inner_shared(py).borrow_mut() | 211 Ok(self.inner(py).borrow_mut() |
212 .has_dir(HgPath::new(d.data(py))) | 212 .has_dir(HgPath::new(d.data(py))) |
213 .map_err(|e| { | 213 .map_err(|e| { |
214 PyErr::new::<exc::ValueError, _>(py, e.to_string()) | 214 PyErr::new::<exc::ValueError, _>(py, e.to_string()) |
215 })? | 215 })? |
216 .to_py_object(py)) | 216 .to_py_object(py)) |
217 } | 217 } |
218 | 218 |
219 def parents(&self, st: PyObject) -> PyResult<PyTuple> { | 219 def parents(&self, st: PyObject) -> PyResult<PyTuple> { |
220 self.inner_shared(py).borrow_mut() | 220 self.inner(py).borrow_mut() |
221 .parents(st.extract::<PyBytes>(py)?.data(py)) | 221 .parents(st.extract::<PyBytes>(py)?.data(py)) |
222 .and_then(|d| { | 222 .and_then(|d| { |
223 Ok((PyBytes::new(py, &d.p1), PyBytes::new(py, &d.p2)) | 223 Ok((PyBytes::new(py, &d.p1), PyBytes::new(py, &d.p2)) |
224 .to_py_object(py)) | 224 .to_py_object(py)) |
225 }) | 225 }) |
233 | 233 |
234 def setparents(&self, p1: PyObject, p2: PyObject) -> PyResult<PyObject> { | 234 def setparents(&self, p1: PyObject, p2: PyObject) -> PyResult<PyObject> { |
235 let p1 = extract_node_id(py, &p1)?; | 235 let p1 = extract_node_id(py, &p1)?; |
236 let p2 = extract_node_id(py, &p2)?; | 236 let p2 = extract_node_id(py, &p2)?; |
237 | 237 |
238 self.inner_shared(py).borrow_mut() | 238 self.inner(py).borrow_mut() |
239 .set_parents(&DirstateParents { p1, p2 }); | 239 .set_parents(&DirstateParents { p1, p2 }); |
240 Ok(py.None()) | 240 Ok(py.None()) |
241 } | 241 } |
242 | 242 |
243 def read(&self, st: PyObject) -> PyResult<Option<PyObject>> { | 243 def read(&self, st: PyObject) -> PyResult<Option<PyObject>> { |
244 match self.inner_shared(py).borrow_mut() | 244 match self.inner(py).borrow_mut() |
245 .read(st.extract::<PyBytes>(py)?.data(py)) | 245 .read(st.extract::<PyBytes>(py)?.data(py)) |
246 { | 246 { |
247 Ok(Some(parents)) => Ok(Some( | 247 Ok(Some(parents)) => Ok(Some( |
248 (PyBytes::new(py, &parents.p1), PyBytes::new(py, &parents.p2)) | 248 (PyBytes::new(py, &parents.p1), PyBytes::new(py, &parents.p2)) |
249 .to_py_object(py) | 249 .to_py_object(py) |
266 let parents = DirstateParents { | 266 let parents = DirstateParents { |
267 p1: extract_node_id(py, &p1)?, | 267 p1: extract_node_id(py, &p1)?, |
268 p2: extract_node_id(py, &p2)?, | 268 p2: extract_node_id(py, &p2)?, |
269 }; | 269 }; |
270 | 270 |
271 match self.inner_shared(py).borrow_mut().pack(parents, now) { | 271 match self.inner(py).borrow_mut().pack(parents, now) { |
272 Ok(packed) => Ok(PyBytes::new(py, &packed)), | 272 Ok(packed) => Ok(PyBytes::new(py, &packed)), |
273 Err(_) => Err(PyErr::new::<exc::OSError, _>( | 273 Err(_) => Err(PyErr::new::<exc::OSError, _>( |
274 py, | 274 py, |
275 "Dirstate error".to_string(), | 275 "Dirstate error".to_string(), |
276 )), | 276 )), |
278 } | 278 } |
279 | 279 |
280 def filefoldmapasdict(&self) -> PyResult<PyDict> { | 280 def filefoldmapasdict(&self) -> PyResult<PyDict> { |
281 let dict = PyDict::new(py); | 281 let dict = PyDict::new(py); |
282 for (key, value) in | 282 for (key, value) in |
283 self.inner_shared(py).borrow_mut().build_file_fold_map().iter() | 283 self.inner(py).borrow_mut().build_file_fold_map().iter() |
284 { | 284 { |
285 dict.set_item(py, key.as_ref().to_vec(), value.as_ref().to_vec())?; | 285 dict.set_item(py, key.as_ref().to_vec(), value.as_ref().to_vec())?; |
286 } | 286 } |
287 Ok(dict) | 287 Ok(dict) |
288 } | 288 } |
289 | 289 |
290 def __len__(&self) -> PyResult<usize> { | 290 def __len__(&self) -> PyResult<usize> { |
291 Ok(self.inner_shared(py).borrow().len()) | 291 Ok(self.inner(py).borrow().len()) |
292 } | 292 } |
293 | 293 |
294 def __contains__(&self, key: PyObject) -> PyResult<bool> { | 294 def __contains__(&self, key: PyObject) -> PyResult<bool> { |
295 let key = key.extract::<PyBytes>(py)?; | 295 let key = key.extract::<PyBytes>(py)?; |
296 Ok(self.inner_shared(py).borrow().contains_key(HgPath::new(key.data(py)))) | 296 Ok(self.inner(py).borrow().contains_key(HgPath::new(key.data(py)))) |
297 } | 297 } |
298 | 298 |
299 def __getitem__(&self, key: PyObject) -> PyResult<PyObject> { | 299 def __getitem__(&self, key: PyObject) -> PyResult<PyObject> { |
300 let key = key.extract::<PyBytes>(py)?; | 300 let key = key.extract::<PyBytes>(py)?; |
301 let key = HgPath::new(key.data(py)); | 301 let key = HgPath::new(key.data(py)); |
302 match self.inner_shared(py).borrow().get(key) { | 302 match self.inner(py).borrow().get(key) { |
303 Some(entry) => { | 303 Some(entry) => { |
304 Ok(make_dirstate_tuple(py, entry)?) | 304 Ok(make_dirstate_tuple(py, entry)?) |
305 }, | 305 }, |
306 None => Err(PyErr::new::<exc::KeyError, _>( | 306 None => Err(PyErr::new::<exc::KeyError, _>( |
307 py, | 307 py, |
309 )), | 309 )), |
310 } | 310 } |
311 } | 311 } |
312 | 312 |
313 def keys(&self) -> PyResult<DirstateMapKeysIterator> { | 313 def keys(&self) -> PyResult<DirstateMapKeysIterator> { |
314 let leaked_ref = self.inner_shared(py).leak_immutable(); | 314 let leaked_ref = self.inner(py).leak_immutable(); |
315 DirstateMapKeysIterator::from_inner( | 315 DirstateMapKeysIterator::from_inner( |
316 py, | 316 py, |
317 unsafe { leaked_ref.map(py, |o| o.iter()) }, | 317 unsafe { leaked_ref.map(py, |o| o.iter()) }, |
318 ) | 318 ) |
319 } | 319 } |
320 | 320 |
321 def items(&self) -> PyResult<DirstateMapItemsIterator> { | 321 def items(&self) -> PyResult<DirstateMapItemsIterator> { |
322 let leaked_ref = self.inner_shared(py).leak_immutable(); | 322 let leaked_ref = self.inner(py).leak_immutable(); |
323 DirstateMapItemsIterator::from_inner( | 323 DirstateMapItemsIterator::from_inner( |
324 py, | 324 py, |
325 unsafe { leaked_ref.map(py, |o| o.iter()) }, | 325 unsafe { leaked_ref.map(py, |o| o.iter()) }, |
326 ) | 326 ) |
327 } | 327 } |
328 | 328 |
329 def __iter__(&self) -> PyResult<DirstateMapKeysIterator> { | 329 def __iter__(&self) -> PyResult<DirstateMapKeysIterator> { |
330 let leaked_ref = self.inner_shared(py).leak_immutable(); | 330 let leaked_ref = self.inner(py).leak_immutable(); |
331 DirstateMapKeysIterator::from_inner( | 331 DirstateMapKeysIterator::from_inner( |
332 py, | 332 py, |
333 unsafe { leaked_ref.map(py, |o| o.iter()) }, | 333 unsafe { leaked_ref.map(py, |o| o.iter()) }, |
334 ) | 334 ) |
335 } | 335 } |
336 | 336 |
337 def getdirs(&self) -> PyResult<Dirs> { | 337 def getdirs(&self) -> PyResult<Dirs> { |
338 // TODO don't copy, share the reference | 338 // TODO don't copy, share the reference |
339 self.inner_shared(py).borrow_mut().set_dirs() | 339 self.inner(py).borrow_mut().set_dirs() |
340 .map_err(|e| { | 340 .map_err(|e| { |
341 PyErr::new::<exc::ValueError, _>(py, e.to_string()) | 341 PyErr::new::<exc::ValueError, _>(py, e.to_string()) |
342 })?; | 342 })?; |
343 Dirs::from_inner( | 343 Dirs::from_inner( |
344 py, | 344 py, |
345 DirsMultiset::from_dirstate( | 345 DirsMultiset::from_dirstate( |
346 &self.inner_shared(py).borrow(), | 346 &self.inner(py).borrow(), |
347 Some(EntryState::Removed), | 347 Some(EntryState::Removed), |
348 ) | 348 ) |
349 .map_err(|e| { | 349 .map_err(|e| { |
350 PyErr::new::<exc::ValueError, _>(py, e.to_string()) | 350 PyErr::new::<exc::ValueError, _>(py, e.to_string()) |
351 })?, | 351 })?, |
352 ) | 352 ) |
353 } | 353 } |
354 def getalldirs(&self) -> PyResult<Dirs> { | 354 def getalldirs(&self) -> PyResult<Dirs> { |
355 // TODO don't copy, share the reference | 355 // TODO don't copy, share the reference |
356 self.inner_shared(py).borrow_mut().set_all_dirs() | 356 self.inner(py).borrow_mut().set_all_dirs() |
357 .map_err(|e| { | 357 .map_err(|e| { |
358 PyErr::new::<exc::ValueError, _>(py, e.to_string()) | 358 PyErr::new::<exc::ValueError, _>(py, e.to_string()) |
359 })?; | 359 })?; |
360 Dirs::from_inner( | 360 Dirs::from_inner( |
361 py, | 361 py, |
362 DirsMultiset::from_dirstate( | 362 DirsMultiset::from_dirstate( |
363 &self.inner_shared(py).borrow(), | 363 &self.inner(py).borrow(), |
364 None, | 364 None, |
365 ).map_err(|e| { | 365 ).map_err(|e| { |
366 PyErr::new::<exc::ValueError, _>(py, e.to_string()) | 366 PyErr::new::<exc::ValueError, _>(py, e.to_string()) |
367 })?, | 367 })?, |
368 ) | 368 ) |
369 } | 369 } |
370 | 370 |
371 // TODO all copymap* methods, see docstring above | 371 // TODO all copymap* methods, see docstring above |
372 def copymapcopy(&self) -> PyResult<PyDict> { | 372 def copymapcopy(&self) -> PyResult<PyDict> { |
373 let dict = PyDict::new(py); | 373 let dict = PyDict::new(py); |
374 for (key, value) in self.inner_shared(py).borrow().copy_map.iter() { | 374 for (key, value) in self.inner(py).borrow().copy_map.iter() { |
375 dict.set_item( | 375 dict.set_item( |
376 py, | 376 py, |
377 PyBytes::new(py, key.as_ref()), | 377 PyBytes::new(py, key.as_ref()), |
378 PyBytes::new(py, value.as_ref()), | 378 PyBytes::new(py, value.as_ref()), |
379 )?; | 379 )?; |
381 Ok(dict) | 381 Ok(dict) |
382 } | 382 } |
383 | 383 |
384 def copymapgetitem(&self, key: PyObject) -> PyResult<PyBytes> { | 384 def copymapgetitem(&self, key: PyObject) -> PyResult<PyBytes> { |
385 let key = key.extract::<PyBytes>(py)?; | 385 let key = key.extract::<PyBytes>(py)?; |
386 match self.inner_shared(py).borrow().copy_map.get(HgPath::new(key.data(py))) { | 386 match self.inner(py).borrow().copy_map.get(HgPath::new(key.data(py))) { |
387 Some(copy) => Ok(PyBytes::new(py, copy.as_ref())), | 387 Some(copy) => Ok(PyBytes::new(py, copy.as_ref())), |
388 None => Err(PyErr::new::<exc::KeyError, _>( | 388 None => Err(PyErr::new::<exc::KeyError, _>( |
389 py, | 389 py, |
390 String::from_utf8_lossy(key.data(py)), | 390 String::from_utf8_lossy(key.data(py)), |
391 )), | 391 )), |
394 def copymap(&self) -> PyResult<CopyMap> { | 394 def copymap(&self) -> PyResult<CopyMap> { |
395 CopyMap::from_inner(py, self.clone_ref(py)) | 395 CopyMap::from_inner(py, self.clone_ref(py)) |
396 } | 396 } |
397 | 397 |
398 def copymaplen(&self) -> PyResult<usize> { | 398 def copymaplen(&self) -> PyResult<usize> { |
399 Ok(self.inner_shared(py).borrow().copy_map.len()) | 399 Ok(self.inner(py).borrow().copy_map.len()) |
400 } | 400 } |
401 def copymapcontains(&self, key: PyObject) -> PyResult<bool> { | 401 def copymapcontains(&self, key: PyObject) -> PyResult<bool> { |
402 let key = key.extract::<PyBytes>(py)?; | 402 let key = key.extract::<PyBytes>(py)?; |
403 Ok(self | 403 Ok(self |
404 .inner_shared(py) | 404 .inner(py) |
405 .borrow() | 405 .borrow() |
406 .copy_map | 406 .copy_map |
407 .contains_key(HgPath::new(key.data(py)))) | 407 .contains_key(HgPath::new(key.data(py)))) |
408 } | 408 } |
409 def copymapget( | 409 def copymapget( |
411 key: PyObject, | 411 key: PyObject, |
412 default: Option<PyObject> | 412 default: Option<PyObject> |
413 ) -> PyResult<Option<PyObject>> { | 413 ) -> PyResult<Option<PyObject>> { |
414 let key = key.extract::<PyBytes>(py)?; | 414 let key = key.extract::<PyBytes>(py)?; |
415 match self | 415 match self |
416 .inner_shared(py) | 416 .inner(py) |
417 .borrow() | 417 .borrow() |
418 .copy_map | 418 .copy_map |
419 .get(HgPath::new(key.data(py))) | 419 .get(HgPath::new(key.data(py))) |
420 { | 420 { |
421 Some(copy) => Ok(Some( | 421 Some(copy) => Ok(Some( |
429 key: PyObject, | 429 key: PyObject, |
430 value: PyObject | 430 value: PyObject |
431 ) -> PyResult<PyObject> { | 431 ) -> PyResult<PyObject> { |
432 let key = key.extract::<PyBytes>(py)?; | 432 let key = key.extract::<PyBytes>(py)?; |
433 let value = value.extract::<PyBytes>(py)?; | 433 let value = value.extract::<PyBytes>(py)?; |
434 self.inner_shared(py).borrow_mut().copy_map.insert( | 434 self.inner(py).borrow_mut().copy_map.insert( |
435 HgPathBuf::from_bytes(key.data(py)), | 435 HgPathBuf::from_bytes(key.data(py)), |
436 HgPathBuf::from_bytes(value.data(py)), | 436 HgPathBuf::from_bytes(value.data(py)), |
437 ); | 437 ); |
438 Ok(py.None()) | 438 Ok(py.None()) |
439 } | 439 } |
442 key: PyObject, | 442 key: PyObject, |
443 default: Option<PyObject> | 443 default: Option<PyObject> |
444 ) -> PyResult<Option<PyObject>> { | 444 ) -> PyResult<Option<PyObject>> { |
445 let key = key.extract::<PyBytes>(py)?; | 445 let key = key.extract::<PyBytes>(py)?; |
446 match self | 446 match self |
447 .inner_shared(py) | 447 .inner(py) |
448 .borrow_mut() | 448 .borrow_mut() |
449 .copy_map | 449 .copy_map |
450 .remove(HgPath::new(key.data(py))) | 450 .remove(HgPath::new(key.data(py))) |
451 { | 451 { |
452 Some(_) => Ok(None), | 452 Some(_) => Ok(None), |
453 None => Ok(default), | 453 None => Ok(default), |
454 } | 454 } |
455 } | 455 } |
456 | 456 |
457 def copymapiter(&self) -> PyResult<CopyMapKeysIterator> { | 457 def copymapiter(&self) -> PyResult<CopyMapKeysIterator> { |
458 let leaked_ref = self.inner_shared(py).leak_immutable(); | 458 let leaked_ref = self.inner(py).leak_immutable(); |
459 CopyMapKeysIterator::from_inner( | 459 CopyMapKeysIterator::from_inner( |
460 py, | 460 py, |
461 unsafe { leaked_ref.map(py, |o| o.copy_map.iter()) }, | 461 unsafe { leaked_ref.map(py, |o| o.copy_map.iter()) }, |
462 ) | 462 ) |
463 } | 463 } |
464 | 464 |
465 def copymapitemsiter(&self) -> PyResult<CopyMapItemsIterator> { | 465 def copymapitemsiter(&self) -> PyResult<CopyMapItemsIterator> { |
466 let leaked_ref = self.inner_shared(py).leak_immutable(); | 466 let leaked_ref = self.inner(py).leak_immutable(); |
467 CopyMapItemsIterator::from_inner( | 467 CopyMapItemsIterator::from_inner( |
468 py, | 468 py, |
469 unsafe { leaked_ref.map(py, |o| o.copy_map.iter()) }, | 469 unsafe { leaked_ref.map(py, |o| o.copy_map.iter()) }, |
470 ) | 470 ) |
471 } | 471 } |
475 impl DirstateMap { | 475 impl DirstateMap { |
476 pub fn get_inner<'a>( | 476 pub fn get_inner<'a>( |
477 &'a self, | 477 &'a self, |
478 py: Python<'a>, | 478 py: Python<'a>, |
479 ) -> Ref<'a, RustDirstateMap> { | 479 ) -> Ref<'a, RustDirstateMap> { |
480 self.inner_shared(py).borrow() | 480 self.inner(py).borrow() |
481 } | 481 } |
482 fn translate_key( | 482 fn translate_key( |
483 py: Python, | 483 py: Python, |
484 res: (&HgPathBuf, &DirstateEntry), | 484 res: (&HgPathBuf, &DirstateEntry), |
485 ) -> PyResult<Option<PyBytes>> { | 485 ) -> PyResult<Option<PyBytes>> { |
495 make_dirstate_tuple(py, entry)?, | 495 make_dirstate_tuple(py, entry)?, |
496 ))) | 496 ))) |
497 } | 497 } |
498 } | 498 } |
499 | 499 |
500 py_shared_ref!(DirstateMap, RustDirstateMap, inner, inner_shared); | 500 py_shared_ref!(DirstateMap, RustDirstateMap, inner_, inner); |
501 | 501 |
502 py_shared_iterator!( | 502 py_shared_iterator!( |
503 DirstateMapKeysIterator, | 503 DirstateMapKeysIterator, |
504 PyLeaked<StateMapIter<'static>>, | 504 PyLeaked<StateMapIter<'static>>, |
505 DirstateMap::translate_key, | 505 DirstateMap::translate_key, |