Mercurial > hg
diff rust/hg-core/src/lib.rs @ 44303:d42eea9a0494
rust-filepatterns: improve API and robustness for pattern files parsing
Within the next few patches we will be using this new API.
Differential Revision: https://phab.mercurial-scm.org/D7908
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Thu, 16 Jan 2020 10:28:40 +0100 |
parents | 934a79697c36 |
children | 2fe89bec8011 |
line wrap: on
line diff
--- a/rust/hg-core/src/lib.rs Tue Jan 14 17:10:20 2020 +0100 +++ b/rust/hg-core/src/lib.rs Thu Jan 16 10:28:40 2020 +0100 @@ -25,7 +25,8 @@ use crate::utils::hg_path::{HgPathBuf, HgPathError}; pub use filepatterns::{ - build_single_regex, read_pattern_file, PatternSyntax, PatternTuple, + parse_pattern_syntax, read_pattern_file, IgnorePattern, + PatternFileWarning, PatternSyntax, }; use std::collections::HashMap; use twox_hash::RandomXxHashBuilder64; @@ -115,18 +116,31 @@ #[derive(Debug)] pub enum PatternError { + Path(HgPathError), UnsupportedSyntax(String), + UnsupportedSyntaxInFile(String, String, usize), + TooLong(usize), + IO(std::io::Error), } -#[derive(Debug)] -pub enum PatternFileError { - IO(std::io::Error), - Pattern(PatternError, LineNumber), -} - -impl From<std::io::Error> for PatternFileError { - fn from(e: std::io::Error) -> Self { - PatternFileError::IO(e) +impl ToString for PatternError { + fn to_string(&self) -> String { + match self { + PatternError::UnsupportedSyntax(syntax) => { + format!("Unsupported syntax {}", syntax) + } + PatternError::UnsupportedSyntaxInFile(syntax, file_path, line) => { + format!( + "{}:{}: unsupported syntax {}", + file_path, line, syntax + ) + } + PatternError::TooLong(size) => { + format!("matcher pattern is too long ({} bytes)", size) + } + PatternError::IO(e) => e.to_string(), + PatternError::Path(e) => e.to_string(), + } } } @@ -141,3 +155,15 @@ DirstateError::IO(e) } } + +impl From<std::io::Error> for PatternError { + fn from(e: std::io::Error) -> Self { + PatternError::IO(e) + } +} + +impl From<HgPathError> for PatternError { + fn from(e: HgPathError) -> Self { + PatternError::Path(e) + } +}