[Updated] D11410: rust: Return HgError instead of RevlogError in revlog constructors
SimonSapin
phabricator at mercurial-scm.org
Tue Sep 14 08:21:59 UTC 2021
Closed by commit rHG001d747c2baf: rust: Return HgError instead of RevlogError in revlog constructors (authored by SimonSapin).
This revision was automatically updated to reflect the committed changes.
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D11410?vs=30228&id=30238
CHANGES SINCE LAST ACTION
https://phab.mercurial-scm.org/D11410/new/
REVISION DETAIL
https://phab.mercurial-scm.org/D11410
AFFECTED FILES
rust/hg-core/src/repo.rs
rust/hg-core/src/revlog/changelog.rs
rust/hg-core/src/revlog/filelog.rs
rust/hg-core/src/revlog/index.rs
rust/hg-core/src/revlog/manifest.rs
rust/hg-core/src/revlog/nodemap_docket.rs
rust/hg-core/src/revlog/revlog.rs
CHANGE DETAILS
diff --git a/rust/hg-core/src/revlog/revlog.rs b/rust/hg-core/src/revlog/revlog.rs
--- a/rust/hg-core/src/revlog/revlog.rs
+++ b/rust/hg-core/src/revlog/revlog.rs
@@ -68,14 +68,14 @@
repo: &Repo,
index_path: impl AsRef<Path>,
data_path: Option<&Path>,
- ) -> Result<Self, RevlogError> {
+ ) -> Result<Self, HgError> {
let index_path = index_path.as_ref();
let index_mmap = repo.store_vfs().mmap_open(&index_path)?;
let version = get_version(&index_mmap);
if version != 1 {
// A proper new version should have had a repo/store requirement.
- return Err(RevlogError::corrupted());
+ return Err(HgError::corrupted("corrupted revlog"));
}
let index = Index::new(Box::new(index_mmap))?;
diff --git a/rust/hg-core/src/revlog/nodemap_docket.rs b/rust/hg-core/src/revlog/nodemap_docket.rs
--- a/rust/hg-core/src/revlog/nodemap_docket.rs
+++ b/rust/hg-core/src/revlog/nodemap_docket.rs
@@ -4,7 +4,6 @@
use memmap2::Mmap;
use std::path::{Path, PathBuf};
-use super::revlog::RevlogError;
use crate::repo::Repo;
use crate::utils::strip_suffix;
@@ -38,7 +37,7 @@
pub fn read_from_file(
repo: &Repo,
index_path: &Path,
- ) -> Result<Option<(Self, Mmap)>, RevlogError> {
+ ) -> Result<Option<(Self, Mmap)>, HgError> {
if !repo
.requirements()
.contains(requirements::NODEMAP_REQUIREMENT)
@@ -65,10 +64,9 @@
};
/// Treat any error as a parse error
- fn parse<T, E>(result: Result<T, E>) -> Result<T, RevlogError> {
- result.map_err(|_| {
- HgError::corrupted("nodemap docket parse error").into()
- })
+ fn parse<T, E>(result: Result<T, E>) -> Result<T, HgError> {
+ result
+ .map_err(|_| HgError::corrupted("nodemap docket parse error"))
}
let (header, rest) = parse(DocketHeader::from_bytes(input))?;
@@ -94,7 +92,7 @@
if mmap.len() >= data_length {
Ok(Some((docket, mmap)))
} else {
- Err(HgError::corrupted("persistent nodemap too short").into())
+ Err(HgError::corrupted("persistent nodemap too short"))
}
} else {
// Even if .hg/requires opted in, some revlogs are deemed small
diff --git a/rust/hg-core/src/revlog/manifest.rs b/rust/hg-core/src/revlog/manifest.rs
--- a/rust/hg-core/src/revlog/manifest.rs
+++ b/rust/hg-core/src/revlog/manifest.rs
@@ -1,3 +1,4 @@
+use crate::errors::HgError;
use crate::repo::Repo;
use crate::revlog::revlog::{Revlog, RevlogError};
use crate::revlog::NodePrefix;
@@ -12,7 +13,7 @@
impl Manifestlog {
/// Open the `manifest` of a repository given by its root.
- pub fn open(repo: &Repo) -> Result<Self, RevlogError> {
+ pub fn open(repo: &Repo) -> Result<Self, HgError> {
let revlog = Revlog::open(repo, "00manifest.i", None)?;
Ok(Self { revlog })
}
diff --git a/rust/hg-core/src/revlog/index.rs b/rust/hg-core/src/revlog/index.rs
--- a/rust/hg-core/src/revlog/index.rs
+++ b/rust/hg-core/src/revlog/index.rs
@@ -5,7 +5,6 @@
use crate::errors::HgError;
use crate::revlog::node::Node;
-use crate::revlog::revlog::RevlogError;
use crate::revlog::{Revision, NULL_REVISION};
pub const INDEX_ENTRY_SIZE: usize = 64;
@@ -23,7 +22,7 @@
/// Calculate the start of each entry when is_inline is true.
pub fn new(
bytes: Box<dyn Deref<Target = [u8]> + Send>,
- ) -> Result<Self, RevlogError> {
+ ) -> Result<Self, HgError> {
if is_inline(&bytes) {
let mut offset: usize = 0;
let mut offsets = Vec::new();
diff --git a/rust/hg-core/src/revlog/filelog.rs b/rust/hg-core/src/revlog/filelog.rs
--- a/rust/hg-core/src/revlog/filelog.rs
+++ b/rust/hg-core/src/revlog/filelog.rs
@@ -17,7 +17,7 @@
}
impl Filelog {
- pub fn open(repo: &Repo, file_path: &HgPath) -> Result<Self, RevlogError> {
+ pub fn open(repo: &Repo, file_path: &HgPath) -> Result<Self, HgError> {
let index_path = store_path(file_path, b".i");
let data_path = store_path(file_path, b".d");
let revlog = Revlog::open(repo, index_path, Some(&data_path))?;
diff --git a/rust/hg-core/src/revlog/changelog.rs b/rust/hg-core/src/revlog/changelog.rs
--- a/rust/hg-core/src/revlog/changelog.rs
+++ b/rust/hg-core/src/revlog/changelog.rs
@@ -12,7 +12,7 @@
impl Changelog {
/// Open the `changelog` of a repository given by its root.
- pub fn open(repo: &Repo) -> Result<Self, RevlogError> {
+ pub fn open(repo: &Repo) -> Result<Self, HgError> {
let revlog = Revlog::open(repo, "00changelog.i", None)?;
Ok(Self { revlog })
}
diff --git a/rust/hg-core/src/repo.rs b/rust/hg-core/src/repo.rs
--- a/rust/hg-core/src/repo.rs
+++ b/rust/hg-core/src/repo.rs
@@ -29,8 +29,8 @@
// None means not known/initialized yet
dirstate_parents: Cell<Option<DirstateParents>>,
dirstate_map: LazyCell<OwningDirstateMap, DirstateError>,
- changelog: LazyCell<Changelog, RevlogError>,
- manifestlog: LazyCell<Manifestlog, RevlogError>,
+ changelog: LazyCell<Changelog, HgError>,
+ manifestlog: LazyCell<Manifestlog, HgError>,
}
#[derive(Debug, derive_more::From)]
@@ -320,19 +320,19 @@
self.dirstate_map.get_mut_or_init(self)
}
- pub fn changelog(&self) -> Result<Ref<Changelog>, RevlogError> {
+ pub fn changelog(&self) -> Result<Ref<Changelog>, HgError> {
self.changelog.get_or_init(self)
}
- pub fn changelog_mut(&self) -> Result<RefMut<Changelog>, RevlogError> {
+ pub fn changelog_mut(&self) -> Result<RefMut<Changelog>, HgError> {
self.changelog.get_mut_or_init(self)
}
- pub fn manifestlog(&self) -> Result<Ref<Manifestlog>, RevlogError> {
+ pub fn manifestlog(&self) -> Result<Ref<Manifestlog>, HgError> {
self.manifestlog.get_or_init(self)
}
- pub fn manifestlog_mut(&self) -> Result<RefMut<Manifestlog>, RevlogError> {
+ pub fn manifestlog_mut(&self) -> Result<RefMut<Manifestlog>, HgError> {
self.manifestlog.get_mut_or_init(self)
}
@@ -349,7 +349,7 @@
manifest.get_node(manifest_node.into())
}
- pub fn filelog(&self, path: &HgPath) -> Result<Filelog, RevlogError> {
+ pub fn filelog(&self, path: &HgPath) -> Result<Filelog, HgError> {
Filelog::open(self, path)
}
}
To: SimonSapin, #hg-reviewers, Alphare
Cc: Alphare, mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20210914/184b3da7/attachment-0002.html>
More information about the Mercurial-patches
mailing list