Mercurial > public > mercurial-scm > hg
diff rust/hg-core/src/operations/cat.rs @ 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 | 3e2d539d0d1a |
children | 43d63979a75e |
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) {