rust-lib: move `PatternError` to the `filepatterns` module
authorRaphaël Gomès <rgomes@octobus.net>
Mon, 04 Nov 2024 11:21:43 +0100
changeset 52306 f33b87b46135
parent 52305 79e8118cd846
child 52307 22d24f6d6411
rust-lib: move `PatternError` to the `filepatterns` module This is where it belongs
rust/hg-core/src/dirstate/status.rs
rust/hg-core/src/filepatterns.rs
rust/hg-core/src/lib.rs
rust/hg-core/src/matchers.rs
rust/hg-core/src/sparse.rs
rust/hg-cpython/src/dirstate/status.rs
rust/rhg/src/error.rs
--- a/rust/hg-core/src/dirstate/status.rs	Mon Nov 04 11:18:36 2024 +0100
+++ b/rust/hg-core/src/dirstate/status.rs	Mon Nov 04 11:21:43 2024 +0100
@@ -16,6 +16,7 @@
 use crate::dirstate::dirstate_map::NodeRef;
 use crate::dirstate::entry::TruncatedTimestamp;
 use crate::dirstate::on_disk::DirstateV2ParseError;
+use crate::filepatterns::PatternError;
 use crate::matchers::get_ignore_function;
 use crate::matchers::{Matcher, VisitChildrenSet};
 use crate::utils::files::filesystem_now;
@@ -24,8 +25,8 @@
 use crate::utils::files::get_path_from_bytes;
 use crate::utils::hg_path::hg_path_to_path_buf;
 use crate::utils::hg_path::HgPath;
+use crate::utils::hg_path::HgPathError;
 use crate::PatternFileWarning;
-use crate::{utils::hg_path::HgPathError, PatternError};
 use once_cell::sync::OnceCell;
 use rayon::prelude::*;
 use sha1::{Digest, Sha1};
--- a/rust/hg-core/src/filepatterns.rs	Mon Nov 04 11:18:36 2024 +0100
+++ b/rust/hg-core/src/filepatterns.rs	Mon Nov 04 11:21:43 2024 +0100
@@ -13,13 +13,52 @@
         hg_path::{path_to_hg_path_buf, HgPathBuf, HgPathError},
         SliceExt,
     },
-    FastHashMap, PatternError,
+    FastHashMap,
 };
 use lazy_static::lazy_static;
 use regex::bytes::{NoExpand, Regex};
-use std::ops::Deref;
 use std::path::{Path, PathBuf};
 use std::vec::Vec;
+use std::{fmt, ops::Deref};
+
+#[derive(Debug, derive_more::From)]
+pub enum PatternError {
+    #[from]
+    Path(HgPathError),
+    UnsupportedSyntax(String),
+    UnsupportedSyntaxInFile(String, String, usize),
+    TooLong(usize),
+    #[from]
+    IO(std::io::Error),
+    /// Needed a pattern that can be turned into a regex but got one that
+    /// can't. This should only happen through programmer error.
+    NonRegexPattern(IgnorePattern),
+}
+
+impl fmt::Display for PatternError {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        match self {
+            PatternError::UnsupportedSyntax(syntax) => {
+                write!(f, "Unsupported syntax {}", syntax)
+            }
+            PatternError::UnsupportedSyntaxInFile(syntax, file_path, line) => {
+                write!(
+                    f,
+                    "{}:{}: unsupported syntax {}",
+                    file_path, line, syntax
+                )
+            }
+            PatternError::TooLong(size) => {
+                write!(f, "matcher pattern is too long ({} bytes)", size)
+            }
+            PatternError::IO(error) => error.fmt(f),
+            PatternError::Path(error) => error.fmt(f),
+            PatternError::NonRegexPattern(pattern) => {
+                write!(f, "'{:?}' cannot be turned into a regex", pattern)
+            }
+        }
+    }
+}
 
 lazy_static! {
     static ref RE_ESCAPE: Vec<Vec<u8>> = {
--- a/rust/hg-core/src/lib.rs	Mon Nov 04 11:18:36 2024 +0100
+++ b/rust/hg-core/src/lib.rs	Mon Nov 04 11:21:43 2024 +0100
@@ -42,12 +42,10 @@
 pub mod utils;
 pub mod vfs;
 
-use crate::utils::hg_path::HgPathError;
 pub use filepatterns::{
     parse_pattern_syntax_kind, read_pattern_file, IgnorePattern,
     PatternFileWarning, PatternSyntax,
 };
-use std::fmt;
 use std::{collections::HashMap, sync::atomic::AtomicBool};
 use twox_hash::RandomXxHashBuilder64;
 
@@ -66,42 +64,3 @@
 // dirstate? How does XxHash compare with AHash, hashbrown’s default?
 pub type FastHashbrownMap<K, V> =
     hashbrown::HashMap<K, V, RandomXxHashBuilder64>;
-
-#[derive(Debug, derive_more::From)]
-pub enum PatternError {
-    #[from]
-    Path(HgPathError),
-    UnsupportedSyntax(String),
-    UnsupportedSyntaxInFile(String, String, usize),
-    TooLong(usize),
-    #[from]
-    IO(std::io::Error),
-    /// Needed a pattern that can be turned into a regex but got one that
-    /// can't. This should only happen through programmer error.
-    NonRegexPattern(IgnorePattern),
-}
-
-impl fmt::Display for PatternError {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        match self {
-            PatternError::UnsupportedSyntax(syntax) => {
-                write!(f, "Unsupported syntax {}", syntax)
-            }
-            PatternError::UnsupportedSyntaxInFile(syntax, file_path, line) => {
-                write!(
-                    f,
-                    "{}:{}: unsupported syntax {}",
-                    file_path, line, syntax
-                )
-            }
-            PatternError::TooLong(size) => {
-                write!(f, "matcher pattern is too long ({} bytes)", size)
-            }
-            PatternError::IO(error) => error.fmt(f),
-            PatternError::Path(error) => error.fmt(f),
-            PatternError::NonRegexPattern(pattern) => {
-                write!(f, "'{:?}' cannot be turned into a regex", pattern)
-            }
-        }
-    }
-}
--- a/rust/hg-core/src/matchers.rs	Mon Nov 04 11:18:36 2024 +0100
+++ b/rust/hg-core/src/matchers.rs	Mon Nov 04 11:21:43 2024 +0100
@@ -14,14 +14,14 @@
     dirstate::dirs_multiset::{DirsChildrenMultiset, DirsMultiset},
     filepatterns::{
         build_single_regex, filter_subincludes, get_patterns_from_file,
-        PatternFileWarning, PatternResult,
+        PatternError, PatternFileWarning, PatternResult,
     },
     utils::{
         files::{dir_ancestors, find_dirs},
         hg_path::{HgPath, HgPathBuf, HgPathError},
         Escaped,
     },
-    FastHashMap, IgnorePattern, PatternError, PatternSyntax,
+    FastHashMap, IgnorePattern, PatternSyntax,
 };
 
 use crate::dirstate::status::IgnoreFnType;
--- a/rust/hg-core/src/sparse.rs	Mon Nov 04 11:18:36 2024 +0100
+++ b/rust/hg-core/src/sparse.rs	Mon Nov 04 11:21:43 2024 +0100
@@ -5,7 +5,7 @@
 use crate::{
     errors::HgError,
     exit_codes::STATE_ERROR,
-    filepatterns::parse_pattern_file_contents,
+    filepatterns::{PatternError, parse_pattern_file_contents},
     matchers::{
         AlwaysMatcher, DifferenceMatcher, IncludeMatcher, Matcher,
         UnionMatcher,
@@ -15,7 +15,7 @@
     repo::Repo,
     requirements::SPARSE_REQUIREMENT,
     utils::{hg_path::HgPath, SliceExt},
-    IgnorePattern, PatternError, PatternFileWarning, PatternSyntax, Revision,
+    IgnorePattern, PatternFileWarning, PatternSyntax, Revision,
     NULL_REVISION,
 };
 
--- a/rust/hg-cpython/src/dirstate/status.rs	Mon Nov 04 11:18:36 2024 +0100
+++ b/rust/hg-cpython/src/dirstate/status.rs	Mon Nov 04 11:21:43 2024 +0100
@@ -17,6 +17,7 @@
 use hg::dirstate::status::{
     BadMatch, DirstateStatus, StatusError, StatusOptions, StatusPath,
 };
+use hg::filepatterns::PatternError;
 use hg::matchers::{
     DifferenceMatcher, IntersectionMatcher, Matcher, NeverMatcher,
     PatternMatcher, UnionMatcher,
@@ -28,7 +29,7 @@
         files::{get_bytes_from_path, get_path_from_bytes},
         hg_path::{HgPath, HgPathBuf},
     },
-    IgnorePattern, PatternError, PatternFileWarning,
+    IgnorePattern, PatternFileWarning,
 };
 use std::borrow::Borrow;
 
--- a/rust/rhg/src/error.rs	Mon Nov 04 11:18:36 2024 +0100
+++ b/rust/rhg/src/error.rs	Mon Nov 04 11:21:43 2024 +0100
@@ -9,12 +9,12 @@
 use hg::dirstate::DirstateMapError;
 use hg::errors::HgError;
 use hg::exit_codes;
+use hg::filepatterns::PatternError;
 use hg::repo::RepoError;
 use hg::revlog::RevlogError;
 use hg::sparse::SparseConfigError;
 use hg::utils::files::get_bytes_from_path;
 use hg::utils::hg_path::HgPathError;
-use hg::PatternError;
 use std::convert::From;
 
 /// The kind of command error