Mercurial > hg
comparison rust/hg-cpython/src/dirstate/dirstate_map.rs @ 46595:98a455a62699
rust: Make `DirstateParents`’s fields typed `Node`s
Instead of plain byte arrays.
Differential Revision: https://phab.mercurial-scm.org/D10006
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Wed, 17 Feb 2021 12:24:53 +0100 |
parents | 776b97179c06 |
children | 441024b279a6 |
comparison
equal
deleted
inserted
replaced
46594:f88e8ae0aa8f | 46595:98a455a62699 |
---|---|
22 dirstate::copymap::{CopyMap, CopyMapItemsIterator, CopyMapKeysIterator}, | 22 dirstate::copymap::{CopyMap, CopyMapItemsIterator, CopyMapKeysIterator}, |
23 dirstate::non_normal_entries::{ | 23 dirstate::non_normal_entries::{ |
24 NonNormalEntries, NonNormalEntriesIterator, | 24 NonNormalEntries, NonNormalEntriesIterator, |
25 }, | 25 }, |
26 dirstate::{dirs_multiset::Dirs, make_dirstate_tuple}, | 26 dirstate::{dirs_multiset::Dirs, make_dirstate_tuple}, |
27 parsers::dirstate_parents_to_pytuple, | |
27 }; | 28 }; |
28 use hg::{ | 29 use hg::{ |
29 errors::HgError, | 30 errors::HgError, |
31 revlog::Node, | |
30 utils::hg_path::{HgPath, HgPathBuf}, | 32 utils::hg_path::{HgPath, HgPathBuf}, |
31 DirsMultiset, DirstateEntry, DirstateMap as RustDirstateMap, | 33 DirsMultiset, DirstateEntry, DirstateMap as RustDirstateMap, |
32 DirstateMapError, DirstateParents, EntryState, StateMapIter, PARENT_SIZE, | 34 DirstateMapError, DirstateParents, EntryState, StateMapIter, |
33 }; | 35 }; |
34 | 36 |
35 // TODO | 37 // TODO |
36 // This object needs to share references to multiple members of its Rust | 38 // This object needs to share references to multiple members of its Rust |
37 // inner struct, namely `copy_map`, `dirs` and `all_dirs`. | 39 // inner struct, namely `copy_map`, `dirs` and `all_dirs`. |
283 } | 285 } |
284 | 286 |
285 def parents(&self, st: PyObject) -> PyResult<PyTuple> { | 287 def parents(&self, st: PyObject) -> PyResult<PyTuple> { |
286 self.inner(py).borrow_mut() | 288 self.inner(py).borrow_mut() |
287 .parents(st.extract::<PyBytes>(py)?.data(py)) | 289 .parents(st.extract::<PyBytes>(py)?.data(py)) |
288 .and_then(|d| { | 290 .map(|parents| dirstate_parents_to_pytuple(py, parents)) |
289 Ok((PyBytes::new(py, &d.p1), PyBytes::new(py, &d.p2)) | |
290 .to_py_object(py)) | |
291 }) | |
292 .or_else(|_| { | 291 .or_else(|_| { |
293 Err(PyErr::new::<exc::OSError, _>( | 292 Err(PyErr::new::<exc::OSError, _>( |
294 py, | 293 py, |
295 "Dirstate error".to_string(), | 294 "Dirstate error".to_string(), |
296 )) | 295 )) |
309 def read(&self, st: PyObject) -> PyResult<Option<PyObject>> { | 308 def read(&self, st: PyObject) -> PyResult<Option<PyObject>> { |
310 match self.inner(py).borrow_mut() | 309 match self.inner(py).borrow_mut() |
311 .read(st.extract::<PyBytes>(py)?.data(py)) | 310 .read(st.extract::<PyBytes>(py)?.data(py)) |
312 { | 311 { |
313 Ok(Some(parents)) => Ok(Some( | 312 Ok(Some(parents)) => Ok(Some( |
314 (PyBytes::new(py, &parents.p1), PyBytes::new(py, &parents.p2)) | 313 dirstate_parents_to_pytuple(py, parents) |
315 .to_py_object(py) | 314 .into_object() |
316 .into_object(), | |
317 )), | 315 )), |
318 Ok(None) => Ok(Some(py.None())), | 316 Ok(None) => Ok(Some(py.None())), |
319 Err(_) => Err(PyErr::new::<exc::OSError, _>( | 317 Err(_) => Err(PyErr::new::<exc::OSError, _>( |
320 py, | 318 py, |
321 "Dirstate error".to_string(), | 319 "Dirstate error".to_string(), |
599 UnsafePyLeaked<StateMapIter<'static>>, | 597 UnsafePyLeaked<StateMapIter<'static>>, |
600 DirstateMap::translate_key_value, | 598 DirstateMap::translate_key_value, |
601 Option<(PyBytes, PyObject)> | 599 Option<(PyBytes, PyObject)> |
602 ); | 600 ); |
603 | 601 |
604 fn extract_node_id(py: Python, obj: &PyObject) -> PyResult<[u8; PARENT_SIZE]> { | 602 fn extract_node_id(py: Python, obj: &PyObject) -> PyResult<Node> { |
605 let bytes = obj.extract::<PyBytes>(py)?; | 603 let bytes = obj.extract::<PyBytes>(py)?; |
606 match bytes.data(py).try_into() { | 604 match bytes.data(py).try_into() { |
607 Ok(s) => Ok(s), | 605 Ok(s) => Ok(s), |
608 Err(e) => Err(PyErr::new::<exc::ValueError, _>(py, e.to_string())), | 606 Err(e) => Err(PyErr::new::<exc::ValueError, _>(py, e.to_string())), |
609 } | 607 } |