##// END OF EJS Templates
rust: Keep lazily-initialized Changelog and Manifest log on the Repo object...
Simon Sapin -
r48773:21d25e9e default
parent child Browse files
Show More
@@ -8,8 +8,6 b''
8 use std::path::PathBuf;
8 use std::path::PathBuf;
9
9
10 use crate::repo::Repo;
10 use crate::repo::Repo;
11 use crate::revlog::changelog::Changelog;
12 use crate::revlog::manifest::Manifestlog;
13 use crate::revlog::path_encode::path_encode;
11 use crate::revlog::path_encode::path_encode;
14 use crate::revlog::revlog::Revlog;
12 use crate::revlog::revlog::Revlog;
15 use crate::revlog::revlog::RevlogError;
13 use crate::revlog::revlog::RevlogError;
@@ -42,8 +40,8 b" pub fn cat<'a>("
42 files: &'a [HgPathBuf],
40 files: &'a [HgPathBuf],
43 ) -> Result<CatOutput, RevlogError> {
41 ) -> Result<CatOutput, RevlogError> {
44 let rev = crate::revset::resolve_single(revset, repo)?;
42 let rev = crate::revset::resolve_single(revset, repo)?;
45 let changelog = Changelog::open(repo)?;
43 let changelog = repo.changelog()?;
46 let manifest = Manifestlog::open(repo)?;
44 let manifest = repo.manifestlog()?;
47 let changelog_entry = changelog.get_rev(rev)?;
45 let changelog_entry = changelog.get_rev(rev)?;
48 let node = *changelog
46 let node = *changelog
49 .node_from_rev(rev)
47 .node_from_rev(rev)
@@ -9,8 +9,7 b' use crate::dirstate::parsers::parse_dirs'
9 use crate::dirstate_tree::on_disk::{for_each_tracked_path, read_docket};
9 use crate::dirstate_tree::on_disk::{for_each_tracked_path, read_docket};
10 use crate::errors::HgError;
10 use crate::errors::HgError;
11 use crate::repo::Repo;
11 use crate::repo::Repo;
12 use crate::revlog::changelog::Changelog;
12 use crate::revlog::manifest::Manifest;
13 use crate::revlog::manifest::{Manifest, Manifestlog};
14 use crate::revlog::node::Node;
13 use crate::revlog::node::Node;
15 use crate::revlog::revlog::RevlogError;
14 use crate::revlog::revlog::RevlogError;
16 use crate::utils::hg_path::HgPath;
15 use crate::utils::hg_path::HgPath;
@@ -72,8 +71,8 b' pub fn list_rev_tracked_files('
72 revset: &str,
71 revset: &str,
73 ) -> Result<FilesForRev, RevlogError> {
72 ) -> Result<FilesForRev, RevlogError> {
74 let rev = crate::revset::resolve_single(revset, repo)?;
73 let rev = crate::revset::resolve_single(revset, repo)?;
75 let changelog = Changelog::open(repo)?;
74 let changelog = repo.changelog()?;
76 let manifest = Manifestlog::open(repo)?;
75 let manifest = repo.manifestlog()?;
77 let changelog_entry = changelog.get_rev(rev)?;
76 let changelog_entry = changelog.get_rev(rev)?;
78 let manifest_node =
77 let manifest_node =
79 Node::from_hex_for_repo(&changelog_entry.manifest_node()?)?;
78 Node::from_hex_for_repo(&changelog_entry.manifest_node()?)?;
@@ -1,3 +1,4 b''
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;
@@ -5,7 +6,9 b' use crate::dirstate_tree::owning::Owning'
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};
@@ -24,6 +27,8 b' pub struct Repo {'
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)]
@@ -197,6 +202,8 b' impl Repo {'
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)?;
@@ -310,6 +317,22 b' impl Repo {'
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
@@ -4,7 +4,6 b''
4
4
5 use crate::errors::HgError;
5 use crate::errors::HgError;
6 use crate::repo::Repo;
6 use crate::repo::Repo;
7 use crate::revlog::changelog::Changelog;
8 use crate::revlog::revlog::{Revlog, RevlogError};
7 use crate::revlog::revlog::{Revlog, RevlogError};
9 use crate::revlog::NodePrefix;
8 use crate::revlog::NodePrefix;
10 use crate::revlog::{Revision, NULL_REVISION, WORKING_DIRECTORY_HEX};
9 use crate::revlog::{Revision, NULL_REVISION, WORKING_DIRECTORY_HEX};
@@ -17,7 +16,7 b' pub fn resolve_single('
17 input: &str,
16 input: &str,
18 repo: &Repo,
17 repo: &Repo,
19 ) -> Result<Revision, RevlogError> {
18 ) -> Result<Revision, RevlogError> {
20 let changelog = Changelog::open(repo)?;
19 let changelog = repo.changelog()?;
21
20
22 match resolve_rev_number_or_hex_prefix(input, &changelog.revlog) {
21 match resolve_rev_number_or_hex_prefix(input, &changelog.revlog) {
23 Err(RevlogError::InvalidRevision) => {} // Try other syntax
22 Err(RevlogError::InvalidRevision) => {} // Try other syntax
General Comments 0
You need to be logged in to leave comments. Login now