Mercurial > hg
changeset 49085:07d8d144c222
rust-nodemap-docket: move check of nodemap requirement to caller
I think it's cleaner if `NodeMapDocket` doesn't know about the `Repo`
type. That makes it more easily reusable and testable. This patch
moves out one of the uses of `Repo` out of it.
Differential Revision: https://phab.mercurial-scm.org/D12544
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Thu, 31 Mar 2022 22:59:19 -0700 |
parents | ea98850a136e |
children | 704e993e8ee9 |
files | rust/hg-core/src/revlog/nodemap_docket.rs rust/hg-core/src/revlog/revlog.rs |
diffstat | 2 files changed, 7 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/rust/hg-core/src/revlog/nodemap_docket.rs Tue Apr 19 10:53:58 2022 -0400 +++ b/rust/hg-core/src/revlog/nodemap_docket.rs Thu Mar 31 22:59:19 2022 -0700 @@ -1,5 +1,4 @@ use crate::errors::{HgError, HgResultExt}; -use crate::requirements; use bytes_cast::{unaligned, BytesCast}; use memmap2::Mmap; use std::path::{Path, PathBuf}; @@ -38,14 +37,6 @@ repo: &Repo, index_path: &Path, ) -> Result<Option<(Self, Mmap)>, HgError> { - if !repo - .requirements() - .contains(requirements::NODEMAP_REQUIREMENT) - { - // If .hg/requires does not opt it, don’t try to open a nodemap - return Ok(None); - } - let docket_path = index_path.with_extension("n"); let docket_bytes = if let Some(bytes) = repo.store_vfs().read(&docket_path).io_not_found_as_none()?
--- a/rust/hg-core/src/revlog/revlog.rs Tue Apr 19 10:53:58 2022 -0400 +++ b/rust/hg-core/src/revlog/revlog.rs Thu Mar 31 22:59:19 2022 -0700 @@ -18,7 +18,7 @@ use crate::errors::HgError; use crate::repo::Repo; use crate::revlog::Revision; -use crate::{Node, NULL_REVISION}; +use crate::{requirements, Node, NULL_REVISION}; const REVISION_FLAG_CENSORED: u16 = 1 << 15; const REVISION_FLAG_ELLIPSIS: u16 = 1 << 14; @@ -111,6 +111,12 @@ 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 + None } else { NodeMapDocket::read_from_file(repo, index_path)?.map( |(docket, data)| {