rust/hg-cpython/src/dirstate/dirs_multiset.rs
changeset 42849 8db8fa1de2ef
parent 42802 2e1f74cc3350
child 42850 8f549c46bc64
equal deleted inserted replaced
42846:01d3ce3281cf 42849:8db8fa1de2ef
    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,
    17 };
    17 };
    18 
    18 
    19 use crate::{dirstate::extract_dirstate, ref_sharing::PySharedState};
    19 use crate::dirstate::extract_dirstate;
       
    20 use crate::ref_sharing::{PySharedRefCell, PySharedState};
    20 use hg::{DirsMultiset, DirstateMapError, DirstateParseError, EntryState};
    21 use hg::{DirsMultiset, DirstateMapError, DirstateParseError, EntryState};
    21 
    22 
    22 py_class!(pub class Dirs |py| {
    23 py_class!(pub class Dirs |py| {
    23     data inner: RefCell<DirsMultiset>;
    24     data inner: PySharedRefCell<DirsMultiset>;
    24     data py_shared_state: PySharedState;
    25     data py_shared_state: PySharedState;
    25 
    26 
    26     // `map` is either a `dict` or a flat iterator (usually a `set`, sometimes
    27     // `map` is either a `dict` or a flat iterator (usually a `set`, sometimes
    27     // a `list`)
    28     // a `list`)
    28     def __new__(
    29     def __new__(
    51             DirsMultiset::from_manifest(&map?)
    52             DirsMultiset::from_manifest(&map?)
    52         };
    53         };
    53 
    54 
    54         Self::create_instance(
    55         Self::create_instance(
    55             py,
    56             py,
    56             RefCell::new(inner),
    57             PySharedRefCell::new(inner),
    57             PySharedState::default()
    58             PySharedState::default()
    58         )
    59         )
    59     }
    60     }
    60 
    61 
    61     def addpath(&self, path: PyObject) -> PyResult<PyObject> {
    62     def addpath(&self, path: PyObject) -> PyResult<PyObject> {
   102 
   103 
   103 py_shared_ref!(Dirs, DirsMultiset, inner, DirsMultisetLeakedRef,);
   104 py_shared_ref!(Dirs, DirsMultiset, inner, DirsMultisetLeakedRef,);
   104 
   105 
   105 impl Dirs {
   106 impl Dirs {
   106     pub fn from_inner(py: Python, d: DirsMultiset) -> PyResult<Self> {
   107     pub fn from_inner(py: Python, d: DirsMultiset) -> PyResult<Self> {
   107         Self::create_instance(py, RefCell::new(d), PySharedState::default())
   108         Self::create_instance(
       
   109             py,
       
   110             PySharedRefCell::new(d),
       
   111             PySharedState::default(),
       
   112         )
   108     }
   113     }
   109 
   114 
   110     fn translate_key(py: Python, res: &Vec<u8>) -> PyResult<Option<PyBytes>> {
   115     fn translate_key(py: Python, res: &Vec<u8>) -> PyResult<Option<PyBytes>> {
   111         Ok(Some(PyBytes::new(py, res)))
   116         Ok(Some(PyBytes::new(py, res)))
   112     }
   117     }