##// END OF EJS Templates
tags-fnode-cache: skip building a changectx in getfnode...
tags-fnode-cache: skip building a changectx in getfnode Building a changectx object is costly, doing it just to retrieve the revision number is suboptimal. Directly fetching the revision number from the changelog provide a sizeable speedup to `hg debugupdatecache`. ### data-env-vars.name = mercurial-2018-08-01-zstd-sparse-revlog # benchmark.name = debug-update-cache # benchmark.variants.pre-state = warm before: 0.213229 seconds after: 0.165577 seconds (-22.35%) # data-env-vars.name = mercurial-filtered-2019-11-22-zstd-sparse-revlog before: 1.200383 seconds after: 1.071618 seconds (-10.73%) # data-env-vars.name = mozilla-central-2018-08-01-zstd-sparse-revlog before: 1.465735 seconds after: 0.923128 seconds (-37.02%) # data-env-vars.name = mozilla-try-2019-02-18-zstd-sparse-revlog before: 6.511771 seconds after: 4.507316 seconds (-30.78%) # data-env-vars.name = netbeans-2018-08-01-zstd-sparse-revlog before: 1.023007 seconds after: 0.645026 seconds (-36.95%) # data-env-vars.name = pypy-2018-08-01-zstd-sparse-revlog before: 0.381141 seconds after: 0.268654 seconds (-29.51%)

File last commit:

r49284:9b0e1f64 default
r50475:08fe5c4d stable
Show More
path_utils.rs
55 lines | 1.7 KiB | application/rls-services+xml | RustLexer
Pulkit Goyal
rhg: refactor function to relativize paths in utils...
r48988 // path utils module
//
// This software may be used and distributed according to the terms of the
// GNU General Public License version 2 or any later version.
Simon Sapin
rhg: Propogate manifest parse errors instead of panicking...
r49165 use hg::errors::HgError;
Pulkit Goyal
rhg: refactor function to relativize paths in utils...
r48988 use hg::repo::Repo;
use hg::utils::current_dir;
use hg::utils::files::{get_bytes_from_path, relativize_path};
use hg::utils::hg_path::HgPath;
use hg::utils::hg_path::HgPathBuf;
use std::borrow::Cow;
Simon Sapin
rhg: refactor relativize_path into a struct + method...
r49284 pub struct RelativizePaths {
repo_root: HgPathBuf,
cwd: HgPathBuf,
outside_repo: bool,
}
impl RelativizePaths {
pub fn new(repo: &Repo) -> Result<Self, HgError> {
let cwd = current_dir()?;
let repo_root = repo.working_directory_path();
let repo_root = cwd.join(repo_root); // Make it absolute
let repo_root_hgpath =
HgPathBuf::from(get_bytes_from_path(repo_root.to_owned()));
Pulkit Goyal
rhg: refactor function to relativize paths in utils...
r48988
Simon Sapin
rhg: refactor relativize_path into a struct + method...
r49284 if let Ok(cwd_relative_to_repo) = cwd.strip_prefix(&repo_root) {
// The current directory is inside the repo, so we can work with
// relative paths
Ok(Self {
repo_root: repo_root_hgpath,
cwd: HgPathBuf::from(get_bytes_from_path(
cwd_relative_to_repo,
)),
outside_repo: false,
})
} else {
Ok(Self {
repo_root: repo_root_hgpath,
cwd: HgPathBuf::from(get_bytes_from_path(cwd)),
outside_repo: true,
})
}
Pulkit Goyal
rhg: refactor function to relativize paths in utils...
r48988 }
Simon Sapin
rhg: refactor relativize_path into a struct + method...
r49284 pub fn relativize<'a>(&self, path: &'a HgPath) -> Cow<'a, [u8]> {
if self.outside_repo {
let joined = self.repo_root.join(path);
Cow::Owned(relativize_path(&joined, &self.cwd).into_owned())
Pulkit Goyal
rhg: refactor function to relativize paths in utils...
r48988 } else {
Simon Sapin
rhg: refactor relativize_path into a struct + method...
r49284 relativize_path(path, &self.cwd)
Pulkit Goyal
rhg: refactor function to relativize paths in utils...
r48988 }
}
}