D6261: rust-discovery: exposing sampling to python

gracinet (Georges Racinet) phabricator at mercurial-scm.org
Wed May 15 14:31:07 EDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rHGe7d3e56fa32e: rust-discovery: exposing sampling to python (authored by gracinet, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6261?vs=15023&id=15119

REVISION DETAIL
  https://phab.mercurial-scm.org/D6261

AFFECTED FILES
  rust/hg-cpython/src/discovery.rs

CHANGE DETAILS

diff --git a/rust/hg-cpython/src/discovery.rs b/rust/hg-cpython/src/discovery.rs
--- a/rust/hg-cpython/src/discovery.rs
+++ b/rust/hg-cpython/src/discovery.rs
@@ -15,7 +15,8 @@
 use crate::conversion::{py_set, rev_pyiter_collect};
 use cindex::Index;
 use cpython::{
-    ObjectProtocol, PyDict, PyModule, PyObject, PyResult, Python, ToPyObject,
+    ObjectProtocol, PyDict, PyModule, PyObject, PyResult, PyTuple, Python,
+    PythonObject, ToPyObject,
 };
 use exceptions::GraphError;
 use hg::discovery::PartialDiscovery as CorePartialDiscovery;
@@ -101,6 +102,32 @@
                 .map_err(|e| GraphError::pynew(py, e))?
         )
     }
+
+    def takefullsample(&self, _headrevs: PyObject,
+                       size: usize) -> PyResult<PyObject> {
+        let mut inner = self.inner(py).borrow_mut();
+        let sample = inner.take_full_sample(size)
+            .map_err(|e| GraphError::pynew(py, e))?;
+        let as_vec: Vec<PyObject> = sample
+            .iter()
+            .map(|rev| rev.to_py_object(py).into_object())
+            .collect();
+        Ok(PyTuple::new(py, as_vec.as_slice()).into_object())
+    }
+
+    def takequicksample(&self, headrevs: PyObject,
+                        size: usize) -> PyResult<PyObject> {
+        let mut inner = self.inner(py).borrow_mut();
+        let revsvec: Vec<Revision> = rev_pyiter_collect(py, &headrevs)?;
+        let sample = inner.take_quick_sample(revsvec, size)
+            .map_err(|e| GraphError::pynew(py, e))?;
+        let as_vec: Vec<PyObject> = sample
+            .iter()
+            .map(|rev| rev.to_py_object(py).into_object())
+            .collect();
+        Ok(PyTuple::new(py, as_vec.as_slice()).into_object())
+    }
+
 });
 
 /// Create the module, with __package__ given from parent



To: gracinet, #hg-reviewers, kevincox
Cc: durin42, kevincox, mercurial-devel


More information about the Mercurial-devel mailing list