rust/hg-cpython/src/dirstate/copymap.rs
changeset 42957 7a01778bc7b7
parent 42889 ea91a126c803
child 43177 5cb8867c9e2b
equal deleted inserted replaced
42956:3fe40dd6355d 42957:7a01778bc7b7
    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,