Patchwork D12546: rust-revlog: move check for nodemap requirement to caller

login
register
mail settings
Submitter phabricator
Date April 13, 2022, 1:11 p.m.
Message ID <differential-rev-PHID-DREV-ojyg7ehssqifinfs6wgo-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/50894/
State New
Headers show

Comments

phabricator - April 13, 2022, 1:11 p.m.
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  It's good for both making `Revlog` testable and reusable to have it
  not depend on the higher-level `Repo` type. This patch is one step in
  towards that. Additionally, this change in particular gives the
  callers more control over when to use a nodemap.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  rust/hg-core/src/operations/debugdata.rs
  rust/hg-core/src/revlog/changelog.rs
  rust/hg-core/src/revlog/filelog.rs
  rust/hg-core/src/revlog/manifest.rs
  rust/hg-core/src/revlog/revlog.rs

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/rust/hg-core/src/revlog/revlog.rs b/rust/hg-core/src/revlog/revlog.rs
--- a/rust/hg-core/src/revlog/revlog.rs
+++ b/rust/hg-core/src/revlog/revlog.rs
@@ -18,7 +18,7 @@ 
 use crate::errors::HgError;
 use crate::repo::Repo;
 use crate::revlog::Revision;
-use crate::{requirements, Node, NULL_REVISION};
+use crate::{Node, NULL_REVISION};
 
 const REVISION_FLAG_CENSORED: u16 = 1 << 15;
 const REVISION_FLAG_ELLIPSIS: u16 = 1 << 14;
@@ -84,6 +84,7 @@ 
         repo: &Repo,
         index_path: impl AsRef<Path>,
         data_path: Option<&Path>,
+        use_nodemap: bool,
     ) -> Result<Self, HgError> {
         let index_path = index_path.as_ref();
         let index = {
@@ -111,11 +112,7 @@ 
 
         let nodemap = if index.is_inline() {
             None
-        } else if !repo
-            .requirements()
-            .contains(requirements::NODEMAP_REQUIREMENT)
-        {
-            // If .hg/requires does not opt it, don’t try to open a nodemap
+        } else if !use_nodemap {
             None
         } else {
             NodeMapDocket::read_from_file(&repo.store_vfs(), index_path)?.map(
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,5 +1,6 @@ 
 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};
@@ -15,7 +16,10 @@ 
 impl Manifestlog {
     /// Open the `manifest` of a repository given by its root.
     pub fn open(repo: &Repo) -> Result<Self, HgError> {
-        let revlog = Revlog::open(repo, "00manifest.i", None)?;
+        let use_nodemap = repo
+            .requirements()
+            .contains(requirements::NODEMAP_REQUIREMENT);
+        let revlog = Revlog::open(repo, "00manifest.i", None, use_nodemap)?;
         Ok(Self { revlog })
     }
 
diff --git a/rust/hg-core/src/revlog/filelog.rs b/rust/hg-core/src/revlog/filelog.rs
--- a/rust/hg-core/src/revlog/filelog.rs
+++ b/rust/hg-core/src/revlog/filelog.rs
@@ -1,5 +1,6 @@ 
 use crate::errors::HgError;
 use crate::repo::Repo;
+use crate::requirements;
 use crate::revlog::path_encode::path_encode;
 use crate::revlog::revlog::RevlogEntry;
 use crate::revlog::revlog::{Revlog, RevlogError};
@@ -20,7 +21,11 @@ 
     pub fn open(repo: &Repo, file_path: &HgPath) -> Result<Self, HgError> {
         let index_path = store_path(file_path, b".i");
         let data_path = store_path(file_path, b".d");
-        let revlog = Revlog::open(repo, index_path, Some(&data_path))?;
+        let use_nodemap = repo
+            .requirements()
+            .contains(requirements::NODEMAP_REQUIREMENT);
+        let revlog =
+            Revlog::open(repo, index_path, Some(&data_path), 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,5 +1,6 @@ 
 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};
@@ -17,7 +18,10 @@ 
 impl Changelog {
     /// Open the `changelog` of a repository given by its root.
     pub fn open(repo: &Repo) -> Result<Self, HgError> {
-        let revlog = Revlog::open(repo, "00changelog.i", None)?;
+        let use_nodemap = repo
+            .requirements()
+            .contains(requirements::NODEMAP_REQUIREMENT);
+        let revlog = Revlog::open(repo, "00changelog.i", None, use_nodemap)?;
         Ok(Self { revlog })
     }
 
diff --git a/rust/hg-core/src/operations/debugdata.rs b/rust/hg-core/src/operations/debugdata.rs
--- a/rust/hg-core/src/operations/debugdata.rs
+++ b/rust/hg-core/src/operations/debugdata.rs
@@ -6,6 +6,7 @@ 
 // GNU General Public License version 2 or any later version.
 
 use crate::repo::Repo;
+use crate::requirements;
 use crate::revlog::revlog::{Revlog, RevlogError};
 
 /// Kind of data to debug
@@ -25,7 +26,10 @@ 
         DebugDataKind::Changelog => "00changelog.i",
         DebugDataKind::Manifest => "00manifest.i",
     };
-    let revlog = Revlog::open(repo, index_file, None)?;
+    let use_nodemap = repo
+        .requirements()
+        .contains(requirements::NODEMAP_REQUIREMENT);
+    let revlog = Revlog::open(repo, index_file, None, use_nodemap)?;
     let rev =
         crate::revset::resolve_rev_number_or_hex_prefix(revset, &revlog)?;
     let data = revlog.get_rev_data(rev)?;