##// END OF EJS Templates
rust: expose rank computation function to python...
pacien -
r49709:8b8054b8 default
parent child Browse files
Show More
@@ -14,6 +14,8 b' use cpython::{PyDict, PyModule, PyObject'
14 use hg::dagops;
14 use hg::dagops;
15 use hg::Revision;
15 use hg::Revision;
16 use std::collections::HashSet;
16 use std::collections::HashSet;
17 use vcsgraph::ancestors::node_rank;
18 use vcsgraph::graph::{Parents, Rank};
17
19
18 use crate::revlog::pyindex_to_graph;
20 use crate::revlog::pyindex_to_graph;
19
21
@@ -31,6 +33,18 b' pub fn headrevs('
31 Ok(as_set)
33 Ok(as_set)
32 }
34 }
33
35
36 /// Computes the rank, i.e. the number of ancestors including itself,
37 /// of a node represented by its parents.
38 pub fn rank(
39 py: Python,
40 index: PyObject,
41 p1r: Revision,
42 p2r: Revision,
43 ) -> PyResult<Rank> {
44 node_rank(&pyindex_to_graph(py, index)?, &Parents([p1r, p2r]))
45 .map_err(|e| GraphError::pynew_from_vcsgraph(py, e))
46 }
47
34 /// Create the module, with `__package__` given from parent
48 /// Create the module, with `__package__` given from parent
35 pub fn init_module(py: Python, package: &str) -> PyResult<PyModule> {
49 pub fn init_module(py: Python, package: &str) -> PyResult<PyModule> {
36 let dotted_name = &format!("{}.dagop", package);
50 let dotted_name = &format!("{}.dagop", package);
@@ -42,6 +56,11 b' pub fn init_module(py: Python, package: '
42 "headrevs",
56 "headrevs",
43 py_fn!(py, headrevs(index: PyObject, revs: PyObject)),
57 py_fn!(py, headrevs(index: PyObject, revs: PyObject)),
44 )?;
58 )?;
59 m.add(
60 py,
61 "rank",
62 py_fn!(py, rank(index: PyObject, p1r: Revision, p2r: Revision)),
63 )?;
45
64
46 let sys = PyModule::import(py, "sys")?;
65 let sys = PyModule::import(py, "sys")?;
47 let sys_modules: PyDict = sys.get(py, "modules")?.extract(py)?;
66 let sys_modules: PyDict = sys.get(py, "modules")?.extract(py)?;
General Comments 0
You need to be logged in to leave comments. Login now