D5439: rust-cpython: binding for AncestorsIterator

yuja (Yuya Nishihara) phabricator at mercurial-scm.org
Sat Dec 15 23:02:35 EST 2018


yuja added a comment.


  >   // GNU General Public License version 2 or any later version.
  > 
  > - //! Bindings for the hg::ancestors module provided by the
  
  Nit: perhaps the empty line was removed by mistake.
  
  > +fn reviter_to_revvec(py: Python, revs: PyObject) -> PyResult<Vec<Revision>> {
  >  +    let revs_iter = revs.iter(py)?;
  >  +    // we need to convert to a vector, because Python iterables can
  >  +    // raise errors at each step.
  >  +    let cap = match revs.len(py) {
  >  +        Ok(l) => l,
  >  +        Err(_) => 0, // unknown
  >  +    };
  >  +    let mut initvec: Vec<Revision> = Vec::with_capacity(cap);
  >  +    for result_revpy in revs_iter {
  >  +        let as_pyint: PyInt = match result_revpy {
  >  +            Err(e) => {
  >  +                return Err(e);
  >  +            }
  >  +            Ok(revpy) => revpy.extract(py)?,
  >  +        };
  >  +        initvec.push(as_pyint.value(py) as Revision);
  >  +    }
  >  +    Ok(initvec)
  
  
  
    revs_iter.map(|r| r.and_then(|o| o.extract::<Revision>(py))).collect()
  
  `PyInt::value()` isn't supported on Python 3, and it should be better to
  extract int directly with bounds checking.
  
  https://dgrunwald.github.io/rust-cpython/doc/cpython/struct.PyInt.html#method.value
  
  > +impl AncestorsIterator {
  >  +    pub fn from_inner(py: Python, ait: CoreIterator<Index>) -> PyResult<Self> {
  
  Nit: I slightly prefer spelling it as `hg::AncestorsIterator`.

REPOSITORY
  rHG Mercurial

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

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


More information about the Mercurial-devel mailing list