[Request] [+ ] D12211: rust: expose rank computation function to python
pacien (Pacien)
phabricator at mercurial-scm.org
Mon Feb 21 17:13:30 UTC 2022
pacien created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.
REPOSITORY
rHG Mercurial
BRANCH
default
REVISION DETAIL
https://phab.mercurial-scm.org/D12211
AFFECTED FILES
rust/hg-cpython/src/dagops.rs
CHANGE DETAILS
diff --git a/rust/hg-cpython/src/dagops.rs b/rust/hg-cpython/src/dagops.rs
--- a/rust/hg-cpython/src/dagops.rs
+++ b/rust/hg-cpython/src/dagops.rs
@@ -14,6 +14,8 @@
use hg::dagops;
use hg::Revision;
use std::collections::HashSet;
+use vcsgraph::ancestors::node_rank;
+use vcsgraph::graph::{Parents, Rank};
use crate::revlog::pyindex_to_graph;
@@ -31,6 +33,18 @@
Ok(as_set)
}
+/// Computes the rank, i.e. the number of ancestors including itself,
+/// of a node represented by its parents.
+pub fn rank(
+ py: Python,
+ index: PyObject,
+ p1r: i32,
+ p2r: i32,
+) -> PyResult<Rank> {
+ node_rank(&pyindex_to_graph(py, index)?, &Parents([p1r, p2r]))
+ .map_err(|e| GraphError::pynew_from_vcsgraph(py, e))
+}
+
/// Create the module, with `__package__` given from parent
pub fn init_module(py: Python, package: &str) -> PyResult<PyModule> {
let dotted_name = &format!("{}.dagop", package);
@@ -42,6 +56,11 @@
"headrevs",
py_fn!(py, headrevs(index: PyObject, revs: PyObject)),
)?;
+ m.add(
+ py,
+ "rank",
+ py_fn!(py, rank(index: PyObject, p1r: i32, p2r: i32)),
+ )?;
let sys = PyModule::import(py, "sys")?;
let sys_modules: PyDict = sys.get(py, "modules")?.extract(py)?;
To: pacien, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mercurial-scm.org/pipermail/mercurial-patches/attachments/20220221/7aef07a1/attachment-0001.html>
More information about the Mercurial-patches
mailing list