D11407: rust: Add Repo::manifest(revision)
SimonSapin
phabricator at mercurial-scm.org
Mon Sep 13 18:14:55 UTC 2021
SimonSapin created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.
REVISION SUMMARY
This deduplicates some common code.
REPOSITORY
rHG Mercurial
BRANCH
default
REVISION DETAIL
https://phab.mercurial-scm.org/D11407
AFFECTED FILES
rust/hg-core/src/operations/cat.rs
rust/hg-core/src/operations/list_tracked_files.rs
rust/hg-core/src/repo.rs
CHANGE DETAILS
diff --git a/rust/hg-core/src/repo.rs b/rust/hg-core/src/repo.rs
--- a/rust/hg-core/src/repo.rs
+++ b/rust/hg-core/src/repo.rs
@@ -5,14 +5,14 @@
use crate::dirstate_tree::owning::OwningDirstateMap;
use crate::errors::HgError;
use crate::errors::HgResultExt;
-use crate::exit_codes;
-use crate::manifest::Manifestlog;
+use crate::manifest::{Manifest, Manifestlog};
use crate::requirements;
use crate::revlog::revlog::RevlogError;
use crate::utils::files::get_path_from_bytes;
use crate::utils::SliceExt;
use crate::vfs::{is_dir, is_file, Vfs};
-use crate::DirstateError;
+use crate::{exit_codes, Node};
+use crate::{DirstateError, Revision};
use std::cell::{Cell, Ref, RefCell, RefMut};
use std::collections::HashSet;
use std::path::{Path, PathBuf};
@@ -333,6 +333,19 @@
pub fn manifestlog_mut(&self) -> Result<RefMut<Manifestlog>, RevlogError> {
self.manifestlog.get_mut_or_init(self)
}
+
+ /// Returns the manifest of the given revision
+ pub fn manifest(
+ &self,
+ revision: Revision,
+ ) -> Result<Manifest, RevlogError> {
+ let changelog = self.changelog()?;
+ let manifest = self.manifestlog()?;
+ let changelog_entry = changelog.get_rev(revision)?;
+ let manifest_node =
+ Node::from_hex_for_repo(&changelog_entry.manifest_node()?)?;
+ manifest.get_node(manifest_node.into())
+ }
}
/// Lazily-initialized component of `Repo` with interior mutability
diff --git a/rust/hg-core/src/operations/list_tracked_files.rs b/rust/hg-core/src/operations/list_tracked_files.rs
--- a/rust/hg-core/src/operations/list_tracked_files.rs
+++ b/rust/hg-core/src/operations/list_tracked_files.rs
@@ -10,7 +10,6 @@
use crate::errors::HgError;
use crate::repo::Repo;
use crate::revlog::manifest::Manifest;
-use crate::revlog::node::Node;
use crate::revlog::revlog::RevlogError;
use crate::utils::hg_path::HgPath;
use crate::DirstateError;
@@ -71,13 +70,7 @@
revset: &str,
) -> Result<FilesForRev, RevlogError> {
let rev = crate::revset::resolve_single(revset, repo)?;
- let changelog = repo.changelog()?;
- let manifest = repo.manifestlog()?;
- let changelog_entry = changelog.get_rev(rev)?;
- let manifest_node =
- Node::from_hex_for_repo(&changelog_entry.manifest_node()?)?;
- let manifest_entry = manifest.get_node(manifest_node.into())?;
- Ok(FilesForRev(manifest_entry))
+ Ok(FilesForRev(repo.manifest(rev)?))
}
pub struct FilesForRev(Manifest);
diff --git a/rust/hg-core/src/operations/cat.rs b/rust/hg-core/src/operations/cat.rs
--- a/rust/hg-core/src/operations/cat.rs
+++ b/rust/hg-core/src/operations/cat.rs
@@ -40,20 +40,16 @@
files: &'a [HgPathBuf],
) -> Result<CatOutput, RevlogError> {
let rev = crate::revset::resolve_single(revset, repo)?;
- let changelog = repo.changelog()?;
- let manifest = repo.manifestlog()?;
- let changelog_entry = changelog.get_rev(rev)?;
- let node = *changelog
+ let manifest = repo.manifest(rev)?;
+ let node = *repo
+ .changelog()?
.node_from_rev(rev)
- .expect("should succeed when changelog.get_rev did");
- let manifest_node =
- Node::from_hex_for_repo(&changelog_entry.manifest_node()?)?;
- let manifest_entry = manifest.get_node(manifest_node.into())?;
+ .expect("should succeed when repo.manifest did");
let mut bytes = vec![];
let mut matched = vec![false; files.len()];
let mut found_any = false;
- for (manifest_file, node_bytes) in manifest_entry.files_with_nodes() {
+ for (manifest_file, node_bytes) in manifest.files_with_nodes() {
for (cat_file, is_matched) in files.iter().zip(&mut matched) {
if cat_file.as_bytes() == manifest_file.as_bytes() {
*is_matched = true;
To: SimonSapin, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
More information about the Mercurial-devel
mailing list