martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  As with other recent patches, this makes the types easier to test and
  reuse.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12561

AFFECTED FILES
  rust/hg-core/src/repo.rs
  rust/hg-core/src/revlog/changelog.rs
  rust/hg-core/src/revlog/manifest.rs

CHANGE DETAILS

diff --git a/rust/hg-core/src/revlog/manifest.rs 
b/rust/hg-core/src/revlog/manifest.rs
--- a/rust/hg-core/src/revlog/manifest.rs
+++ b/rust/hg-core/src/revlog/manifest.rs
@@ -1,11 +1,10 @@
 use crate::errors::HgError;
-use crate::repo::Repo;
-use crate::requirements;
 use crate::revlog::revlog::{Revlog, RevlogError};
 use crate::revlog::Revision;
 use crate::revlog::{Node, NodePrefix};
 use crate::utils::hg_path::HgPath;
 use crate::utils::SliceExt;
+use crate::vfs::Vfs;
 
 /// A specialized `Revlog` to work with `manifest` data format.
 pub struct Manifestlog {
@@ -15,16 +14,9 @@
 
 impl Manifestlog {
     /// Open the `manifest` of a repository given by its root.
-    pub fn open(repo: &Repo) -> Result<Self, HgError> {
-        let use_nodemap = repo
-            .requirements()
-            .contains(requirements::NODEMAP_REQUIREMENT);
-        let revlog = Revlog::open(
-            &repo.store_vfs(),
-            "00manifest.i",
-            None,
-            use_nodemap,
-        )?;
+    pub fn open(store_vfs: &Vfs, use_nodemap: bool) -> Result<Self, HgError> {
+        let revlog =
+            Revlog::open(store_vfs, "00manifest.i", None, use_nodemap)?;
         Ok(Self { revlog })
     }
 
diff --git a/rust/hg-core/src/revlog/changelog.rs 
b/rust/hg-core/src/revlog/changelog.rs
--- a/rust/hg-core/src/revlog/changelog.rs
+++ b/rust/hg-core/src/revlog/changelog.rs
@@ -1,10 +1,9 @@
 use crate::errors::HgError;
-use crate::repo::Repo;
-use crate::requirements;
 use crate::revlog::revlog::{Revlog, RevlogEntry, RevlogError};
 use crate::revlog::Revision;
 use crate::revlog::{Node, NodePrefix};
 use crate::utils::hg_path::HgPath;
+use crate::vfs::Vfs;
 use itertools::Itertools;
 use std::ascii::escape_default;
 use std::fmt::{Debug, Formatter};
@@ -17,16 +16,9 @@
 
 impl Changelog {
     /// Open the `changelog` of a repository given by its root.
-    pub fn open(repo: &Repo) -> Result<Self, HgError> {
-        let use_nodemap = repo
-            .requirements()
-            .contains(requirements::NODEMAP_REQUIREMENT);
-        let revlog = Revlog::open(
-            &repo.store_vfs(),
-            "00changelog.i",
-            None,
-            use_nodemap,
-        )?;
+    pub fn open(store_vfs: &Vfs, use_nodemap: bool) -> Result<Self, HgError> {
+        let revlog =
+            Revlog::open(store_vfs, "00changelog.i", None, use_nodemap)?;
         Ok(Self { revlog })
     }
 
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
@@ -187,8 +187,8 @@
                 Self::read_dirstate_data_file_uuid,
             ),
             dirstate_map: LazyCell::new(Self::new_dirstate_map),
-            changelog: LazyCell::new(Changelog::open),
-            manifestlog: LazyCell::new(Manifestlog::open),
+            changelog: LazyCell::new(Self::new_changelog),
+            manifestlog: LazyCell::new(Self::new_manifestlog),
         };
 
         requirements::check(&repo)?;
@@ -344,6 +344,13 @@
         self.dirstate_map.get_mut_or_init(self)
     }
 
+    fn new_changelog(&self) -> Result<Changelog, HgError> {
+        let use_nodemap = self
+            .requirements
+            .contains(requirements::NODEMAP_REQUIREMENT);
+        Changelog::open(&self.store_vfs(), use_nodemap)
+    }
+
     pub fn changelog(&self) -> Result<Ref<Changelog>, HgError> {
         self.changelog.get_or_init(self)
     }
@@ -352,6 +359,13 @@
         self.changelog.get_mut_or_init(self)
     }
 
+    fn new_manifestlog(&self) -> Result<Manifestlog, HgError> {
+        let use_nodemap = self
+            .requirements
+            .contains(requirements::NODEMAP_REQUIREMENT);
+        Manifestlog::open(&self.store_vfs(), use_nodemap)
+    }
+
     pub fn manifestlog(&self) -> Result<Ref<Manifestlog>, HgError> {
         self.manifestlog.get_or_init(self)
     }



To: martinvonz, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to