rust/hg-core/src/lib.rs
changeset 44303 d42eea9a0494
parent 44283 934a79697c36
child 44304 2fe89bec8011
equal deleted inserted replaced
44301:4caac36c66bc 44303:d42eea9a0494
    23 pub use revlog::*;
    23 pub use revlog::*;
    24 pub mod utils;
    24 pub mod utils;
    25 
    25 
    26 use crate::utils::hg_path::{HgPathBuf, HgPathError};
    26 use crate::utils::hg_path::{HgPathBuf, HgPathError};
    27 pub use filepatterns::{
    27 pub use filepatterns::{
    28     build_single_regex, read_pattern_file, PatternSyntax, PatternTuple,
    28     parse_pattern_syntax, read_pattern_file, IgnorePattern,
       
    29     PatternFileWarning, PatternSyntax,
    29 };
    30 };
    30 use std::collections::HashMap;
    31 use std::collections::HashMap;
    31 use twox_hash::RandomXxHashBuilder64;
    32 use twox_hash::RandomXxHashBuilder64;
    32 
    33 
    33 pub type LineNumber = usize;
    34 pub type LineNumber = usize;
   113     }
   114     }
   114 }
   115 }
   115 
   116 
   116 #[derive(Debug)]
   117 #[derive(Debug)]
   117 pub enum PatternError {
   118 pub enum PatternError {
       
   119     Path(HgPathError),
   118     UnsupportedSyntax(String),
   120     UnsupportedSyntax(String),
       
   121     UnsupportedSyntaxInFile(String, String, usize),
       
   122     TooLong(usize),
       
   123     IO(std::io::Error),
   119 }
   124 }
   120 
   125 
   121 #[derive(Debug)]
   126 impl ToString for PatternError {
   122 pub enum PatternFileError {
   127     fn to_string(&self) -> String {
   123     IO(std::io::Error),
   128         match self {
   124     Pattern(PatternError, LineNumber),
   129             PatternError::UnsupportedSyntax(syntax) => {
   125 }
   130                 format!("Unsupported syntax {}", syntax)
   126 
   131             }
   127 impl From<std::io::Error> for PatternFileError {
   132             PatternError::UnsupportedSyntaxInFile(syntax, file_path, line) => {
   128     fn from(e: std::io::Error) -> Self {
   133                 format!(
   129         PatternFileError::IO(e)
   134                     "{}:{}: unsupported syntax {}",
       
   135                     file_path, line, syntax
       
   136                 )
       
   137             }
       
   138             PatternError::TooLong(size) => {
       
   139                 format!("matcher pattern is too long ({} bytes)", size)
       
   140             }
       
   141             PatternError::IO(e) => e.to_string(),
       
   142             PatternError::Path(e) => e.to_string(),
       
   143         }
   130     }
   144     }
   131 }
   145 }
   132 
   146 
   133 impl From<DirstateMapError> for DirstateError {
   147 impl From<DirstateMapError> for DirstateError {
   134     fn from(e: DirstateMapError) -> Self {
   148     fn from(e: DirstateMapError) -> Self {
   139 impl From<std::io::Error> for DirstateError {
   153 impl From<std::io::Error> for DirstateError {
   140     fn from(e: std::io::Error) -> Self {
   154     fn from(e: std::io::Error) -> Self {
   141         DirstateError::IO(e)
   155         DirstateError::IO(e)
   142     }
   156     }
   143 }
   157 }
       
   158 
       
   159 impl From<std::io::Error> for PatternError {
       
   160     fn from(e: std::io::Error) -> Self {
       
   161         PatternError::IO(e)
       
   162     }
       
   163 }
       
   164 
       
   165 impl From<HgPathError> for PatternError {
       
   166     fn from(e: HgPathError) -> Self {
       
   167         PatternError::Path(e)
       
   168     }
       
   169 }