##// END OF EJS Templates
rhg: Fall back to Python if ui.relative-paths is configured...
Simon Sapin -
r47473:c184b490 default
parent child Browse files
Show More
@@ -1,61 +1,68 b''
1 use crate::error::CommandError;
1 use crate::error::CommandError;
2 use crate::ui::Ui;
2 use crate::ui::Ui;
3 use clap::Arg;
3 use clap::Arg;
4 use hg::operations::list_rev_tracked_files;
4 use hg::operations::list_rev_tracked_files;
5 use hg::operations::Dirstate;
5 use hg::operations::Dirstate;
6 use hg::repo::Repo;
6 use hg::repo::Repo;
7 use hg::utils::files::{get_bytes_from_path, relativize_path};
7 use hg::utils::files::{get_bytes_from_path, relativize_path};
8 use hg::utils::hg_path::{HgPath, HgPathBuf};
8 use hg::utils::hg_path::{HgPath, HgPathBuf};
9
9
10 pub const HELP_TEXT: &str = "
10 pub const HELP_TEXT: &str = "
11 List tracked files.
11 List tracked files.
12
12
13 Returns 0 on success.
13 Returns 0 on success.
14 ";
14 ";
15
15
16 pub fn args() -> clap::App<'static, 'static> {
16 pub fn args() -> clap::App<'static, 'static> {
17 clap::SubCommand::with_name("files")
17 clap::SubCommand::with_name("files")
18 .arg(
18 .arg(
19 Arg::with_name("rev")
19 Arg::with_name("rev")
20 .help("search the repository as it is in REV")
20 .help("search the repository as it is in REV")
21 .short("-r")
21 .short("-r")
22 .long("--revision")
22 .long("--revision")
23 .value_name("REV")
23 .value_name("REV")
24 .takes_value(true),
24 .takes_value(true),
25 )
25 )
26 .about(HELP_TEXT)
26 .about(HELP_TEXT)
27 }
27 }
28
28
29 pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> {
29 pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> {
30 let relative = invocation.config.get(b"ui", b"relative-paths");
31 if relative.is_some() {
32 return Err(CommandError::unsupported(
33 "non-default ui.relative-paths",
34 ));
35 }
36
30 let rev = invocation.subcommand_args.value_of("rev");
37 let rev = invocation.subcommand_args.value_of("rev");
31
38
32 let repo = invocation.repo?;
39 let repo = invocation.repo?;
33 if let Some(rev) = rev {
40 if let Some(rev) = rev {
34 let files = list_rev_tracked_files(repo, rev).map_err(|e| (e, rev))?;
41 let files = list_rev_tracked_files(repo, rev).map_err(|e| (e, rev))?;
35 display_files(invocation.ui, repo, files.iter())
42 display_files(invocation.ui, repo, files.iter())
36 } else {
43 } else {
37 let distate = Dirstate::new(repo)?;
44 let distate = Dirstate::new(repo)?;
38 let files = distate.tracked_files()?;
45 let files = distate.tracked_files()?;
39 display_files(invocation.ui, repo, files)
46 display_files(invocation.ui, repo, files)
40 }
47 }
41 }
48 }
42
49
43 fn display_files<'a>(
50 fn display_files<'a>(
44 ui: &Ui,
51 ui: &Ui,
45 repo: &Repo,
52 repo: &Repo,
46 files: impl IntoIterator<Item = &'a HgPath>,
53 files: impl IntoIterator<Item = &'a HgPath>,
47 ) -> Result<(), CommandError> {
54 ) -> Result<(), CommandError> {
48 let cwd = HgPathBuf::from(get_bytes_from_path(hg::utils::current_dir()?));
55 let cwd = HgPathBuf::from(get_bytes_from_path(hg::utils::current_dir()?));
49 let working_directory =
56 let working_directory =
50 HgPathBuf::from(get_bytes_from_path(repo.working_directory_path()));
57 HgPathBuf::from(get_bytes_from_path(repo.working_directory_path()));
51
58
52 let mut stdout = ui.stdout_buffer();
59 let mut stdout = ui.stdout_buffer();
53
60
54 for file in files {
61 for file in files {
55 let file = working_directory.join(file);
62 let file = working_directory.join(file);
56 stdout.write_all(relativize_path(&file, &cwd).as_ref())?;
63 stdout.write_all(relativize_path(&file, &cwd).as_ref())?;
57 stdout.write_all(b"\n")?;
64 stdout.write_all(b"\n")?;
58 }
65 }
59 stdout.flush()?;
66 stdout.flush()?;
60 Ok(())
67 Ok(())
61 }
68 }
General Comments 0
You need to be logged in to leave comments. Login now