Patchwork D7657: rust-index: handle `MixedIndex` in `pyindex_to_graph`

login
register
mail settings
Submitter phabricator
Date Dec. 19, 2019, 6:11 p.m.
Message ID <d7a3c04de8cddba1eb3694f7500d1a0a@localhost.localdomain>
Download mbox | patch
Permalink /patch/44000/
State Not Applicable
Headers show

Comments

phabricator - Dec. 19, 2019, 6:11 p.m.
marmoute updated this revision to Diff 18890.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D7657?vs=18703&id=18890

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7657/new/

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

AFFECTED FILES
  rust/hg-cpython/src/revlog.rs
  tests/test-rust-revlog.py

CHANGE DETAILS




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

Patch

diff --git a/tests/test-rust-revlog.py b/tests/test-rust-revlog.py
--- a/tests/test-rust-revlog.py
+++ b/tests/test-rust-revlog.py
@@ -10,6 +10,9 @@ 
 else:
     from mercurial.rustext import revlog
 
+    # this would fail already without appropriate ancestor.__package__
+    from mercurial.rustext.ancestor import LazyAncestors
+
 from mercurial.testing import revlog as revlogtesting
 
 
@@ -27,6 +30,22 @@ 
         rustidx = revlog.MixedIndex(idx)
         self.assertEqual(len(rustidx), len(idx))
 
+    def test_ancestors(self):
+        idx = self.parseindex()
+        rustidx = revlog.MixedIndex(idx)
+        lazy = LazyAncestors(rustidx, [3], 0, True)
+        # we have two more references to the index:
+        # - in its inner iterator for __contains__ and __bool__
+        # - in the LazyAncestors instance itself (to spawn new iterators)
+        self.assertTrue(2 in lazy)
+        self.assertTrue(bool(lazy))
+        self.assertEqual(list(lazy), [3, 2, 1, 0])
+        # a second time to validate that we spawn new iterators
+        self.assertEqual(list(lazy), [3, 2, 1, 0])
+
+        # let's check bool for an empty one
+        self.assertFalse(LazyAncestors(idx, [0], 0, False))
+
 
 if __name__ == '__main__':
     import silenttestrunner
diff --git a/rust/hg-cpython/src/revlog.rs b/rust/hg-cpython/src/revlog.rs
--- a/rust/hg-cpython/src/revlog.rs
+++ b/rust/hg-cpython/src/revlog.rs
@@ -18,7 +18,10 @@ 
     py: Python,
     index: PyObject,
 ) -> PyResult<cindex::Index> {
-    cindex::Index::new(py, index)
+    match index.extract::<MixedIndex>(py) {
+        Ok(midx) => Ok(midx.clone_cindex(py)),
+        Err(_) => cindex::Index::new(py, index),
+    }
 }
 
 py_class!(pub class MixedIndex |py| {