Show More
@@ -156,6 +156,16 b' impl Revlog {' | |||||
156 | data_path: Option<&Path>, |
|
156 | data_path: Option<&Path>, | |
157 | use_nodemap: bool, |
|
157 | use_nodemap: bool, | |
158 | ) -> Result<Self, HgError> { |
|
158 | ) -> Result<Self, HgError> { | |
|
159 | Self::open_gen(store_vfs, index_path, data_path, use_nodemap, None) | |||
|
160 | } | |||
|
161 | ||||
|
162 | fn open_gen( | |||
|
163 | store_vfs: &Vfs, | |||
|
164 | index_path: impl AsRef<Path>, | |||
|
165 | data_path: Option<&Path>, | |||
|
166 | use_nodemap: bool, | |||
|
167 | nodemap_for_test: Option<nodemap::NodeTree>, | |||
|
168 | ) -> Result<Self, HgError> { | |||
159 | let index_path = index_path.as_ref(); |
|
169 | let index_path = index_path.as_ref(); | |
160 | let index = { |
|
170 | let index = { | |
161 | match store_vfs.mmap_open_opt(&index_path)? { |
|
171 | match store_vfs.mmap_open_opt(&index_path)? { | |
@@ -193,6 +203,8 b' impl Revlog {' | |||||
193 | ) |
|
203 | ) | |
194 | }; |
|
204 | }; | |
195 |
|
205 | |||
|
206 | let nodemap = nodemap_for_test.or(nodemap); | |||
|
207 | ||||
196 | Ok(Revlog { |
|
208 | Ok(Revlog { | |
197 | index, |
|
209 | index, | |
198 | data_bytes, |
|
210 | data_bytes, | |
@@ -790,7 +802,13 b' mod tests {' | |||||
790 | .flatten() |
|
802 | .flatten() | |
791 | .collect_vec(); |
|
803 | .collect_vec(); | |
792 | std::fs::write(temp.path().join("foo.i"), contents).unwrap(); |
|
804 | std::fs::write(temp.path().join("foo.i"), contents).unwrap(); | |
793 | let revlog = Revlog::open(&vfs, "foo.i", None, false).unwrap(); |
|
805 | ||
|
806 | let mut idx = nodemap::tests::TestNtIndex::new(); | |||
|
807 | idx.insert_node(0, node0).unwrap(); | |||
|
808 | idx.insert_node(1, node1).unwrap(); | |||
|
809 | ||||
|
810 | let revlog = | |||
|
811 | Revlog::open_gen(&vfs, "foo.i", None, true, Some(idx.nt)).unwrap(); | |||
794 |
|
812 | |||
795 | // accessing the data shows the corruption |
|
813 | // accessing the data shows the corruption | |
796 | revlog.get_entry(0).unwrap().data().unwrap_err(); |
|
814 | revlog.get_entry(0).unwrap().data().unwrap_err(); |
@@ -680,7 +680,7 b' impl NodeMap for NodeTree {' | |||||
680 | } |
|
680 | } | |
681 |
|
681 | |||
682 | #[cfg(test)] |
|
682 | #[cfg(test)] | |
683 | mod tests { |
|
683 | pub mod tests { | |
684 | use super::NodeMapError::*; |
|
684 | use super::NodeMapError::*; | |
685 | use super::*; |
|
685 | use super::*; | |
686 | use crate::revlog::node::{hex_pad_right, Node}; |
|
686 | use crate::revlog::node::{hex_pad_right, Node}; | |
@@ -844,28 +844,35 b' mod tests {' | |||||
844 | Ok(()) |
|
844 | Ok(()) | |
845 | } |
|
845 | } | |
846 |
|
846 | |||
847 | struct TestNtIndex { |
|
847 | pub struct TestNtIndex { | |
848 | index: TestIndex, |
|
848 | pub index: TestIndex, | |
849 | nt: NodeTree, |
|
849 | pub nt: NodeTree, | |
850 | } |
|
850 | } | |
851 |
|
851 | |||
852 | impl TestNtIndex { |
|
852 | impl TestNtIndex { | |
853 | fn new() -> Self { |
|
853 | pub fn new() -> Self { | |
854 | TestNtIndex { |
|
854 | TestNtIndex { | |
855 | index: HashMap::new(), |
|
855 | index: HashMap::new(), | |
856 | nt: NodeTree::default(), |
|
856 | nt: NodeTree::default(), | |
857 | } |
|
857 | } | |
858 | } |
|
858 | } | |
859 |
|
859 | |||
860 | fn insert( |
|
860 | pub fn insert_node( | |
|
861 | &mut self, | |||
|
862 | rev: Revision, | |||
|
863 | node: Node, | |||
|
864 | ) -> Result<(), NodeMapError> { | |||
|
865 | self.index.insert(rev, node); | |||
|
866 | self.nt.insert(&self.index, &node, rev)?; | |||
|
867 | Ok(()) | |||
|
868 | } | |||
|
869 | ||||
|
870 | pub fn insert( | |||
861 | &mut self, |
|
871 | &mut self, | |
862 | rev: Revision, |
|
872 | rev: Revision, | |
863 | hex: &str, |
|
873 | hex: &str, | |
864 | ) -> Result<(), NodeMapError> { |
|
874 | ) -> Result<(), NodeMapError> { | |
865 |
|
|
875 | return self.insert_node(rev, pad_node(hex)); | |
866 | self.index.insert(rev, node); |
|
|||
867 | self.nt.insert(&self.index, &node, rev)?; |
|
|||
868 | Ok(()) |
|
|||
869 | } |
|
876 | } | |
870 |
|
877 | |||
871 | fn find_hex( |
|
878 | fn find_hex( |
General Comments 0
You need to be logged in to leave comments.
Login now