##// END OF EJS Templates
upgrade: implement partial upgrade for upgrading persistent-nodemap...
upgrade: implement partial upgrade for upgrading persistent-nodemap Upgrading repositories to use persistent nodemap should be fast and easy as it requires only two things: 1) Updating the requirements 2) Writing a persistent-nodemap on disk For both of the steps above, we don't need to edit existing revlogs. This patch makes upgrade only do the above mentioned two steps if we are only upgarding to use persistent-nodemap feature. Since `nodemap.persist_nodemap()` assumes that there exists a nodemap file for the given revlog if we are trying to call it, this patch adds `force` argument to create a file if does not exist which is true in our upgrade case. The test changes demonstrate that we no longer write nodemap files for manifest after upgrade which I think is desirable. Differential Revision: https://phab.mercurial-scm.org/D9936

File last commit:

r47175:1dcd9c99 default
r47199:98e39f04 default
Show More
error.rs
83 lines | 2.6 KiB | application/rls-services+xml | RustLexer
use crate::ui::utf8_to_local;
use crate::ui::UiError;
use format_bytes::format_bytes;
use hg::errors::HgError;
use hg::repo::RepoFindError;
use hg::revlog::revlog::RevlogError;
use hg::utils::files::get_bytes_from_path;
use std::convert::From;
/// The kind of command error
#[derive(Debug)]
pub enum CommandError {
/// Exit with an error message and "standard" failure exit code.
Abort { message: Vec<u8> },
/// A mercurial capability as not been implemented.
///
/// There is no error message printed in this case.
/// Instead, we exit with a specic status code and a wrapper script may
/// fallback to Python-based Mercurial.
Unimplemented,
}
impl CommandError {
pub fn abort(message: impl AsRef<str>) -> Self {
CommandError::Abort {
// TODO: bytes-based (instead of Unicode-based) formatting
// of error messages to handle non-UTF-8 filenames etc:
// https://www.mercurial-scm.org/wiki/EncodingStrategy#Mixing_output
message: utf8_to_local(message.as_ref()).into(),
}
}
}
impl From<HgError> for CommandError {
fn from(error: HgError) -> Self {
match error {
HgError::UnsupportedFeature(_) => CommandError::Unimplemented,
_ => CommandError::abort(error.to_string()),
}
}
}
impl From<UiError> for CommandError {
fn from(_error: UiError) -> Self {
// If we already failed writing to stdout or stderr,
// writing an error message to stderr about it would be likely to fail
// too.
CommandError::abort("")
}
}
impl From<RepoFindError> for CommandError {
fn from(error: RepoFindError) -> Self {
match error {
RepoFindError::NotFoundInCurrentDirectoryOrAncestors {
current_directory,
} => CommandError::Abort {
message: format_bytes!(
b"no repository found in '{}' (.hg not found)!",
get_bytes_from_path(current_directory)
),
},
RepoFindError::Other(error) => error.into(),
}
}
}
impl From<(RevlogError, &str)> for CommandError {
fn from((err, rev): (RevlogError, &str)) -> CommandError {
match err {
RevlogError::InvalidRevision => CommandError::abort(format!(
"invalid revision identifier {}",
rev
)),
RevlogError::AmbiguousPrefix => CommandError::abort(format!(
"ambiguous revision identifier {}",
rev
)),
RevlogError::Other(error) => error.into(),
}
}
}