D5550: rust-cpython: bindings for MissingAncestors

Yuya Nishihara yuya at tcha.org
Fri Jan 11 09:05:29 EST 2019


Queued up to this patch, thanks.

> +    def __new__(_cls, index: PyObject, bases: PyObject) -> PyResult<MissingAncestors> {
> +        let bases_vec: Vec<Revision> = rev_pyiter_collect(py, &bases)?;
> +        let inner = CoreMissing::new(Index::new(py, index)?, bases_vec);

We might want to directly build `HashSet<Revision>` here if that matters.

> +    def missingancestors(&self, revs: PyObject) -> PyResult<PyList> {
> +        let mut inner = self.inner(py).borrow_mut();
> +        let revs_vec: Vec<Revision> = rev_pyiter_collect(py, &revs)?;
> +        let missing_vec = match inner.missing_ancestors(revs_vec) {
> +            Ok(missing) => missing,
> +            Err(e) => {
> +                return Err(GraphError::pynew(py, e));
> +            }
> +        };

> +        // convert as Python list
> +        let mut missing_pyint_vec: Vec<PyObject> = Vec::with_capacity(
> +            missing_vec.len());
> +        for rev in missing_vec {
> +            missing_pyint_vec.push(rev.to_py_object(py).into_object());
> +        }
> +        Ok(PyList::new(py, missing_pyint_vec.as_slice()))

Maybe this can be extracted to a helper function so that we can `.map()`
the result.


More information about the Mercurial-devel mailing list