##// 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:

r47174:ca3f73cc default
r47202:32da5891 stable
Show More
main.rs
185 lines | 5.9 KiB | application/rls-services+xml | RustLexer
extern crate log;
use clap::App;
use clap::AppSettings;
use clap::Arg;
use clap::ArgGroup;
use clap::ArgMatches;
use clap::SubCommand;
use hg::operations::DebugDataKind;
use std::convert::TryFrom;
mod commands;
mod error;
mod exitcode;
mod ui;
use commands::Command;
use error::CommandError;
fn main() {
env_logger::init();
let app = App::new("rhg")
.setting(AppSettings::AllowInvalidUtf8)
.setting(AppSettings::SubcommandRequired)
.setting(AppSettings::VersionlessSubcommands)
.version("0.0.1")
.subcommand(
SubCommand::with_name("root").about(commands::root::HELP_TEXT),
)
.subcommand(
SubCommand::with_name("files")
.arg(
Arg::with_name("rev")
.help("search the repository as it is in REV")
.short("-r")
.long("--revision")
.value_name("REV")
.takes_value(true),
)
.about(commands::files::HELP_TEXT),
)
.subcommand(
SubCommand::with_name("cat")
.arg(
Arg::with_name("rev")
.help("search the repository as it is in REV")
.short("-r")
.long("--revision")
.value_name("REV")
.takes_value(true),
)
.arg(
clap::Arg::with_name("files")
.required(true)
.multiple(true)
.empty_values(false)
.value_name("FILE")
.help("Activity to start: activity@category"),
)
.about(commands::cat::HELP_TEXT),
)
.subcommand(
SubCommand::with_name("debugdata")
.about(commands::debugdata::HELP_TEXT)
.arg(
Arg::with_name("changelog")
.help("open changelog")
.short("-c")
.long("--changelog"),
)
.arg(
Arg::with_name("manifest")
.help("open manifest")
.short("-m")
.long("--manifest"),
)
.group(
ArgGroup::with_name("")
.args(&["changelog", "manifest"])
.required(true),
)
.arg(
Arg::with_name("rev")
.help("revision")
.required(true)
.value_name("REV"),
),
)
.subcommand(
SubCommand::with_name("debugrequirements")
.about(commands::debugrequirements::HELP_TEXT),
);
let matches = app.clone().get_matches_safe().unwrap_or_else(|err| {
let _ = ui::Ui::new().writeln_stderr_str(&err.message);
std::process::exit(exitcode::UNIMPLEMENTED_COMMAND)
});
let ui = ui::Ui::new();
let command_result = match_subcommand(matches, &ui);
match command_result {
Ok(_) => std::process::exit(exitcode::OK),
Err(e) => {
let message = e.get_error_message_bytes();
if let Some(msg) = message {
match ui.write_stderr(&msg) {
Ok(_) => (),
Err(_) => std::process::exit(exitcode::ABORT),
};
};
e.exit()
}
}
}
fn match_subcommand(
matches: ArgMatches,
ui: &ui::Ui,
) -> Result<(), CommandError> {
match matches.subcommand() {
("root", _) => commands::root::RootCommand::new().run(&ui),
("files", Some(matches)) => {
commands::files::FilesCommand::try_from(matches)?.run(&ui)
}
("cat", Some(matches)) => {
commands::cat::CatCommand::try_from(matches)?.run(&ui)
}
("debugdata", Some(matches)) => {
commands::debugdata::DebugDataCommand::try_from(matches)?.run(&ui)
}
("debugrequirements", _) => {
commands::debugrequirements::DebugRequirementsCommand::new()
.run(&ui)
}
_ => unreachable!(), // Because of AppSettings::SubcommandRequired,
}
}
impl<'a> TryFrom<&'a ArgMatches<'_>> for commands::files::FilesCommand<'a> {
type Error = CommandError;
fn try_from(args: &'a ArgMatches) -> Result<Self, Self::Error> {
let rev = args.value_of("rev");
Ok(commands::files::FilesCommand::new(rev))
}
}
impl<'a> TryFrom<&'a ArgMatches<'_>> for commands::cat::CatCommand<'a> {
type Error = CommandError;
fn try_from(args: &'a ArgMatches) -> Result<Self, Self::Error> {
let rev = args.value_of("rev");
let files = match args.values_of("files") {
Some(files) => files.collect(),
None => vec![],
};
Ok(commands::cat::CatCommand::new(rev, files))
}
}
impl<'a> TryFrom<&'a ArgMatches<'_>>
for commands::debugdata::DebugDataCommand<'a>
{
type Error = CommandError;
fn try_from(args: &'a ArgMatches) -> Result<Self, Self::Error> {
let rev = args
.value_of("rev")
.expect("rev should be a required argument");
let kind = match (
args.is_present("changelog"),
args.is_present("manifest"),
) {
(true, false) => DebugDataKind::Changelog,
(false, true) => DebugDataKind::Manifest,
(true, true) => {
unreachable!("Should not happen since options are exclusive")
}
(false, false) => {
unreachable!("Should not happen since options are required")
}
};
Ok(commands::debugdata::DebugDataCommand::new(rev, kind))
}
}