Mercurial > public > mercurial-scm > hg
comparison rust/hg-core/src/repo.rs @ 52156:039b7caeb4d9
rust-revlog: introduce an `options` module
This helps group all the relevant revlog options code and makes the `mod.rs`
more readable.
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Wed, 25 Sep 2024 18:24:15 +0200 |
parents | ea0467ed76aa |
children | 7be39c5110c9 |
comparison
equal
deleted
inserted
replaced
52155:426696af24d3 | 52156:039b7caeb4d9 |
---|---|
8 use crate::dirstate_tree::owning::OwningDirstateMap; | 8 use crate::dirstate_tree::owning::OwningDirstateMap; |
9 use crate::errors::HgResultExt; | 9 use crate::errors::HgResultExt; |
10 use crate::errors::{HgError, IoResultExt}; | 10 use crate::errors::{HgError, IoResultExt}; |
11 use crate::lock::{try_with_lock_no_wait, LockError}; | 11 use crate::lock::{try_with_lock_no_wait, LockError}; |
12 use crate::manifest::{Manifest, Manifestlog}; | 12 use crate::manifest::{Manifest, Manifestlog}; |
13 use crate::requirements::{ | 13 use crate::options::default_revlog_options; |
14 CHANGELOGV2_REQUIREMENT, DIRSTATE_TRACKED_HINT_V1, | 14 use crate::requirements::DIRSTATE_TRACKED_HINT_V1; |
15 GENERALDELTA_REQUIREMENT, NODEMAP_REQUIREMENT, REVLOGV1_REQUIREMENT, | |
16 REVLOGV2_REQUIREMENT, | |
17 }; | |
18 use crate::revlog::filelog::Filelog; | 15 use crate::revlog::filelog::Filelog; |
19 use crate::revlog::RevlogError; | 16 use crate::revlog::RevlogError; |
20 use crate::utils::debug::debug_wait_for_file_or_print; | 17 use crate::utils::debug::debug_wait_for_file_or_print; |
21 use crate::utils::files::get_path_from_bytes; | 18 use crate::utils::files::get_path_from_bytes; |
22 use crate::utils::hg_path::HgPath; | 19 use crate::utils::hg_path::HgPath; |
23 use crate::utils::SliceExt; | 20 use crate::utils::SliceExt; |
24 use crate::vfs::{is_dir, is_file, VfsImpl}; | 21 use crate::vfs::{is_dir, is_file, VfsImpl}; |
22 use crate::DirstateError; | |
25 use crate::{ | 23 use crate::{ |
26 exit_codes, requirements, NodePrefix, RevlogDataConfig, RevlogDeltaConfig, | 24 exit_codes, requirements, NodePrefix, RevlogType, UncheckedRevision, |
27 RevlogFeatureConfig, RevlogType, RevlogVersionOptions, UncheckedRevision, | |
28 }; | 25 }; |
29 use crate::{DirstateError, RevlogOpenOptions}; | |
30 use std::cell::{Ref, RefCell, RefMut}; | 26 use std::cell::{Ref, RefCell, RefMut}; |
31 use std::collections::HashSet; | 27 use std::collections::HashSet; |
32 use std::io::Seek; | 28 use std::io::Seek; |
33 use std::io::SeekFrom; | 29 use std::io::SeekFrom; |
34 use std::io::Write as IoWrite; | 30 use std::io::Write as IoWrite; |
575 } | 571 } |
576 | 572 |
577 fn new_changelog(&self) -> Result<Changelog, HgError> { | 573 fn new_changelog(&self) -> Result<Changelog, HgError> { |
578 Changelog::open( | 574 Changelog::open( |
579 &self.store_vfs(), | 575 &self.store_vfs(), |
580 self.default_revlog_options(RevlogType::Changelog)?, | 576 default_revlog_options( |
577 self.config(), | |
578 self.requirements(), | |
579 RevlogType::Changelog, | |
580 )?, | |
581 ) | 581 ) |
582 } | 582 } |
583 | 583 |
584 pub fn changelog(&self) -> Result<Ref<Changelog>, HgError> { | 584 pub fn changelog(&self) -> Result<Ref<Changelog>, HgError> { |
585 self.changelog.get_or_init(|| self.new_changelog()) | 585 self.changelog.get_or_init(|| self.new_changelog()) |
590 } | 590 } |
591 | 591 |
592 fn new_manifestlog(&self) -> Result<Manifestlog, HgError> { | 592 fn new_manifestlog(&self) -> Result<Manifestlog, HgError> { |
593 Manifestlog::open( | 593 Manifestlog::open( |
594 &self.store_vfs(), | 594 &self.store_vfs(), |
595 self.default_revlog_options(RevlogType::Manifestlog)?, | 595 default_revlog_options( |
596 self.config(), | |
597 self.requirements(), | |
598 RevlogType::Manifestlog, | |
599 )?, | |
596 ) | 600 ) |
597 } | 601 } |
598 | 602 |
599 pub fn manifestlog(&self) -> Result<Ref<Manifestlog>, HgError> { | 603 pub fn manifestlog(&self) -> Result<Ref<Manifestlog>, HgError> { |
600 self.manifestlog.get_or_init(|| self.new_manifestlog()) | 604 self.manifestlog.get_or_init(|| self.new_manifestlog()) |
640 | 644 |
641 pub fn filelog(&self, path: &HgPath) -> Result<Filelog, HgError> { | 645 pub fn filelog(&self, path: &HgPath) -> Result<Filelog, HgError> { |
642 Filelog::open( | 646 Filelog::open( |
643 self, | 647 self, |
644 path, | 648 path, |
645 self.default_revlog_options(RevlogType::Filelog)?, | 649 default_revlog_options( |
650 self.config(), | |
651 self.requirements(), | |
652 RevlogType::Filelog, | |
653 )?, | |
646 ) | 654 ) |
647 } | 655 } |
648 /// Write to disk any updates that were made through `dirstate_map_mut`. | 656 /// Write to disk any updates that were made through `dirstate_map_mut`. |
649 /// | 657 /// |
650 /// The "wlock" must be held while calling this. | 658 /// The "wlock" must be held while calling this. |
790 vfs.remove_file(format!("dirstate.{}", uuid))?; | 798 vfs.remove_file(format!("dirstate.{}", uuid))?; |
791 } | 799 } |
792 Ok(()) | 800 Ok(()) |
793 } | 801 } |
794 | 802 |
795 pub fn default_revlog_options( | |
796 &self, | |
797 revlog_type: RevlogType, | |
798 ) -> Result<RevlogOpenOptions, HgError> { | |
799 let requirements = self.requirements(); | |
800 let is_changelog = revlog_type == RevlogType::Changelog; | |
801 let version = if is_changelog | |
802 && requirements.contains(CHANGELOGV2_REQUIREMENT) | |
803 { | |
804 let compute_rank = self | |
805 .config() | |
806 .get_bool(b"experimental", b"changelog-v2.compute-rank")?; | |
807 RevlogVersionOptions::ChangelogV2 { compute_rank } | |
808 } else if requirements.contains(REVLOGV2_REQUIREMENT) { | |
809 RevlogVersionOptions::V2 | |
810 } else if requirements.contains(REVLOGV1_REQUIREMENT) { | |
811 RevlogVersionOptions::V1 { | |
812 general_delta: requirements.contains(GENERALDELTA_REQUIREMENT), | |
813 inline: !is_changelog, | |
814 } | |
815 } else { | |
816 RevlogVersionOptions::V0 | |
817 }; | |
818 Ok(RevlogOpenOptions { | |
819 version, | |
820 // We don't need to dance around the slow path like in the Python | |
821 // implementation since we know we have access to the fast code. | |
822 use_nodemap: requirements.contains(NODEMAP_REQUIREMENT), | |
823 delta_config: RevlogDeltaConfig::new( | |
824 self.config(), | |
825 self.requirements(), | |
826 revlog_type, | |
827 )?, | |
828 data_config: RevlogDataConfig::new( | |
829 self.config(), | |
830 self.requirements(), | |
831 )?, | |
832 feature_config: RevlogFeatureConfig::new( | |
833 self.config(), | |
834 requirements, | |
835 )?, | |
836 }) | |
837 } | |
838 | |
839 pub fn node(&self, rev: UncheckedRevision) -> Option<crate::Node> { | 803 pub fn node(&self, rev: UncheckedRevision) -> Option<crate::Node> { |
840 self.changelog() | 804 self.changelog() |
841 .ok() | 805 .ok() |
842 .and_then(|c| c.node_from_rev(rev).copied()) | 806 .and_then(|c| c.node_from_rev(rev).copied()) |
843 } | 807 } |