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

r47474:97ac588b default
r47687:b5e8bf10 default
Show More
root.rs
28 lines | 889 B | application/rls-services+xml | RustLexer
Antoine Cezar
rhg: simplify `FindRootError` handling...
r45922 use crate::error::CommandError;
Raphaël Gomès
rhg: use `format_bytes!` for error messages...
r46598 use format_bytes::format_bytes;
Simon Sapin
rhg: Don’t make repository path absolute too early...
r47474 use hg::errors::{IoErrorContext, IoResultExt};
Antoine Cezar
rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`...
r45592 use hg::utils::files::get_bytes_from_path;
pub const HELP_TEXT: &str = "
Print the root directory of the current repository.
Returns 0 on success.
";
Simon Sapin
rhg: Move subcommand CLI arguments definitions to respective modules...
r47251 pub fn args() -> clap::App<'static, 'static> {
clap::SubCommand::with_name("root").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> {
Simon Sapin
rhg: Move `Repo` object creation into `main()`...
r47335 let repo = invocation.repo?;
Simon Sapin
rhg: Don’t make repository path absolute too early...
r47474 let working_directory = repo.working_directory_path();
let working_directory = std::fs::canonicalize(working_directory)
.with_context(|| {
IoErrorContext::CanonicalizingPath(working_directory.to_owned())
})?;
let bytes = get_bytes_from_path(&working_directory);
Simon Sapin
rhg: Group values passed to every sub-command into a struct...
r47334 invocation
.ui
.write_stdout(&format_bytes!(b"{}\n", bytes.as_slice()))?;
Simon Sapin
rhg: replace command structs with functions...
r47250 Ok(())
Antoine Cezar
rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`...
r45592 }