##// END OF EJS Templates
fix: don't include obsolete descendants with -s...
fix: don't include obsolete descendants with -s The `-s/--source` option is for regular users (`-r` is there for power users). If there are obsolete commits that are descendants of the given revision(s), then they almost definitely should just be left alone. That's what `hg rebase` does as well. So this patch makes it so we skip obsolete commits (including those in the input set itself). Differential Revision: https://phab.mercurial-scm.org/D9226

File last commit:

r46113:33ded2d3 default
r46400:7f07e634 default
Show More
error.rs
113 lines | 3.5 KiB | application/rls-services+xml | RustLexer
Antoine Cezar
rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`...
r45592 use crate::exitcode;
use crate::ui::UiError;
Antoine Cezar
rhg: simplify `FindRootError` handling...
r45922 use hg::operations::{FindRootError, FindRootErrorKind};
Antoine Cezar
rhg: ask the error message from `CommandError`...
r45920 use hg::utils::files::get_bytes_from_path;
Antoine Cezar
rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`...
r45592 use std::convert::From;
Antoine Cezar
rhg: ask the error message from `CommandError`...
r45920 use std::path::PathBuf;
Antoine Cezar
rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`...
r45592
/// The kind of command error
Antoine Cezar
rhg: ask the error message from `CommandError`...
r45920 #[derive(Debug)]
Antoine Cezar
rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`...
r45592 pub enum CommandErrorKind {
/// The root of the repository cannot be found
Antoine Cezar
rhg: ask the error message from `CommandError`...
r45920 RootNotFound(PathBuf),
Antoine Cezar
rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`...
r45592 /// The current directory cannot be found
Antoine Cezar
rhg: ask the error message from `CommandError`...
r45920 CurrentDirNotFound(std::io::Error),
Antoine Cezar
rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`...
r45592 /// The standard output stream cannot be written to
StdoutError,
/// The standard error stream cannot be written to
StderrError,
Antoine Cezar
rhg: add a `Files` `Command` to prepare the `rhg files` subcommand...
r45923 /// The command aborted
Abort(Option<Vec<u8>>),
Antoine Cezar
rhg: add a limited `rhg cat -r` subcommand...
r46113 /// A mercurial capability as not been implemented.
Unimplemented,
Antoine Cezar
rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`...
r45592 }
impl CommandErrorKind {
pub fn get_exit_code(&self) -> exitcode::ExitCode {
match self {
Antoine Cezar
rhg: ask the error message from `CommandError`...
r45920 CommandErrorKind::RootNotFound(_) => exitcode::ABORT,
CommandErrorKind::CurrentDirNotFound(_) => exitcode::ABORT,
Antoine Cezar
rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`...
r45592 CommandErrorKind::StdoutError => exitcode::ABORT,
CommandErrorKind::StderrError => exitcode::ABORT,
Antoine Cezar
rhg: add a `Files` `Command` to prepare the `rhg files` subcommand...
r45923 CommandErrorKind::Abort(_) => exitcode::ABORT,
Antoine Cezar
rhg: add a limited `rhg cat -r` subcommand...
r46113 CommandErrorKind::Unimplemented => exitcode::UNIMPLEMENTED_COMMAND,
Antoine Cezar
rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`...
r45592 }
}
Antoine Cezar
rhg: ask the error message from `CommandError`...
r45920
/// Return the message corresponding to the error kind if any
pub fn get_error_message_bytes(&self) -> Option<Vec<u8>> {
match self {
// TODO use formating macro
CommandErrorKind::RootNotFound(path) => {
let bytes = get_bytes_from_path(path);
Some(
[
b"abort: no repository found in '",
bytes.as_slice(),
b"' (.hg not found)!\n",
]
.concat(),
)
}
// TODO use formating macro
CommandErrorKind::CurrentDirNotFound(e) => Some(
[
b"abort: error getting current working directory: ",
e.to_string().as_bytes(),
b"\n",
]
.concat(),
),
Antoine Cezar
rhg: add a `Files` `Command` to prepare the `rhg files` subcommand...
r45923 CommandErrorKind::Abort(message) => message.to_owned(),
Antoine Cezar
rhg: ask the error message from `CommandError`...
r45920 _ => None,
}
}
Antoine Cezar
rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`...
r45592 }
Antoine Cezar
rhg: add Command trait for subcommands implemented by rhg...
r45515 /// The error type for the Command trait
Antoine Cezar
rhg: ask the error message from `CommandError`...
r45920 #[derive(Debug)]
Antoine Cezar
rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`...
r45592 pub struct CommandError {
pub kind: CommandErrorKind,
}
impl CommandError {
/// Exist the process with the corresponding exit code.
Antoine Cezar
rhg: fix `clippy` warnings...
r46010 pub fn exit(&self) {
Antoine Cezar
rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`...
r45592 std::process::exit(self.kind.get_exit_code())
}
Antoine Cezar
rhg: ask the error message from `CommandError`...
r45920
/// Return the message corresponding to the command error if any
pub fn get_error_message_bytes(&self) -> Option<Vec<u8>> {
self.kind.get_error_message_bytes()
}
Antoine Cezar
rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`...
r45592 }
impl From<CommandErrorKind> for CommandError {
fn from(kind: CommandErrorKind) -> Self {
CommandError { kind }
}
}
impl From<UiError> for CommandError {
fn from(error: UiError) -> Self {
CommandError {
kind: match error {
UiError::StdoutError(_) => CommandErrorKind::StdoutError,
UiError::StderrError(_) => CommandErrorKind::StderrError,
},
}
}
}
Antoine Cezar
rhg: simplify `FindRootError` handling...
r45922
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),
},
}
}
}