Mercurial > hg
changeset 49984: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 |
files | rust/rhg/src/commands/files.rs tests/test-rhg-sparse-narrow.t |
diffstat | 2 files changed, 30 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/rust/rhg/src/commands/files.rs Wed Jan 11 17:28:48 2023 +0100 +++ b/rust/rhg/src/commands/files.rs Wed Jan 11 17:08:23 2023 +0100 @@ -1,7 +1,8 @@ use crate::error::CommandError; -use crate::ui::Ui; +use crate::ui::{print_narrow_sparse_warnings, Ui}; use crate::utils::path_utils::RelativizePaths; use clap::Arg; +use hg::narrow; use hg::operations::list_rev_tracked_files; use hg::repo::Repo; use hg::utils::filter_map_results; @@ -60,27 +61,33 @@ .map_err(|e| (e, rev.as_ref()))?; display_files(invocation.ui, repo, files.iter()) } else { - // The dirstate always reflects the sparse narrowspec, so if - // we only have sparse without narrow all is fine. - // If we have narrow, then [hg files] needs to check if - // the store narrowspec is in sync with the one of the dirstate, - // so we can't support that without explicit code. - if repo.has_narrow() { - return Err(CommandError::unsupported( - "rhg files is not supported in narrow clones", - )); - } + // The dirstate always reflects the sparse narrowspec. + let (narrow_matcher, narrow_warnings) = narrow::matcher(repo)?; + print_narrow_sparse_warnings( + &narrow_warnings, + &[], + invocation.ui, + repo, + )?; let dirstate = repo.dirstate_map()?; let files_res: Result<Vec<_>, _> = filter_map_results(dirstate.iter(), |(path, entry)| { - Ok(if entry.tracked() { Some(path) } else { None }) + Ok(if entry.tracked() && narrow_matcher.matches(path) { + Some(path) + } else { + None + }) }) .collect(); let mut files = files_res?; files.par_sort_unstable(); - display_files(invocation.ui, repo, files.into_iter().map(Ok)) + display_files( + invocation.ui, + repo, + files.into_iter().map::<Result<_, CommandError>, _>(Ok), + ) } }
--- a/tests/test-rhg-sparse-narrow.t Wed Jan 11 17:28:48 2023 +0100 +++ b/tests/test-rhg-sparse-narrow.t Wed Jan 11 17:08:23 2023 +0100 @@ -76,7 +76,7 @@ [1] A naive implementation of [rhg files] leaks the paths that are supposed to be -hidden by narrow, so we just fall back to hg. +hidden by narrow, so we just fall back to hg when accessing a revision. $ $NO_FALLBACK rhg files -r "$tip" unsupported feature: rhg files -r <rev> is not supported in narrow clones @@ -85,6 +85,15 @@ dir1/x dir1/y +The working copy version works with narrow correctly + + $ $NO_FALLBACK rhg files + dir1/x + dir1/y + $ "$real_hg" files + dir1/x + dir1/y + Hg status needs to do some filtering based on narrow spec $ mkdir dir2