Show More
@@ -30,13 +30,18 b' use exceptions::GraphError;' | |||||
30 | use hg::Revision; |
|
30 | use hg::Revision; | |
31 | use hg::{AncestorsIterator as CoreIterator, LazyAncestors as CoreLazy}; |
|
31 | use hg::{AncestorsIterator as CoreIterator, LazyAncestors as CoreLazy}; | |
32 | use std::cell::RefCell; |
|
32 | use std::cell::RefCell; | |
|
33 | use std::iter::FromIterator; | |||
33 |
|
34 | |||
34 |
/// Utility function to convert a Python iterable into |
|
35 | /// Utility function to convert a Python iterable into various collections | |
35 | /// |
|
36 | /// | |
36 | /// We need this to feed to `AncestorIterators` constructors because |
|
37 | /// We need this in particular to feed to various methods of inner objects | |
37 | /// a `PyErr` can arise at each step of iteration, whereas our inner objects |
|
38 | /// with `impl IntoIterator<Item=Revision>` arguments, because | |
|
39 | /// a `PyErr` can arise at each step of iteration, whereas these methods | |||
38 | /// expect iterables over `Revision`, not over some `Result<Revision, PyErr>` |
|
40 | /// expect iterables over `Revision`, not over some `Result<Revision, PyErr>` | |
39 |
fn rev |
|
41 | fn rev_pyiter_collect<C>(py: Python, revs: &PyObject) -> PyResult<C> | |
|
42 | where | |||
|
43 | C: FromIterator<Revision>, | |||
|
44 | { | |||
40 | revs.iter(py)? |
|
45 | revs.iter(py)? | |
41 | .map(|r| r.and_then(|o| o.extract::<Revision>(py))) |
|
46 | .map(|r| r.and_then(|o| o.extract::<Revision>(py))) | |
42 | .collect() |
|
47 | .collect() | |
@@ -64,7 +69,7 b' py_class!(pub class AncestorsIterator |p' | |||||
64 |
|
69 | |||
65 | def __new__(_cls, index: PyObject, initrevs: PyObject, stoprev: Revision, |
|
70 | def __new__(_cls, index: PyObject, initrevs: PyObject, stoprev: Revision, | |
66 | inclusive: bool) -> PyResult<AncestorsIterator> { |
|
71 | inclusive: bool) -> PyResult<AncestorsIterator> { | |
67 |
let initvec = rev |
|
72 | let initvec: Vec<Revision> = rev_pyiter_collect(py, &initrevs)?; | |
68 | let ait = CoreIterator::new( |
|
73 | let ait = CoreIterator::new( | |
69 | Index::new(py, index)?, |
|
74 | Index::new(py, index)?, | |
70 | initvec, |
|
75 | initvec, | |
@@ -103,7 +108,7 b' py_class!(pub class LazyAncestors |py| {' | |||||
103 |
|
108 | |||
104 | def __new__(_cls, index: PyObject, initrevs: PyObject, stoprev: Revision, |
|
109 | def __new__(_cls, index: PyObject, initrevs: PyObject, stoprev: Revision, | |
105 | inclusive: bool) -> PyResult<Self> { |
|
110 | inclusive: bool) -> PyResult<Self> { | |
106 |
let initvec = rev |
|
111 | let initvec: Vec<Revision> = rev_pyiter_collect(py, &initrevs)?; | |
107 |
|
112 | |||
108 | let lazy = |
|
113 | let lazy = | |
109 | CoreLazy::new(Index::new(py, index)?, initvec, stoprev, inclusive) |
|
114 | CoreLazy::new(Index::new(py, index)?, initvec, stoprev, inclusive) |
General Comments 0
You need to be logged in to leave comments.
Login now