Mercurial > hg
changeset 48047:9b2a51b2c36a
dirstate: Propagate dirstate-v2 parse errors from set_dirstate_item
… so that Python sees a proper ValueError instead of only
`SystemError: Rust panic`
Differential Revision: https://phab.mercurial-scm.org/D11489
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Wed, 22 Sep 2021 18:56:58 +0200 |
parents | f6d0a89fdf80 |
children | 76f1c76186a1 |
files | rust/hg-core/src/dirstate_tree/dirstate_map.rs rust/hg-core/src/dirstate_tree/dispatch.rs rust/hg-core/src/dirstate_tree/owning_dispatch.rs rust/hg-cpython/src/dirstate/dirstate_map.rs |
diffstat | 4 files changed, 28 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/rust/hg-core/src/dirstate_tree/dirstate_map.rs Wed Sep 22 18:42:00 2021 +0200 +++ b/rust/hg-core/src/dirstate_tree/dirstate_map.rs Wed Sep 22 18:56:58 2021 +0200 @@ -758,10 +758,13 @@ self.nodes_with_copy_source_count = 0; } - fn set_entry(&mut self, filename: &HgPath, entry: DirstateEntry) { - let node = - self.get_or_insert(&filename).expect("no parse error in v1"); - node.data = NodeData::Entry(entry); + fn set_entry( + &mut self, + filename: &HgPath, + entry: DirstateEntry, + ) -> Result<(), DirstateV2ParseError> { + self.get_or_insert(&filename)?.data = NodeData::Entry(entry); + Ok(()) } fn add_file(
--- a/rust/hg-core/src/dirstate_tree/dispatch.rs Wed Sep 22 18:42:00 2021 +0200 +++ b/rust/hg-core/src/dirstate_tree/dispatch.rs Wed Sep 22 18:56:58 2021 +0200 @@ -39,7 +39,11 @@ /// Add the given filename to the map if it is not already there, and /// associate the given entry with it. - fn set_entry(&mut self, filename: &HgPath, entry: DirstateEntry); + fn set_entry( + &mut self, + filename: &HgPath, + entry: DirstateEntry, + ) -> Result<(), DirstateV2ParseError>; /// Add or change the information associated to a given file. /// @@ -321,8 +325,13 @@ /// /// XXX Is temporary during a refactor of V1 dirstate and will disappear /// shortly. - fn set_entry(&mut self, filename: &HgPath, entry: DirstateEntry) { - self.set_entry(&filename, entry) + fn set_entry( + &mut self, + filename: &HgPath, + entry: DirstateEntry, + ) -> Result<(), DirstateV2ParseError> { + self.set_entry(&filename, entry); + Ok(()) } fn add_file(
--- a/rust/hg-core/src/dirstate_tree/owning_dispatch.rs Wed Sep 22 18:42:00 2021 +0200 +++ b/rust/hg-core/src/dirstate_tree/owning_dispatch.rs Wed Sep 22 18:56:58 2021 +0200 @@ -20,7 +20,11 @@ self.get_mut().clear() } - fn set_entry(&mut self, filename: &HgPath, entry: DirstateEntry) { + fn set_entry( + &mut self, + filename: &HgPath, + entry: DirstateEntry, + ) -> Result<(), DirstateV2ParseError> { self.get_mut().set_entry(filename, entry) }
--- a/rust/hg-cpython/src/dirstate/dirstate_map.rs Wed Sep 22 18:42:00 2021 +0200 +++ b/rust/hg-cpython/src/dirstate/dirstate_map.rs Wed Sep 22 18:56:58 2021 +0200 @@ -136,7 +136,10 @@ ) -> PyResult<PyObject> { let f = path.extract::<PyBytes>(py)?; let filename = HgPath::new(f.data(py)); - self.inner(py).borrow_mut().set_entry(filename, item.get_entry(py)); + self.inner(py) + .borrow_mut() + .set_entry(filename, item.get_entry(py)) + .map_err(|e| v2_error(py, e))?; Ok(py.None()) }