rust/rhg/src/commands/cat.rs
changeset 46445 ca3f73cc3cf4
parent 46436 252d1bdba33d
child 46446 1dcd9c9975ed
equal deleted inserted replaced
46444:6c778d20c8c2 46445:ca3f73cc3cf4
    30 impl<'a> Command for CatCommand<'a> {
    30 impl<'a> Command for CatCommand<'a> {
    31     #[timed]
    31     #[timed]
    32     fn run(&self, ui: &Ui) -> Result<(), CommandError> {
    32     fn run(&self, ui: &Ui) -> Result<(), CommandError> {
    33         let repo = Repo::find()?;
    33         let repo = Repo::find()?;
    34         repo.check_requirements()?;
    34         repo.check_requirements()?;
    35         let cwd = std::env::current_dir()
    35         let cwd = hg::utils::current_dir()?;
    36             .or_else(|e| Err(CommandError::CurrentDirNotFound(e)))?;
       
    37 
    36 
    38         let mut files = vec![];
    37         let mut files = vec![];
    39         for file in self.files.iter() {
    38         for file in self.files.iter() {
       
    39             // TODO: actually normalize `..` path segments etc?
    40             let normalized = cwd.join(&file);
    40             let normalized = cwd.join(&file);
    41             let stripped = normalized
    41             let stripped = normalized
    42                 .strip_prefix(&repo.working_directory_path())
    42                 .strip_prefix(&repo.working_directory_path())
    43                 .or(Err(CommandError::Abort(None)))?;
    43                 // TODO: error message for path arguments outside of the repo
       
    44                 .map_err(|_| CommandError::abort(""))?;
    44             let hg_file = HgPathBuf::try_from(stripped.to_path_buf())
    45             let hg_file = HgPathBuf::try_from(stripped.to_path_buf())
    45                 .or(Err(CommandError::Abort(None)))?;
    46                 .map_err(|e| CommandError::abort(e.to_string()))?;
    46             files.push(hg_file);
    47             files.push(hg_file);
    47         }
    48         }
    48 
    49 
    49         match self.rev {
    50         match self.rev {
    50             Some(rev) => {
    51             Some(rev) => {