diff rust/hg-core/src/matchers.rs @ 52352:2ff004fb491c

hgignore: add a GlobSuffix type, instead of passing byte arrays I think this makes it easier to understand the purpose of this extra argument.
author Arseniy Alekseyev <aalekseyev@janestreet.com>
date Mon, 02 Dec 2024 11:25:26 +0000
parents a876ab6c3fd5
children e2e49069eeb6
line wrap: on
line diff
--- a/rust/hg-core/src/matchers.rs	Fri Nov 29 19:43:39 2024 -0500
+++ b/rust/hg-core/src/matchers.rs	Mon Dec 02 11:25:26 2024 +0000
@@ -14,8 +14,8 @@
     dirstate::dirs_multiset::{DirsChildrenMultiset, DirsMultiset},
     filepatterns::{
         build_single_regex, filter_subincludes, get_patterns_from_file,
-        IgnorePattern, PatternError, PatternFileWarning, PatternResult,
-        PatternSyntax,
+        GlobSuffix, IgnorePattern, PatternError, PatternFileWarning,
+        PatternResult, PatternSyntax,
     },
     utils::{
         files::{dir_ancestors, find_dirs},
@@ -328,7 +328,8 @@
         let prefix = ignore_patterns.iter().all(|k| {
             matches!(k.syntax, PatternSyntax::Path | PatternSyntax::RelPath)
         });
-        let (patterns, match_fn) = build_match(ignore_patterns, b"$")?;
+        let (patterns, match_fn) =
+            build_match(ignore_patterns, GlobSuffix::Empty)?;
 
         Ok(Self {
             patterns,
@@ -807,7 +808,7 @@
 /// said regex formed by the given ignore patterns.
 fn build_regex_match<'a>(
     ignore_patterns: &[IgnorePattern],
-    glob_suffix: &[u8],
+    glob_suffix: GlobSuffix,
 ) -> PatternResult<(Vec<u8>, IgnoreFnType<'a>)> {
     let mut regexps = vec![];
     let mut exact_set = HashSet::new();
@@ -927,7 +928,7 @@
 /// should be matched.
 fn build_match<'a>(
     ignore_patterns: Vec<IgnorePattern>,
-    glob_suffix: &[u8],
+    glob_suffix: GlobSuffix,
 ) -> PatternResult<(Vec<u8>, IgnoreFnType<'a>)> {
     let mut match_funcs: Vec<IgnoreFnType<'a>> = vec![];
     // For debugging and printing
@@ -1067,7 +1068,8 @@
         let prefix = ignore_patterns.iter().all(|k| {
             matches!(k.syntax, PatternSyntax::Path | PatternSyntax::RelPath)
         });
-        let (patterns, match_fn) = build_match(ignore_patterns, b"(?:/|$)")?;
+        let (patterns, match_fn) =
+            build_match(ignore_patterns, GlobSuffix::MoreComponents)?;
 
         Ok(Self {
             patterns,