##// END OF EJS Templates
rust-index: add a function to convert PyObject index for hg-core...
marmoute -
r44398:f98f0e3d default
parent child Browse files
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 //! [`LazyAncestors`]: struct.LazyAncestors.html
34 //! [`LazyAncestors`]: struct.LazyAncestors.html
35 //! [`MissingAncestors`]: struct.MissingAncestors.html
35 //! [`MissingAncestors`]: struct.MissingAncestors.html
36 //! [`AncestorsIterator`]: struct.AncestorsIterator.html
36 //! [`AncestorsIterator`]: struct.AncestorsIterator.html
37 use crate::revlog::pyindex_to_graph;
37 use crate::{
38 use crate::{
38 cindex::Index, conversion::rev_pyiter_collect, exceptions::GraphError,
39 cindex::Index, conversion::rev_pyiter_collect, exceptions::GraphError,
39 };
40 };
@@ -73,7 +74,7 b' py_class!(pub class AncestorsIterator |p'
73 inclusive: bool) -> PyResult<AncestorsIterator> {
74 inclusive: bool) -> PyResult<AncestorsIterator> {
74 let initvec: Vec<Revision> = rev_pyiter_collect(py, &initrevs)?;
75 let initvec: Vec<Revision> = rev_pyiter_collect(py, &initrevs)?;
75 let ait = CoreIterator::new(
76 let ait = CoreIterator::new(
76 Index::new(py, index)?,
77 pyindex_to_graph(py, index)?,
77 initvec,
78 initvec,
78 stoprev,
79 stoprev,
79 inclusive,
80 inclusive,
@@ -113,7 +114,8 b' py_class!(pub class LazyAncestors |py| {'
113 let initvec: Vec<Revision> = rev_pyiter_collect(py, &initrevs)?;
114 let initvec: Vec<Revision> = rev_pyiter_collect(py, &initrevs)?;
114
115
115 let lazy =
116 let lazy =
116 CoreLazy::new(Index::new(py, index)?, initvec, stoprev, inclusive)
117 CoreLazy::new(pyindex_to_graph(py, index)?,
118 initvec, stoprev, inclusive)
117 .map_err(|e| GraphError::pynew(py, e))?;
119 .map_err(|e| GraphError::pynew(py, e))?;
118
120
119 Self::create_instance(py, RefCell::new(Box::new(lazy)))
121 Self::create_instance(py, RefCell::new(Box::new(lazy)))
@@ -126,7 +128,7 b' py_class!(pub class MissingAncestors |py'
126
128
127 def __new__(_cls, index: PyObject, bases: PyObject) -> PyResult<MissingAncestors> {
129 def __new__(_cls, index: PyObject, bases: PyObject) -> PyResult<MissingAncestors> {
128 let bases_vec: Vec<Revision> = rev_pyiter_collect(py, &bases)?;
130 let bases_vec: Vec<Revision> = rev_pyiter_collect(py, &bases)?;
129 let inner = CoreMissing::new(Index::new(py, index)?, bases_vec);
131 let inner = CoreMissing::new(pyindex_to_graph(py, index)?, bases_vec);
130 MissingAncestors::create_instance(py, RefCell::new(Box::new(inner)))
132 MissingAncestors::create_instance(py, RefCell::new(Box::new(inner)))
131 }
133 }
132
134
@@ -9,14 +9,14 b''
9 //! `hg-core` package.
9 //! `hg-core` package.
10 //!
10 //!
11 //! From Python, this will be seen as `mercurial.rustext.dagop`
11 //! From Python, this will be seen as `mercurial.rustext.dagop`
12 use crate::{
12 use crate::{conversion::rev_pyiter_collect, exceptions::GraphError};
13 cindex::Index, conversion::rev_pyiter_collect, exceptions::GraphError,
14 };
15 use cpython::{PyDict, PyModule, PyObject, PyResult, Python};
13 use cpython::{PyDict, PyModule, PyObject, PyResult, Python};
16 use hg::dagops;
14 use hg::dagops;
17 use hg::Revision;
15 use hg::Revision;
18 use std::collections::HashSet;
16 use std::collections::HashSet;
19
17
18 use crate::revlog::pyindex_to_graph;
19
20 /// Using the the `index`, return heads out of any Python iterable of Revisions
20 /// Using the the `index`, return heads out of any Python iterable of Revisions
21 ///
21 ///
22 /// This is the Rust counterpart for `mercurial.dagop.headrevs`
22 /// This is the Rust counterpart for `mercurial.dagop.headrevs`
@@ -26,7 +26,7 b' pub fn headrevs('
26 revs: PyObject,
26 revs: PyObject,
27 ) -> PyResult<HashSet<Revision>> {
27 ) -> PyResult<HashSet<Revision>> {
28 let mut as_set: HashSet<Revision> = rev_pyiter_collect(py, &revs)?;
28 let mut as_set: HashSet<Revision> = rev_pyiter_collect(py, &revs)?;
29 dagops::retain_heads(&Index::new(py, index)?, &mut as_set)
29 dagops::retain_heads(&pyindex_to_graph(py, index)?, &mut as_set)
30 .map_err(|e| GraphError::pynew(py, e))?;
30 .map_err(|e| GraphError::pynew(py, e))?;
31 Ok(as_set)
31 Ok(as_set)
32 }
32 }
@@ -25,6 +25,8 b' use std::collections::HashSet;'
25
25
26 use std::cell::RefCell;
26 use std::cell::RefCell;
27
27
28 use crate::revlog::pyindex_to_graph;
29
28 py_class!(pub class PartialDiscovery |py| {
30 py_class!(pub class PartialDiscovery |py| {
29 data inner: RefCell<Box<CorePartialDiscovery<Index>>>;
31 data inner: RefCell<Box<CorePartialDiscovery<Index>>>;
30
32
@@ -42,7 +44,7 b' py_class!(pub class PartialDiscovery |py'
42 Self::create_instance(
44 Self::create_instance(
43 py,
45 py,
44 RefCell::new(Box::new(CorePartialDiscovery::new(
46 RefCell::new(Box::new(CorePartialDiscovery::new(
45 Index::new(py, index)?,
47 pyindex_to_graph(py, index)?,
46 rev_pyiter_collect(py, &targetheads)?,
48 rev_pyiter_collect(py, &targetheads)?,
47 respectsize,
49 respectsize,
48 randomize,
50 randomize,
@@ -35,6 +35,7 b' pub mod discovery;'
35 pub mod exceptions;
35 pub mod exceptions;
36 pub mod filepatterns;
36 pub mod filepatterns;
37 pub mod parsers;
37 pub mod parsers;
38 pub mod revlog;
38 pub mod utils;
39 pub mod utils;
39
40
40 py_module_initializer!(rustext, initrustext, PyInit_rustext, |py, m| {
41 py_module_initializer!(rustext, initrustext, PyInit_rustext, |py, m| {
General Comments 0
You need to be logged in to leave comments. Login now