Mercurial > public > mercurial-scm > hg
comparison rust/hg-cpython/src/revlog.rs @ 51251:f94c10334bcb
rust-index: renamed `MixedIndex` as `Index`
It is simply not mixed any more, hence the name had become a
future source of confusion.
author | Georges Racinet on incendie.racinet.fr <georges@racinet.fr> |
---|---|
date | Sun, 29 Oct 2023 12:18:03 +0100 |
parents | 96e05f1a99bd |
children | 24d3298189d7 |
comparison
equal
deleted
inserted
replaced
51250:96e05f1a99bd | 51251:f94c10334bcb |
---|---|
38 /// Return a Struct implementing the Graph trait | 38 /// Return a Struct implementing the Graph trait |
39 pub(crate) fn py_rust_index_to_graph( | 39 pub(crate) fn py_rust_index_to_graph( |
40 py: Python, | 40 py: Python, |
41 index: PyObject, | 41 index: PyObject, |
42 ) -> PyResult<UnsafePyLeaked<PySharedIndex>> { | 42 ) -> PyResult<UnsafePyLeaked<PySharedIndex>> { |
43 let midx = index.extract::<MixedIndex>(py)?; | 43 let midx = index.extract::<Index>(py)?; |
44 let leaked = midx.index(py).leak_immutable(); | 44 let leaked = midx.index(py).leak_immutable(); |
45 Ok(unsafe { leaked.map(py, |idx| PySharedIndex { inner: idx }) }) | 45 Ok(unsafe { leaked.map(py, |idx| PySharedIndex { inner: idx }) }) |
46 } | 46 } |
47 | 47 |
48 impl Clone for PySharedIndex { | 48 impl Clone for PySharedIndex { |
83 fn node(&self, rev: Revision) -> Option<&Node> { | 83 fn node(&self, rev: Revision) -> Option<&Node> { |
84 self.inner.node(rev) | 84 self.inner.node(rev) |
85 } | 85 } |
86 } | 86 } |
87 | 87 |
88 py_class!(pub class MixedIndex |py| { | 88 py_class!(pub class Index |py| { |
89 @shared data index: hg::index::Index; | 89 @shared data index: hg::index::Index; |
90 data nt: RefCell<Option<CoreNodeTree>>; | 90 data nt: RefCell<Option<CoreNodeTree>>; |
91 data docket: RefCell<Option<PyObject>>; | 91 data docket: RefCell<Option<PyObject>>; |
92 // Holds a reference to the mmap'ed persistent nodemap data | 92 // Holds a reference to the mmap'ed persistent nodemap data |
93 data nodemap_mmap: RefCell<Option<PyBuffer>>; | 93 data nodemap_mmap: RefCell<Option<PyBuffer>>; |
96 | 96 |
97 def __new__( | 97 def __new__( |
98 _cls, | 98 _cls, |
99 data: PyObject, | 99 data: PyObject, |
100 default_header: u32, | 100 default_header: u32, |
101 ) -> PyResult<MixedIndex> { | 101 ) -> PyResult<Self> { |
102 Self::new(py, data, default_header) | 102 Self::new(py, data, default_header) |
103 } | 103 } |
104 | 104 |
105 /// 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 |
106 /// | 106 /// |
596 )) | 596 )) |
597 }) | 597 }) |
598 } | 598 } |
599 } | 599 } |
600 | 600 |
601 impl MixedIndex { | 601 impl Index { |
602 fn new(py: Python, data: PyObject, header: u32) -> PyResult<MixedIndex> { | 602 fn new(py: Python, data: PyObject, header: u32) -> PyResult<Self> { |
603 // 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` |
604 let (buf, bytes) = unsafe { mmap_keeparound(py, data)? }; | 604 let (buf, bytes) = unsafe { mmap_keeparound(py, data)? }; |
605 | 605 |
606 Self::create_instance( | 606 Self::create_instance( |
607 py, | 607 py, |
1106 let dotted_name = &format!("{}.revlog", package); | 1106 let dotted_name = &format!("{}.revlog", package); |
1107 let m = PyModule::new(py, dotted_name)?; | 1107 let m = PyModule::new(py, dotted_name)?; |
1108 m.add(py, "__package__", package)?; | 1108 m.add(py, "__package__", package)?; |
1109 m.add(py, "__doc__", "RevLog - Rust implementations")?; | 1109 m.add(py, "__doc__", "RevLog - Rust implementations")?; |
1110 | 1110 |
1111 m.add_class::<MixedIndex>(py)?; | 1111 m.add_class::<Index>(py)?; |
1112 m.add_class::<NodeTree>(py)?; | 1112 m.add_class::<NodeTree>(py)?; |
1113 | 1113 |
1114 let sys = PyModule::import(py, "sys")?; | 1114 let sys = PyModule::import(py, "sys")?; |
1115 let sys_modules: PyDict = sys.get(py, "modules")?.extract(py)?; | 1115 let sys_modules: PyDict = sys.get(py, "modules")?.extract(py)?; |
1116 sys_modules.set_item(py, dotted_name, &m)?; | 1116 sys_modules.set_item(py, dotted_name, &m)?; |