Mercurial > hg
diff rust/hg-cpython/src/dirstate/dirs_multiset.rs @ 42957:7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Differential Revision: https://phab.mercurial-scm.org/D6774
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Sun, 01 Sep 2019 20:53:14 +0200 |
parents | 5ccc08d02280 |
children | 070a38737334 |
line wrap: on
line diff
--- a/rust/hg-cpython/src/dirstate/dirs_multiset.rs Sun Sep 01 20:53:14 2019 +0200 +++ b/rust/hg-cpython/src/dirstate/dirs_multiset.rs Sun Sep 01 20:53:14 2019 +0200 @@ -16,9 +16,12 @@ Python, }; -use crate::dirstate::extract_dirstate; -use crate::ref_sharing::{PySharedRefCell, PySharedState}; +use crate::{ + dirstate::extract_dirstate, + ref_sharing::{PySharedRefCell, PySharedState}, +}; use hg::{ + utils::hg_path::{HgPath, HgPathBuf}, DirsMultiset, DirsMultisetIter, DirstateMapError, DirstateParseError, EntryState, }; @@ -48,9 +51,13 @@ let dirstate = extract_dirstate(py, &map)?; DirsMultiset::from_dirstate(&dirstate, skip_state) } else { - let map: Result<Vec<Vec<u8>>, PyErr> = map + let map: Result<Vec<HgPathBuf>, PyErr> = map .iter(py)? - .map(|o| Ok(o?.extract::<PyBytes>(py)?.data(py).to_owned())) + .map(|o| { + Ok(HgPathBuf::from_bytes( + o?.extract::<PyBytes>(py)?.data(py), + )) + }) .collect(); DirsMultiset::from_manifest(&map?) }; @@ -64,14 +71,14 @@ def addpath(&self, path: PyObject) -> PyResult<PyObject> { self.borrow_mut(py)?.add_path( - path.extract::<PyBytes>(py)?.data(py), + HgPath::new(path.extract::<PyBytes>(py)?.data(py)), ); Ok(py.None()) } def delpath(&self, path: PyObject) -> PyResult<PyObject> { self.borrow_mut(py)?.delete_path( - path.extract::<PyBytes>(py)?.data(py), + HgPath::new(path.extract::<PyBytes>(py)?.data(py)), ) .and(Ok(py.None())) .or_else(|e| { @@ -98,10 +105,9 @@ } def __contains__(&self, item: PyObject) -> PyResult<bool> { - Ok(self - .inner(py) - .borrow() - .contains(item.extract::<PyBytes>(py)?.data(py).as_ref())) + Ok(self.inner(py).borrow().contains(HgPath::new( + item.extract::<PyBytes>(py)?.data(py).as_ref(), + ))) } }); @@ -116,8 +122,11 @@ ) } - fn translate_key(py: Python, res: &Vec<u8>) -> PyResult<Option<PyBytes>> { - Ok(Some(PyBytes::new(py, res))) + fn translate_key( + py: Python, + res: &HgPathBuf, + ) -> PyResult<Option<PyBytes>> { + Ok(Some(PyBytes::new(py, res.as_ref()))) } }