Mercurial > public > mercurial-scm > hg
comparison rust/hg-core/src/revlog/nodemap_docket.rs @ 46630:842f2372ced6
rhg: Don?t attempt to read persistent nodemap without .hg/requires opt-in
Differential Revision: https://phab.mercurial-scm.org/D10077
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Thu, 25 Feb 2021 21:29:12 +0100 |
parents | 43d63979a75e |
children | e834b79def74 |
comparison
equal
deleted
inserted
replaced
46629:90481550467c | 46630:842f2372ced6 |
---|---|
1 use crate::errors::{HgError, HgResultExt}; | 1 use crate::errors::{HgError, HgResultExt}; |
2 use crate::requirements; | |
2 use bytes_cast::{unaligned, BytesCast}; | 3 use bytes_cast::{unaligned, BytesCast}; |
3 use memmap::Mmap; | 4 use memmap::Mmap; |
4 use std::path::{Path, PathBuf}; | 5 use std::path::{Path, PathBuf}; |
5 | 6 |
6 use super::revlog::RevlogError; | 7 use super::revlog::RevlogError; |
36 /// can happen in a rare race condition). | 37 /// can happen in a rare race condition). |
37 pub fn read_from_file( | 38 pub fn read_from_file( |
38 repo: &Repo, | 39 repo: &Repo, |
39 index_path: &Path, | 40 index_path: &Path, |
40 ) -> Result<Option<(Self, Mmap)>, RevlogError> { | 41 ) -> Result<Option<(Self, Mmap)>, RevlogError> { |
42 if !repo | |
43 .requirements() | |
44 .contains(requirements::NODEMAP_REQUIREMENT) | |
45 { | |
46 // If .hg/requires does not opt it, don’t try to open a nodemap | |
47 return Ok(None); | |
48 } | |
49 | |
41 let docket_path = index_path.with_extension("n"); | 50 let docket_path = index_path.with_extension("n"); |
42 let docket_bytes = if let Some(bytes) = | 51 let docket_bytes = if let Some(bytes) = |
43 repo.store_vfs().read(&docket_path).io_not_found_as_none()? | 52 repo.store_vfs().read(&docket_path).io_not_found_as_none()? |
44 { | 53 { |
45 bytes | 54 bytes |
86 Ok(Some((docket, mmap))) | 95 Ok(Some((docket, mmap))) |
87 } else { | 96 } else { |
88 Err(HgError::corrupted("persistent nodemap too short").into()) | 97 Err(HgError::corrupted("persistent nodemap too short").into()) |
89 } | 98 } |
90 } else { | 99 } else { |
100 // Even if .hg/requires opted in, some revlogs are deemed small | |
101 // enough to not need a persistent nodemap. | |
91 Ok(None) | 102 Ok(None) |
92 } | 103 } |
93 } | 104 } |
94 } | 105 } |
95 | 106 |