Mercurial > public > mercurial-scm > hg
diff rust/rhg/src/commands/files.rs @ 46434:3e2d539d0d1a
rust: remove `FooError` structs with only `kind: FooErrorKind` enum field
Use the enum directly as `FooError` instead.
Differential Revision: https://phab.mercurial-scm.org/D9874
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Tue, 26 Jan 2021 19:07:24 +0100 |
parents | 8a4914397d02 |
children | 252d1bdba33d |
line wrap: on
line diff
--- a/rust/rhg/src/commands/files.rs Tue Jan 26 18:31:46 2021 +0100 +++ b/rust/rhg/src/commands/files.rs Tue Jan 26 19:07:24 2021 +0100 @@ -1,14 +1,9 @@ use crate::commands::Command; -use crate::error::{CommandError, CommandErrorKind}; +use crate::error::CommandError; use crate::ui::utf8_to_local; use crate::ui::Ui; -use hg::operations::{ - list_rev_tracked_files, ListRevTrackedFilesError, - ListRevTrackedFilesErrorKind, -}; -use hg::operations::{ - Dirstate, ListDirstateTrackedFilesError, ListDirstateTrackedFilesErrorKind, -}; +use hg::operations::{list_rev_tracked_files, ListRevTrackedFilesError}; +use hg::operations::{Dirstate, ListDirstateTrackedFilesError}; use hg::repo::Repo; use hg::utils::files::{get_bytes_from_path, relativize_path}; use hg::utils::hg_path::{HgPath, HgPathBuf}; @@ -35,7 +30,7 @@ files: impl IntoIterator<Item = &'a HgPath>, ) -> Result<(), CommandError> { let cwd = std::env::current_dir() - .or_else(|e| Err(CommandErrorKind::CurrentDirNotFound(e)))?; + .or_else(|e| Err(CommandError::CurrentDirNotFound(e)))?; let rooted_cwd = cwd .strip_prefix(repo.working_directory_path()) .expect("cwd was already checked within the repository"); @@ -68,75 +63,65 @@ } } -/// Convert `ListRevTrackedFilesErrorKind` to `CommandError` +/// Convert `ListRevTrackedFilesError` to `CommandError` fn map_rev_error(rev: &str, err: ListRevTrackedFilesError) -> CommandError { - CommandError { - kind: match err.kind { - ListRevTrackedFilesErrorKind::IoError(err) => { - CommandErrorKind::Abort(Some( - utf8_to_local(&format!("abort: {}\n", err)).into(), + 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 )) - } - ListRevTrackedFilesErrorKind::InvalidRevision => { - CommandErrorKind::Abort(Some( - utf8_to_local(&format!( - "abort: invalid revision identifier {}\n", - rev - )) - .into(), - )) - } - ListRevTrackedFilesErrorKind::AmbiguousPrefix => { - CommandErrorKind::Abort(Some( - utf8_to_local(&format!( - "abort: ambiguous revision identifier {}\n", - rev - )) - .into(), + .into(), + )) + } + ListRevTrackedFilesError::AmbiguousPrefix => { + CommandError::Abort(Some( + utf8_to_local(&format!( + "abort: ambiguous revision identifier {}\n", + rev )) - } - ListRevTrackedFilesErrorKind::UnsuportedRevlogVersion(version) => { - CommandErrorKind::Abort(Some( - utf8_to_local(&format!( - "abort: unsupported revlog version {}\n", - version - )) - .into(), + .into(), + )) + } + ListRevTrackedFilesError::UnsuportedRevlogVersion(version) => { + CommandError::Abort(Some( + utf8_to_local(&format!( + "abort: unsupported revlog version {}\n", + version )) - } - ListRevTrackedFilesErrorKind::CorruptedRevlog => { - CommandErrorKind::Abort(Some( - "abort: corrupted revlog\n".into(), + .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 )) - } - ListRevTrackedFilesErrorKind::UnknowRevlogDataFormat(format) => { - CommandErrorKind::Abort(Some( - utf8_to_local(&format!( - "abort: unknow revlog dataformat {:?}\n", - format - )) - .into(), - )) - } - }, + .into(), + )) + } } } /// Convert `ListDirstateTrackedFilesError` to `CommandError` fn map_dirstate_error(err: ListDirstateTrackedFilesError) -> CommandError { - CommandError { - kind: match err.kind { - ListDirstateTrackedFilesErrorKind::IoError(err) => { - CommandErrorKind::Abort(Some( - utf8_to_local(&format!("abort: {}\n", err)).into(), - )) - } - ListDirstateTrackedFilesErrorKind::ParseError(_) => { - CommandErrorKind::Abort(Some( - // TODO find a better error message - b"abort: parse error\n".to_vec(), - )) - } - }, + match err { + ListDirstateTrackedFilesError::IoError(err) => CommandError::Abort( + Some(utf8_to_local(&format!("abort: {}\n", err)).into()), + ), + ListDirstateTrackedFilesError::ParseError(_) => { + CommandError::Abort(Some( + // TODO find a better error message + b"abort: parse error\n".to_vec(), + )) + } } }