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