##// END OF EJS Templates
rhg: support rhg files [FILE]...
Spencer Baugh -
r51760:788113f0 default
parent child Browse files
Show More
@@ -4,9 +4,12 b' use crate::ui::{'
4 };
4 };
5 use crate::utils::path_utils::RelativizePaths;
5 use crate::utils::path_utils::RelativizePaths;
6 use clap::Arg;
6 use clap::Arg;
7 use hg::filepatterns::parse_pattern_args;
8 use hg::matchers::IntersectionMatcher;
7 use hg::narrow;
9 use hg::narrow;
8 use hg::operations::list_rev_tracked_files;
10 use hg::operations::list_rev_tracked_files;
9 use hg::repo::Repo;
11 use hg::repo::Repo;
12 use hg::utils::files::get_bytes_from_os_str;
10 use hg::utils::filter_map_results;
13 use hg::utils::filter_map_results;
11 use hg::utils::hg_path::HgPath;
14 use hg::utils::hg_path::HgPath;
12 use rayon::prelude::*;
15 use rayon::prelude::*;
@@ -26,6 +29,12 b' pub fn args() -> clap::Command {'
26 .long("revision")
29 .long("revision")
27 .value_name("REV"),
30 .value_name("REV"),
28 )
31 )
32 .arg(
33 Arg::new("file")
34 .value_parser(clap::value_parser!(std::ffi::OsString))
35 .help("show only these files")
36 .action(clap::ArgAction::Append),
37 )
29 .about(HELP_TEXT)
38 .about(HELP_TEXT)
30 }
39 }
31
40
@@ -35,7 +44,8 b' pub fn run(invocation: &crate::CliInvoca'
35 RelativePaths::Bool(v) => v,
44 RelativePaths::Bool(v) => v,
36 };
45 };
37
46
38 let rev = invocation.subcommand_args.get_one::<String>("rev");
47 let args = invocation.subcommand_args;
48 let rev = args.get_one::<String>("rev");
39
49
40 let repo = invocation.repo?;
50 let repo = invocation.repo?;
41
51
@@ -51,11 +61,34 b' pub fn run(invocation: &crate::CliInvoca'
51 ));
61 ));
52 }
62 }
53
63
54 let (narrow_matcher, narrow_warnings) = narrow::matcher(repo)?;
64 let (matcher, narrow_warnings) = narrow::matcher(repo)?;
55 print_narrow_sparse_warnings(&narrow_warnings, &[], invocation.ui, repo)?;
65 print_narrow_sparse_warnings(&narrow_warnings, &[], invocation.ui, repo)?;
66 let matcher = match args.get_many::<std::ffi::OsString>("file") {
67 None => matcher,
68 Some(files) => {
69 let patterns: Vec<Vec<u8>> = files
70 .filter(|s| !s.is_empty())
71 .map(get_bytes_from_os_str)
72 .collect();
73 for file in &patterns {
74 if file.starts_with(b"set:") {
75 return Err(CommandError::unsupported("fileset"));
76 }
77 }
78 let cwd = hg::utils::current_dir()?;
79 let root = repo.working_directory_path();
80 let ignore_patterns = parse_pattern_args(patterns, &cwd, root)?;
81 let files_matcher =
82 hg::matchers::PatternMatcher::new(ignore_patterns)?;
83 Box::new(IntersectionMatcher::new(
84 Box::new(files_matcher),
85 matcher,
86 ))
87 }
88 };
56
89
57 if let Some(rev) = rev {
90 if let Some(rev) = rev {
58 let files = list_rev_tracked_files(repo, rev, narrow_matcher)
91 let files = list_rev_tracked_files(repo, rev, matcher)
59 .map_err(|e| (e, rev.as_ref()))?;
92 .map_err(|e| (e, rev.as_ref()))?;
60 display_files(invocation.ui, repo, relative_paths, files.iter())
93 display_files(invocation.ui, repo, relative_paths, files.iter())
61 } else {
94 } else {
@@ -63,7 +96,7 b' pub fn run(invocation: &crate::CliInvoca'
63 let dirstate = repo.dirstate_map()?;
96 let dirstate = repo.dirstate_map()?;
64 let files_res: Result<Vec<_>, _> =
97 let files_res: Result<Vec<_>, _> =
65 filter_map_results(dirstate.iter(), |(path, entry)| {
98 filter_map_results(dirstate.iter(), |(path, entry)| {
66 Ok(if entry.tracked() && narrow_matcher.matches(path) {
99 Ok(if entry.tracked() && matcher.matches(path) {
67 Some(path)
100 Some(path)
68 } else {
101 } else {
69 None
102 None
General Comments 0
You need to be logged in to leave comments. Login now