rust/hg-core/src/matchers.rs
changeset 49930 e98fd81bb151
parent 49913 c15b415d1bff
child 50695 1c31b343e514
equal deleted inserted replaced
49929:5f1cd6839c69 49930:e98fd81bb151
   300     fn exact_match(&self, _filename: &HgPath) -> bool {
   300     fn exact_match(&self, _filename: &HgPath) -> bool {
   301         false
   301         false
   302     }
   302     }
   303 
   303 
   304     fn matches(&self, filename: &HgPath) -> bool {
   304     fn matches(&self, filename: &HgPath) -> bool {
   305         (self.match_fn)(filename.as_ref())
   305         (self.match_fn)(filename)
   306     }
   306     }
   307 
   307 
   308     fn visit_children_set(&self, directory: &HgPath) -> VisitChildrenSet {
   308     fn visit_children_set(&self, directory: &HgPath) -> VisitChildrenSet {
   309         let dir = directory.as_ref();
   309         let dir = directory;
   310         if self.prefix && self.roots.contains(dir) {
   310         if self.prefix && self.roots.contains(dir) {
   311             return VisitChildrenSet::Recursive;
   311             return VisitChildrenSet::Recursive;
   312         }
   312         }
   313         if self.roots.contains(HgPath::new(b""))
   313         if self.roots.contains(HgPath::new(b""))
   314             || self.roots.contains(dir)
   314             || self.roots.contains(dir)
   316             || find_dirs(dir).any(|parent_dir| self.roots.contains(parent_dir))
   316             || find_dirs(dir).any(|parent_dir| self.roots.contains(parent_dir))
   317         {
   317         {
   318             return VisitChildrenSet::This;
   318             return VisitChildrenSet::This;
   319         }
   319         }
   320 
   320 
   321         if self.parents.contains(directory.as_ref()) {
   321         if self.parents.contains(dir.as_ref()) {
   322             let multiset = self.get_all_parents_children();
   322             let multiset = self.get_all_parents_children();
   323             if let Some(children) = multiset.get(dir) {
   323             if let Some(children) = multiset.get(dir) {
   324                 return VisitChildrenSet::Set(
   324                 return VisitChildrenSet::Set(
   325                     children.into_iter().map(HgPathBuf::from).collect(),
   325                     children.iter().map(HgPathBuf::from).collect(),
   326                 );
   326                 );
   327             }
   327             }
   328         }
   328         }
   329         VisitChildrenSet::Empty
   329         VisitChildrenSet::Empty
   330     }
   330     }
   444             (_, VisitChildrenSet::Recursive) => m1_set,
   444             (_, VisitChildrenSet::Recursive) => m1_set,
   445             (VisitChildrenSet::This, _) | (_, VisitChildrenSet::This) => {
   445             (VisitChildrenSet::This, _) | (_, VisitChildrenSet::This) => {
   446                 VisitChildrenSet::This
   446                 VisitChildrenSet::This
   447             }
   447             }
   448             (VisitChildrenSet::Set(m1), VisitChildrenSet::Set(m2)) => {
   448             (VisitChildrenSet::Set(m1), VisitChildrenSet::Set(m2)) => {
   449                 let set: HashSet<_> = m1.intersection(&m2).cloned().collect();
   449                 let set: HashSet<_> = m1.intersection(m2).cloned().collect();
   450                 if set.is_empty() {
   450                 if set.is_empty() {
   451                     VisitChildrenSet::Empty
   451                     VisitChildrenSet::Empty
   452                 } else {
   452                 } else {
   453                     VisitChildrenSet::Set(set)
   453                     VisitChildrenSet::Set(set)
   454                 }
   454                 }
   697         } = ignore_pattern;
   697         } = ignore_pattern;
   698         match syntax {
   698         match syntax {
   699             PatternSyntax::RootGlob | PatternSyntax::Glob => {
   699             PatternSyntax::RootGlob | PatternSyntax::Glob => {
   700                 let mut root = HgPathBuf::new();
   700                 let mut root = HgPathBuf::new();
   701                 for p in pattern.split(|c| *c == b'/') {
   701                 for p in pattern.split(|c| *c == b'/') {
   702                     if p.iter().any(|c| match *c {
   702                     if p.iter()
   703                         b'[' | b'{' | b'*' | b'?' => true,
   703                         .any(|c| matches!(*c, b'[' | b'{' | b'*' | b'?'))
   704                         _ => false,
   704                     {
   705                     }) {
       
   706                         break;
   705                         break;
   707                     }
   706                     }
   708                     root.push(HgPathBuf::from_bytes(p).as_ref());
   707                     root.push(HgPathBuf::from_bytes(p).as_ref());
   709                 }
   708                 }
   710                 roots.push(root);
   709                 roots.push(root);
   778     })
   777     })
   779 }
   778 }
   780 
   779 
   781 /// Returns a function that checks whether a given file (in the general sense)
   780 /// Returns a function that checks whether a given file (in the general sense)
   782 /// should be matched.
   781 /// should be matched.
   783 fn build_match<'a, 'b>(
   782 fn build_match<'a>(
   784     ignore_patterns: Vec<IgnorePattern>,
   783     ignore_patterns: Vec<IgnorePattern>,
   785 ) -> PatternResult<(Vec<u8>, IgnoreFnType<'b>)> {
   784 ) -> PatternResult<(Vec<u8>, IgnoreFnType<'a>)> {
   786     let mut match_funcs: Vec<IgnoreFnType<'b>> = vec![];
   785     let mut match_funcs: Vec<IgnoreFnType<'a>> = vec![];
   787     // For debugging and printing
   786     // For debugging and printing
   788     let mut patterns = vec![];
   787     let mut patterns = vec![];
   789 
   788 
   790     let (subincludes, ignore_patterns) = filter_subincludes(ignore_patterns)?;
   789     let (subincludes, ignore_patterns) = filter_subincludes(ignore_patterns)?;
   791 
   790 
   919         let RootsDirsAndParents {
   918         let RootsDirsAndParents {
   920             roots,
   919             roots,
   921             dirs,
   920             dirs,
   922             parents,
   921             parents,
   923         } = roots_dirs_and_parents(&ignore_patterns)?;
   922         } = roots_dirs_and_parents(&ignore_patterns)?;
   924         let prefix = ignore_patterns.iter().all(|k| match k.syntax {
   923         let prefix = ignore_patterns.iter().all(|k| {
   925             PatternSyntax::Path | PatternSyntax::RelPath => true,
   924             matches!(k.syntax, PatternSyntax::Path | PatternSyntax::RelPath)
   926             _ => false,
       
   927         });
   925         });
   928         let (patterns, match_fn) = build_match(ignore_patterns)?;
   926         let (patterns, match_fn) = build_match(ignore_patterns)?;
   929 
   927 
   930         Ok(Self {
   928         Ok(Self {
   931             patterns,
   929             patterns,