##// END OF EJS Templates
rhg: Don’t make repository path absolute too early...
Simon Sapin -
r47474:97ac588b default
parent child Browse files
Show More
@@ -50,6 +50,8 b' pub enum IoErrorContext {'
50 50 from: std::path::PathBuf,
51 51 to: std::path::PathBuf,
52 52 },
53 /// `std::fs::canonicalize`
54 CanonicalizingPath(std::path::PathBuf),
53 55 /// `std::env::current_dir`
54 56 CurrentDir,
55 57 /// `std::env::current_exe`
@@ -128,6 +130,9 b' impl fmt::Display for IoErrorContext {'
128 130 from.display(),
129 131 to.display()
130 132 ),
133 IoErrorContext::CanonicalizingPath(path) => {
134 write!(f, "when canonicalizing {}", path.display())
135 }
131 136 IoErrorContext::CurrentDir => {
132 137 write!(f, "error getting current working directory")
133 138 }
@@ -2,7 +2,7 b' use crate::config::{Config, ConfigError,'
2 2 use crate::errors::{HgError, IoErrorContext, IoResultExt};
3 3 use crate::requirements;
4 4 use crate::utils::files::get_path_from_bytes;
5 use crate::utils::{current_dir, SliceExt};
5 use crate::utils::SliceExt;
6 6 use memmap::{Mmap, MmapOptions};
7 7 use std::collections::HashSet;
8 8 use std::path::{Path, PathBuf};
@@ -56,12 +56,9 b' impl Repo {'
56 56 explicit_path: Option<&Path>,
57 57 ) -> Result<Self, RepoError> {
58 58 if let Some(root) = explicit_path {
59 // Having an absolute path isn’t necessary here but can help code
60 // elsewhere
61 let absolute_root = current_dir()?.join(root);
62 if absolute_root.join(".hg").is_dir() {
63 Self::new_at_path(absolute_root, config)
64 } else if absolute_root.is_file() {
59 if root.join(".hg").is_dir() {
60 Self::new_at_path(root.to_owned(), config)
61 } else if root.is_file() {
65 62 Err(HgError::unsupported("bundle repository").into())
66 63 } else {
67 64 Err(RepoError::NotFound {
@@ -40,13 +40,15 b' pub fn run(invocation: &crate::CliInvoca'
40 40
41 41 let repo = invocation.repo?;
42 42 let cwd = hg::utils::current_dir()?;
43 let working_directory = repo.working_directory_path();
44 let working_directory = cwd.join(working_directory); // Make it absolute
43 45
44 46 let mut files = vec![];
45 47 for file in file_args.iter() {
46 48 // TODO: actually normalize `..` path segments etc?
47 49 let normalized = cwd.join(&file);
48 50 let stripped = normalized
49 .strip_prefix(&repo.working_directory_path())
51 .strip_prefix(&working_directory)
50 52 // TODO: error message for path arguments outside of the repo
51 53 .map_err(|_| CommandError::abort(""))?;
52 54 let hg_file = HgPathBuf::try_from(stripped.to_path_buf())
@@ -4,6 +4,7 b' use clap::Arg;'
4 4 use hg::operations::list_rev_tracked_files;
5 5 use hg::operations::Dirstate;
6 6 use hg::repo::Repo;
7 use hg::utils::current_dir;
7 8 use hg::utils::files::{get_bytes_from_path, relativize_path};
8 9 use hg::utils::hg_path::{HgPath, HgPathBuf};
9 10
@@ -53,8 +54,10 b" fn display_files<'a>("
53 54 files: impl IntoIterator<Item = &'a HgPath>,
54 55 ) -> Result<(), CommandError> {
55 56 let cwd = HgPathBuf::from(get_bytes_from_path(hg::utils::current_dir()?));
57 let working_directory = repo.working_directory_path();
58 let working_directory = current_dir()?.join(working_directory); // Make it absolute
56 59 let working_directory =
57 HgPathBuf::from(get_bytes_from_path(repo.working_directory_path()));
60 HgPathBuf::from(get_bytes_from_path(working_directory));
58 61
59 62 let mut stdout = ui.stdout_buffer();
60 63
@@ -1,5 +1,6 b''
1 1 use crate::error::CommandError;
2 2 use format_bytes::format_bytes;
3 use hg::errors::{IoErrorContext, IoResultExt};
3 4 use hg::utils::files::get_bytes_from_path;
4 5
5 6 pub const HELP_TEXT: &str = "
@@ -14,7 +15,12 b" pub fn args() -> clap::App<'static, 'sta"
14 15
15 16 pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> {
16 17 let repo = invocation.repo?;
17 let bytes = get_bytes_from_path(repo.working_directory_path());
18 let working_directory = repo.working_directory_path();
19 let working_directory = std::fs::canonicalize(working_directory)
20 .with_context(|| {
21 IoErrorContext::CanonicalizingPath(working_directory.to_owned())
22 })?;
23 let bytes = get_bytes_from_path(&working_directory);
18 24 invocation
19 25 .ui
20 26 .write_stdout(&format_bytes!(b"{}\n", bytes.as_slice()))?;
General Comments 0
You need to be logged in to leave comments. Login now