##// END OF EJS Templates
rust: Return HgError instead of RevlogError in revlog constructors...
Simon Sapin -
r48777:001d747c default
parent child Browse files
Show More
@@ -29,8 +29,8 b' pub struct Repo {'
29 29 // None means not known/initialized yet
30 30 dirstate_parents: Cell<Option<DirstateParents>>,
31 31 dirstate_map: LazyCell<OwningDirstateMap, DirstateError>,
32 changelog: LazyCell<Changelog, RevlogError>,
33 manifestlog: LazyCell<Manifestlog, RevlogError>,
32 changelog: LazyCell<Changelog, HgError>,
33 manifestlog: LazyCell<Manifestlog, HgError>,
34 34 }
35 35
36 36 #[derive(Debug, derive_more::From)]
@@ -320,19 +320,19 b' impl Repo {'
320 320 self.dirstate_map.get_mut_or_init(self)
321 321 }
322 322
323 pub fn changelog(&self) -> Result<Ref<Changelog>, RevlogError> {
323 pub fn changelog(&self) -> Result<Ref<Changelog>, HgError> {
324 324 self.changelog.get_or_init(self)
325 325 }
326 326
327 pub fn changelog_mut(&self) -> Result<RefMut<Changelog>, RevlogError> {
327 pub fn changelog_mut(&self) -> Result<RefMut<Changelog>, HgError> {
328 328 self.changelog.get_mut_or_init(self)
329 329 }
330 330
331 pub fn manifestlog(&self) -> Result<Ref<Manifestlog>, RevlogError> {
331 pub fn manifestlog(&self) -> Result<Ref<Manifestlog>, HgError> {
332 332 self.manifestlog.get_or_init(self)
333 333 }
334 334
335 pub fn manifestlog_mut(&self) -> Result<RefMut<Manifestlog>, RevlogError> {
335 pub fn manifestlog_mut(&self) -> Result<RefMut<Manifestlog>, HgError> {
336 336 self.manifestlog.get_mut_or_init(self)
337 337 }
338 338
@@ -349,7 +349,7 b' impl Repo {'
349 349 manifest.get_node(manifest_node.into())
350 350 }
351 351
352 pub fn filelog(&self, path: &HgPath) -> Result<Filelog, RevlogError> {
352 pub fn filelog(&self, path: &HgPath) -> Result<Filelog, HgError> {
353 353 Filelog::open(self, path)
354 354 }
355 355 }
@@ -12,7 +12,7 b' pub struct Changelog {'
12 12
13 13 impl Changelog {
14 14 /// Open the `changelog` of a repository given by its root.
15 pub fn open(repo: &Repo) -> Result<Self, RevlogError> {
15 pub fn open(repo: &Repo) -> Result<Self, HgError> {
16 16 let revlog = Revlog::open(repo, "00changelog.i", None)?;
17 17 Ok(Self { revlog })
18 18 }
@@ -17,7 +17,7 b' pub struct Filelog {'
17 17 }
18 18
19 19 impl Filelog {
20 pub fn open(repo: &Repo, file_path: &HgPath) -> Result<Self, RevlogError> {
20 pub fn open(repo: &Repo, file_path: &HgPath) -> Result<Self, HgError> {
21 21 let index_path = store_path(file_path, b".i");
22 22 let data_path = store_path(file_path, b".d");
23 23 let revlog = Revlog::open(repo, index_path, Some(&data_path))?;
@@ -5,7 +5,6 b' use byteorder::{BigEndian, ByteOrder};'
5 5
6 6 use crate::errors::HgError;
7 7 use crate::revlog::node::Node;
8 use crate::revlog::revlog::RevlogError;
9 8 use crate::revlog::{Revision, NULL_REVISION};
10 9
11 10 pub const INDEX_ENTRY_SIZE: usize = 64;
@@ -23,7 +22,7 b' impl Index {'
23 22 /// Calculate the start of each entry when is_inline is true.
24 23 pub fn new(
25 24 bytes: Box<dyn Deref<Target = [u8]> + Send>,
26 ) -> Result<Self, RevlogError> {
25 ) -> Result<Self, HgError> {
27 26 if is_inline(&bytes) {
28 27 let mut offset: usize = 0;
29 28 let mut offsets = Vec::new();
@@ -1,3 +1,4 b''
1 use crate::errors::HgError;
1 2 use crate::repo::Repo;
2 3 use crate::revlog::revlog::{Revlog, RevlogError};
3 4 use crate::revlog::NodePrefix;
@@ -12,7 +13,7 b' pub struct Manifestlog {'
12 13
13 14 impl Manifestlog {
14 15 /// Open the `manifest` of a repository given by its root.
15 pub fn open(repo: &Repo) -> Result<Self, RevlogError> {
16 pub fn open(repo: &Repo) -> Result<Self, HgError> {
16 17 let revlog = Revlog::open(repo, "00manifest.i", None)?;
17 18 Ok(Self { revlog })
18 19 }
@@ -4,7 +4,6 b' use bytes_cast::{unaligned, BytesCast};'
4 4 use memmap2::Mmap;
5 5 use std::path::{Path, PathBuf};
6 6
7 use super::revlog::RevlogError;
8 7 use crate::repo::Repo;
9 8 use crate::utils::strip_suffix;
10 9
@@ -38,7 +37,7 b' impl NodeMapDocket {'
38 37 pub fn read_from_file(
39 38 repo: &Repo,
40 39 index_path: &Path,
41 ) -> Result<Option<(Self, Mmap)>, RevlogError> {
40 ) -> Result<Option<(Self, Mmap)>, HgError> {
42 41 if !repo
43 42 .requirements()
44 43 .contains(requirements::NODEMAP_REQUIREMENT)
@@ -65,10 +64,9 b' impl NodeMapDocket {'
65 64 };
66 65
67 66 /// Treat any error as a parse error
68 fn parse<T, E>(result: Result<T, E>) -> Result<T, RevlogError> {
69 result.map_err(|_| {
70 HgError::corrupted("nodemap docket parse error").into()
71 })
67 fn parse<T, E>(result: Result<T, E>) -> Result<T, HgError> {
68 result
69 .map_err(|_| HgError::corrupted("nodemap docket parse error"))
72 70 }
73 71
74 72 let (header, rest) = parse(DocketHeader::from_bytes(input))?;
@@ -94,7 +92,7 b' impl NodeMapDocket {'
94 92 if mmap.len() >= data_length {
95 93 Ok(Some((docket, mmap)))
96 94 } else {
97 Err(HgError::corrupted("persistent nodemap too short").into())
95 Err(HgError::corrupted("persistent nodemap too short"))
98 96 }
99 97 } else {
100 98 // Even if .hg/requires opted in, some revlogs are deemed small
@@ -68,14 +68,14 b' impl Revlog {'
68 68 repo: &Repo,
69 69 index_path: impl AsRef<Path>,
70 70 data_path: Option<&Path>,
71 ) -> Result<Self, RevlogError> {
71 ) -> Result<Self, HgError> {
72 72 let index_path = index_path.as_ref();
73 73 let index_mmap = repo.store_vfs().mmap_open(&index_path)?;
74 74
75 75 let version = get_version(&index_mmap);
76 76 if version != 1 {
77 77 // A proper new version should have had a repo/store requirement.
78 return Err(RevlogError::corrupted());
78 return Err(HgError::corrupted("corrupted revlog"));
79 79 }
80 80
81 81 let index = Index::new(Box::new(index_mmap))?;
General Comments 0
You need to be logged in to leave comments. Login now