Changeset View
Changeset View
Standalone View
Standalone View
rust/hg-core/src/revlog/revlog.rs
Show First 20 Lines • Show All 70 Lines • ▼ Show 20 Line(s) | impl Revlog { | ||||
) -> Result<Self, HgError> { | ) -> Result<Self, HgError> { | ||||
let index_path = index_path.as_ref(); | let index_path = index_path.as_ref(); | ||||
let index = { | let index = { | ||||
match repo.store_vfs().mmap_open_opt(&index_path)? { | match repo.store_vfs().mmap_open_opt(&index_path)? { | ||||
None => Index::new(Box::new(vec![])), | None => Index::new(Box::new(vec![])), | ||||
Some(index_mmap) => { | Some(index_mmap) => { | ||||
let version = get_version(&index_mmap)?; | let version = get_version(&index_mmap)?; | ||||
if version != 1 { | if version != 1 { | ||||
// A proper new version should have had a repo/store requirement. | // A proper new version should have had a repo/store | ||||
// requirement. | |||||
return Err(HgError::corrupted("corrupted revlog")); | return Err(HgError::corrupted("corrupted revlog")); | ||||
} | } | ||||
let index = Index::new(Box::new(index_mmap))?; | let index = Index::new(Box::new(index_mmap))?; | ||||
Ok(index) | Ok(index) | ||||
} | } | ||||
} | } | ||||
}?; | }?; | ||||
▲ Show 20 Lines • Show All 335 Lines • ▼ Show 20 Line(s) | mod tests { | ||||
#[test] | #[test] | ||||
fn version_test() { | fn version_test() { | ||||
let bytes = IndexEntryBuilder::new() | let bytes = IndexEntryBuilder::new() | ||||
.is_first(true) | .is_first(true) | ||||
.with_version(1) | .with_version(1) | ||||
.build(); | .build(); | ||||
assert_eq!(get_version(&bytes).map_err(|_err|()), Ok(1)) | assert_eq!(get_version(&bytes).map_err(|_err| ()), Ok(1)) | ||||
} | } | ||||
} | } |