##// END OF EJS Templates
rhg: Make `files` work on repo-relative paths when possible...
rhg: Make `files` work on repo-relative paths when possible When the current directory is outside of the repository we need to turn everything into absolute filesystem paths in order to compute correct relative paths. This was previously done unconditionally, but is not necessary when the current directory is inside the repository. With this change `rhg files > /dev/null` at the root of a mozilla-central snapshot goes from ~150 ms to ~70 ms. My repository is located at a somewhat long path though (93 bytes). The effect may not be as pronounced at a shorter path. Differential Revision: https://phab.mercurial-scm.org/D10200

File last commit:

r47481:b1e6265e default
r47687:b5e8bf10 default
Show More
config.rs
38 lines | 1.1 KiB | application/rls-services+xml | RustLexer
Simon Sapin
rhg: add limited support for the `config` sub-command...
r47255 use crate::error::CommandError;
use clap::Arg;
use format_bytes::format_bytes;
use hg::errors::HgError;
use hg::utils::SliceExt;
pub const HELP_TEXT: &str = "
With one argument of the form section.name, print just the value of that config item.
";
pub fn args() -> clap::App<'static, 'static> {
clap::SubCommand::with_name("config")
.arg(
Arg::with_name("name")
.help("the section.name to print")
.value_name("NAME")
.required(true)
.takes_value(true),
)
.about(HELP_TEXT)
}
Simon Sapin
rhg: Group values passed to every sub-command into a struct...
r47334 pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> {
let (section, name) = invocation
.subcommand_args
Simon Sapin
rhg: add limited support for the `config` sub-command...
r47255 .value_of("name")
.expect("missing required CLI argument")
.as_bytes()
.split_2(b'.')
Simon Sapin
rhg: Fall back to Python on unsupported `rhg config <section>`...
r47460 .ok_or_else(|| HgError::unsupported("hg config <section>"))?;
Simon Sapin
rhg: add limited support for the `config` sub-command...
r47255
Simon Sapin
rhg: Return an error code for `rhg config Section.idontexist`...
r47481 if let Some(value) = invocation.config.get(section, name) {
invocation.ui.write_stdout(&format_bytes!(b"{}\n", value))?;
Ok(())
} else {
Err(CommandError::Unsuccessful)
}
Simon Sapin
rhg: add limited support for the `config` sub-command...
r47255 }