rust-discovery: read the index from a repo passed at init
This makes the API of the Rust PartialDiscovery object now
the same (or rather a subset) of the Python object, hence
easier to control through module policy down the road.
Differential Revision: https://phab.mercurial-scm.org/D6517
--- a/rust/hg-cpython/src/discovery.rs Wed Jun 12 14:18:12 2019 +0100
+++ b/rust/hg-cpython/src/discovery.rs Wed Jun 12 14:31:41 2019 +0100
@@ -34,10 +34,11 @@
// implemented.
def __new__(
_cls,
- index: PyObject,
+ repo: PyObject,
targetheads: PyObject,
_respectsize: bool
) -> PyResult<PartialDiscovery> {
+ let index = repo.getattr(py, "changelog")?.getattr(py, "index")?;
Self::create_instance(
py,
RefCell::new(Box::new(CorePartialDiscovery::new(
--- a/tests/test-rust-discovery.py Wed Jun 12 14:18:12 2019 +0100
+++ b/tests/test-rust-discovery.py Wed Jun 12 14:31:41 2019 +0100
@@ -31,6 +31,11 @@
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00'
)
+class fakerepo(object):
+ def __init__(self, idx):
+ """Just make so that self.changelog.index is the given idx."""
+ self.index = idx
+ self.changelog = self
@unittest.skipIf(PartialDiscovery is None or cparsers is None,
"rustext or the C Extension parsers module "
@@ -50,6 +55,9 @@
def parseindex(self):
return cparsers.parse_index2(data_non_inlined, False)[0]
+ def repo(self):
+ return fakerepo(self.parseindex())
+
def testindex(self):
idx = self.parseindex()
# checking our assumptions about the index binary data:
@@ -60,8 +68,7 @@
3: (2, -1)})
def testaddcommonsmissings(self):
- idx = self.parseindex()
- disco = PartialDiscovery(idx, [3], True)
+ disco = PartialDiscovery(self.repo(), [3], True)
self.assertFalse(disco.hasinfo())
self.assertFalse(disco.iscomplete())
@@ -76,24 +83,21 @@
self.assertEqual(disco.commonheads(), {1})
def testaddmissingsstats(self):
- idx = self.parseindex()
- disco = PartialDiscovery(idx, [3], True)
+ disco = PartialDiscovery(self.repo(), [3], True)
self.assertIsNone(disco.stats()['undecided'], None)
disco.addmissings([2])
self.assertEqual(disco.stats()['undecided'], 2)
def testaddinfocommonfirst(self):
- idx = self.parseindex()
- disco = PartialDiscovery(idx, [3], True)
+ disco = PartialDiscovery(self.repo(), [3], True)
disco.addinfo([(1, True), (2, False)])
self.assertTrue(disco.hasinfo())
self.assertTrue(disco.iscomplete())
self.assertEqual(disco.commonheads(), {1})
def testaddinfomissingfirst(self):
- idx = self.parseindex()
- disco = PartialDiscovery(idx, [3], True)
+ disco = PartialDiscovery(self.repo(), [3], True)
disco.addinfo([(2, False), (1, True)])
self.assertTrue(disco.hasinfo())
self.assertTrue(disco.iscomplete())