Mercurial > hg
comparison rust/hg-cpython/src/revlog.rs @ 51247:8dbd985733ff
rust-cpython-revlog: renamed NodeTree import as CoreNodeTree
We're about to introduce a `NodeTree` Python class (hence also
a Rust struct) and it would be a collision with the import
author | Georges Racinet <georges.racinet@octobus.net> |
---|---|
date | Mon, 30 Oct 2023 15:32:33 +0100 |
parents | 41e19e8a6133 |
children | 8b243e2a3bc4 |
comparison
equal
deleted
inserted
replaced
51246:41e19e8a6133 | 51247:8dbd985733ff |
---|---|
22 errors::HgError, | 22 errors::HgError, |
23 index::{ | 23 index::{ |
24 IndexHeader, Phase, RevisionDataParams, SnapshotsCache, | 24 IndexHeader, Phase, RevisionDataParams, SnapshotsCache, |
25 INDEX_ENTRY_SIZE, | 25 INDEX_ENTRY_SIZE, |
26 }, | 26 }, |
27 nodemap::{Block, NodeMapError, NodeTree}, | 27 nodemap::{Block, NodeMapError, NodeTree as CoreNodeTree}, |
28 revlog::{nodemap::NodeMap, Graph, NodePrefix, RevlogError, RevlogIndex}, | 28 revlog::{nodemap::NodeMap, Graph, NodePrefix, RevlogError, RevlogIndex}, |
29 BaseRevision, Node, Revision, UncheckedRevision, NULL_REVISION, | 29 BaseRevision, Node, Revision, UncheckedRevision, NULL_REVISION, |
30 }; | 30 }; |
31 use std::{cell::RefCell, collections::HashMap}; | 31 use std::{cell::RefCell, collections::HashMap}; |
32 use vcsgraph::graph::Graph as VCSGraph; | 32 use vcsgraph::graph::Graph as VCSGraph; |
87 } | 87 } |
88 | 88 |
89 py_class!(pub class MixedIndex |py| { | 89 py_class!(pub class MixedIndex |py| { |
90 data cindex: RefCell<cindex::Index>; | 90 data cindex: RefCell<cindex::Index>; |
91 @shared data index: hg::index::Index; | 91 @shared data index: hg::index::Index; |
92 data nt: RefCell<Option<NodeTree>>; | 92 data nt: RefCell<Option<CoreNodeTree>>; |
93 data docket: RefCell<Option<PyObject>>; | 93 data docket: RefCell<Option<PyObject>>; |
94 // Holds a reference to the mmap'ed persistent nodemap data | 94 // Holds a reference to the mmap'ed persistent nodemap data |
95 data nodemap_mmap: RefCell<Option<PyBuffer>>; | 95 data nodemap_mmap: RefCell<Option<PyBuffer>>; |
96 // Holds a reference to the mmap'ed persistent index data | 96 // Holds a reference to the mmap'ed persistent index data |
97 data index_mmap: RefCell<Option<PyBuffer>>; | 97 data index_mmap: RefCell<Option<PyBuffer>>; |
630 /// a way to start a persistent nodemap or perform a | 630 /// a way to start a persistent nodemap or perform a |
631 /// vacuum / repack operation | 631 /// vacuum / repack operation |
632 fn fill_nodemap( | 632 fn fill_nodemap( |
633 &self, | 633 &self, |
634 py: Python, | 634 py: Python, |
635 nt: &mut NodeTree, | 635 nt: &mut CoreNodeTree, |
636 ) -> PyResult<PyObject> { | 636 ) -> PyResult<PyObject> { |
637 let index = self.index(py).borrow(); | 637 let index = self.index(py).borrow(); |
638 for r in 0..self.len(py)? { | 638 for r in 0..self.len(py)? { |
639 let rev = Revision(r as BaseRevision); | 639 let rev = Revision(r as BaseRevision); |
640 // in this case node() won't ever return None | 640 // in this case node() won't ever return None |
645 } | 645 } |
646 | 646 |
647 fn get_nodetree<'a>( | 647 fn get_nodetree<'a>( |
648 &'a self, | 648 &'a self, |
649 py: Python<'a>, | 649 py: Python<'a>, |
650 ) -> PyResult<&'a RefCell<Option<NodeTree>>> { | 650 ) -> PyResult<&'a RefCell<Option<CoreNodeTree>>> { |
651 if self.nt(py).borrow().is_none() { | 651 if self.nt(py).borrow().is_none() { |
652 let readonly = Box::<Vec<_>>::default(); | 652 let readonly = Box::<Vec<_>>::default(); |
653 let mut nt = NodeTree::load_bytes(readonly, 0); | 653 let mut nt = CoreNodeTree::load_bytes(readonly, 0); |
654 self.fill_nodemap(py, &mut nt)?; | 654 self.fill_nodemap(py, &mut nt)?; |
655 self.nt(py).borrow_mut().replace(nt); | 655 self.nt(py).borrow_mut().replace(nt); |
656 } | 656 } |
657 Ok(self.nt(py)) | 657 Ok(self.nt(py)) |
658 } | 658 } |
667 let (readonly, bytes) = nodemap.into_readonly_and_added_bytes(); | 667 let (readonly, bytes) = nodemap.into_readonly_and_added_bytes(); |
668 | 668 |
669 // If there's anything readonly, we need to build the data again from | 669 // If there's anything readonly, we need to build the data again from |
670 // scratch | 670 // scratch |
671 let bytes = if readonly.len() > 0 { | 671 let bytes = if readonly.len() > 0 { |
672 let mut nt = NodeTree::load_bytes(Box::<Vec<_>>::default(), 0); | 672 let mut nt = CoreNodeTree::load_bytes(Box::<Vec<_>>::default(), 0); |
673 self.fill_nodemap(py, &mut nt)?; | 673 self.fill_nodemap(py, &mut nt)?; |
674 | 674 |
675 let (readonly, bytes) = nt.into_readonly_and_added_bytes(); | 675 let (readonly, bytes) = nt.into_readonly_and_added_bytes(); |
676 assert_eq!(readonly.len(), 0); | 676 assert_eq!(readonly.len(), 0); |
677 | 677 |
717 // Safety: we keep the buffer around inside the class as `nodemap_mmap` | 717 // Safety: we keep the buffer around inside the class as `nodemap_mmap` |
718 let (buf, bytes) = unsafe { mmap_keeparound(py, nm_data)? }; | 718 let (buf, bytes) = unsafe { mmap_keeparound(py, nm_data)? }; |
719 let len = buf.item_count(); | 719 let len = buf.item_count(); |
720 self.nodemap_mmap(py).borrow_mut().replace(buf); | 720 self.nodemap_mmap(py).borrow_mut().replace(buf); |
721 | 721 |
722 let mut nt = NodeTree::load_bytes(bytes, len); | 722 let mut nt = CoreNodeTree::load_bytes(bytes, len); |
723 | 723 |
724 let data_tip = docket | 724 let data_tip = docket |
725 .getattr(py, "tip_rev")? | 725 .getattr(py, "tip_rev")? |
726 .extract::<BaseRevision>(py)? | 726 .extract::<BaseRevision>(py)? |
727 .into(); | 727 .into(); |