Patchwork D6517: rust-discovery: read the index from a repo passed at init

login
register
mail settings
Submitter phabricator
Date June 12, 2019, 6:13 p.m.
Message ID <differential-rev-PHID-DREV-tuhv3tsphlajhv7cssjc-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/40455/
State New
Headers show

Comments

phabricator - June 12, 2019, 6:13 p.m.
gracinet created this revision.
Herald added subscribers: mercurial-devel, kevincox, durin42.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  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.

REPOSITORY
  rHG Mercurial

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

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

CHANGE DETAILS




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

Patch

diff --git a/tests/test-rust-discovery.py b/tests/test-rust-discovery.py
--- a/tests/test-rust-discovery.py
+++ b/tests/test-rust-discovery.py
@@ -38,6 +38,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(rustext is None or cparsers is None,
                  "rustext or the C Extension parsers module "
@@ -57,6 +62,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:
@@ -67,8 +75,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())
 
@@ -83,24 +90,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())
diff --git a/rust/hg-cpython/src/discovery.rs b/rust/hg-cpython/src/discovery.rs
--- a/rust/hg-cpython/src/discovery.rs
+++ b/rust/hg-cpython/src/discovery.rs
@@ -29,10 +29,11 @@ 
 
     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(