Mercurial > public > mercurial-scm > hg-stable
comparison rust/rhg/src/commands/files.rs @ 45447:1b3197047f5c
rhg: make output of `files` relative to the current directory and the root
This matches the behavior of `hg files`.
The util is added in `hg-core` instead of `rhg` because this operation could
be useful for other external tools. (this was definitely not prompted by rust
issue #50784, I swear)
Differential Revision: https://phab.mercurial-scm.org/D8872
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Thu, 30 Jul 2020 16:55:44 +0200 |
parents | 5fe25f8ef5d9 |
children | ed95ccc94333 |
comparison
equal
deleted
inserted
replaced
45446:64de86fd0984 | 45447:1b3197047f5c |
---|---|
1 use crate::commands::Command; | 1 use crate::commands::Command; |
2 use crate::error::{CommandError, CommandErrorKind}; | 2 use crate::error::{CommandError, CommandErrorKind}; |
3 use crate::ui::Ui; | 3 use crate::ui::Ui; |
4 use hg::operations::{ListTrackedFiles, ListTrackedFilesErrorKind}; | 4 use hg::operations::{ListTrackedFiles, ListTrackedFilesErrorKind}; |
5 use hg::utils::files::{get_bytes_from_path, relativize_path}; | |
6 use hg::utils::hg_path::HgPathBuf; | |
5 | 7 |
6 pub const HELP_TEXT: &str = " | 8 pub const HELP_TEXT: &str = " |
7 List tracked files. | 9 List tracked files. |
8 | 10 |
9 Returns 0 on success. | 11 Returns 0 on success. |
36 b"abort: parse error\n".to_vec(), | 38 b"abort: parse error\n".to_vec(), |
37 )) | 39 )) |
38 } | 40 } |
39 })?; | 41 })?; |
40 | 42 |
43 let cwd = std::env::current_dir() | |
44 .or_else(|e| Err(CommandErrorKind::CurrentDirNotFound(e)))?; | |
45 let rooted_cwd = cwd | |
46 .strip_prefix(operation_builder.get_root()) | |
47 .expect("cwd was already checked within the repository"); | |
48 let rooted_cwd = HgPathBuf::from(get_bytes_from_path(rooted_cwd)); | |
49 | |
41 let mut stdout = self.ui.stdout_buffer(); | 50 let mut stdout = self.ui.stdout_buffer(); |
51 | |
42 for file in files { | 52 for file in files { |
43 stdout.write_all(file.as_bytes())?; | 53 stdout.write_all(relativize_path(file, &rooted_cwd).as_ref())?; |
44 stdout.write_all(b"\n")?; | 54 stdout.write_all(b"\n")?; |
45 } | 55 } |
46 stdout.flush()?; | 56 stdout.flush()?; |
47 | 57 |
48 Ok(()) | 58 Ok(()) |