Mercurial > public > mercurial-scm > hg
diff rust/hg-cpython/src/dirstate/dirstate_map.rs @ 43863:bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
In 1fe2e574616e I introduced a temporary bugfix to align Rust code with a new
behavior from C/Python and forgot about a few `Result`s (cargo's compiler cache
does not re-emit warnings on cached modules). This fixes it.
For the record, I am still unsure that this behavior change is a good idea.
Note: I was already quite unhappy with the setters and getters for the
`DirstateMap` and, indirectly, `Dirs`, and this only further reinforces my
feelings. I hope we can one day fix that situation at the type level; Georges
Racinet and I were just talking about devising a POC for using the builder
pattern in the context of FFI with Python, we'll see what comes out of it.
Differential Revision: https://phab.mercurial-scm.org/D7609
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Thu, 12 Dec 2019 15:55:25 +0100 |
parents | 1fe2e574616e |
children | 2a24ead003f0 71e13cfd6154 |
line wrap: on
line diff
--- a/rust/hg-cpython/src/dirstate/dirstate_map.rs Fri Dec 13 09:43:43 2019 -0800 +++ b/rust/hg-cpython/src/dirstate/dirstate_map.rs Thu Dec 12 15:55:25 2019 +0100 @@ -200,6 +200,9 @@ let d = d.extract::<PyBytes>(py)?; Ok(self.inner_shared(py).borrow_mut()? .has_tracked_dir(HgPath::new(d.data(py))) + .map_err(|e| { + PyErr::new::<exc::ValueError, _>(py, e.to_string()) + })? .to_py_object(py)) } @@ -207,6 +210,9 @@ let d = d.extract::<PyBytes>(py)?; Ok(self.inner_shared(py).borrow_mut()? .has_dir(HgPath::new(d.data(py))) + .map_err(|e| { + PyErr::new::<exc::ValueError, _>(py, e.to_string()) + })? .to_py_object(py)) } @@ -330,24 +336,35 @@ def getdirs(&self) -> PyResult<Dirs> { // TODO don't copy, share the reference - self.inner_shared(py).borrow_mut()?.set_dirs(); + self.inner_shared(py).borrow_mut()?.set_dirs() + .map_err(|e| { + PyErr::new::<exc::ValueError, _>(py, e.to_string()) + })?; Dirs::from_inner( py, DirsMultiset::from_dirstate( &self.inner_shared(py).borrow(), Some(EntryState::Removed), - ), + ) + .map_err(|e| { + PyErr::new::<exc::ValueError, _>(py, e.to_string()) + })?, ) } def getalldirs(&self) -> PyResult<Dirs> { // TODO don't copy, share the reference - self.inner_shared(py).borrow_mut()?.set_all_dirs(); + self.inner_shared(py).borrow_mut()?.set_all_dirs() + .map_err(|e| { + PyErr::new::<exc::ValueError, _>(py, e.to_string()) + })?; Dirs::from_inner( py, DirsMultiset::from_dirstate( &self.inner_shared(py).borrow(), None, - ), + ).map_err(|e| { + PyErr::new::<exc::ValueError, _>(py, e.to_string()) + })?, ) }