Mercurial > hg
changeset 52305:79e8118cd846
rust-lib: move `Dirstate*Error` to the `dirstate` module
That's where they belong and should always have been there.
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Mon, 04 Nov 2024 11:18:36 +0100 |
parents | 04b9a56c2d25 |
children | f33b87b46135 |
files | rust/hg-core/src/dirstate.rs rust/hg-core/src/dirstate/dirs_multiset.rs rust/hg-core/src/dirstate/dirstate_map.rs rust/hg-core/src/dirstate/on_disk.rs rust/hg-core/src/dirstate/owning.rs rust/hg-core/src/lib.rs rust/hg-core/src/repo.rs rust/hg-cpython/src/dirstate/dirstate_map.rs rust/rhg/src/commands/status.rs rust/rhg/src/error.rs |
diffstat | 10 files changed, 69 insertions(+), 63 deletions(-) [+] |
line wrap: on
line diff
--- a/rust/hg-core/src/dirstate.rs Mon Nov 04 11:13:05 2024 +0100 +++ b/rust/hg-core/src/dirstate.rs Mon Nov 04 11:18:36 2024 +0100 @@ -5,10 +5,13 @@ // This software may be used and distributed according to the terms of the // GNU General Public License version 2 or any later version. +use std::fmt; + use crate::dirstate::on_disk::DirstateV2ParseError; +use crate::errors; use crate::revlog::node::NULL_NODE; use crate::revlog::Node; -use crate::utils::hg_path::HgPath; +use crate::utils::hg_path::{HgPath, HgPathBuf, HgPathError}; use bytes_cast::BytesCast; use entry::DirstateEntry; @@ -51,3 +54,47 @@ + Send + 'a, >; + +#[derive(Debug, PartialEq)] +pub enum DirstateMapError { + PathNotFound(HgPathBuf), + InvalidPath(HgPathError), +} + +impl From<HgPathError> for DirstateMapError { + fn from(error: HgPathError) -> Self { + Self::InvalidPath(error) + } +} + +impl fmt::Display for DirstateMapError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + DirstateMapError::PathNotFound(_) => { + f.write_str("expected a value, found none") + } + DirstateMapError::InvalidPath(path_error) => path_error.fmt(f), + } + } +} + +#[derive(Debug, derive_more::From)] +pub enum DirstateError { + Map(DirstateMapError), + Common(errors::HgError), +} + +impl From<HgPathError> for DirstateError { + fn from(error: HgPathError) -> Self { + Self::Map(DirstateMapError::InvalidPath(error)) + } +} + +impl fmt::Display for DirstateError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + DirstateError::Map(error) => error.fmt(f), + DirstateError::Common(error) => error.fmt(f), + } + } +}
--- a/rust/hg-core/src/dirstate/dirs_multiset.rs Mon Nov 04 11:13:05 2024 +0100 +++ b/rust/hg-core/src/dirstate/dirs_multiset.rs Mon Nov 04 11:18:36 2024 +0100 @@ -14,11 +14,12 @@ files, hg_path::{HgPath, HgPathBuf, HgPathError}, }, - DirstateError, DirstateMapError, FastHashMap, + FastHashMap, }; use std::collections::{hash_map, hash_map::Entry, HashMap, HashSet}; use super::entry::DirstateEntry; +use super::{DirstateError, DirstateMapError}; // could be encapsulated if we care API stability more seriously pub type DirsMultisetIter<'a> = hash_map::Keys<'a, HgPathBuf, u32>;
--- a/rust/hg-core/src/dirstate/dirstate_map.rs Mon Nov 04 11:13:05 2024 +0100 +++ b/rust/hg-core/src/dirstate/dirstate_map.rs Mon Nov 04 11:18:36 2024 +0100 @@ -4,11 +4,11 @@ use std::os::unix::fs::MetadataExt; use std::path::PathBuf; -use super::on_disk; use super::on_disk::DirstateV2ParseError; use super::owning::OwningDirstateMap; use super::path_with_basename::WithBasename; use super::status::{DirstateStatus, StatusError, StatusOptions}; +use super::{on_disk, DirstateError, DirstateMapError}; use crate::dirstate::entry::{ DirstateEntry, DirstateV2Data, ParentFileData, TruncatedTimestamp, }; @@ -20,8 +20,6 @@ use crate::matchers::Matcher; use crate::utils::filter_map_results; use crate::utils::hg_path::{HgPath, HgPathBuf}; -use crate::DirstateError; -use crate::DirstateMapError; use crate::DirstateParents; use crate::FastHashbrownMap as FastHashMap; use crate::PatternFileWarning;
--- a/rust/hg-core/src/dirstate/on_disk.rs Mon Nov 04 11:13:05 2024 +0100 +++ b/rust/hg-core/src/dirstate/on_disk.rs Mon Nov 04 11:18:36 2024 +0100 @@ -14,7 +14,6 @@ use crate::repo::Repo; use crate::requirements::DIRSTATE_TRACKED_HINT_V1; use crate::utils::hg_path::HgPath; -use crate::DirstateError; use crate::DirstateParents; use bitflags::bitflags; use bytes_cast::unaligned::{U16Be, U32Be}; @@ -26,6 +25,7 @@ use uuid::Uuid; use super::dirstate_map::DirstateIdentity; +use super::DirstateError; /// Added at the start of `.hg/dirstate` when the "v2" format is used. /// This a redundant sanity check more than an actual "magic number" since @@ -200,7 +200,7 @@ } } -impl From<DirstateV2ParseError> for crate::DirstateError { +impl From<DirstateV2ParseError> for DirstateError { fn from(error: DirstateV2ParseError) -> Self { HgError::from(error).into() }
--- a/rust/hg-core/src/dirstate/owning.rs Mon Nov 04 11:13:05 2024 +0100 +++ b/rust/hg-core/src/dirstate/owning.rs Mon Nov 04 11:18:36 2024 +0100 @@ -1,6 +1,9 @@ -use crate::{DirstateError, DirstateParents}; +use crate::DirstateParents; -use super::dirstate_map::{DirstateIdentity, DirstateMap}; +use super::{ + dirstate_map::{DirstateIdentity, DirstateMap}, + DirstateError, +}; use self_cell::self_cell; use std::ops::Deref;
--- a/rust/hg-core/src/lib.rs Mon Nov 04 11:13:05 2024 +0100 +++ b/rust/hg-core/src/lib.rs Mon Nov 04 11:18:36 2024 +0100 @@ -42,7 +42,7 @@ pub mod utils; pub mod vfs; -use crate::utils::hg_path::{HgPathBuf, HgPathError}; +use crate::utils::hg_path::HgPathError; pub use filepatterns::{ parse_pattern_syntax_kind, read_pattern_file, IgnorePattern, PatternFileWarning, PatternSyntax, @@ -67,50 +67,6 @@ pub type FastHashbrownMap<K, V> = hashbrown::HashMap<K, V, RandomXxHashBuilder64>; -#[derive(Debug, PartialEq)] -pub enum DirstateMapError { - PathNotFound(HgPathBuf), - InvalidPath(HgPathError), -} - -impl From<HgPathError> for DirstateMapError { - fn from(error: HgPathError) -> Self { - Self::InvalidPath(error) - } -} - -impl fmt::Display for DirstateMapError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match self { - DirstateMapError::PathNotFound(_) => { - f.write_str("expected a value, found none") - } - DirstateMapError::InvalidPath(path_error) => path_error.fmt(f), - } - } -} - -#[derive(Debug, derive_more::From)] -pub enum DirstateError { - Map(DirstateMapError), - Common(errors::HgError), -} - -impl From<HgPathError> for DirstateError { - fn from(error: HgPathError) -> Self { - Self::Map(DirstateMapError::InvalidPath(error)) - } -} - -impl fmt::Display for DirstateError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match self { - DirstateError::Map(error) => error.fmt(f), - DirstateError::Common(error) => error.fmt(f), - } - } -} - #[derive(Debug, derive_more::From)] pub enum PatternError { #[from]
--- a/rust/hg-core/src/repo.rs Mon Nov 04 11:13:05 2024 +0100 +++ b/rust/hg-core/src/repo.rs Mon Nov 04 11:18:36 2024 +0100 @@ -2,7 +2,7 @@ use crate::dirstate::dirstate_map::{DirstateIdentity, DirstateMapWriteMode}; use crate::dirstate::on_disk::Docket as DirstateDocket; use crate::dirstate::owning::OwningDirstateMap; -use crate::dirstate::DirstateParents; +use crate::dirstate::{DirstateError, DirstateParents}; use crate::errors::HgResultExt; use crate::errors::{HgError, IoResultExt}; use crate::lock::{try_with_lock_no_wait, LockError}; @@ -17,7 +17,6 @@ use crate::utils::hg_path::HgPath; use crate::utils::SliceExt; use crate::vfs::{is_dir, is_file, Vfs, VfsImpl}; -use crate::DirstateError; use crate::{exit_codes, requirements, NodePrefix, UncheckedRevision}; use std::cell::{Ref, RefCell, RefMut}; use std::collections::HashSet;
--- a/rust/hg-cpython/src/dirstate/dirstate_map.rs Mon Nov 04 11:13:05 2024 +0100 +++ b/rust/hg-cpython/src/dirstate/dirstate_map.rs Mon Nov 04 11:18:36 2024 +0100 @@ -14,11 +14,12 @@ exc, PyBool, PyBytes, PyClone, PyDict, PyErr, PyList, PyNone, PyObject, PyResult, Python, PythonObject, ToPyObject, UnsafePyLeaked, }; -use hg::{ - dirstate::dirstate_map::{ +use hg::dirstate::{ + dirstate_map::{ DirstateEntryReset, DirstateIdentity as CoreDirstateIdentity, }, - dirstate::entry::{DirstateEntry, ParentFileData, TruncatedTimestamp}, + entry::{DirstateEntry, ParentFileData, TruncatedTimestamp}, + DirstateError, }; use crate::{ @@ -30,8 +31,7 @@ dirstate::dirstate_map::DirstateMapWriteMode, dirstate::on_disk::DirstateV2ParseError, dirstate::owning::OwningDirstateMap, dirstate::StateMapIter, revlog::Node, - utils::files::normalize_case, utils::hg_path::HgPath, DirstateError, - DirstateParents, + utils::files::normalize_case, utils::hg_path::HgPath, DirstateParents, }; // TODO
--- a/rust/rhg/src/commands/status.rs Mon Nov 04 11:13:05 2024 +0100 +++ b/rust/rhg/src/commands/status.rs Mon Nov 04 11:18:36 2024 +0100 @@ -16,7 +16,7 @@ use hg::config::Config; use hg::dirstate::entry::{has_exec_bit, TruncatedTimestamp}; use hg::dirstate::status::{ - BadMatch, DirstateStatus, StatusError, StatusOptions, StatusPath + BadMatch, DirstateStatus, StatusError, StatusOptions, StatusPath, }; use hg::errors::{HgError, IoResultExt}; use hg::filepatterns::parse_pattern_args;
--- a/rust/rhg/src/error.rs Mon Nov 04 11:13:05 2024 +0100 +++ b/rust/rhg/src/error.rs Mon Nov 04 11:18:36 2024 +0100 @@ -5,6 +5,8 @@ use hg::config::{ConfigError, ConfigParseError, ConfigValueParseError}; use hg::dirstate::on_disk::DirstateV2ParseError; use hg::dirstate::status::StatusError; +use hg::dirstate::DirstateError; +use hg::dirstate::DirstateMapError; use hg::errors::HgError; use hg::exit_codes; use hg::repo::RepoError; @@ -12,7 +14,7 @@ use hg::sparse::SparseConfigError; use hg::utils::files::get_bytes_from_path; use hg::utils::hg_path::HgPathError; -use hg::{DirstateError, DirstateMapError, PatternError}; +use hg::PatternError; use std::convert::From; /// The kind of command error