Mercurial > public > mercurial-scm > hg
diff tests/test-rust-ancestor.py @ 51236:7eea2e4109ae
rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Since there is no Rust implementation for REVLOGV2/CHANGELOGv2, we declare
them to be incompatible with Rust, hence indexes in these formats will use
the implementations from Python `mercurial.ancestor`. If this is an unacceptable
performance hit for current users of these formats, we can later on add Rust
implementations based on the C index for them or implement these formats for
the Rust indexes.
Among the challenges that we had to meet, we wanted to avoid taking the GIL each
time the inner (vcsgraph) iterator has to call the parents function. This would probably
still be acceptable in terms of performance with `AncestorsIterator`, but not with
`LazyAncestors` nor for the upcoming change in `MissingAncestors`.
Hence we enclose the reference to the index in a `PySharedRef`, leading to more
rigourous checking of mutations, which does pass now that there no logically immutable
methods of `hg::index::Index` that take a mutable reference as input.
author | Georges Racinet <georges.racinet@octobus.net> |
---|---|
date | Fri, 27 Oct 2023 22:11:05 +0200 |
parents | 4c5f6e95df84 |
children | 59d81768ad6d |
line wrap: on
line diff
--- a/tests/test-rust-ancestor.py Fri Oct 27 23:29:29 2023 +0200 +++ b/tests/test-rust-ancestor.py Fri Oct 27 22:11:05 2023 +0200 @@ -50,7 +50,7 @@ """ def testiteratorrevlist(self): - idx = self.parseindex() + idx = self.parserustindex() # checking test assumption about the index binary data: self.assertEqual( {i: (r[5], r[6]) for i, r in enumerate(idx)}, @@ -63,7 +63,7 @@ self.assertEqual([r for r in ait], [2, 1, 0]) def testlazyancestors(self): - idx = self.parseindex() + idx = self.parserustindex() start_count = sys.getrefcount(idx) # should be 2 (see Python doc) self.assertEqual( {i: (r[5], r[6]) for i, r in enumerate(idx)}, @@ -110,7 +110,7 @@ self.assertEqual(revs, {2, 3}) def testrefcount(self): - idx = self.parseindex() + idx = self.parserustindex() start_count = sys.getrefcount(idx) # refcount increases upon iterator init... @@ -127,13 +127,17 @@ del idx self.assertEqual(list(ait), [3, 2, 1, 0]) + # the index is not tracked by the GC, hence there is nothing more + # we can assert to check that it is properly deleted once its refcount + # drops to 0 + def testgrapherror(self): data = ( revlogtesting.data_non_inlined[: 64 + 27] + b'\xf2' + revlogtesting.data_non_inlined[64 + 28 :] ) - idx = cparsers.parse_index2(data, False)[0] + idx = self.parserustindex(data=data) with self.assertRaises(rustext.GraphError) as arc: AncestorsIterator(idx, [1], -1, False) exc = arc.exception @@ -143,7 +147,7 @@ def testwdirunsupported(self): # trying to access ancestors of the working directory raises - idx = self.parseindex() + idx = self.parserustindex() with self.assertRaises(rustext.GraphError) as arc: list(AncestorsIterator(idx, [wdirrev], -1, False))