Show More
@@ -0,0 +1,17 b'' | |||
|
1 | // revlog.rs | |
|
2 | // | |
|
3 | // Copyright 2019 Georges Racinet <georges.racinet@octobus.net> | |
|
4 | // | |
|
5 | // This software may be used and distributed according to the terms of the | |
|
6 | // GNU General Public License version 2 or any later version. | |
|
7 | ||
|
8 | use crate::cindex; | |
|
9 | use cpython::{PyObject, PyResult, Python}; | |
|
10 | ||
|
11 | /// Return a Struct implementing the Graph trait | |
|
12 | pub(crate) fn pyindex_to_graph( | |
|
13 | py: Python, | |
|
14 | index: PyObject, | |
|
15 | ) -> PyResult<cindex::Index> { | |
|
16 | cindex::Index::new(py, index) | |
|
17 | } |
@@ -34,6 +34,7 b'' | |||
|
34 | 34 | //! [`LazyAncestors`]: struct.LazyAncestors.html |
|
35 | 35 | //! [`MissingAncestors`]: struct.MissingAncestors.html |
|
36 | 36 | //! [`AncestorsIterator`]: struct.AncestorsIterator.html |
|
37 | use crate::revlog::pyindex_to_graph; | |
|
37 | 38 | use crate::{ |
|
38 | 39 | cindex::Index, conversion::rev_pyiter_collect, exceptions::GraphError, |
|
39 | 40 | }; |
@@ -73,7 +74,7 b' py_class!(pub class AncestorsIterator |p' | |||
|
73 | 74 | inclusive: bool) -> PyResult<AncestorsIterator> { |
|
74 | 75 | let initvec: Vec<Revision> = rev_pyiter_collect(py, &initrevs)?; |
|
75 | 76 | let ait = CoreIterator::new( |
|
76 |
|
|
|
77 | pyindex_to_graph(py, index)?, | |
|
77 | 78 | initvec, |
|
78 | 79 | stoprev, |
|
79 | 80 | inclusive, |
@@ -113,7 +114,8 b' py_class!(pub class LazyAncestors |py| {' | |||
|
113 | 114 | let initvec: Vec<Revision> = rev_pyiter_collect(py, &initrevs)?; |
|
114 | 115 | |
|
115 | 116 | let lazy = |
|
116 |
CoreLazy::new( |
|
|
117 | CoreLazy::new(pyindex_to_graph(py, index)?, | |
|
118 | initvec, stoprev, inclusive) | |
|
117 | 119 | .map_err(|e| GraphError::pynew(py, e))?; |
|
118 | 120 | |
|
119 | 121 | Self::create_instance(py, RefCell::new(Box::new(lazy))) |
@@ -126,7 +128,7 b' py_class!(pub class MissingAncestors |py' | |||
|
126 | 128 | |
|
127 | 129 | def __new__(_cls, index: PyObject, bases: PyObject) -> PyResult<MissingAncestors> { |
|
128 | 130 | let bases_vec: Vec<Revision> = rev_pyiter_collect(py, &bases)?; |
|
129 |
let inner = CoreMissing::new( |
|
|
131 | let inner = CoreMissing::new(pyindex_to_graph(py, index)?, bases_vec); | |
|
130 | 132 | MissingAncestors::create_instance(py, RefCell::new(Box::new(inner))) |
|
131 | 133 | } |
|
132 | 134 |
@@ -9,14 +9,14 b'' | |||
|
9 | 9 | //! `hg-core` package. |
|
10 | 10 | //! |
|
11 | 11 | //! From Python, this will be seen as `mercurial.rustext.dagop` |
|
12 | use crate::{ | |
|
13 | cindex::Index, conversion::rev_pyiter_collect, exceptions::GraphError, | |
|
14 | }; | |
|
12 | use crate::{conversion::rev_pyiter_collect, exceptions::GraphError}; | |
|
15 | 13 | use cpython::{PyDict, PyModule, PyObject, PyResult, Python}; |
|
16 | 14 | use hg::dagops; |
|
17 | 15 | use hg::Revision; |
|
18 | 16 | use std::collections::HashSet; |
|
19 | 17 | |
|
18 | use crate::revlog::pyindex_to_graph; | |
|
19 | ||
|
20 | 20 | /// Using the the `index`, return heads out of any Python iterable of Revisions |
|
21 | 21 | /// |
|
22 | 22 | /// This is the Rust counterpart for `mercurial.dagop.headrevs` |
@@ -26,7 +26,7 b' pub fn headrevs(' | |||
|
26 | 26 | revs: PyObject, |
|
27 | 27 | ) -> PyResult<HashSet<Revision>> { |
|
28 | 28 | let mut as_set: HashSet<Revision> = rev_pyiter_collect(py, &revs)?; |
|
29 |
dagops::retain_heads(& |
|
|
29 | dagops::retain_heads(&pyindex_to_graph(py, index)?, &mut as_set) | |
|
30 | 30 | .map_err(|e| GraphError::pynew(py, e))?; |
|
31 | 31 | Ok(as_set) |
|
32 | 32 | } |
@@ -25,6 +25,8 b' use std::collections::HashSet;' | |||
|
25 | 25 | |
|
26 | 26 | use std::cell::RefCell; |
|
27 | 27 | |
|
28 | use crate::revlog::pyindex_to_graph; | |
|
29 | ||
|
28 | 30 | py_class!(pub class PartialDiscovery |py| { |
|
29 | 31 | data inner: RefCell<Box<CorePartialDiscovery<Index>>>; |
|
30 | 32 | |
@@ -42,7 +44,7 b' py_class!(pub class PartialDiscovery |py' | |||
|
42 | 44 | Self::create_instance( |
|
43 | 45 | py, |
|
44 | 46 | RefCell::new(Box::new(CorePartialDiscovery::new( |
|
45 |
|
|
|
47 | pyindex_to_graph(py, index)?, | |
|
46 | 48 | rev_pyiter_collect(py, &targetheads)?, |
|
47 | 49 | respectsize, |
|
48 | 50 | randomize, |
General Comments 0
You need to be logged in to leave comments.
Login now