##// END OF EJS Templates
match: add exact flag to match() to unify all match forms
Matt Mackall -
r8586:347fe1ac default
parent child Browse files
Show More
@@ -37,7 +37,7 b' class _match(object):'
37
37
38 class match(_match):
38 class match(_match):
39 def __init__(self, root, cwd, patterns, include=[], exclude=[],
39 def __init__(self, root, cwd, patterns, include=[], exclude=[],
40 default='glob'):
40 default='glob', exact=False):
41 """build an object to match a set of file patterns
41 """build an object to match a set of file patterns
42
42
43 arguments:
43 arguments:
@@ -47,6 +47,7 b' class match(_match):'
47 include - patterns to include
47 include - patterns to include
48 exclude - patterns to exclude
48 exclude - patterns to exclude
49 default - if a pattern in names has no explicit type, assume this one
49 default - if a pattern in names has no explicit type, assume this one
50 exact - patterns are actually literals
50
51
51 a pattern is one of:
52 a pattern is one of:
52 'glob:<glob>' - a glob relative to cwd
53 'glob:<glob>' - a glob relative to cwd
@@ -61,17 +62,20 b' class match(_match):'
61 roots = []
62 roots = []
62 anypats = bool(include or exclude)
63 anypats = bool(include or exclude)
63
64
64 if patterns:
65 if include:
66 im = _buildmatch(_normalize(include, 'glob', root, cwd), '(?:/|$)')
67 if exclude:
68 em = _buildmatch(_normalize(exclude, 'glob', root, cwd), '(?:/|$)')
69 if exact:
70 roots = patterns
71 pm = self.exact
72 elif patterns:
65 pats = _normalize(patterns, default, root, cwd)
73 pats = _normalize(patterns, default, root, cwd)
66 roots = _roots(pats)
74 roots = _roots(pats)
67 anypats = anypats or _anypats(pats)
75 anypats = anypats or _anypats(pats)
68 pm = _buildmatch(pats, '$')
76 pm = _buildmatch(pats, '$')
69 if include:
70 im = _buildmatch(_normalize(include, 'glob', root, cwd), '(?:/|$)')
71 if exclude:
72 em = _buildmatch(_normalize(exclude, 'glob', root, cwd), '(?:/|$)')
73
77
74 if patterns:
78 if patterns or exact:
75 if include:
79 if include:
76 if exclude:
80 if exclude:
77 m = lambda f: im(f) and not em(f) and pm(f)
81 m = lambda f: im(f) and not em(f) and pm(f)
@@ -96,17 +100,17 b' class match(_match):'
96
100
97 _match.__init__(self, root, cwd, roots, m, anypats)
101 _match.__init__(self, root, cwd, roots, m, anypats)
98
102
99 class exact(_match):
103 class exact(match):
100 def __init__(self, root, cwd, files):
104 def __init__(self, root, cwd, files):
101 _match.__init__(self, root, cwd, files, self.exact, False)
105 match.__init__(self, root, cwd, files, exact = True)
102
106
103 class always(match):
107 class always(match):
104 def __init__(self, root, cwd):
108 def __init__(self, root, cwd):
105 match.__init__(self, root, cwd, [])
109 match.__init__(self, root, cwd, [])
106
110
107 class never(exact):
111 class never(match):
108 def __init__(self, root, cwd):
112 def __init__(self, root, cwd):
109 exact.__init__(self, root, cwd, [])
113 match.__init__(self, root, cwd, [], exact = True)
110
114
111 def patkind(pat):
115 def patkind(pat):
112 return _patsplit(pat, None)[0]
116 return _patsplit(pat, None)[0]
General Comments 0
You need to be logged in to leave comments. Login now