##// END OF EJS Templates
rust-index: pass data down to the Rust index...
Raphaël Gomès -
r52083:6ec8387e default
parent child Browse files
Show More
@@ -226,7 +226,7 b' else:'
226
226
227 def parse_index_v1_mixed(data, inline):
227 def parse_index_v1_mixed(data, inline):
228 index, cache = parse_index_v1(data, inline)
228 index, cache = parse_index_v1(data, inline)
229 return rustrevlog.MixedIndex(index), cache
229 return rustrevlog.MixedIndex(index, data), cache
230
230
231
231
232 # corresponds to uncompressed length of indexformatng (2 gigs, 4-byte
232 # corresponds to uncompressed length of indexformatng (2 gigs, 4-byte
@@ -36,13 +36,20 b' pub(crate) fn pyindex_to_graph('
36
36
37 py_class!(pub class MixedIndex |py| {
37 py_class!(pub class MixedIndex |py| {
38 data cindex: RefCell<cindex::Index>;
38 data cindex: RefCell<cindex::Index>;
39 data index: RefCell<hg::index::Index>;
39 data nt: RefCell<Option<NodeTree>>;
40 data nt: RefCell<Option<NodeTree>>;
40 data docket: RefCell<Option<PyObject>>;
41 data docket: RefCell<Option<PyObject>>;
41 // Holds a reference to the mmap'ed persistent nodemap data
42 // Holds a reference to the mmap'ed persistent nodemap data
42 data nodemap_mmap: RefCell<Option<PyBuffer>>;
43 data nodemap_mmap: RefCell<Option<PyBuffer>>;
44 // Holds a reference to the mmap'ed persistent index data
45 data index_mmap: RefCell<Option<PyBuffer>>;
43
46
44 def __new__(_cls, cindex: PyObject) -> PyResult<MixedIndex> {
47 def __new__(
45 Self::new(py, cindex)
48 _cls,
49 cindex: PyObject,
50 data: PyObject
51 ) -> PyResult<MixedIndex> {
52 Self::new(py, cindex, data)
46 }
53 }
47
54
48 /// Compatibility layer used for Python consumers needing access to the C index
55 /// Compatibility layer used for Python consumers needing access to the C index
@@ -353,13 +360,22 b' unsafe fn mmap_keeparound('
353 }
360 }
354
361
355 impl MixedIndex {
362 impl MixedIndex {
356 fn new(py: Python, cindex: PyObject) -> PyResult<MixedIndex> {
363 fn new(
364 py: Python,
365 cindex: PyObject,
366 data: PyObject,
367 ) -> PyResult<MixedIndex> {
368 // Safety: we keep the buffer around inside the class as `index_mmap`
369 let (buf, bytes) = unsafe { mmap_keeparound(py, data)? };
370
357 Self::create_instance(
371 Self::create_instance(
358 py,
372 py,
359 RefCell::new(cindex::Index::new(py, cindex)?),
373 RefCell::new(cindex::Index::new(py, cindex)?),
374 RefCell::new(hg::index::Index::new(bytes).unwrap()),
360 RefCell::new(None),
375 RefCell::new(None),
361 RefCell::new(None),
376 RefCell::new(None),
362 RefCell::new(None),
377 RefCell::new(None),
378 RefCell::new(Some(buf)),
363 )
379 )
364 }
380 }
365
381
@@ -22,24 +22,24 b' from mercurial.testing import revlog as '
22 class RustRevlogIndexTest(revlogtesting.RevlogBasedTestBase):
22 class RustRevlogIndexTest(revlogtesting.RevlogBasedTestBase):
23 def test_heads(self):
23 def test_heads(self):
24 idx = self.parseindex()
24 idx = self.parseindex()
25 rustidx = revlog.MixedIndex(idx)
25 rustidx = revlog.MixedIndex(idx, revlogtesting.data_non_inlined)
26 self.assertEqual(rustidx.headrevs(), idx.headrevs())
26 self.assertEqual(rustidx.headrevs(), idx.headrevs())
27
27
28 def test_get_cindex(self):
28 def test_get_cindex(self):
29 # drop me once we no longer need the method for shortest node
29 # drop me once we no longer need the method for shortest node
30 idx = self.parseindex()
30 idx = self.parseindex()
31 rustidx = revlog.MixedIndex(idx)
31 rustidx = revlog.MixedIndex(idx, revlogtesting.data_non_inlined)
32 cidx = rustidx.get_cindex()
32 cidx = rustidx.get_cindex()
33 self.assertTrue(idx is cidx)
33 self.assertTrue(idx is cidx)
34
34
35 def test_len(self):
35 def test_len(self):
36 idx = self.parseindex()
36 idx = self.parseindex()
37 rustidx = revlog.MixedIndex(idx)
37 rustidx = revlog.MixedIndex(idx, revlogtesting.data_non_inlined)
38 self.assertEqual(len(rustidx), len(idx))
38 self.assertEqual(len(rustidx), len(idx))
39
39
40 def test_ancestors(self):
40 def test_ancestors(self):
41 idx = self.parseindex()
41 idx = self.parseindex()
42 rustidx = revlog.MixedIndex(idx)
42 rustidx = revlog.MixedIndex(idx, revlogtesting.data_non_inlined)
43 lazy = LazyAncestors(rustidx, [3], 0, True)
43 lazy = LazyAncestors(rustidx, [3], 0, True)
44 # we have two more references to the index:
44 # we have two more references to the index:
45 # - in its inner iterator for __contains__ and __bool__
45 # - in its inner iterator for __contains__ and __bool__
General Comments 0
You need to be logged in to leave comments. Login now