Skip to content
Snippets Groups Projects
Commit 5a7d5fd6 authored by Georges Racinet's avatar Georges Racinet
Browse files

hg-cpython: rev_pyiter_collect_or_else

It will be useful to give callers the control on the generated errors
parent c817d9f6
No related branches found
No related tags found
2 merge requests!737Improvements to the Rust index's performance,!708Implement pure rust revlog Index
......@@ -28,8 +28,24 @@
C: FromIterator<Revision>,
I: RevlogIndex,
{
rev_pyiter_collect_or_else(py, revs, index, |r| {
PyErr::new::<GraphError, _>(py, ("InvalidRevision", r.0))
})
}
/// Same as [`rev_pyiter_collect`], giving control on returned errors
pub fn rev_pyiter_collect_or_else<C, I>(
py: Python,
revs: &PyObject,
index: &I,
invalid_rev_error: impl FnOnce(PyRevision) -> PyErr + Copy,
) -> PyResult<C>
where
C: FromIterator<Revision>,
I: RevlogIndex,
{
revs.iter(py)?
.map(|r| {
r.and_then(|o| match o.extract::<PyRevision>(py) {
Ok(r) => index
.check_revision(UncheckedRevision(r.0))
......@@ -31,14 +47,9 @@
revs.iter(py)?
.map(|r| {
r.and_then(|o| match o.extract::<PyRevision>(py) {
Ok(r) => index
.check_revision(UncheckedRevision(r.0))
.ok_or_else(|| {
PyErr::new::<GraphError, _>(
py,
("InvalidRevision", r.0),
)
}),
.ok_or_else(|| invalid_rev_error(r)),
Err(e) => Err(e),
})
})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment