10 |
10 |
11 use cpython::{PyBytes, PyClone, PyDict, PyObject, PyResult, Python}; |
11 use cpython::{PyBytes, PyClone, PyDict, PyObject, PyResult, Python}; |
12 use std::cell::RefCell; |
12 use std::cell::RefCell; |
13 |
13 |
14 use crate::dirstate::dirstate_map::{DirstateMap, DirstateMapLeakedRef}; |
14 use crate::dirstate::dirstate_map::{DirstateMap, DirstateMapLeakedRef}; |
15 use hg::CopyMapIter; |
15 use hg::{utils::hg_path::HgPathBuf, CopyMapIter}; |
16 |
16 |
17 py_class!(pub class CopyMap |py| { |
17 py_class!(pub class CopyMap |py| { |
18 data dirstate_map: DirstateMap; |
18 data dirstate_map: DirstateMap; |
19 |
19 |
20 def __getitem__(&self, key: PyObject) -> PyResult<PyBytes> { |
20 def __getitem__(&self, key: PyObject) -> PyResult<PyBytes> { |
83 pub fn from_inner(py: Python, dm: DirstateMap) -> PyResult<Self> { |
83 pub fn from_inner(py: Python, dm: DirstateMap) -> PyResult<Self> { |
84 Self::create_instance(py, dm) |
84 Self::create_instance(py, dm) |
85 } |
85 } |
86 fn translate_key( |
86 fn translate_key( |
87 py: Python, |
87 py: Python, |
88 res: (&Vec<u8>, &Vec<u8>), |
88 res: (&HgPathBuf, &HgPathBuf), |
89 ) -> PyResult<Option<PyBytes>> { |
89 ) -> PyResult<Option<PyBytes>> { |
90 Ok(Some(PyBytes::new(py, res.0))) |
90 Ok(Some(PyBytes::new(py, res.0.as_ref()))) |
91 } |
91 } |
92 fn translate_key_value( |
92 fn translate_key_value( |
93 py: Python, |
93 py: Python, |
94 res: (&Vec<u8>, &Vec<u8>), |
94 res: (&HgPathBuf, &HgPathBuf), |
95 ) -> PyResult<Option<(PyBytes, PyBytes)>> { |
95 ) -> PyResult<Option<(PyBytes, PyBytes)>> { |
96 let (k, v) = res; |
96 let (k, v) = res; |
97 Ok(Some((PyBytes::new(py, k), PyBytes::new(py, v)))) |
97 Ok(Some(( |
|
98 PyBytes::new(py, k.as_ref()), |
|
99 PyBytes::new(py, v.as_ref()), |
|
100 ))) |
98 } |
101 } |
99 } |
102 } |
100 |
103 |
101 py_shared_iterator!( |
104 py_shared_iterator!( |
102 CopyMapKeysIterator, |
105 CopyMapKeysIterator, |