D5550: rust-cpython: bindings for MissingAncestors

yuja (Yuya Nishihara) phabricator at mercurial-scm.org
Fri Jan 11 09:10:36 EST 2019


yuja added a comment.


  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.

REPOSITORY
  rHG Mercurial

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

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


More information about the Mercurial-devel mailing list