comparison mercurial/match.py @ 25233:9789b4a7c595

match: introduce boolean prefix() method tl;dr: This is another step towards a (previously unstated) goal of eliminating match.files() in conditions. There are four types of matchers: * always: Matches everything, checked with always(), files() is empty * exact: Matches exact set of files, checked with isexact(), files() contains the files to match * patterns: Matches more complex patterns, checked with anypats(), files() contains roots of the matched patterns * prefix: Matches simple 'path:' patterns as prefixes ('foo' matches both 'foo' and 'foo/bar'), no single method to check, files() contains the prefixes to match For completeness, it would be nice to have a method for checking for the "prefix" type of matcher as well, so let's add that, making it return True simply when none of the others do. The larger goal here is to eliminate uses of match.files() in conditions (i.e. bool(match.files())). The reason for this is that there are scenarios when you would like to create a "prefix" matcher that happens to match no files. One example is for 'hg files -I foo bar'. The narrowmatcher also restricts the set of files given and it would not surprise me if have bugs caused by that already. Note that 'if m.files() and not m.anypats()' and similar is sometimes used to catch the "exact" and "prefix" cases above.
author Martin von Zweigbergk <martinvonz@google.com>
date Tue, 28 Oct 2014 22:47:22 -0700
parents 8545bd381504
children 5a55ad6e8e24
comparison
equal deleted inserted replaced
25232:e50d8b21f4f4 25233:9789b4a7c595
226 slightly different.''' 226 slightly different.'''
227 return not self._always 227 return not self._always
228 228
229 def isexact(self): 229 def isexact(self):
230 return self.matchfn == self.exact 230 return self.matchfn == self.exact
231
232 def prefix(self):
233 return not self.always() and not self.isexact() and not self.anypats()
231 234
232 def _normalize(self, patterns, default, root, cwd, auditor): 235 def _normalize(self, patterns, default, root, cwd, auditor):
233 '''Convert 'kind:pat' from the patterns list to tuples with kind and 236 '''Convert 'kind:pat' from the patterns list to tuples with kind and
234 normalized and rooted patterns and with listfiles expanded.''' 237 normalized and rooted patterns and with listfiles expanded.'''
235 kindpats = [] 238 kindpats = []