Mercurial > public > mercurial-scm > hg-stable
diff rust/rhg/src/commands/files.rs @ 46555:d8730ff51d5a
rhg: Add support for -R and --repository command-line arguments
Differential Revision: https://phab.mercurial-scm.org/D9970
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Mon, 08 Feb 2021 21:37:30 +0100 |
parents | 1ecaf09d9964 |
children | 80840b651721 |
line wrap: on
line diff
--- a/rust/rhg/src/commands/files.rs Mon Feb 08 21:28:52 2021 +0100 +++ b/rust/rhg/src/commands/files.rs Mon Feb 08 21:37:30 2021 +0100 @@ -8,6 +8,7 @@ use hg::repo::Repo; use hg::utils::files::{get_bytes_from_path, relativize_path}; use hg::utils::hg_path::{HgPath, HgPathBuf}; +use std::path::Path; pub const HELP_TEXT: &str = " List tracked files. @@ -31,11 +32,12 @@ pub fn run( ui: &Ui, config: &Config, + repo_path: Option<&Path>, args: &ArgMatches, ) -> Result<(), CommandError> { let rev = args.value_of("rev"); - let repo = Repo::find(config)?; + let repo = Repo::find(config, repo_path)?; if let Some(rev) = rev { let files = list_rev_tracked_files(&repo, rev).map_err(|e| (e, rev))?; @@ -52,16 +54,15 @@ repo: &Repo, files: impl IntoIterator<Item = &'a HgPath>, ) -> Result<(), CommandError> { - let cwd = hg::utils::current_dir()?; - let rooted_cwd = cwd - .strip_prefix(repo.working_directory_path()) - .expect("cwd was already checked within the repository"); - let rooted_cwd = HgPathBuf::from(get_bytes_from_path(rooted_cwd)); + let cwd = HgPathBuf::from(get_bytes_from_path(hg::utils::current_dir()?)); + let working_directory = + HgPathBuf::from(get_bytes_from_path(repo.working_directory_path())); let mut stdout = ui.stdout_buffer(); for file in files { - stdout.write_all(relativize_path(file, &rooted_cwd).as_ref())?; + let file = working_directory.join(file); + stdout.write_all(relativize_path(&file, &cwd).as_ref())?; stdout.write_all(b"\n")?; } stdout.flush()?;