##// END OF EJS Templates
revlog: make the rust test for node hex prefix resolution exercise the nodemap
Arseniy Alekseyev -
r51879:eccf7dc7 stable
parent child Browse files
Show More
@@ -156,6 +156,16 b' impl Revlog {'
156 156 data_path: Option<&Path>,
157 157 use_nodemap: bool,
158 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 169 let index_path = index_path.as_ref();
160 170 let index = {
161 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 208 Ok(Revlog {
197 209 index,
198 210 data_bytes,
@@ -790,7 +802,13 b' mod tests {'
790 802 .flatten()
791 803 .collect_vec();
792 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 813 // accessing the data shows the corruption
796 814 revlog.get_entry(0).unwrap().data().unwrap_err();
@@ -680,7 +680,7 b' impl NodeMap for NodeTree {'
680 680 }
681 681
682 682 #[cfg(test)]
683 mod tests {
683 pub mod tests {
684 684 use super::NodeMapError::*;
685 685 use super::*;
686 686 use crate::revlog::node::{hex_pad_right, Node};
@@ -844,28 +844,35 b' mod tests {'
844 844 Ok(())
845 845 }
846 846
847 struct TestNtIndex {
848 index: TestIndex,
849 nt: NodeTree,
847 pub struct TestNtIndex {
848 pub index: TestIndex,
849 pub nt: NodeTree,
850 850 }
851 851
852 852 impl TestNtIndex {
853 fn new() -> Self {
853 pub fn new() -> Self {
854 854 TestNtIndex {
855 855 index: HashMap::new(),
856 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 871 &mut self,
862 872 rev: Revision,
863 873 hex: &str,
864 874 ) -> Result<(), NodeMapError> {
865 let node = pad_node(hex);
866 self.index.insert(rev, node);
867 self.nt.insert(&self.index, &node, rev)?;
868 Ok(())
875 return self.insert_node(rev, pad_node(hex));
869 876 }
870 877
871 878 fn find_hex(
General Comments 0
You need to be logged in to leave comments. Login now