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