[Updated] D11407: rust: Add Repo::manifest(revision)

SimonSapin phabricator at mercurial-scm.org
Tue Sep 14 08:20:25 UTC 2021


Closed by commit rHGcfb6e6699b25: rust: Add Repo::manifest(revision) (authored by SimonSapin).
This revision was automatically updated to reflect the committed changes.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D11407?vs=30225&id=30235

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D11407/new/

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, Alphare
Cc: mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20210914/fad595b3/attachment-0002.html>


More information about the Mercurial-patches mailing list