diff --git a/rust/hg-core/src/dirstate.rs b/rust/hg-core/src/dirstate.rs index 04b9a56c2d25223dc6560c5002644b46c40a4052_cnVzdC9oZy1jb3JlL3NyYy9kaXJzdGF0ZS5ycw==..79e8118cd8465e62d5b5ab393968e6bf2af5dc09_cnVzdC9oZy1jb3JlL3NyYy9kaXJzdGF0ZS5ycw== 100644 --- a/rust/hg-core/src/dirstate.rs +++ b/rust/hg-core/src/dirstate.rs @@ -5,4 +5,6 @@ // 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; @@ -8,3 +10,4 @@ use crate::dirstate::on_disk::DirstateV2ParseError; +use crate::errors; use crate::revlog::node::NULL_NODE; use crate::revlog::Node; @@ -9,6 +12,6 @@ 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), + } + } +} diff --git a/rust/hg-core/src/dirstate/dirs_multiset.rs b/rust/hg-core/src/dirstate/dirs_multiset.rs index 04b9a56c2d25223dc6560c5002644b46c40a4052_cnVzdC9oZy1jb3JlL3NyYy9kaXJzdGF0ZS9kaXJzX211bHRpc2V0LnJz..79e8118cd8465e62d5b5ab393968e6bf2af5dc09_cnVzdC9oZy1jb3JlL3NyYy9kaXJzdGF0ZS9kaXJzX211bHRpc2V0LnJz 100644 --- a/rust/hg-core/src/dirstate/dirs_multiset.rs +++ b/rust/hg-core/src/dirstate/dirs_multiset.rs @@ -14,8 +14,8 @@ files, hg_path::{HgPath, HgPathBuf, HgPathError}, }, - DirstateError, DirstateMapError, FastHashMap, + FastHashMap, }; use std::collections::{hash_map, hash_map::Entry, HashMap, HashSet}; use super::entry::DirstateEntry; @@ -18,7 +18,8 @@ }; 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>; diff --git a/rust/hg-core/src/dirstate/dirstate_map.rs b/rust/hg-core/src/dirstate/dirstate_map.rs index 04b9a56c2d25223dc6560c5002644b46c40a4052_cnVzdC9oZy1jb3JlL3NyYy9kaXJzdGF0ZS9kaXJzdGF0ZV9tYXAucnM=..79e8118cd8465e62d5b5ab393968e6bf2af5dc09_cnVzdC9oZy1jb3JlL3NyYy9kaXJzdGF0ZS9kaXJzdGF0ZV9tYXAucnM= 100644 --- a/rust/hg-core/src/dirstate/dirstate_map.rs +++ b/rust/hg-core/src/dirstate/dirstate_map.rs @@ -4,8 +4,7 @@ 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}; @@ -8,7 +7,8 @@ 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; diff --git a/rust/hg-core/src/dirstate/on_disk.rs b/rust/hg-core/src/dirstate/on_disk.rs index 04b9a56c2d25223dc6560c5002644b46c40a4052_cnVzdC9oZy1jb3JlL3NyYy9kaXJzdGF0ZS9vbl9kaXNrLnJz..79e8118cd8465e62d5b5ab393968e6bf2af5dc09_cnVzdC9oZy1jb3JlL3NyYy9kaXJzdGF0ZS9vbl9kaXNrLnJz 100644 --- a/rust/hg-core/src/dirstate/on_disk.rs +++ b/rust/hg-core/src/dirstate/on_disk.rs @@ -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() } diff --git a/rust/hg-core/src/dirstate/owning.rs b/rust/hg-core/src/dirstate/owning.rs index 04b9a56c2d25223dc6560c5002644b46c40a4052_cnVzdC9oZy1jb3JlL3NyYy9kaXJzdGF0ZS9vd25pbmcucnM=..79e8118cd8465e62d5b5ab393968e6bf2af5dc09_cnVzdC9oZy1jb3JlL3NyYy9kaXJzdGF0ZS9vd25pbmcucnM= 100644 --- a/rust/hg-core/src/dirstate/owning.rs +++ b/rust/hg-core/src/dirstate/owning.rs @@ -1,2 +1,2 @@ -use crate::{DirstateError, DirstateParents}; +use crate::DirstateParents; @@ -2,5 +2,8 @@ -use super::dirstate_map::{DirstateIdentity, DirstateMap}; +use super::{ + dirstate_map::{DirstateIdentity, DirstateMap}, + DirstateError, +}; use self_cell::self_cell; use std::ops::Deref; diff --git a/rust/hg-core/src/lib.rs b/rust/hg-core/src/lib.rs index 04b9a56c2d25223dc6560c5002644b46c40a4052_cnVzdC9oZy1jb3JlL3NyYy9saWIucnM=..79e8118cd8465e62d5b5ab393968e6bf2af5dc09_cnVzdC9oZy1jb3JlL3NyYy9saWIucnM= 100644 --- a/rust/hg-core/src/lib.rs +++ b/rust/hg-core/src/lib.rs @@ -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] diff --git a/rust/hg-core/src/repo.rs b/rust/hg-core/src/repo.rs index 04b9a56c2d25223dc6560c5002644b46c40a4052_cnVzdC9oZy1jb3JlL3NyYy9yZXBvLnJz..79e8118cd8465e62d5b5ab393968e6bf2af5dc09_cnVzdC9oZy1jb3JlL3NyYy9yZXBvLnJz 100644 --- a/rust/hg-core/src/repo.rs +++ b/rust/hg-core/src/repo.rs @@ -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; diff --git a/rust/hg-cpython/src/dirstate/dirstate_map.rs b/rust/hg-cpython/src/dirstate/dirstate_map.rs index 04b9a56c2d25223dc6560c5002644b46c40a4052_cnVzdC9oZy1jcHl0aG9uL3NyYy9kaXJzdGF0ZS9kaXJzdGF0ZV9tYXAucnM=..79e8118cd8465e62d5b5ab393968e6bf2af5dc09_cnVzdC9oZy1jcHl0aG9uL3NyYy9kaXJzdGF0ZS9kaXJzdGF0ZV9tYXAucnM= 100644 --- a/rust/hg-cpython/src/dirstate/dirstate_map.rs +++ b/rust/hg-cpython/src/dirstate/dirstate_map.rs @@ -14,7 +14,7 @@ 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, }, @@ -19,6 +19,7 @@ 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 diff --git a/rust/rhg/src/commands/status.rs b/rust/rhg/src/commands/status.rs index 04b9a56c2d25223dc6560c5002644b46c40a4052_cnVzdC9yaGcvc3JjL2NvbW1hbmRzL3N0YXR1cy5ycw==..79e8118cd8465e62d5b5ab393968e6bf2af5dc09_cnVzdC9yaGcvc3JjL2NvbW1hbmRzL3N0YXR1cy5ycw== 100644 --- a/rust/rhg/src/commands/status.rs +++ b/rust/rhg/src/commands/status.rs @@ -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; diff --git a/rust/rhg/src/error.rs b/rust/rhg/src/error.rs index 04b9a56c2d25223dc6560c5002644b46c40a4052_cnVzdC9yaGcvc3JjL2Vycm9yLnJz..79e8118cd8465e62d5b5ab393968e6bf2af5dc09_cnVzdC9yaGcvc3JjL2Vycm9yLnJz 100644 --- a/rust/rhg/src/error.rs +++ b/rust/rhg/src/error.rs @@ -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