Mercurial > hg
comparison rust/hg-cpython/src/dirstate/dirstate_map.rs @ 42799:5399532510ae
rust: simply use TryInto to convert slice to array
Since our rust module depends on TryInto, there's no point to avoid using it.
While rewriting copy_into_array(), I noticed CPython interface doesn't check
the length of the p1/p2 values, which is marked as TODO.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 17 Aug 2019 11:37:42 +0900 |
parents | 4e8f504424f3 |
children | 79561843729a |
comparison
equal
deleted
inserted
replaced
42798:99dff4264524 | 42799:5399532510ae |
---|---|
22 dirstate::copymap::{CopyMap, CopyMapItemsIterator, CopyMapKeysIterator}, | 22 dirstate::copymap::{CopyMap, CopyMapItemsIterator, CopyMapKeysIterator}, |
23 dirstate::{decapsule_make_dirstate_tuple, dirs_multiset::Dirs}, | 23 dirstate::{decapsule_make_dirstate_tuple, dirs_multiset::Dirs}, |
24 ref_sharing::PySharedState, | 24 ref_sharing::PySharedState, |
25 }; | 25 }; |
26 use hg::{ | 26 use hg::{ |
27 utils::copy_into_array, DirsIterable, DirsMultiset, DirstateEntry, | 27 DirsIterable, DirsMultiset, DirstateEntry, |
28 DirstateMap as RustDirstateMap, DirstateParents, DirstateParseError, | 28 DirstateMap as RustDirstateMap, DirstateParents, DirstateParseError, |
29 EntryState, | 29 EntryState, |
30 }; | 30 }; |
31 | 31 |
32 // TODO | 32 // TODO |
237 )) | 237 )) |
238 }) | 238 }) |
239 } | 239 } |
240 | 240 |
241 def setparents(&self, p1: PyObject, p2: PyObject) -> PyResult<PyObject> { | 241 def setparents(&self, p1: PyObject, p2: PyObject) -> PyResult<PyObject> { |
242 let p1 = copy_into_array(p1.extract::<PyBytes>(py)?.data(py)); | 242 // TODO: don't panic; raise Python exception instead. |
243 let p2 = copy_into_array(p2.extract::<PyBytes>(py)?.data(py)); | 243 let p1 = p1.extract::<PyBytes>(py)?.data(py).try_into().unwrap(); |
244 let p2 = p2.extract::<PyBytes>(py)?.data(py).try_into().unwrap(); | |
244 | 245 |
245 self.inner(py) | 246 self.inner(py) |
246 .borrow_mut() | 247 .borrow_mut() |
247 .set_parents(DirstateParents { p1, p2 }); | 248 .set_parents(DirstateParents { p1, p2 }); |
248 Ok(py.None()) | 249 Ok(py.None()) |
272 p2: PyObject, | 273 p2: PyObject, |
273 now: PyObject | 274 now: PyObject |
274 ) -> PyResult<PyBytes> { | 275 ) -> PyResult<PyBytes> { |
275 let now = Duration::new(now.extract(py)?, 0); | 276 let now = Duration::new(now.extract(py)?, 0); |
276 let parents = DirstateParents { | 277 let parents = DirstateParents { |
277 p1: copy_into_array(p1.extract::<PyBytes>(py)?.data(py)), | 278 // TODO: don't panic; raise Python exception instead. |
278 p2: copy_into_array(p2.extract::<PyBytes>(py)?.data(py)), | 279 p1: p1.extract::<PyBytes>(py)?.data(py).try_into().unwrap(), |
280 p2: p2.extract::<PyBytes>(py)?.data(py).try_into().unwrap(), | |
279 }; | 281 }; |
280 | 282 |
281 match self.borrow_mut(py)?.pack(parents, now) { | 283 match self.borrow_mut(py)?.pack(parents, now) { |
282 Ok(packed) => Ok(PyBytes::new(py, &packed)), | 284 Ok(packed) => Ok(PyBytes::new(py, &packed)), |
283 Err(_) => Err(PyErr::new::<exc::OSError, _>( | 285 Err(_) => Err(PyErr::new::<exc::OSError, _>( |