--- a/rust/hg-core/src/revlog/mod.rs Wed Sep 13 18:28:51 2023 +0100
+++ b/rust/hg-core/src/revlog/mod.rs Thu Sep 14 10:52:09 2023 +0100
@@ -156,6 +156,16 @@
data_path: Option<&Path>,
use_nodemap: bool,
) -> Result<Self, HgError> {
+ Self::open_gen(store_vfs, index_path, data_path, use_nodemap, None)
+ }
+
+ fn open_gen(
+ store_vfs: &Vfs,
+ index_path: impl AsRef<Path>,
+ data_path: Option<&Path>,
+ use_nodemap: bool,
+ nodemap_for_test: Option<nodemap::NodeTree>,
+ ) -> Result<Self, HgError> {
let index_path = index_path.as_ref();
let index = {
match store_vfs.mmap_open_opt(&index_path)? {
@@ -193,6 +203,8 @@
)
};
+ let nodemap = nodemap_for_test.or(nodemap);
+
Ok(Revlog {
index,
data_bytes,
@@ -790,7 +802,13 @@
.flatten()
.collect_vec();
std::fs::write(temp.path().join("foo.i"), contents).unwrap();
- let revlog = Revlog::open(&vfs, "foo.i", None, false).unwrap();
+
+ let mut idx = nodemap::tests::TestNtIndex::new();
+ idx.insert_node(0, node0).unwrap();
+ idx.insert_node(1, node1).unwrap();
+
+ let revlog =
+ Revlog::open_gen(&vfs, "foo.i", None, true, Some(idx.nt)).unwrap();
// accessing the data shows the corruption
revlog.get_entry(0).unwrap().data().unwrap_err();
--- a/rust/hg-core/src/revlog/nodemap.rs Wed Sep 13 18:28:51 2023 +0100
+++ b/rust/hg-core/src/revlog/nodemap.rs Thu Sep 14 10:52:09 2023 +0100
@@ -680,7 +680,7 @@
}
#[cfg(test)]
-mod tests {
+pub mod tests {
use super::NodeMapError::*;
use super::*;
use crate::revlog::node::{hex_pad_right, Node};
@@ -844,28 +844,35 @@
Ok(())
}
- struct TestNtIndex {
- index: TestIndex,
- nt: NodeTree,
+ pub struct TestNtIndex {
+ pub index: TestIndex,
+ pub nt: NodeTree,
}
impl TestNtIndex {
- fn new() -> Self {
+ pub fn new() -> Self {
TestNtIndex {
index: HashMap::new(),
nt: NodeTree::default(),
}
}
- fn insert(
+ pub fn insert_node(
+ &mut self,
+ rev: Revision,
+ node: Node,
+ ) -> Result<(), NodeMapError> {
+ self.index.insert(rev, node);
+ self.nt.insert(&self.index, &node, rev)?;
+ Ok(())
+ }
+
+ pub fn insert(
&mut self,
rev: Revision,
hex: &str,
) -> Result<(), NodeMapError> {
- let node = pad_node(hex);
- self.index.insert(rev, node);
- self.nt.insert(&self.index, &node, rev)?;
- Ok(())
+ return self.insert_node(rev, pad_node(hex));
}
fn find_hex(