Mercurial > public > mercurial-scm > hg
diff rust/rhg/src/commands/files.rs @ 45436: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 |
line wrap: on
line diff
--- a/rust/rhg/src/commands/files.rs Tue Sep 08 19:36:40 2020 +0530 +++ b/rust/rhg/src/commands/files.rs Thu Jul 30 16:55:44 2020 +0200 @@ -2,6 +2,8 @@ use crate::error::{CommandError, CommandErrorKind}; use crate::ui::Ui; use hg::operations::{ListTrackedFiles, ListTrackedFilesErrorKind}; +use hg::utils::files::{get_bytes_from_path, relativize_path}; +use hg::utils::hg_path::HgPathBuf; pub const HELP_TEXT: &str = " List tracked files. @@ -38,9 +40,17 @@ } })?; + let cwd = std::env::current_dir() + .or_else(|e| Err(CommandErrorKind::CurrentDirNotFound(e)))?; + let rooted_cwd = cwd + .strip_prefix(operation_builder.get_root()) + .expect("cwd was already checked within the repository"); + let rooted_cwd = HgPathBuf::from(get_bytes_from_path(rooted_cwd)); + let mut stdout = self.ui.stdout_buffer(); + for file in files { - stdout.write_all(file.as_bytes())?; + stdout.write_all(relativize_path(file, &rooted_cwd).as_ref())?; stdout.write_all(b"\n")?; } stdout.flush()?;