Mercurial > public > mercurial-scm > hg
diff rust/hg-cpython/src/discovery.rs @ 42180:1b0be75cb61f
rust-discovery: implementing and exposing stats()
This time, it's simple enough that we can do it in all layers in
one shot.
Differential Revision: https://phab.mercurial-scm.org/D6233
author | Georges Racinet <georges.racinet@octobus.net> |
---|---|
date | Thu, 14 Mar 2019 17:57:31 +0000 |
parents | 13b64247f48f |
children | 163b8fd7bb72 |
line wrap: on
line diff
--- a/rust/hg-cpython/src/discovery.rs Wed Feb 20 09:04:39 2019 +0100 +++ b/rust/hg-cpython/src/discovery.rs Thu Mar 14 17:57:31 2019 +0000 @@ -14,7 +14,9 @@ use crate::conversion::{py_set, rev_pyiter_collect}; use cindex::Index; -use cpython::{ObjectProtocol, PyDict, PyModule, PyObject, PyResult, Python}; +use cpython::{ + ObjectProtocol, PyDict, PyModule, PyObject, PyResult, Python, ToPyObject, +}; use exceptions::GraphError; use hg::discovery::PartialDiscovery as CorePartialDiscovery; use hg::Revision; @@ -83,6 +85,15 @@ Ok(self.inner(py).borrow().is_complete()) } + def stats(&self) -> PyResult<PyDict> { + let stats = self.inner(py).borrow().stats(); + let as_dict: PyDict = PyDict::new(py); + as_dict.set_item(py, "undecided", + stats.undecided.map(|l| l.to_py_object(py)) + .unwrap_or_else(|| py.None()))?; + Ok(as_dict) + } + def commonheads(&self) -> PyResult<PyObject> { py_set( py,