Mercurial > public > mercurial-scm > hg
view rust/rhg/src/commands/config.rs @ 48471:b005d07ded7d
rhg: Skip reading the contents of ambiguous files in some cases
If the size of the file in the working directory does not match the length of
the filelog data, we know its contents will be different and don?t need to
read it.
rhg still decodes the filelog revision, which is not needed in some cases.
Differential Revision: https://phab.mercurial-scm.org/D11910
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Tue, 14 Dec 2021 20:36:36 +0100 |
parents | b1e6265e8336 |
children | 37bc3edef76f |
line wrap: on
line source
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) } pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> { let (section, name) = invocation .subcommand_args .value_of("name") .expect("missing required CLI argument") .as_bytes() .split_2(b'.') .ok_or_else(|| HgError::unsupported("hg config <section>"))?; if let Some(value) = invocation.config.get(section, name) { invocation.ui.write_stdout(&format_bytes!(b"{}\n", value))?; Ok(()) } else { Err(CommandError::Unsuccessful) } }