diff rust/hg-cpython/src/ancestors.rs @ 43945:f98f0e3ddaa1

rust-index: add a function to convert PyObject index for hg-core Function in hg-core need something implementing the `Graph` trait. Right now, the `hg-cpython` entry points directly turn the PyObject passed as argument into a `cindex::Index`. However, if we start having the option to use an Index in Rust, we need to dispatch between the different possible PyObject we could receive. So move the "duplicate" call into a unified function. When time come. It will be easy to update the logic of all interface when the time come. Differential Revision: https://phab.mercurial-scm.org/D7653
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Fri, 13 Dec 2019 19:59:59 +0100
parents 33fe96a5c522
children b24721e7c5ee
line wrap: on
line diff
--- a/rust/hg-cpython/src/ancestors.rs	Wed Dec 11 18:40:04 2019 +0100
+++ b/rust/hg-cpython/src/ancestors.rs	Fri Dec 13 19:59:59 2019 +0100
@@ -34,6 +34,7 @@
 //! [`LazyAncestors`]: struct.LazyAncestors.html
 //! [`MissingAncestors`]: struct.MissingAncestors.html
 //! [`AncestorsIterator`]: struct.AncestorsIterator.html
+use crate::revlog::pyindex_to_graph;
 use crate::{
     cindex::Index, conversion::rev_pyiter_collect, exceptions::GraphError,
 };
@@ -73,7 +74,7 @@
                 inclusive: bool) -> PyResult<AncestorsIterator> {
         let initvec: Vec<Revision> = rev_pyiter_collect(py, &initrevs)?;
         let ait = CoreIterator::new(
-            Index::new(py, index)?,
+            pyindex_to_graph(py, index)?,
             initvec,
             stoprev,
             inclusive,
@@ -113,7 +114,8 @@
         let initvec: Vec<Revision> = rev_pyiter_collect(py, &initrevs)?;
 
         let lazy =
-            CoreLazy::new(Index::new(py, index)?, initvec, stoprev, inclusive)
+            CoreLazy::new(pyindex_to_graph(py, index)?,
+                          initvec, stoprev, inclusive)
                 .map_err(|e| GraphError::pynew(py, e))?;
 
         Self::create_instance(py, RefCell::new(Box::new(lazy)))
@@ -126,7 +128,7 @@
 
     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);
+        let inner = CoreMissing::new(pyindex_to_graph(py, index)?, bases_vec);
         MissingAncestors::create_instance(py, RefCell::new(Box::new(inner)))
     }