diff rust/hg-core/src/repo.rs @ 47988:cfb6e6699b25

rust: Add Repo::manifest(revision) This deduplicates some common code. Differential Revision: https://phab.mercurial-scm.org/D11407
author Simon Sapin <simon.sapin@octobus.net>
date Mon, 13 Sep 2021 13:45:10 +0200
parents 21d25e9ee58e
children 4d2a5ca060e3
line wrap: on
line diff
--- a/rust/hg-core/src/repo.rs	Mon Sep 13 13:29:55 2021 +0200
+++ b/rust/hg-core/src/repo.rs	Mon Sep 13 13:45:10 2021 +0200
@@ -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