##// END OF EJS Templates
largefiles: properly pass kwargs into url.open...
largefiles: properly pass kwargs into url.open The url.open function has acquired a lot of kwargs over the years. When running `hg import http://example.com/hg/diff/1`, since at least a708e1e4d7a8 in March, 2018, the calling sites for url.open try to pass a `sendaccept` parameter that largefiles' override doesn't accept. Currently that stack traces something like this: Traceback (most recent call last): File "/tmp/hgtests.sv744r5t/install/bin/hg", line 59, in <module> dispatch.run() File "/tmp/hgtests.sv744r5t/install/lib/python/mercurial/dispatch.py", line 143, in run status = dispatch(req) File "/tmp/hgtests.sv744r5t/install/lib/python/mercurial/dispatch.py", line 245, in dispatch status = _rundispatch(req) File "/tmp/hgtests.sv744r5t/install/lib/python/mercurial/dispatch.py", line 289, in _rundispatch ret = _runcatch(req) or 0 File "/tmp/hgtests.sv744r5t/install/lib/python/mercurial/dispatch.py", line 465, in _runcatch return _callcatch(ui, _runcatchfunc) File "/tmp/hgtests.sv744r5t/install/lib/python/mercurial/dispatch.py", line 475, in _callcatch return scmutil.callcatch(ui, func) File "/tmp/hgtests.sv744r5t/install/lib/python/mercurial/scmutil.py", line 155, in callcatch return func() File "/tmp/hgtests.sv744r5t/install/lib/python/mercurial/dispatch.py", line 455, in _runcatchfunc return _dispatch(req) File "/tmp/hgtests.sv744r5t/install/lib/python/mercurial/dispatch.py", line 1259, in _dispatch lui, repo, cmd, fullargs, ui, options, d, cmdpats, cmdoptions File "/tmp/hgtests.sv744r5t/install/lib/python/mercurial/dispatch.py", line 913, in runcommand ret = _runcommand(ui, options, cmd, d) File "/tmp/hgtests.sv744r5t/install/lib/python/mercurial/dispatch.py", line 1270, in _runcommand return cmdfunc() File "/tmp/hgtests.sv744r5t/install/lib/python/mercurial/dispatch.py", line 1256, in <lambda> d = lambda: util.checksignature(func)(ui, *args, **strcmdopt) File "/tmp/hgtests.sv744r5t/install/lib/python/mercurial/util.py", line 1867, in check return func(*args, **kwargs) File "/tmp/hgtests.sv744r5t/install/lib/python/mercurial/commands.py", line 4184, in import_ patchfile = hg.openpath(ui, patchurl, sendaccept=False) File "/tmp/hgtests.sv744r5t/install/lib/python/mercurial/hg.py", line 181, in openpath return url.open(ui, path, sendaccept=sendaccept) TypeError: openlargefile() got an unexpected keyword argument 'sendaccept' So, just accept and pass along any kwargs of the overridden function.

File last commit:

r47175:1dcd9c99 default
r47202:32da5891 stable
Show More
error.rs
124 lines | 4.0 KiB | application/rls-services+xml | RustLexer
use crate::exitcode;
use crate::ui::UiError;
use format_bytes::format_bytes;
use hg::operations::{FindRootError, FindRootErrorKind};
use hg::requirements::RequirementsError;
use hg::utils::files::get_bytes_from_path;
use std::convert::From;
use std::path::PathBuf;
/// The kind of command error
#[derive(Debug)]
pub enum CommandErrorKind {
/// The root of the repository cannot be found
RootNotFound(PathBuf),
/// The current directory cannot be found
CurrentDirNotFound(std::io::Error),
/// `.hg/requires`
RequirementsError(RequirementsError),
/// The standard output stream cannot be written to
StdoutError,
/// The standard error stream cannot be written to
StderrError,
/// The command aborted
Abort(Option<Vec<u8>>),
/// A mercurial capability as not been implemented.
Unimplemented,
}
impl CommandErrorKind {
pub fn get_exit_code(&self) -> exitcode::ExitCode {
match self {
CommandErrorKind::RootNotFound(_) => exitcode::ABORT,
CommandErrorKind::CurrentDirNotFound(_) => exitcode::ABORT,
CommandErrorKind::RequirementsError(
RequirementsError::Unsupported { .. },
) => exitcode::UNIMPLEMENTED_COMMAND,
CommandErrorKind::RequirementsError(_) => exitcode::ABORT,
CommandErrorKind::StdoutError => exitcode::ABORT,
CommandErrorKind::StderrError => exitcode::ABORT,
CommandErrorKind::Abort(_) => exitcode::ABORT,
CommandErrorKind::Unimplemented => exitcode::UNIMPLEMENTED_COMMAND,
}
}
/// Return the message corresponding to the error kind if any
pub fn get_error_message_bytes(&self) -> Option<Vec<u8>> {
match self {
CommandErrorKind::RootNotFound(path) => {
let bytes = get_bytes_from_path(path);
Some(format_bytes!(
b"abort: no repository found in '{}' (.hg not found)!\n",
bytes.as_slice()
))
}
CommandErrorKind::CurrentDirNotFound(e) => Some(format_bytes!(
b"abort: error getting current working directory: {}\n",
e.to_string().as_bytes(),
)),
CommandErrorKind::RequirementsError(
RequirementsError::Corrupted,
) => Some(
"abort: .hg/requires is corrupted\n".as_bytes().to_owned(),
),
CommandErrorKind::Abort(message) => message.to_owned(),
_ => None,
}
}
}
/// The error type for the Command trait
#[derive(Debug)]
pub struct CommandError {
pub kind: CommandErrorKind,
}
impl CommandError {
/// Exist the process with the corresponding exit code.
pub fn exit(&self) {
std::process::exit(self.kind.get_exit_code())
}
/// 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()
}
}
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,
},
}
}
}
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),
},
}
}
}
impl From<RequirementsError> for CommandError {
fn from(err: RequirementsError) -> Self {
CommandError {
kind: CommandErrorKind::RequirementsError(err),
}
}
}