types.rs (ripgrep-12.1.1) | : | types.rs (ripgrep-13.0.0) | ||
---|---|---|---|---|
skipping to change at line 96 | skipping to change at line 96 | |||
use std::cell::RefCell; | use std::cell::RefCell; | |||
use std::collections::HashMap; | use std::collections::HashMap; | |||
use std::path::Path; | use std::path::Path; | |||
use std::sync::Arc; | use std::sync::Arc; | |||
use globset::{GlobBuilder, GlobSet, GlobSetBuilder}; | use globset::{GlobBuilder, GlobSet, GlobSetBuilder}; | |||
use regex::Regex; | use regex::Regex; | |||
use thread_local::ThreadLocal; | use thread_local::ThreadLocal; | |||
use default_types::DEFAULT_TYPES; | use crate::default_types::DEFAULT_TYPES; | |||
use pathutil::file_name; | use crate::pathutil::file_name; | |||
use {Error, Match}; | use crate::{Error, Match}; | |||
/// Glob represents a single glob in a set of file type definitions. | /// Glob represents a single glob in a set of file type definitions. | |||
/// | /// | |||
/// There may be more than one glob for a particular file type. | /// There may be more than one glob for a particular file type. | |||
/// | /// | |||
/// This is used to report information about the highest precedent glob | /// This is used to report information about the highest precedent glob | |||
/// that matched. | /// that matched. | |||
/// | /// | |||
/// Note that not all matches necessarily correspond to a specific glob. | /// Note that not all matches necessarily correspond to a specific glob. | |||
/// For example, if there are one or more selections and a file path doesn't | /// For example, if there are one or more selections and a file path doesn't | |||
skipping to change at line 137 | skipping to change at line 137 | |||
/// Whether the selection was negated or not. | /// Whether the selection was negated or not. | |||
negated: bool, | negated: bool, | |||
}, | }, | |||
} | } | |||
impl<'a> Glob<'a> { | impl<'a> Glob<'a> { | |||
fn unmatched() -> Glob<'a> { | fn unmatched() -> Glob<'a> { | |||
Glob(GlobInner::UnmatchedIgnore) | Glob(GlobInner::UnmatchedIgnore) | |||
} | } | |||
/// Return the file type defintion that matched, if one exists. A file type | /// Return the file type definition that matched, if one exists. A file type | |||
/// definition always exists when a specific definition matches a file | /// definition always exists when a specific definition matches a file | |||
/// path. | /// path. | |||
pub fn file_type_def(&self) -> Option<&FileTypeDef> { | pub fn file_type_def(&self) -> Option<&FileTypeDef> { | |||
match self { | match self { | |||
Glob(GlobInner::UnmatchedIgnore) => None, | Glob(GlobInner::UnmatchedIgnore) => None, | |||
Glob(GlobInner::Matched { def, .. }) => Some(def), | Glob(GlobInner::Matched { def, .. }) => Some(def), | |||
} | } | |||
} | } | |||
} | } | |||
skipping to change at line 430 | skipping to change at line 430 | |||
self.types.remove(name); | self.types.remove(name); | |||
self | self | |||
} | } | |||
/// Add a new file type definition. `name` can be arbitrary and `pat` | /// Add a new file type definition. `name` can be arbitrary and `pat` | |||
/// should be a glob recognizing file paths belonging to the `name` type. | /// should be a glob recognizing file paths belonging to the `name` type. | |||
/// | /// | |||
/// If `name` is `all` or otherwise contains any character that is not a | /// If `name` is `all` or otherwise contains any character that is not a | |||
/// Unicode letter or number, then an error is returned. | /// Unicode letter or number, then an error is returned. | |||
pub fn add(&mut self, name: &str, glob: &str) -> Result<(), Error> { | pub fn add(&mut self, name: &str, glob: &str) -> Result<(), Error> { | |||
lazy_static! { | lazy_static::lazy_static! { | |||
static ref RE: Regex = Regex::new(r"^[\pL\pN]+$").unwrap(); | static ref RE: Regex = Regex::new(r"^[\pL\pN]+$").unwrap(); | |||
}; | }; | |||
if name == "all" || !RE.is_match(name) { | if name == "all" || !RE.is_match(name) { | |||
return Err(Error::InvalidDefinition); | return Err(Error::InvalidDefinition); | |||
} | } | |||
let (key, glob) = (name.to_string(), glob.to_string()); | let (key, glob) = (name.to_string(), glob.to_string()); | |||
self.types | self.types | |||
.entry(key) | .entry(key) | |||
.or_insert_with(|| FileTypeDef { | .or_insert_with(|| FileTypeDef { | |||
name: name.to_string(), | name: name.to_string(), | |||
End of changes. 3 change blocks. | ||||
5 lines changed or deleted | 5 lines changed or added |