Mercurial > hg
comparison rust/hg-cpython/src/revlog.rs @ 51190:6ec8387eb0be
rust-index: pass data down to the Rust index
This will allow us to start keeping the Rust index synchronized with the
cindex as we gradually implement more and more methods in Rust. This will
eventually be removed.
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Tue, 27 Jun 2023 17:34:51 +0200 |
parents | 8c4e8d06432e |
children | 13f58ce70299 |
comparison
equal
deleted
inserted
replaced
51189:b4d152a28742 | 51190:6ec8387eb0be |
---|---|
34 } | 34 } |
35 } | 35 } |
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>>; |
43 | 44 // Holds a reference to the mmap'ed persistent index data |
44 def __new__(_cls, cindex: PyObject) -> PyResult<MixedIndex> { | 45 data index_mmap: RefCell<Option<PyBuffer>>; |
45 Self::new(py, cindex) | 46 |
47 def __new__( | |
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 |
49 /// | 56 /// |
50 /// Only use case so far is `scmutil.shortesthexnodeidprefix`, | 57 /// Only use case so far is `scmutil.shortesthexnodeidprefix`, |
351 | 358 |
352 Ok((buf, Box::new(bytes))) | 359 Ok((buf, Box::new(bytes))) |
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 |
366 /// This is scaffolding at this point, but it could also become | 382 /// This is scaffolding at this point, but it could also become |
367 /// a way to start a persistent nodemap or perform a | 383 /// a way to start a persistent nodemap or perform a |