Patchwork D10077: rhg: Don’t attempt to read persistent nodemap without .hg/requires opt-in

login
register
mail settings
Submitter phabricator
Date Feb. 25, 2021, 8:32 p.m.
Message ID <differential-rev-PHID-DREV-ym7nyk7xazjtzmvrk2bc-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48392/
State Superseded
Headers show

Comments

phabricator - Feb. 25, 2021, 8:32 p.m.
SimonSapin created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  rust/hg-core/src/revlog/nodemap_docket.rs

CHANGE DETAILS




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

Patch

diff --git a/rust/hg-core/src/revlog/nodemap_docket.rs b/rust/hg-core/src/revlog/nodemap_docket.rs
--- a/rust/hg-core/src/revlog/nodemap_docket.rs
+++ b/rust/hg-core/src/revlog/nodemap_docket.rs
@@ -1,4 +1,5 @@ 
 use crate::errors::{HgError, HgResultExt};
+use crate::requirements;
 use bytes_cast::{unaligned, BytesCast};
 use memmap::Mmap;
 use std::path::{Path, PathBuf};
@@ -38,6 +39,14 @@ 
         repo: &Repo,
         index_path: &Path,
     ) -> Result<Option<(Self, Mmap)>, RevlogError> {
+        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()?
@@ -88,6 +97,8 @@ 
                 Err(HgError::corrupted("persistent nodemap too short").into())
             }
         } else {
+            // Even if .hg/requires opted in, some revlogs are deemed small
+            // enough to not need a persistent nodemap.
             Ok(None)
         }
     }