[Updated] D8867: rhg: simplify `FindRootError` handling
acezar (Antoine Cezar)
phabricator at mercurial-scm.org
Sat Aug 8 20:31:32 UTC 2020
Closed by commit rHG5dbf875b3275: rhg: simplify `FindRootError` handling (authored by acezar).
This revision was automatically updated to reflect the committed changes.
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D8867?vs=22244&id=22362
CHANGES SINCE LAST ACTION
https://phab.mercurial-scm.org/D8867/new/
REVISION DETAIL
https://phab.mercurial-scm.org/D8867
AFFECTED FILES
rust/rhg/src/commands/root.rs
rust/rhg/src/error.rs
CHANGE DETAILS
diff --git a/rust/rhg/src/error.rs b/rust/rhg/src/error.rs
--- a/rust/rhg/src/error.rs
+++ b/rust/rhg/src/error.rs
@@ -1,5 +1,6 @@
use crate::exitcode;
use crate::ui::UiError;
+use hg::operations::{FindRootError, FindRootErrorKind};
use hg::utils::files::get_bytes_from_path;
use std::convert::From;
use std::path::PathBuf;
@@ -90,3 +91,16 @@
}
}
}
+
+impl From<FindRootError> for CommandError {
+ fn from(err: FindRootError) -> Self {
+ match err.kind {
+ FindRootErrorKind::RootNotFound(path) => CommandError {
+ kind: CommandErrorKind::RootNotFound(path),
+ },
+ FindRootErrorKind::GetCurrentDirError(e) => CommandError {
+ kind: CommandErrorKind::CurrentDirNotFound(e),
+ },
+ }
+ }
+}
diff --git a/rust/rhg/src/commands/root.rs b/rust/rhg/src/commands/root.rs
--- a/rust/rhg/src/commands/root.rs
+++ b/rust/rhg/src/commands/root.rs
@@ -1,7 +1,7 @@
use crate::commands::Command;
-use crate::error::{CommandError, CommandErrorKind};
+use crate::error::CommandError;
use crate::ui::Ui;
-use hg::operations::{FindRoot, FindRootErrorKind};
+use hg::operations::FindRoot;
use hg::utils::files::get_bytes_from_path;
pub const HELP_TEXT: &str = "
@@ -22,15 +22,7 @@
impl<'a> Command<'a> for RootCommand<'a> {
fn run(&self) -> Result<(), CommandError> {
- let path_buf =
- FindRoot::new().run().map_err(|err| match err.kind {
- FindRootErrorKind::RootNotFound(path) => {
- CommandErrorKind::RootNotFound(path)
- }
- FindRootErrorKind::GetCurrentDirError(e) => {
- CommandErrorKind::CurrentDirNotFound(e)
- }
- })?;
+ let path_buf = FindRoot::new().run()?;
let bytes = get_bytes_from_path(path_buf);
To: acezar, #hg-reviewers, Alphare, indygreg
Cc: Alphare, mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20200808/874c643e/attachment-0002.html>
More information about the Mercurial-patches
mailing list