Mercurial > hg
changeset 46437:b274aa2f20fd
rust: remove three enums that were identical to `RevlogError`
Differential Revision: https://phab.mercurial-scm.org/D9877
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Tue, 26 Jan 2021 20:42:36 +0100 |
parents | 252d1bdba33d |
children | 39e9407820ac |
files | rust/hg-core/src/operations/cat.rs rust/hg-core/src/operations/debugdata.rs rust/hg-core/src/operations/list_tracked_files.rs rust/hg-core/src/operations/mod.rs rust/rhg/src/error.rs |
diffstat | 5 files changed, 21 insertions(+), 232 deletions(-) [+] |
line wrap: on
line diff
--- a/rust/hg-core/src/operations/cat.rs Tue Jan 26 20:31:26 2021 +0100 +++ b/rust/hg-core/src/operations/cat.rs Tue Jan 26 20:42:36 2021 +0100 @@ -5,7 +5,6 @@ // This software may be used and distributed according to the terms of the // GNU General Public License version 2 or any later version. -use std::convert::From; use std::path::PathBuf; use crate::repo::Repo; @@ -20,40 +19,6 @@ const METADATA_DELIMITER: [u8; 2] = [b'\x01', b'\n']; -/// Error type for `cat` -#[derive(Debug)] -pub enum CatRevError { - /// Error when reading a `revlog` file. - IoError(std::io::Error), - /// The revision has not been found. - InvalidRevision, - /// Found more than one revision whose ID match the requested prefix - AmbiguousPrefix, - /// A `revlog` file is corrupted. - CorruptedRevlog, - /// The `revlog` format version is not supported. - UnsuportedRevlogVersion(u16), - /// The `revlog` data format is not supported. - UnknowRevlogDataFormat(u8), -} - -impl From<RevlogError> for CatRevError { - fn from(err: RevlogError) -> Self { - match err { - RevlogError::IoError(err) => CatRevError::IoError(err), - RevlogError::UnsuportedVersion(version) => { - CatRevError::UnsuportedRevlogVersion(version) - } - RevlogError::InvalidRevision => CatRevError::InvalidRevision, - RevlogError::AmbiguousPrefix => CatRevError::AmbiguousPrefix, - RevlogError::Corrupted => CatRevError::CorruptedRevlog, - RevlogError::UnknowDataFormat(format) => { - CatRevError::UnknowRevlogDataFormat(format) - } - } - } -} - /// List files under Mercurial control at a given revision. /// /// * `root`: Repository root @@ -63,13 +28,13 @@ repo: &Repo, revset: &str, files: &[HgPathBuf], -) -> Result<Vec<u8>, CatRevError> { +) -> Result<Vec<u8>, RevlogError> { let rev = crate::revset::resolve_single(revset, repo)?; let changelog = Changelog::open(repo)?; let manifest = Manifest::open(repo)?; let changelog_entry = changelog.get_rev(rev)?; let manifest_node = Node::from_hex(&changelog_entry.manifest_node()?) - .map_err(|_| CatRevError::CorruptedRevlog)?; + .map_err(|_| RevlogError::Corrupted)?; let manifest_entry = manifest.get_node(manifest_node.into())?; let mut bytes = vec![]; @@ -82,7 +47,7 @@ let file_log = Revlog::open(repo, &index_path, Some(&data_path))?; let file_node = Node::from_hex(node_bytes) - .map_err(|_| CatRevError::CorruptedRevlog)?; + .map_err(|_| RevlogError::Corrupted)?; let file_rev = file_log.get_node_rev(file_node.into())?; let data = file_log.get_rev_data(file_rev)?; if data.starts_with(&METADATA_DELIMITER) {
--- a/rust/hg-core/src/operations/debugdata.rs Tue Jan 26 20:31:26 2021 +0100 +++ b/rust/hg-core/src/operations/debugdata.rs Tue Jan 26 20:42:36 2021 +0100 @@ -15,47 +15,12 @@ Manifest, } -/// Error type for `debug_data` -#[derive(Debug, derive_more::From)] -pub enum DebugDataError { - /// Error when reading a `revlog` file. - #[from] - IoError(std::io::Error), - /// The revision has not been found. - InvalidRevision, - /// Found more than one revision whose ID match the requested prefix - AmbiguousPrefix, - /// A `revlog` file is corrupted. - CorruptedRevlog, - /// The `revlog` format version is not supported. - UnsuportedRevlogVersion(u16), - /// The `revlog` data format is not supported. - UnknowRevlogDataFormat(u8), -} - -impl From<RevlogError> for DebugDataError { - fn from(err: RevlogError) -> Self { - match err { - RevlogError::IoError(err) => DebugDataError::IoError(err), - RevlogError::UnsuportedVersion(version) => { - DebugDataError::UnsuportedRevlogVersion(version) - } - RevlogError::InvalidRevision => DebugDataError::InvalidRevision, - RevlogError::AmbiguousPrefix => DebugDataError::AmbiguousPrefix, - RevlogError::Corrupted => DebugDataError::CorruptedRevlog, - RevlogError::UnknowDataFormat(format) => { - DebugDataError::UnknowRevlogDataFormat(format) - } - } - } -} - /// Dump the contents data of a revision. pub fn debug_data( repo: &Repo, revset: &str, kind: DebugDataKind, -) -> Result<Vec<u8>, DebugDataError> { +) -> Result<Vec<u8>, RevlogError> { let index_file = match kind { DebugDataKind::Changelog => "00changelog.i", DebugDataKind::Manifest => "00manifest.i",
--- a/rust/hg-core/src/operations/list_tracked_files.rs Tue Jan 26 20:31:26 2021 +0100 +++ b/rust/hg-core/src/operations/list_tracked_files.rs Tue Jan 26 20:42:36 2021 +0100 @@ -14,7 +14,6 @@ use crate::utils::hg_path::HgPath; use crate::{DirstateParseError, EntryState}; use rayon::prelude::*; -use std::convert::From; /// Error type for `Dirstate` methods #[derive(Debug, derive_more::From)] @@ -55,59 +54,17 @@ } } -/// Error type `list_rev_tracked_files` -#[derive(Debug)] -pub enum ListRevTrackedFilesError { - /// Error when reading a `revlog` file. - IoError(std::io::Error), - /// The revision has not been found. - InvalidRevision, - /// Found more than one revision whose ID match the requested prefix - AmbiguousPrefix, - /// A `revlog` file is corrupted. - CorruptedRevlog, - /// The `revlog` format version is not supported. - UnsuportedRevlogVersion(u16), - /// The `revlog` data format is not supported. - UnknowRevlogDataFormat(u8), -} - -impl From<RevlogError> for ListRevTrackedFilesError { - fn from(err: RevlogError) -> Self { - match err { - RevlogError::IoError(err) => { - ListRevTrackedFilesError::IoError(err) - } - RevlogError::UnsuportedVersion(version) => { - ListRevTrackedFilesError::UnsuportedRevlogVersion(version) - } - RevlogError::InvalidRevision => { - ListRevTrackedFilesError::InvalidRevision - } - RevlogError::AmbiguousPrefix => { - ListRevTrackedFilesError::AmbiguousPrefix - } - RevlogError::Corrupted => { - ListRevTrackedFilesError::CorruptedRevlog - } - RevlogError::UnknowDataFormat(format) => { - ListRevTrackedFilesError::UnknowRevlogDataFormat(format) - } - } - } -} - /// List files under Mercurial control at a given revision. pub fn list_rev_tracked_files( repo: &Repo, revset: &str, -) -> Result<FilesForRev, ListRevTrackedFilesError> { +) -> Result<FilesForRev, RevlogError> { let rev = crate::revset::resolve_single(revset, repo)?; let changelog = Changelog::open(repo)?; let manifest = Manifest::open(repo)?; let changelog_entry = changelog.get_rev(rev)?; let manifest_node = Node::from_hex(&changelog_entry.manifest_node()?) - .or(Err(ListRevTrackedFilesError::CorruptedRevlog))?; + .map_err(|_| RevlogError::Corrupted)?; let manifest_entry = manifest.get_node(manifest_node.into())?; Ok(FilesForRev(manifest_entry)) }
--- a/rust/hg-core/src/operations/mod.rs Tue Jan 26 20:31:26 2021 +0100 +++ b/rust/hg-core/src/operations/mod.rs Tue Jan 26 20:42:36 2021 +0100 @@ -7,10 +7,8 @@ mod dirstate_status; mod find_root; mod list_tracked_files; -pub use cat::{cat, CatRevError}; -pub use debugdata::{debug_data, DebugDataError, DebugDataKind}; +pub use cat::cat; +pub use debugdata::{debug_data, DebugDataKind}; pub use find_root::{find_root, find_root_from_path, FindRootError}; -pub use list_tracked_files::{ - list_rev_tracked_files, FilesForRev, ListRevTrackedFilesError, -}; +pub use list_tracked_files::{list_rev_tracked_files, FilesForRev}; pub use list_tracked_files::{Dirstate, ListDirstateTrackedFilesError};
--- a/rust/rhg/src/error.rs Tue Jan 26 20:31:26 2021 +0100 +++ b/rust/rhg/src/error.rs Tue Jan 26 20:42:36 2021 +0100 @@ -2,11 +2,9 @@ use crate::ui::utf8_to_local; use crate::ui::UiError; use format_bytes::format_bytes; -use hg::operations::{ - CatRevError, DebugDataError, FindRootError, ListDirstateTrackedFilesError, - ListRevTrackedFilesError, -}; +use hg::operations::{FindRootError, ListDirstateTrackedFilesError}; use hg::requirements::RequirementsError; +use hg::revlog::revlog::RevlogError; use hg::utils::files::get_bytes_from_path; use std::convert::From; use std::path::PathBuf; @@ -99,27 +97,27 @@ } } -impl From<(DebugDataError, &str)> for CommandError { - fn from((err, rev): (DebugDataError, &str)) -> CommandError { +impl From<(RevlogError, &str)> for CommandError { + fn from((err, rev): (RevlogError, &str)) -> CommandError { match err { - DebugDataError::IoError(err) => CommandError::Abort(Some( + RevlogError::IoError(err) => CommandError::Abort(Some( utf8_to_local(&format!("abort: {}\n", err)).into(), )), - DebugDataError::InvalidRevision => CommandError::Abort(Some( + RevlogError::InvalidRevision => CommandError::Abort(Some( utf8_to_local(&format!( - "abort: invalid revision identifier{}\n", + "abort: invalid revision identifier {}\n", rev )) .into(), )), - DebugDataError::AmbiguousPrefix => CommandError::Abort(Some( + RevlogError::AmbiguousPrefix => CommandError::Abort(Some( utf8_to_local(&format!( - "abort: ambiguous revision identifier{}\n", + "abort: ambiguous revision identifier {}\n", rev )) .into(), )), - DebugDataError::UnsuportedRevlogVersion(version) => { + RevlogError::UnsuportedVersion(version) => { CommandError::Abort(Some( utf8_to_local(&format!( "abort: unsupported revlog version {}\n", @@ -128,104 +126,10 @@ .into(), )) } - DebugDataError::CorruptedRevlog => { + RevlogError::Corrupted => { CommandError::Abort(Some("abort: corrupted revlog\n".into())) } - DebugDataError::UnknowRevlogDataFormat(format) => { - CommandError::Abort(Some( - utf8_to_local(&format!( - "abort: unknow revlog dataformat {:?}\n", - format - )) - .into(), - )) - } - } - } -} - -impl From<(ListRevTrackedFilesError, &str)> for CommandError { - fn from((err, rev): (ListRevTrackedFilesError, &str)) -> CommandError { - match err { - ListRevTrackedFilesError::IoError(err) => CommandError::Abort( - Some(utf8_to_local(&format!("abort: {}\n", err)).into()), - ), - ListRevTrackedFilesError::InvalidRevision => { - CommandError::Abort(Some( - utf8_to_local(&format!( - "abort: invalid revision identifier {}\n", - rev - )) - .into(), - )) - } - ListRevTrackedFilesError::AmbiguousPrefix => { - CommandError::Abort(Some( - utf8_to_local(&format!( - "abort: ambiguous revision identifier {}\n", - rev - )) - .into(), - )) - } - ListRevTrackedFilesError::UnsuportedRevlogVersion(version) => { - CommandError::Abort(Some( - utf8_to_local(&format!( - "abort: unsupported revlog version {}\n", - version - )) - .into(), - )) - } - ListRevTrackedFilesError::CorruptedRevlog => { - CommandError::Abort(Some("abort: corrupted revlog\n".into())) - } - ListRevTrackedFilesError::UnknowRevlogDataFormat(format) => { - CommandError::Abort(Some( - utf8_to_local(&format!( - "abort: unknow revlog dataformat {:?}\n", - format - )) - .into(), - )) - } - } - } -} - -impl From<(CatRevError, &str)> for CommandError { - fn from((err, rev): (CatRevError, &str)) -> CommandError { - match err { - CatRevError::IoError(err) => CommandError::Abort(Some( - utf8_to_local(&format!("abort: {}\n", err)).into(), - )), - CatRevError::InvalidRevision => CommandError::Abort(Some( - utf8_to_local(&format!( - "abort: invalid revision identifier {}\n", - rev - )) - .into(), - )), - CatRevError::AmbiguousPrefix => CommandError::Abort(Some( - utf8_to_local(&format!( - "abort: ambiguous revision identifier {}\n", - rev - )) - .into(), - )), - CatRevError::UnsuportedRevlogVersion(version) => { - CommandError::Abort(Some( - utf8_to_local(&format!( - "abort: unsupported revlog version {}\n", - version - )) - .into(), - )) - } - CatRevError::CorruptedRevlog => { - CommandError::Abort(Some("abort: corrupted revlog\n".into())) - } - CatRevError::UnknowRevlogDataFormat(format) => { + RevlogError::UnknowDataFormat(format) => { CommandError::Abort(Some( utf8_to_local(&format!( "abort: unknow revlog dataformat {:?}\n",