rust-revlog: move check for nodemap requirement to caller
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.
Differential Revision: https://phab.mercurial-scm.org/D12546
--- a/rust/hg-core/src/operations/debugdata.rs Thu Mar 31 22:54:33 2022 -0700
+++ b/rust/hg-core/src/operations/debugdata.rs Tue Apr 12 11:40:37 2022 -0700
@@ -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)?;
--- a/rust/hg-core/src/revlog/changelog.rs Thu Mar 31 22:54:33 2022 -0700
+++ b/rust/hg-core/src/revlog/changelog.rs Tue Apr 12 11:40:37 2022 -0700
@@ -1,5 +1,6 @@
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};
@@ -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 })
}
@@ -213,7 +217,6 @@
#[cfg(test)]
mod tests {
use super::*;
- use itertools::Itertools;
use pretty_assertions::assert_eq;
#[test]
--- a/rust/hg-core/src/revlog/filelog.rs Thu Mar 31 22:54:33 2022 -0700
+++ b/rust/hg-core/src/revlog/filelog.rs Tue Apr 12 11:40:37 2022 -0700
@@ -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 })
}
--- a/rust/hg-core/src/revlog/manifest.rs Thu Mar 31 22:54:33 2022 -0700
+++ b/rust/hg-core/src/revlog/manifest.rs Tue Apr 12 11:40:37 2022 -0700
@@ -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 })
}
--- a/rust/hg-core/src/revlog/revlog.rs Thu Mar 31 22:54:33 2022 -0700
+++ b/rust/hg-core/src/revlog/revlog.rs Tue Apr 12 11:40:37 2022 -0700
@@ -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(