##// END OF EJS Templates
rhg-files: add support for narrow when specifying a revision...
Raphaël Gomès -
r50880:e57f76c2 default
parent child Browse files
Show More
@@ -6,24 +6,40 b''
6 // GNU General Public License version 2 or any later version.
6 // GNU General Public License version 2 or any later version.
7
7
8 use crate::errors::HgError;
8 use crate::errors::HgError;
9 use crate::matchers::Matcher;
9 use crate::repo::Repo;
10 use crate::repo::Repo;
10 use crate::revlog::manifest::Manifest;
11 use crate::revlog::manifest::Manifest;
11 use crate::revlog::RevlogError;
12 use crate::revlog::RevlogError;
13 use crate::utils::filter_map_results;
12 use crate::utils::hg_path::HgPath;
14 use crate::utils::hg_path::HgPath;
13
15
14 /// List files under Mercurial control at a given revision.
16 /// List files under Mercurial control at a given revision.
15 pub fn list_rev_tracked_files(
17 pub fn list_rev_tracked_files(
16 repo: &Repo,
18 repo: &Repo,
17 revset: &str,
19 revset: &str,
20 narrow_matcher: Box<dyn Matcher>,
18 ) -> Result<FilesForRev, RevlogError> {
21 ) -> Result<FilesForRev, RevlogError> {
19 let rev = crate::revset::resolve_single(revset, repo)?;
22 let rev = crate::revset::resolve_single(revset, repo)?;
20 Ok(FilesForRev(repo.manifest_for_rev(rev)?))
23 Ok(FilesForRev {
24 manifest: repo.manifest_for_rev(rev)?,
25 narrow_matcher,
26 })
21 }
27 }
22
28
23 pub struct FilesForRev(Manifest);
29 pub struct FilesForRev {
30 manifest: Manifest,
31 narrow_matcher: Box<dyn Matcher>,
32 }
24
33
25 impl FilesForRev {
34 impl FilesForRev {
26 pub fn iter(&self) -> impl Iterator<Item = Result<&HgPath, HgError>> {
35 pub fn iter(&self) -> impl Iterator<Item = Result<&HgPath, HgError>> {
27 self.0.iter().map(|entry| Ok(entry?.path))
36 filter_map_results(self.manifest.iter(), |entry| {
37 let path = entry.path;
38 Ok(if self.narrow_matcher.matches(path) {
39 Some(path)
40 } else {
41 None
42 })
43 })
28 }
44 }
29 }
45 }
@@ -51,24 +51,15 b' pub fn run(invocation: &crate::CliInvoca'
51 ));
51 ));
52 }
52 }
53
53
54 let (narrow_matcher, narrow_warnings) = narrow::matcher(repo)?;
55 print_narrow_sparse_warnings(&narrow_warnings, &[], invocation.ui, repo)?;
56
54 if let Some(rev) = rev {
57 if let Some(rev) = rev {
55 if repo.has_narrow() {
58 let files = list_rev_tracked_files(repo, rev, narrow_matcher)
56 return Err(CommandError::unsupported(
57 "rhg files -r <rev> is not supported in narrow clones",
58 ));
59 }
60 let files = list_rev_tracked_files(repo, rev)
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, files.iter())
63 } else {
61 } else {
64 // The dirstate always reflects the sparse narrowspec.
62 // The dirstate always reflects the sparse narrowspec.
65 let (narrow_matcher, narrow_warnings) = narrow::matcher(repo)?;
66 print_narrow_sparse_warnings(
67 &narrow_warnings,
68 &[],
69 invocation.ui,
70 repo,
71 )?;
72 let dirstate = repo.dirstate_map()?;
63 let dirstate = repo.dirstate_map()?;
73 let files_res: Result<Vec<_>, _> =
64 let files_res: Result<Vec<_>, _> =
74 filter_map_results(dirstate.iter(), |(path, entry)| {
65 filter_map_results(dirstate.iter(), |(path, entry)| {
@@ -75,12 +75,12 b' TODO: bad error message'
75 $ "$real_hg" cat -r "$tip" hide
75 $ "$real_hg" cat -r "$tip" hide
76 [1]
76 [1]
77
77
78 A naive implementation of [rhg files] leaks the paths that are supposed to be
78 A naive implementation of `rhg files` would leak the paths that are supposed
79 hidden by narrow, so we just fall back to hg when accessing a revision.
79 to be hidden by narrow.
80
80
81 $ $NO_FALLBACK rhg files -r "$tip"
81 $ $NO_FALLBACK rhg files -r "$tip"
82 unsupported feature: rhg files -r <rev> is not supported in narrow clones
82 dir1/x
83 [252]
83 dir1/y
84 $ "$real_hg" files -r "$tip"
84 $ "$real_hg" files -r "$tip"
85 dir1/x
85 dir1/x
86 dir1/y
86 dir1/y
General Comments 0
You need to be logged in to leave comments. Login now