Show More
@@ -19,11 +19,11 use vcsgraph::lazy_ancestors::{ | |||||
19 | }; |
|
19 | }; | |
20 |
|
20 | |||
21 | use crate::convert_cpython::{ |
|
21 | use crate::convert_cpython::{ | |
22 |
|
|
22 | proxy_index_py_leak, py_leaked_borrow, py_leaked_borrow_mut, | |
23 |
|
|
23 | py_leaked_or_map_err, | |
24 | }; |
|
24 | }; | |
25 | use crate::exceptions::{map_lock_error, GraphError}; |
|
25 | use crate::exceptions::{map_lock_error, GraphError}; | |
26 | use crate::revision::{rev_pyiter_collect, PyRevision}; |
|
26 | use crate::revision::{rev_pyiter_collect_with_py_index, PyRevision}; | |
27 | use crate::util::new_submodule; |
|
27 | use crate::util::new_submodule; | |
28 | use rusthg::revlog::PySharedIndex; |
|
28 | use rusthg::revlog::PySharedIndex; | |
29 |
|
29 | |||
@@ -41,12 +41,8 impl AncestorsIterator { | |||||
41 | stoprev: PyRevision, |
|
41 | stoprev: PyRevision, | |
42 | inclusive: bool, |
|
42 | inclusive: bool, | |
43 | ) -> PyResult<Self> { |
|
43 | ) -> PyResult<Self> { | |
44 | // Safety: we don't leak the "faked" reference out of |
|
44 | let initvec: Vec<_> = | |
45 | // `UnsafePyLeaked` |
|
45 | rev_pyiter_collect_with_py_index(initrevs, index_proxy)?; | |
46 | let initvec: Vec<_> = { |
|
|||
47 | let borrowed_idx = unsafe { proxy_index_extract(index_proxy)? }; |
|
|||
48 | rev_pyiter_collect(initrevs, borrowed_idx)? |
|
|||
49 | }; |
|
|||
50 | let (py, leaked_idx) = proxy_index_py_leak(index_proxy)?; |
|
46 | let (py, leaked_idx) = proxy_index_py_leak(index_proxy)?; | |
51 | let res_ait = unsafe { |
|
47 | let res_ait = unsafe { | |
52 | leaked_idx.map(py, |idx| { |
|
48 | leaked_idx.map(py, |idx| { | |
@@ -99,12 +95,8 impl LazyAncestors { | |||||
99 | inclusive: bool, |
|
95 | inclusive: bool, | |
100 | ) -> PyResult<Self> { |
|
96 | ) -> PyResult<Self> { | |
101 | let cloned_proxy = index_proxy.clone().unbind(); |
|
97 | let cloned_proxy = index_proxy.clone().unbind(); | |
102 |
let initvec: Vec<_> = |
|
98 | let initvec: Vec<_> = | |
103 | // Safety: we don't leak the "faked" reference out of |
|
99 | rev_pyiter_collect_with_py_index(initrevs, index_proxy)?; | |
104 | // `UnsafePyLeaked` |
|
|||
105 | let borrowed_idx = unsafe { proxy_index_extract(index_proxy)? }; |
|
|||
106 | rev_pyiter_collect(initrevs, borrowed_idx)? |
|
|||
107 | }; |
|
|||
108 | let (py, leaked_idx) = proxy_index_py_leak(index_proxy)?; |
|
100 | let (py, leaked_idx) = proxy_index_py_leak(index_proxy)?; | |
109 | // Safety: we don't leak the "faked" reference out of |
|
101 | // Safety: we don't leak the "faked" reference out of | |
110 | // `UnsafePyLeaked` |
|
102 | // `UnsafePyLeaked` |
@@ -3,6 +3,7 use pyo3::prelude::*; | |||||
3 | use hg::revlog::RevlogIndex; |
|
3 | use hg::revlog::RevlogIndex; | |
4 | use hg::{BaseRevision, Revision, UncheckedRevision}; |
|
4 | use hg::{BaseRevision, Revision, UncheckedRevision}; | |
5 |
|
5 | |||
|
6 | use crate::convert_cpython::proxy_index_extract; | |||
6 | use crate::exceptions::GraphError; |
|
7 | use crate::exceptions::GraphError; | |
7 |
|
8 | |||
8 | /// Revision as exposed to/from the Python layer. |
|
9 | /// Revision as exposed to/from the Python layer. | |
@@ -55,6 +56,18 where | |||||
55 | }) |
|
56 | }) | |
56 | } |
|
57 | } | |
57 |
|
58 | |||
|
59 | pub fn rev_pyiter_collect_with_py_index<C>( | |||
|
60 | revs: &Bound<'_, PyAny>, | |||
|
61 | proxy_index: &Bound<'_, PyAny>, | |||
|
62 | ) -> PyResult<C> | |||
|
63 | where | |||
|
64 | C: FromIterator<Revision>, | |||
|
65 | { | |||
|
66 | // Safety: we don't leak the "faked" reference out of `UnsafePyLeaked` | |||
|
67 | let borrowed_idx = unsafe { proxy_index_extract(proxy_index)? }; | |||
|
68 | rev_pyiter_collect(revs, borrowed_idx) | |||
|
69 | } | |||
|
70 | ||||
58 | /// Same as [`rev_pyiter_collect`], giving control on returned errors |
|
71 | /// Same as [`rev_pyiter_collect`], giving control on returned errors | |
59 | pub fn rev_pyiter_collect_or_else<C, I>( |
|
72 | pub fn rev_pyiter_collect_or_else<C, I>( | |
60 | revs: &Bound<'_, PyAny>, |
|
73 | revs: &Bound<'_, PyAny>, |
General Comments 0
You need to be logged in to leave comments.
Login now