Mercurial > hg
changeset 42740:1c4b5689bef5
rust-discovery: exposing sampling to python
Differential Revision: https://phab.mercurial-scm.org/D6425
author | Georges Racinet <georges.racinet@octobus.net> |
---|---|
date | Fri, 17 May 2019 01:56:57 +0200 |
parents | 8041a1b45163 |
children | 4e7bd6180b53 |
files | rust/hg-cpython/src/discovery.rs |
diffstat | 1 files changed, 27 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/rust/hg-cpython/src/discovery.rs Fri May 17 01:56:57 2019 +0200 +++ b/rust/hg-cpython/src/discovery.rs Fri May 17 01:56:57 2019 +0200 @@ -18,7 +18,7 @@ exceptions::GraphError, }; use cpython::{ - ObjectProtocol, PyDict, PyModule, PyObject, PyResult, Python, + ObjectProtocol, PyDict, PyModule, PyObject, PyResult, PyTuple, Python, PythonObject, ToPyObject, }; use hg::discovery::PartialDiscovery as CorePartialDiscovery; @@ -111,6 +111,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