Mercurial > hg
changeset 44011:c627f1b2f3c3
rust-index: handle `MixedIndex` in `pyindex_to_graph`
On the long run we will want to implement the Graph trait directly in Rust, but
for now we take the path with the least amount of change to focus on the coming
persistent NodeMap code.
We test this new code through with the lazy ancestors code.
Differential Revision: https://phab.mercurial-scm.org/D7657
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Thu, 12 Dec 2019 18:11:44 +0100 |
parents | 2728fcb8127c |
children | 443dc1655923 |
files | rust/hg-cpython/src/revlog.rs tests/test-rust-revlog.py |
diffstat | 2 files changed, 23 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/rust/hg-cpython/src/revlog.rs Fri Dec 13 19:52:26 2019 +0100 +++ b/rust/hg-cpython/src/revlog.rs Thu Dec 12 18:11:44 2019 +0100 @@ -15,7 +15,10 @@ /// Return a Struct implementing the Graph trait pub(crate) fn pyindex_to_graph(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| {
--- a/tests/test-rust-revlog.py Fri Dec 13 19:52:26 2019 +0100 +++ b/tests/test-rust-revlog.py Thu Dec 12 18:11:44 2019 +0100 @@ -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