1 use crate::error::CommandError; |
1 use crate::error::CommandError; |
2 use crate::ui::{print_narrow_sparse_warnings, Ui, RelativePaths, relative_paths}; |
2 use crate::ui::{ |
|
3 print_narrow_sparse_warnings, relative_paths, RelativePaths, Ui, |
|
4 }; |
3 use crate::utils::path_utils::RelativizePaths; |
5 use crate::utils::path_utils::RelativizePaths; |
4 use clap::Arg; |
6 use clap::Arg; |
5 use hg::narrow; |
7 use hg::narrow; |
6 use hg::operations::list_rev_tracked_files; |
8 use hg::operations::list_rev_tracked_files; |
7 use hg::repo::Repo; |
9 use hg::repo::Repo; |
26 ) |
28 ) |
27 .about(HELP_TEXT) |
29 .about(HELP_TEXT) |
28 } |
30 } |
29 |
31 |
30 pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> { |
32 pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> { |
31 match relative_paths(invocation.config)? { |
33 let relative_paths = match relative_paths(invocation.config)? { |
32 RelativePaths::Legacy | RelativePaths::Bool(true) => (), |
34 RelativePaths::Legacy => true, |
33 RelativePaths::Bool(false) => { |
35 RelativePaths::Bool(v) => v, |
34 return Err(CommandError::unsupported( |
36 }; |
35 "non-default ui.relative-paths", |
|
36 )); |
|
37 } |
|
38 } |
|
39 |
37 |
40 let rev = invocation.subcommand_args.get_one::<String>("rev"); |
38 let rev = invocation.subcommand_args.get_one::<String>("rev"); |
41 |
39 |
42 let repo = invocation.repo?; |
40 let repo = invocation.repo?; |
43 |
41 |
57 print_narrow_sparse_warnings(&narrow_warnings, &[], invocation.ui, repo)?; |
55 print_narrow_sparse_warnings(&narrow_warnings, &[], invocation.ui, repo)?; |
58 |
56 |
59 if let Some(rev) = rev { |
57 if let Some(rev) = rev { |
60 let files = list_rev_tracked_files(repo, rev, narrow_matcher) |
58 let files = list_rev_tracked_files(repo, rev, narrow_matcher) |
61 .map_err(|e| (e, rev.as_ref()))?; |
59 .map_err(|e| (e, rev.as_ref()))?; |
62 display_files(invocation.ui, repo, files.iter()) |
60 display_files(invocation.ui, repo, relative_paths, files.iter()) |
63 } else { |
61 } else { |
64 // The dirstate always reflects the sparse narrowspec. |
62 // The dirstate always reflects the sparse narrowspec. |
65 let dirstate = repo.dirstate_map()?; |
63 let dirstate = repo.dirstate_map()?; |
66 let files_res: Result<Vec<_>, _> = |
64 let files_res: Result<Vec<_>, _> = |
67 filter_map_results(dirstate.iter(), |(path, entry)| { |
65 filter_map_results(dirstate.iter(), |(path, entry)| { |
77 files.par_sort_unstable(); |
75 files.par_sort_unstable(); |
78 |
76 |
79 display_files( |
77 display_files( |
80 invocation.ui, |
78 invocation.ui, |
81 repo, |
79 repo, |
|
80 relative_paths, |
82 files.into_iter().map::<Result<_, CommandError>, _>(Ok), |
81 files.into_iter().map::<Result<_, CommandError>, _>(Ok), |
83 ) |
82 ) |
84 } |
83 } |
85 } |
84 } |
86 |
85 |
87 fn display_files<'a, E>( |
86 fn display_files<'a, E>( |
88 ui: &Ui, |
87 ui: &Ui, |
89 repo: &Repo, |
88 repo: &Repo, |
|
89 relative_paths: bool, |
90 files: impl IntoIterator<Item = Result<&'a HgPath, E>>, |
90 files: impl IntoIterator<Item = Result<&'a HgPath, E>>, |
91 ) -> Result<(), CommandError> |
91 ) -> Result<(), CommandError> |
92 where |
92 where |
93 CommandError: From<E>, |
93 CommandError: From<E>, |
94 { |
94 { |