Show More
@@ -42,20 +42,21 b' use cpython::{' | |||
|
42 | 42 | ObjectProtocol, PyClone, PyDict, PyList, PyModule, PyObject, PyResult, |
|
43 | 43 | Python, PythonObject, ToPyObject, |
|
44 | 44 | }; |
|
45 | use hg::MissingAncestors as CoreMissing; | |
|
45 | 46 | use hg::Revision; |
|
46 | use hg::{ | |
|
47 | AncestorsIterator as CoreIterator, LazyAncestors as CoreLazy, | |
|
48 | MissingAncestors as CoreMissing, | |
|
49 | }; | |
|
50 | 47 | use std::cell::RefCell; |
|
51 | 48 | use std::collections::HashSet; |
|
49 | use vcsgraph::lazy_ancestors::{ | |
|
50 | AncestorsIterator as VCGAncestorsIterator, | |
|
51 | LazyAncestors as VCGLazyAncestors, | |
|
52 | }; | |
|
52 | 53 | |
|
53 | 54 | py_class!(pub class AncestorsIterator |py| { |
|
54 |
data inner: RefCell<Box< |
|
|
55 | data inner: RefCell<Box<VCGAncestorsIterator<Index>>>; | |
|
55 | 56 | |
|
56 | 57 | def __next__(&self) -> PyResult<Option<Revision>> { |
|
57 | 58 | match self.inner(py).borrow_mut().next() { |
|
58 | Some(Err(e)) => Err(GraphError::pynew(py, e)), | |
|
59 | Some(Err(e)) => Err(GraphError::pynew_from_vcsgraph(py, e)), | |
|
59 | 60 | None => Ok(None), |
|
60 | 61 | Some(Ok(r)) => Ok(Some(r)), |
|
61 | 62 | } |
@@ -63,7 +64,7 b' py_class!(pub class AncestorsIterator |p' | |||
|
63 | 64 | |
|
64 | 65 | def __contains__(&self, rev: Revision) -> PyResult<bool> { |
|
65 | 66 | self.inner(py).borrow_mut().contains(rev) |
|
66 | .map_err(|e| GraphError::pynew(py, e)) | |
|
67 | .map_err(|e| GraphError::pynew_from_vcsgraph(py, e)) | |
|
67 | 68 | } |
|
68 | 69 | |
|
69 | 70 | def __iter__(&self) -> PyResult<Self> { |
@@ -73,32 +74,35 b' py_class!(pub class AncestorsIterator |p' | |||
|
73 | 74 | def __new__(_cls, index: PyObject, initrevs: PyObject, stoprev: Revision, |
|
74 | 75 | inclusive: bool) -> PyResult<AncestorsIterator> { |
|
75 | 76 | let initvec: Vec<Revision> = rev_pyiter_collect(py, &initrevs)?; |
|
76 |
let ait = |
|
|
77 | let ait = VCGAncestorsIterator::new( | |
|
77 | 78 | pyindex_to_graph(py, index)?, |
|
78 | 79 | initvec, |
|
79 | 80 | stoprev, |
|
80 | 81 | inclusive, |
|
81 | 82 | ) |
|
82 | .map_err(|e| GraphError::pynew(py, e))?; | |
|
83 | .map_err(|e| GraphError::pynew_from_vcsgraph(py, e))?; | |
|
83 | 84 | AncestorsIterator::from_inner(py, ait) |
|
84 | 85 | } |
|
85 | 86 | |
|
86 | 87 | }); |
|
87 | 88 | |
|
88 | 89 | impl AncestorsIterator { |
|
89 | pub fn from_inner(py: Python, ait: CoreIterator<Index>) -> PyResult<Self> { | |
|
90 | pub fn from_inner( | |
|
91 | py: Python, | |
|
92 | ait: VCGAncestorsIterator<Index>, | |
|
93 | ) -> PyResult<Self> { | |
|
90 | 94 | Self::create_instance(py, RefCell::new(Box::new(ait))) |
|
91 | 95 | } |
|
92 | 96 | } |
|
93 | 97 | |
|
94 | 98 | py_class!(pub class LazyAncestors |py| { |
|
95 |
data inner: RefCell<Box< |
|
|
99 | data inner: RefCell<Box<VCGLazyAncestors<Index>>>; | |
|
96 | 100 | |
|
97 | 101 | def __contains__(&self, rev: Revision) -> PyResult<bool> { |
|
98 | 102 | self.inner(py) |
|
99 | 103 | .borrow_mut() |
|
100 | 104 | .contains(rev) |
|
101 | .map_err(|e| GraphError::pynew(py, e)) | |
|
105 | .map_err(|e| GraphError::pynew_from_vcsgraph(py, e)) | |
|
102 | 106 | } |
|
103 | 107 | |
|
104 | 108 | def __iter__(&self) -> PyResult<AncestorsIterator> { |
@@ -114,9 +118,9 b' py_class!(pub class LazyAncestors |py| {' | |||
|
114 | 118 | let initvec: Vec<Revision> = rev_pyiter_collect(py, &initrevs)?; |
|
115 | 119 | |
|
116 | 120 | let lazy = |
|
117 |
|
|
|
121 | VCGLazyAncestors::new(pyindex_to_graph(py, index)?, | |
|
118 | 122 | initvec, stoprev, inclusive) |
|
119 | .map_err(|e| GraphError::pynew(py, e))?; | |
|
123 | .map_err(|e| GraphError::pynew_from_vcsgraph(py, e))?; | |
|
120 | 124 | |
|
121 | 125 | Self::create_instance(py, RefCell::new(Box::new(lazy))) |
|
122 | 126 | } |
@@ -37,6 +37,32 b' impl GraphError {' | |||
|
37 | 37 | } |
|
38 | 38 | } |
|
39 | 39 | } |
|
40 | ||
|
41 | pub fn pynew_from_vcsgraph( | |
|
42 | py: Python, | |
|
43 | inner: vcsgraph::graph::GraphReadError, | |
|
44 | ) -> PyErr { | |
|
45 | match inner { | |
|
46 | vcsgraph::graph::GraphReadError::InconsistentGraphData => { | |
|
47 | GraphError::new(py, "InconsistentGraphData") | |
|
48 | } | |
|
49 | vcsgraph::graph::GraphReadError::InvalidKey => { | |
|
50 | GraphError::new(py, "ParentOutOfRange") | |
|
51 | } | |
|
52 | vcsgraph::graph::GraphReadError::KeyedInvalidKey(r) => { | |
|
53 | GraphError::new(py, ("ParentOutOfRange", r)) | |
|
54 | } | |
|
55 | vcsgraph::graph::GraphReadError::WorkingDirectoryUnsupported => { | |
|
56 | match py | |
|
57 | .import("mercurial.error") | |
|
58 | .and_then(|m| m.get(py, "WdirUnsupported")) | |
|
59 | { | |
|
60 | Err(e) => e, | |
|
61 | Ok(cls) => PyErr::from_instance(py, cls), | |
|
62 | } | |
|
63 | } | |
|
64 | } | |
|
65 | } | |
|
40 | 66 | } |
|
41 | 67 | |
|
42 | 68 | py_exception!(rustext, HgPathPyError, RuntimeError); |
General Comments 0
You need to be logged in to leave comments.
Login now