rust-files: also return filenode and flags when listing a revision's files
This is going to be useful when implementing parts of `update` and makes it
so we don't have to fetch the manifest and each entry twice.
--- a/rust/hg-core/src/operations/list_tracked_files.rs Mon Sep 30 12:08:49 2024 +0200
+++ b/rust/hg-core/src/operations/list_tracked_files.rs Mon Sep 30 12:10:35 2024 +0200
@@ -5,6 +5,8 @@
// This software may be used and distributed according to the terms of the
// GNU General Public License version 2 or any later version.
+use std::num::NonZeroU8;
+
use crate::errors::HgError;
use crate::matchers::Matcher;
use crate::repo::Repo;
@@ -12,6 +14,7 @@
use crate::revlog::RevlogError;
use crate::utils::filter_map_results;
use crate::utils::hg_path::HgPath;
+use crate::Node;
/// List files under Mercurial control at a given revision.
pub fn list_rev_tracked_files(
@@ -31,12 +34,18 @@
narrow_matcher: Box<dyn Matcher>,
}
+/// Like [`crate::revlog::manifest::ManifestEntry`], but with the `Node`
+/// already checked.
+pub type ExpandedManifestEntry<'a> = (&'a HgPath, Node, Option<NonZeroU8>);
+
impl FilesForRev {
- pub fn iter(&self) -> impl Iterator<Item = Result<&HgPath, HgError>> {
+ pub fn iter(
+ &self,
+ ) -> impl Iterator<Item = Result<ExpandedManifestEntry, HgError>> {
filter_map_results(self.manifest.iter(), |entry| {
let path = entry.path;
Ok(if self.narrow_matcher.matches(path) {
- Some(path)
+ Some((path, entry.node_id()?, entry.flags))
} else {
None
})
--- a/rust/rhg/src/commands/files.rs Mon Sep 30 12:08:49 2024 +0200
+++ b/rust/rhg/src/commands/files.rs Mon Sep 30 12:10:35 2024 +0200
@@ -90,7 +90,15 @@
if let Some(rev) = rev {
let files = list_rev_tracked_files(repo, rev, matcher)
.map_err(|e| (e, rev.as_ref()))?;
- display_files(invocation.ui, repo, relative_paths, files.iter())
+ display_files(
+ invocation.ui,
+ repo,
+ relative_paths,
+ files.iter().map::<Result<_, CommandError>, _>(|f| {
+ let (f, _, _) = f?;
+ Ok(f)
+ }),
+ )
} else {
// The dirstate always reflects the sparse narrowspec.
let dirstate = repo.dirstate_map()?;