Mercurial > hg
comparison mercurial/match.py @ 42084:42537dfc7a7c
match: add doctest examples in match()
Make the docstring raw, as it now includes escape characters.
author | Denis Laxalde <denis@laxalde.org> |
---|---|
date | Mon, 08 Apr 2019 09:34:50 +0200 |
parents | bee1647578b7 |
children | 54e6d7ef5ca5 |
comparison
equal
deleted
inserted
replaced
42083:bee1647578b7 | 42084:42537dfc7a7c |
---|---|
114 return unionmatcher(matchers) | 114 return unionmatcher(matchers) |
115 | 115 |
116 def match(root, cwd, patterns=None, include=None, exclude=None, default='glob', | 116 def match(root, cwd, patterns=None, include=None, exclude=None, default='glob', |
117 auditor=None, ctx=None, listsubrepos=False, warn=None, | 117 auditor=None, ctx=None, listsubrepos=False, warn=None, |
118 badfn=None, icasefs=False): | 118 badfn=None, icasefs=False): |
119 """build an object to match a set of file patterns | 119 r"""build an object to match a set of file patterns |
120 | 120 |
121 arguments: | 121 arguments: |
122 root - the canonical root of the tree you're matching against | 122 root - the canonical root of the tree you're matching against |
123 cwd - the current working directory, if relevant | 123 cwd - the current working directory, if relevant |
124 patterns - patterns to find | 124 patterns - patterns to find |
146 'set:<fileset>' - a fileset expression | 146 'set:<fileset>' - a fileset expression |
147 'include:<path>' - a file of patterns to read and include | 147 'include:<path>' - a file of patterns to read and include |
148 'subinclude:<path>' - a file of patterns to match against files under | 148 'subinclude:<path>' - a file of patterns to match against files under |
149 the same directory | 149 the same directory |
150 '<something>' - a pattern of the specified default type | 150 '<something>' - a pattern of the specified default type |
151 | |
152 Usually a patternmatcher is returned: | |
153 >>> match('foo', '.', ['re:.*\.c$', 'path:foo/a', '*.py']) | |
154 <patternmatcher patterns='.*\\.c$|foo/a(?:/|$)|[^/]*\\.py$'> | |
155 | |
156 Combining 'patterns' with 'include' (resp. 'exclude') gives an | |
157 intersectionmatcher (resp. a differencematcher): | |
158 >>> type(match('foo', '.', ['re:.*\.c$'], include=['path:lib'])) | |
159 <class 'mercurial.match.intersectionmatcher'> | |
160 >>> type(match('foo', '.', ['re:.*\.c$'], exclude=['path:build'])) | |
161 <class 'mercurial.match.differencematcher'> | |
162 | |
163 Notice that, if 'patterns' is empty, an alwaysmatcher is returned: | |
164 >>> match('foo', '.', []) | |
165 <alwaysmatcher> | |
166 | |
167 The 'default' argument determines which kind of pattern is assumed if a | |
168 pattern has no prefix: | |
169 >>> match('foo', '.', ['.*\.c$'], default='re') | |
170 <patternmatcher patterns='.*\\.c$'> | |
171 >>> match('foo', '.', ['main.py'], default='relpath') | |
172 <patternmatcher patterns='main\\.py(?:/|$)'> | |
173 >>> match('foo', '.', ['main.py'], default='re') | |
174 <patternmatcher patterns='main.py'> | |
175 | |
176 The primary use of matchers is to check whether a value (usually a file | |
177 name) matches againset one of the patterns given at initialization. There | |
178 are two ways of doing this check. | |
179 | |
180 >>> m = match('foo', '', ['re:.*\.c$', 'relpath:a']) | |
181 | |
182 1. Calling the matcher with a file name returns True if any pattern | |
183 matches that file name: | |
184 >>> bool(m('a')) | |
185 True | |
186 >>> bool(m('main.c')) | |
187 True | |
188 >>> bool(m('test.py')) | |
189 False | |
190 | |
191 2. Using the exact() method only returns True if the file name matches one | |
192 of the exact patterns (i.e. not re: or glob: patterns): | |
193 >>> m.exact('a') | |
194 True | |
195 >>> m.exact('main.c') | |
196 False | |
151 """ | 197 """ |
152 normalize = _donormalize | 198 normalize = _donormalize |
153 if icasefs: | 199 if icasefs: |
154 dirstate = ctx.repo().dirstate | 200 dirstate = ctx.repo().dirstate |
155 dsnormalize = dirstate.normalize | 201 dsnormalize = dirstate.normalize |