comparison rust/rhg/src/commands/files.rs @ 50040:df9eabc9837b

rust-narrow: enable narrow support for plain `rhg files` Support for `rhg files -r NODE` in a future changeset.
author Rapha?l Gom?s <rgomes@octobus.net>
date Wed, 11 Jan 2023 17:08:23 +0100
parents 795b5b01cbd2
children e57f76c28f7b
comparison
equal deleted inserted replaced
50039:795b5b01cbd2 50040:df9eabc9837b
1 use crate::error::CommandError; 1 use crate::error::CommandError;
2 use crate::ui::Ui; 2 use crate::ui::{print_narrow_sparse_warnings, Ui};
3 use crate::utils::path_utils::RelativizePaths; 3 use crate::utils::path_utils::RelativizePaths;
4 use clap::Arg; 4 use clap::Arg;
5 use hg::narrow;
5 use hg::operations::list_rev_tracked_files; 6 use hg::operations::list_rev_tracked_files;
6 use hg::repo::Repo; 7 use hg::repo::Repo;
7 use hg::utils::filter_map_results; 8 use hg::utils::filter_map_results;
8 use hg::utils::hg_path::HgPath; 9 use hg::utils::hg_path::HgPath;
9 use rayon::prelude::*; 10 use rayon::prelude::*;
58 } 59 }
59 let files = list_rev_tracked_files(repo, rev) 60 let files = list_rev_tracked_files(repo, rev)
60 .map_err(|e| (e, rev.as_ref()))?; 61 .map_err(|e| (e, rev.as_ref()))?;
61 display_files(invocation.ui, repo, files.iter()) 62 display_files(invocation.ui, repo, files.iter())
62 } else { 63 } else {
63 // The dirstate always reflects the sparse narrowspec, so if 64 // The dirstate always reflects the sparse narrowspec.
64 // we only have sparse without narrow all is fine. 65 let (narrow_matcher, narrow_warnings) = narrow::matcher(repo)?;
65 // If we have narrow, then [hg files] needs to check if 66 print_narrow_sparse_warnings(
66 // the store narrowspec is in sync with the one of the dirstate, 67 &narrow_warnings,
67 // so we can't support that without explicit code. 68 &[],
68 if repo.has_narrow() { 69 invocation.ui,
69 return Err(CommandError::unsupported( 70 repo,
70 "rhg files is not supported in narrow clones", 71 )?;
71 ));
72 }
73 let dirstate = repo.dirstate_map()?; 72 let dirstate = repo.dirstate_map()?;
74 let files_res: Result<Vec<_>, _> = 73 let files_res: Result<Vec<_>, _> =
75 filter_map_results(dirstate.iter(), |(path, entry)| { 74 filter_map_results(dirstate.iter(), |(path, entry)| {
76 Ok(if entry.tracked() { Some(path) } else { None }) 75 Ok(if entry.tracked() && narrow_matcher.matches(path) {
76 Some(path)
77 } else {
78 None
79 })
77 }) 80 })
78 .collect(); 81 .collect();
79 82
80 let mut files = files_res?; 83 let mut files = files_res?;
81 files.par_sort_unstable(); 84 files.par_sort_unstable();
82 85
83 display_files(invocation.ui, repo, files.into_iter().map(Ok)) 86 display_files(
87 invocation.ui,
88 repo,
89 files.into_iter().map::<Result<_, CommandError>, _>(Ok),
90 )
84 } 91 }
85 } 92 }
86 93
87 fn display_files<'a, E>( 94 fn display_files<'a, E>(
88 ui: &Ui, 95 ui: &Ui,