comparison rust/hg-core/src/repo.rs @ 47987:21d25e9ee58e

rust: Keep lazily-initialized Changelog and Manifest log on the Repo object That way if one of them is accessed multiple times it won?t be reopened from the filesystem. Differential Revision: https://phab.mercurial-scm.org/D11406
author Simon Sapin <simon.sapin@octobus.net>
date Mon, 13 Sep 2021 13:29:55 +0200
parents fc208d6faed3
children cfb6e6699b25
comparison
equal deleted inserted replaced
47986:fc208d6faed3 47987:21d25e9ee58e
1 use crate::changelog::Changelog;
1 use crate::config::{Config, ConfigError, ConfigParseError}; 2 use crate::config::{Config, ConfigError, ConfigParseError};
2 use crate::dirstate::DirstateParents; 3 use crate::dirstate::DirstateParents;
3 use crate::dirstate_tree::dirstate_map::DirstateMap; 4 use crate::dirstate_tree::dirstate_map::DirstateMap;
4 use crate::dirstate_tree::owning::OwningDirstateMap; 5 use crate::dirstate_tree::owning::OwningDirstateMap;
5 use crate::errors::HgError; 6 use crate::errors::HgError;
6 use crate::errors::HgResultExt; 7 use crate::errors::HgResultExt;
7 use crate::exit_codes; 8 use crate::exit_codes;
9 use crate::manifest::Manifestlog;
8 use crate::requirements; 10 use crate::requirements;
11 use crate::revlog::revlog::RevlogError;
9 use crate::utils::files::get_path_from_bytes; 12 use crate::utils::files::get_path_from_bytes;
10 use crate::utils::SliceExt; 13 use crate::utils::SliceExt;
11 use crate::vfs::{is_dir, is_file, Vfs}; 14 use crate::vfs::{is_dir, is_file, Vfs};
12 use crate::DirstateError; 15 use crate::DirstateError;
13 use std::cell::{Cell, Ref, RefCell, RefMut}; 16 use std::cell::{Cell, Ref, RefCell, RefMut};
22 requirements: HashSet<String>, 25 requirements: HashSet<String>,
23 config: Config, 26 config: Config,
24 // None means not known/initialized yet 27 // None means not known/initialized yet
25 dirstate_parents: Cell<Option<DirstateParents>>, 28 dirstate_parents: Cell<Option<DirstateParents>>,
26 dirstate_map: LazyCell<OwningDirstateMap, DirstateError>, 29 dirstate_map: LazyCell<OwningDirstateMap, DirstateError>,
30 changelog: LazyCell<Changelog, RevlogError>,
31 manifestlog: LazyCell<Manifestlog, RevlogError>,
27 } 32 }
28 33
29 #[derive(Debug, derive_more::From)] 34 #[derive(Debug, derive_more::From)]
30 pub enum RepoError { 35 pub enum RepoError {
31 NotFound { 36 NotFound {
195 store: store_path, 200 store: store_path,
196 dot_hg, 201 dot_hg,
197 config: repo_config, 202 config: repo_config,
198 dirstate_parents: Cell::new(None), 203 dirstate_parents: Cell::new(None),
199 dirstate_map: LazyCell::new(Self::new_dirstate_map), 204 dirstate_map: LazyCell::new(Self::new_dirstate_map),
205 changelog: LazyCell::new(Changelog::open),
206 manifestlog: LazyCell::new(Manifestlog::open),
200 }; 207 };
201 208
202 requirements::check(&repo)?; 209 requirements::check(&repo)?;
203 210
204 Ok(repo) 211 Ok(repo)
308 pub fn dirstate_map_mut( 315 pub fn dirstate_map_mut(
309 &self, 316 &self,
310 ) -> Result<RefMut<OwningDirstateMap>, DirstateError> { 317 ) -> Result<RefMut<OwningDirstateMap>, DirstateError> {
311 self.dirstate_map.get_mut_or_init(self) 318 self.dirstate_map.get_mut_or_init(self)
312 } 319 }
320
321 pub fn changelog(&self) -> Result<Ref<Changelog>, RevlogError> {
322 self.changelog.get_or_init(self)
323 }
324
325 pub fn changelog_mut(&self) -> Result<RefMut<Changelog>, RevlogError> {
326 self.changelog.get_mut_or_init(self)
327 }
328
329 pub fn manifestlog(&self) -> Result<Ref<Manifestlog>, RevlogError> {
330 self.manifestlog.get_or_init(self)
331 }
332
333 pub fn manifestlog_mut(&self) -> Result<RefMut<Manifestlog>, RevlogError> {
334 self.manifestlog.get_mut_or_init(self)
335 }
313 } 336 }
314 337
315 /// Lazily-initialized component of `Repo` with interior mutability 338 /// Lazily-initialized component of `Repo` with interior mutability
316 /// 339 ///
317 /// This differs from `OnceCell` in that the value can still be "deinitialized" 340 /// This differs from `OnceCell` in that the value can still be "deinitialized"