11 use std::cell::RefCell; |
11 use std::cell::RefCell; |
12 use std::convert::TryInto; |
12 use std::convert::TryInto; |
13 |
13 |
14 use cpython::{ |
14 use cpython::{ |
15 exc, ObjectProtocol, PyBytes, PyClone, PyDict, PyErr, PyObject, PyResult, |
15 exc, ObjectProtocol, PyBytes, PyClone, PyDict, PyErr, PyObject, PyResult, |
16 Python, |
16 Python, UnsafePyLeaked, |
17 }; |
17 }; |
18 |
18 |
19 use crate::dirstate::extract_dirstate; |
19 use crate::dirstate::extract_dirstate; |
20 use crate::ref_sharing::{PyLeaked, PySharedRefCell}; |
|
21 use hg::{ |
20 use hg::{ |
22 utils::hg_path::{HgPath, HgPathBuf}, |
21 utils::hg_path::{HgPath, HgPathBuf}, |
23 DirsMultiset, DirsMultisetIter, DirstateMapError, DirstateParseError, |
22 DirsMultiset, DirsMultisetIter, DirstateMapError, DirstateParseError, |
24 EntryState, |
23 EntryState, |
25 }; |
24 }; |
26 |
25 |
27 py_class!(pub class Dirs |py| { |
26 py_class!(pub class Dirs |py| { |
28 data inner_: PySharedRefCell<DirsMultiset>; |
27 @shared data inner: DirsMultiset; |
29 |
28 |
30 // `map` is either a `dict` or a flat iterator (usually a `set`, sometimes |
29 // `map` is either a `dict` or a flat iterator (usually a `set`, sometimes |
31 // a `list`) |
30 // a `list`) |
32 def __new__( |
31 def __new__( |
33 _cls, |
32 _cls, |
63 .map_err(|e| { |
62 .map_err(|e| { |
64 PyErr::new::<exc::ValueError, _>(py, e.to_string()) |
63 PyErr::new::<exc::ValueError, _>(py, e.to_string()) |
65 })? |
64 })? |
66 }; |
65 }; |
67 |
66 |
68 Self::create_instance( |
67 Self::create_instance(py, inner) |
69 py, |
|
70 PySharedRefCell::new(inner), |
|
71 ) |
|
72 } |
68 } |
73 |
69 |
74 def addpath(&self, path: PyObject) -> PyResult<PyObject> { |
70 def addpath(&self, path: PyObject) -> PyResult<PyObject> { |
75 self.inner(py).borrow_mut().add_path( |
71 self.inner(py).borrow_mut().add_path( |
76 HgPath::new(path.extract::<PyBytes>(py)?.data(py)), |
72 HgPath::new(path.extract::<PyBytes>(py)?.data(py)), |
121 item.extract::<PyBytes>(py)?.data(py).as_ref(), |
117 item.extract::<PyBytes>(py)?.data(py).as_ref(), |
122 ))) |
118 ))) |
123 } |
119 } |
124 }); |
120 }); |
125 |
121 |
126 py_shared_ref!(Dirs, DirsMultiset, inner_, inner); |
|
127 |
|
128 impl Dirs { |
122 impl Dirs { |
129 pub fn from_inner(py: Python, d: DirsMultiset) -> PyResult<Self> { |
123 pub fn from_inner(py: Python, d: DirsMultiset) -> PyResult<Self> { |
130 Self::create_instance(py, PySharedRefCell::new(d)) |
124 Self::create_instance(py, d) |
131 } |
125 } |
132 |
126 |
133 fn translate_key( |
127 fn translate_key( |
134 py: Python, |
128 py: Python, |
135 res: &HgPathBuf, |
129 res: &HgPathBuf, |