Mercurial > public > mercurial-scm > hg
diff rust/rhg/src/commands/cat.rs @ 46445:ca3f73cc3cf4
rhg: Simplify CommandError based on its use
Differential Revision: https://phab.mercurial-scm.org/D9905
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Thu, 28 Jan 2021 19:13:55 +0100 |
parents | 252d1bdba33d |
children | 1dcd9c9975ed |
line wrap: on
line diff
--- a/rust/rhg/src/commands/cat.rs Thu Jan 28 19:21:57 2021 +0100 +++ b/rust/rhg/src/commands/cat.rs Thu Jan 28 19:13:55 2021 +0100 @@ -32,17 +32,18 @@ fn run(&self, ui: &Ui) -> Result<(), CommandError> { let repo = Repo::find()?; repo.check_requirements()?; - let cwd = std::env::current_dir() - .or_else(|e| Err(CommandError::CurrentDirNotFound(e)))?; + let cwd = hg::utils::current_dir()?; let mut files = vec![]; for file in self.files.iter() { + // TODO: actually normalize `..` path segments etc? let normalized = cwd.join(&file); let stripped = normalized .strip_prefix(&repo.working_directory_path()) - .or(Err(CommandError::Abort(None)))?; + // TODO: error message for path arguments outside of the repo + .map_err(|_| CommandError::abort(""))?; let hg_file = HgPathBuf::try_from(stripped.to_path_buf()) - .or(Err(CommandError::Abort(None)))?; + .map_err(|e| CommandError::abort(e.to_string()))?; files.push(hg_file); }