Mercurial > hg
changeset 52304:04b9a56c2d25
rust-lib: only export very common types to the top of the crate
This was done very early in the Rust project's lifecycle and I had very little
Rust experience. Let's keep the `DirstateParents` since they'll pop up in
all higher-level code and make the rest more explicit imports to make the
imports less confusing and the lib less cluttered.
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Mon, 04 Nov 2024 11:13:05 +0100 |
parents | b422acba55f1 |
children | 79e8118cd846 |
files | rust/hg-core/src/dirstate/dirstate_map.rs rust/hg-core/src/lib.rs rust/hg-core/src/matchers.rs rust/hg-cpython/src/dirstate/dirs_multiset.rs rust/hg-cpython/src/dirstate/status.rs rust/rhg/src/commands/debugignorerhg.rs rust/rhg/src/commands/status.rs rust/rhg/src/error.rs |
diffstat | 8 files changed, 19 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/rust/hg-core/src/dirstate/dirstate_map.rs Mon Nov 04 11:07:05 2024 +0100 +++ b/rust/hg-core/src/dirstate/dirstate_map.rs Mon Nov 04 11:13:05 2024 +0100 @@ -8,6 +8,7 @@ use super::on_disk::DirstateV2ParseError; use super::owning::OwningDirstateMap; use super::path_with_basename::WithBasename; +use super::status::{DirstateStatus, StatusError, StatusOptions}; use crate::dirstate::entry::{ DirstateEntry, DirstateV2Data, ParentFileData, TruncatedTimestamp, }; @@ -22,11 +23,8 @@ use crate::DirstateError; use crate::DirstateMapError; use crate::DirstateParents; -use crate::DirstateStatus; use crate::FastHashbrownMap as FastHashMap; use crate::PatternFileWarning; -use crate::StatusError; -use crate::StatusOptions; /// Append to an existing data file if the amount of unreachable data (not used /// anymore) is less than this fraction of the total amount of existing data.
--- a/rust/hg-core/src/lib.rs Mon Nov 04 11:07:05 2024 +0100 +++ b/rust/hg-core/src/lib.rs Mon Nov 04 11:13:05 2024 +0100 @@ -16,14 +16,9 @@ pub mod fncache; pub mod requirements; pub mod testing; // unconditionally built, for use from integration tests -pub use dirstate::{ - dirs_multiset::{DirsMultiset, DirsMultisetIter}, - status::{ - BadMatch, BadType, DirstateStatus, HgPathCow, StatusError, - StatusOptions, - }, - DirstateParents, -}; + +// Export very common type to make discovery easier +pub use dirstate::DirstateParents; pub mod copy_tracing; pub mod filepatterns; pub mod matchers;
--- a/rust/hg-core/src/matchers.rs Mon Nov 04 11:07:05 2024 +0100 +++ b/rust/hg-core/src/matchers.rs Mon Nov 04 11:13:05 2024 +0100 @@ -11,7 +11,7 @@ use once_cell::sync::OnceCell; use crate::{ - dirstate::dirs_multiset::DirsChildrenMultiset, + dirstate::dirs_multiset::{DirsChildrenMultiset, DirsMultiset}, filepatterns::{ build_single_regex, filter_subincludes, get_patterns_from_file, PatternFileWarning, PatternResult, @@ -21,7 +21,7 @@ hg_path::{HgPath, HgPathBuf, HgPathError}, Escaped, }, - DirsMultiset, FastHashMap, IgnorePattern, PatternError, PatternSyntax, + FastHashMap, IgnorePattern, PatternError, PatternSyntax, }; use crate::dirstate::status::IgnoreFnType;
--- a/rust/hg-cpython/src/dirstate/dirs_multiset.rs Mon Nov 04 11:07:05 2024 +0100 +++ b/rust/hg-cpython/src/dirstate/dirs_multiset.rs Mon Nov 04 11:13:05 2024 +0100 @@ -16,8 +16,8 @@ }; use hg::{ + dirstate::dirs_multiset::{DirsMultiset, DirsMultisetIter}, utils::hg_path::{HgPath, HgPathBuf}, - DirsMultiset, DirsMultisetIter, }; py_class!(pub class Dirs |py| {
--- a/rust/hg-cpython/src/dirstate/status.rs Mon Nov 04 11:07:05 2024 +0100 +++ b/rust/hg-cpython/src/dirstate/status.rs Mon Nov 04 11:13:05 2024 +0100 @@ -14,7 +14,9 @@ exc::ValueError, ObjectProtocol, PyBool, PyBytes, PyErr, PyList, PyObject, PyResult, PyTuple, Python, PythonObject, ToPyObject, }; -use hg::dirstate::status::StatusPath; +use hg::dirstate::status::{ + BadMatch, DirstateStatus, StatusError, StatusOptions, StatusPath, +}; use hg::matchers::{ DifferenceMatcher, IntersectionMatcher, Matcher, NeverMatcher, PatternMatcher, UnionMatcher, @@ -26,8 +28,7 @@ files::{get_bytes_from_path, get_path_from_bytes}, hg_path::{HgPath, HgPathBuf}, }, - BadMatch, DirstateStatus, IgnorePattern, PatternError, PatternFileWarning, - StatusError, StatusOptions, + IgnorePattern, PatternError, PatternFileWarning, }; use std::borrow::Borrow;
--- a/rust/rhg/src/commands/debugignorerhg.rs Mon Nov 04 11:07:05 2024 +0100 +++ b/rust/rhg/src/commands/debugignorerhg.rs Mon Nov 04 11:13:05 2024 +0100 @@ -1,7 +1,6 @@ use crate::error::CommandError; -use hg; +use hg::dirstate::status::StatusError; use hg::matchers::get_ignore_matcher; -use hg::StatusError; use log::warn; pub const HELP_TEXT: &str = "
--- a/rust/rhg/src/commands/status.rs Mon Nov 04 11:07:05 2024 +0100 +++ b/rust/rhg/src/commands/status.rs Mon Nov 04 11:13:05 2024 +0100 @@ -15,7 +15,9 @@ use format_bytes::format_bytes; use hg::config::Config; use hg::dirstate::entry::{has_exec_bit, TruncatedTimestamp}; -use hg::dirstate::status::StatusPath; +use hg::dirstate::status::{ + BadMatch, DirstateStatus, StatusError, StatusOptions, StatusPath +}; use hg::errors::{HgError, IoResultExt}; use hg::filepatterns::parse_pattern_args; use hg::lock::LockError; @@ -29,11 +31,8 @@ get_bytes_from_os_str, get_bytes_from_os_string, get_path_from_bytes, }; use hg::utils::hg_path::{hg_path_to_path_buf, HgPath}; -use hg::DirstateStatus; use hg::PatternFileWarning; use hg::Revision; -use hg::StatusError; -use hg::StatusOptions; use hg::{self, narrow, sparse}; use log::info; use rayon::prelude::*; @@ -355,10 +354,10 @@ for (path, error) in take(&mut ds_status.bad) { let error = match error { - hg::BadMatch::OsError(code) => { + BadMatch::OsError(code) => { std::io::Error::from_raw_os_error(code).to_string() } - hg::BadMatch::BadType(ty) => { + BadMatch::BadType(ty) => { format!("unsupported file type (type is {})", ty) } };
--- a/rust/rhg/src/error.rs Mon Nov 04 11:07:05 2024 +0100 +++ b/rust/rhg/src/error.rs Mon Nov 04 11:13:05 2024 +0100 @@ -4,6 +4,7 @@ use format_bytes::format_bytes; use hg::config::{ConfigError, ConfigParseError, ConfigValueParseError}; use hg::dirstate::on_disk::DirstateV2ParseError; +use hg::dirstate::status::StatusError; use hg::errors::HgError; use hg::exit_codes; use hg::repo::RepoError; @@ -11,7 +12,7 @@ use hg::sparse::SparseConfigError; use hg::utils::files::get_bytes_from_path; use hg::utils::hg_path::HgPathError; -use hg::{DirstateError, DirstateMapError, PatternError, StatusError}; +use hg::{DirstateError, DirstateMapError, PatternError}; use std::convert::From; /// The kind of command error