##// END OF EJS Templates
rust-index: stop instantiating a C Index...
Georges Racinet -
r52146:96e05f1a default
parent child Browse files
Show More
@@ -226,8 +226,8 b' else:'
226
226
227
227
228 def parse_index_v1_mixed(data, inline, default_header):
228 def parse_index_v1_mixed(data, inline, default_header):
229 index, cache = parse_index_v1(data, inline)
229 cache = (0, data) if inline else None
230 return rustrevlog.MixedIndex(index, data, default_header), cache
230 return rustrevlog.MixedIndex(data, default_header), cache
231
231
232
232
233 # corresponds to uncompressed length of indexformatng (2 gigs, 4-byte
233 # corresponds to uncompressed length of indexformatng (2 gigs, 4-byte
@@ -57,5 +57,4 b' class RustRevlogBasedTestBase(unittest.T'
57 # not inheriting RevlogBasedTestCase to avoid having a
57 # not inheriting RevlogBasedTestCase to avoid having a
58 # `parseindex` method that would be shadowed by future subclasses
58 # `parseindex` method that would be shadowed by future subclasses
59 # this duplication will soon be removed
59 # this duplication will soon be removed
60 cindex = cparsers.parse_index2(data, False)[0]
60 return MixedIndex(data, REVLOGV1)
61 return MixedIndex(cindex, data, REVLOGV1)
@@ -9,7 +9,7 b''
9 //!
9 //!
10 //! Ideally, we should use an Index entirely implemented in Rust,
10 //! Ideally, we should use an Index entirely implemented in Rust,
11 //! but this will take some time to get there.
11 //! but this will take some time to get there.
12
12 #![allow(dead_code)]
13 use cpython::{
13 use cpython::{
14 exc::ImportError, exc::TypeError, ObjectProtocol, PyClone, PyErr,
14 exc::ImportError, exc::TypeError, ObjectProtocol, PyClone, PyErr,
15 PyObject, PyResult, PyTuple, Python, PythonObject,
15 PyObject, PyResult, PyTuple, Python, PythonObject,
@@ -6,7 +6,6 b''
6 // GNU General Public License version 2 or any later version.
6 // GNU General Public License version 2 or any later version.
7
7
8 use crate::{
8 use crate::{
9 cindex,
10 conversion::{rev_pyiter_collect, rev_pyiter_collect_or_else},
9 conversion::{rev_pyiter_collect, rev_pyiter_collect_or_else},
11 utils::{node_from_py_bytes, node_from_py_object},
10 utils::{node_from_py_bytes, node_from_py_object},
12 PyRevision,
11 PyRevision,
@@ -87,7 +86,6 b' impl RevlogIndex for PySharedIndex {'
87 }
86 }
88
87
89 py_class!(pub class MixedIndex |py| {
88 py_class!(pub class MixedIndex |py| {
90 data cindex: RefCell<cindex::Index>;
91 @shared data index: hg::index::Index;
89 @shared data index: hg::index::Index;
92 data nt: RefCell<Option<CoreNodeTree>>;
90 data nt: RefCell<Option<CoreNodeTree>>;
93 data docket: RefCell<Option<PyObject>>;
91 data docket: RefCell<Option<PyObject>>;
@@ -98,11 +96,10 b' py_class!(pub class MixedIndex |py| {'
98
96
99 def __new__(
97 def __new__(
100 _cls,
98 _cls,
101 cindex: PyObject,
102 data: PyObject,
99 data: PyObject,
103 default_header: u32,
100 default_header: u32,
104 ) -> PyResult<MixedIndex> {
101 ) -> PyResult<MixedIndex> {
105 Self::new(py, cindex, data, default_header)
102 Self::new(py, data, default_header)
106 }
103 }
107
104
108 /// Compatibility layer used for Python consumers needing access to the C index
105 /// Compatibility layer used for Python consumers needing access to the C index
@@ -111,11 +108,11 b' py_class!(pub class MixedIndex |py| {'
111 /// that may need to build a custom `nodetree`, based on a specified revset.
108 /// that may need to build a custom `nodetree`, based on a specified revset.
112 /// With a Rust implementation of the nodemap, we will be able to get rid of
109 /// With a Rust implementation of the nodemap, we will be able to get rid of
113 /// this, by exposing our own standalone nodemap class,
110 /// this, by exposing our own standalone nodemap class,
114 /// ready to accept `MixedIndex`.
111 /// ready to accept `Index`.
115 def get_cindex(&self) -> PyResult<PyObject> {
112 /* def get_cindex(&self) -> PyResult<PyObject> {
116 Ok(self.cindex(py).borrow().inner().clone_ref(py))
113 Ok(self.cindex(py).borrow().inner().clone_ref(py))
117 }
114 }
118
115 */
119 // Index API involving nodemap, as defined in mercurial/pure/parsers.py
116 // Index API involving nodemap, as defined in mercurial/pure/parsers.py
120
117
121 /// Return Revision if found, raises a bare `error.RevlogError`
118 /// Return Revision if found, raises a bare `error.RevlogError`
@@ -602,18 +599,12 b" impl<'p> SnapshotsCache for PySnapshotsC"
602 }
599 }
603
600
604 impl MixedIndex {
601 impl MixedIndex {
605 fn new(
602 fn new(py: Python, data: PyObject, header: u32) -> PyResult<MixedIndex> {
606 py: Python,
607 cindex: PyObject,
608 data: PyObject,
609 header: u32,
610 ) -> PyResult<MixedIndex> {
611 // Safety: we keep the buffer around inside the class as `index_mmap`
603 // Safety: we keep the buffer around inside the class as `index_mmap`
612 let (buf, bytes) = unsafe { mmap_keeparound(py, data)? };
604 let (buf, bytes) = unsafe { mmap_keeparound(py, data)? };
613
605
614 Self::create_instance(
606 Self::create_instance(
615 py,
607 py,
616 RefCell::new(cindex::Index::new(py, cindex)?),
617 hg::index::Index::new(
608 hg::index::Index::new(
618 bytes,
609 bytes,
619 IndexHeader::parse(&header.to_be_bytes())
610 IndexHeader::parse(&header.to_be_bytes())
@@ -666,10 +657,6 b' impl MixedIndex {'
666 Ok(self.nt(py))
657 Ok(self.nt(py))
667 }
658 }
668
659
669 pub fn clone_cindex(&self, py: Python) -> cindex::Index {
670 self.cindex(py).borrow().clone_ref(py)
671 }
672
673 /// Returns the full nodemap bytes to be written as-is to disk
660 /// Returns the full nodemap bytes to be written as-is to disk
674 fn inner_nodemap_data_all(&self, py: Python) -> PyResult<PyBytes> {
661 fn inner_nodemap_data_all(&self, py: Python) -> PyResult<PyBytes> {
675 let nodemap = self.get_nodetree(py)?.borrow_mut().take().unwrap();
662 let nodemap = self.get_nodetree(py)?.borrow_mut().take().unwrap();
@@ -27,24 +27,16 b' header = struct.unpack(">I", revlogtesti'
27 class RustRevlogIndexTest(revlogtesting.RevlogBasedTestBase):
27 class RustRevlogIndexTest(revlogtesting.RevlogBasedTestBase):
28 def test_heads(self):
28 def test_heads(self):
29 idx = self.parseindex()
29 idx = self.parseindex()
30 rustidx = revlog.MixedIndex(idx, revlogtesting.data_non_inlined, header)
30 rustidx = revlog.MixedIndex(revlogtesting.data_non_inlined, header)
31 self.assertEqual(rustidx.headrevs(), idx.headrevs())
31 self.assertEqual(rustidx.headrevs(), idx.headrevs())
32
32
33 def test_get_cindex(self):
34 # drop me once we no longer need the method for shortest node
35 idx = self.parseindex()
36 rustidx = revlog.MixedIndex(idx, revlogtesting.data_non_inlined, header)
37 cidx = rustidx.get_cindex()
38 self.assertTrue(idx is cidx)
39
40 def test_len(self):
33 def test_len(self):
41 idx = self.parseindex()
34 idx = self.parseindex()
42 rustidx = revlog.MixedIndex(idx, revlogtesting.data_non_inlined, header)
35 rustidx = revlog.MixedIndex(revlogtesting.data_non_inlined, header)
43 self.assertEqual(len(rustidx), len(idx))
36 self.assertEqual(len(rustidx), len(idx))
44
37
45 def test_ancestors(self):
38 def test_ancestors(self):
46 idx = self.parseindex()
39 rustidx = revlog.MixedIndex(revlogtesting.data_non_inlined, header)
47 rustidx = revlog.MixedIndex(idx, revlogtesting.data_non_inlined, header)
48 lazy = LazyAncestors(rustidx, [3], 0, True)
40 lazy = LazyAncestors(rustidx, [3], 0, True)
49 # we have two more references to the index:
41 # we have two more references to the index:
50 # - in its inner iterator for __contains__ and __bool__
42 # - in its inner iterator for __contains__ and __bool__
@@ -311,7 +311,8 b' test revlog corruption'
311 $ cat start b > .hg/store/data/a.i
311 $ cat start b > .hg/store/data/a.i
312
312
313 $ hg verify -q
313 $ hg verify -q
314 a@1: broken revlog! (index a is corrupted)
314 a@1: broken revlog! (index a is corrupted) (no-rust !)
315 a@1: broken revlog! (abort: unexpected inline revlog length) (rust !)
315 warning: orphan data file 'data/a.i'
316 warning: orphan data file 'data/a.i'
316 not checking dirstate because of previous errors
317 not checking dirstate because of previous errors
317 1 warnings encountered!
318 1 warnings encountered!
General Comments 0
You need to be logged in to leave comments. Login now