Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/fileset.py @ 45957:89a2afe31e82
formating: upgrade to black 20.8b1
This required a couple of small tweaks to un-confuse black, but now it
works. Big formatting changes come from:
* Dramatically improved collection-splitting logic upstream
* Black having a strong (correct IMO) opinion that """ is better than '''
Differential Revision: https://phab.mercurial-scm.org/D9430
author | Augie Fackler <raf@durin42.com> |
---|---|
date | Fri, 27 Nov 2020 17:03:29 -0500 |
parents | b7808443ed6a |
children | d4ba4d51f85f |
comparison
equal
deleted
inserted
replaced
45956:346af7687c6f | 45957:89a2afe31e82 |
---|---|
120 predicate = registrar.filesetpredicate(symbols) | 120 predicate = registrar.filesetpredicate(symbols) |
121 | 121 |
122 | 122 |
123 @predicate(b'modified()', callstatus=True, weight=_WEIGHT_STATUS) | 123 @predicate(b'modified()', callstatus=True, weight=_WEIGHT_STATUS) |
124 def modified(mctx, x): | 124 def modified(mctx, x): |
125 """File that is modified according to :hg:`status`. | 125 """File that is modified according to :hg:`status`.""" |
126 """ | |
127 # i18n: "modified" is a keyword | 126 # i18n: "modified" is a keyword |
128 getargs(x, 0, 0, _(b"modified takes no arguments")) | 127 getargs(x, 0, 0, _(b"modified takes no arguments")) |
129 s = set(mctx.status().modified) | 128 s = set(mctx.status().modified) |
130 return mctx.predicate(s.__contains__, predrepr=b'modified') | 129 return mctx.predicate(s.__contains__, predrepr=b'modified') |
131 | 130 |
132 | 131 |
133 @predicate(b'added()', callstatus=True, weight=_WEIGHT_STATUS) | 132 @predicate(b'added()', callstatus=True, weight=_WEIGHT_STATUS) |
134 def added(mctx, x): | 133 def added(mctx, x): |
135 """File that is added according to :hg:`status`. | 134 """File that is added according to :hg:`status`.""" |
136 """ | |
137 # i18n: "added" is a keyword | 135 # i18n: "added" is a keyword |
138 getargs(x, 0, 0, _(b"added takes no arguments")) | 136 getargs(x, 0, 0, _(b"added takes no arguments")) |
139 s = set(mctx.status().added) | 137 s = set(mctx.status().added) |
140 return mctx.predicate(s.__contains__, predrepr=b'added') | 138 return mctx.predicate(s.__contains__, predrepr=b'added') |
141 | 139 |
142 | 140 |
143 @predicate(b'removed()', callstatus=True, weight=_WEIGHT_STATUS) | 141 @predicate(b'removed()', callstatus=True, weight=_WEIGHT_STATUS) |
144 def removed(mctx, x): | 142 def removed(mctx, x): |
145 """File that is removed according to :hg:`status`. | 143 """File that is removed according to :hg:`status`.""" |
146 """ | |
147 # i18n: "removed" is a keyword | 144 # i18n: "removed" is a keyword |
148 getargs(x, 0, 0, _(b"removed takes no arguments")) | 145 getargs(x, 0, 0, _(b"removed takes no arguments")) |
149 s = set(mctx.status().removed) | 146 s = set(mctx.status().removed) |
150 return mctx.predicate(s.__contains__, predrepr=b'removed') | 147 return mctx.predicate(s.__contains__, predrepr=b'removed') |
151 | 148 |
152 | 149 |
153 @predicate(b'deleted()', callstatus=True, weight=_WEIGHT_STATUS) | 150 @predicate(b'deleted()', callstatus=True, weight=_WEIGHT_STATUS) |
154 def deleted(mctx, x): | 151 def deleted(mctx, x): |
155 """Alias for ``missing()``. | 152 """Alias for ``missing()``.""" |
156 """ | |
157 # i18n: "deleted" is a keyword | 153 # i18n: "deleted" is a keyword |
158 getargs(x, 0, 0, _(b"deleted takes no arguments")) | 154 getargs(x, 0, 0, _(b"deleted takes no arguments")) |
159 s = set(mctx.status().deleted) | 155 s = set(mctx.status().deleted) |
160 return mctx.predicate(s.__contains__, predrepr=b'deleted') | 156 return mctx.predicate(s.__contains__, predrepr=b'deleted') |
161 | 157 |
162 | 158 |
163 @predicate(b'missing()', callstatus=True, weight=_WEIGHT_STATUS) | 159 @predicate(b'missing()', callstatus=True, weight=_WEIGHT_STATUS) |
164 def missing(mctx, x): | 160 def missing(mctx, x): |
165 """File that is missing according to :hg:`status`. | 161 """File that is missing according to :hg:`status`.""" |
166 """ | |
167 # i18n: "missing" is a keyword | 162 # i18n: "missing" is a keyword |
168 getargs(x, 0, 0, _(b"missing takes no arguments")) | 163 getargs(x, 0, 0, _(b"missing takes no arguments")) |
169 s = set(mctx.status().deleted) | 164 s = set(mctx.status().deleted) |
170 return mctx.predicate(s.__contains__, predrepr=b'deleted') | 165 return mctx.predicate(s.__contains__, predrepr=b'deleted') |
171 | 166 |
188 return mctx.predicate(s.__contains__, predrepr=b'ignored') | 183 return mctx.predicate(s.__contains__, predrepr=b'ignored') |
189 | 184 |
190 | 185 |
191 @predicate(b'clean()', callstatus=True, weight=_WEIGHT_STATUS) | 186 @predicate(b'clean()', callstatus=True, weight=_WEIGHT_STATUS) |
192 def clean(mctx, x): | 187 def clean(mctx, x): |
193 """File that is clean according to :hg:`status`. | 188 """File that is clean according to :hg:`status`.""" |
194 """ | |
195 # i18n: "clean" is a keyword | 189 # i18n: "clean" is a keyword |
196 getargs(x, 0, 0, _(b"clean takes no arguments")) | 190 getargs(x, 0, 0, _(b"clean takes no arguments")) |
197 s = set(mctx.status().clean) | 191 s = set(mctx.status().clean) |
198 return mctx.predicate(s.__contains__, predrepr=b'clean') | 192 return mctx.predicate(s.__contains__, predrepr=b'clean') |
199 | 193 |
206 return mctx.predicate(mctx.ctx.__contains__, predrepr=b'tracked') | 200 return mctx.predicate(mctx.ctx.__contains__, predrepr=b'tracked') |
207 | 201 |
208 | 202 |
209 @predicate(b'binary()', weight=_WEIGHT_READ_CONTENTS) | 203 @predicate(b'binary()', weight=_WEIGHT_READ_CONTENTS) |
210 def binary(mctx, x): | 204 def binary(mctx, x): |
211 """File that appears to be binary (contains NUL bytes). | 205 """File that appears to be binary (contains NUL bytes).""" |
212 """ | |
213 # i18n: "binary" is a keyword | 206 # i18n: "binary" is a keyword |
214 getargs(x, 0, 0, _(b"binary takes no arguments")) | 207 getargs(x, 0, 0, _(b"binary takes no arguments")) |
215 return mctx.fpredicate( | 208 return mctx.fpredicate( |
216 lambda fctx: fctx.isbinary(), predrepr=b'binary', cache=True | 209 lambda fctx: fctx.isbinary(), predrepr=b'binary', cache=True |
217 ) | 210 ) |
218 | 211 |
219 | 212 |
220 @predicate(b'exec()') | 213 @predicate(b'exec()') |
221 def exec_(mctx, x): | 214 def exec_(mctx, x): |
222 """File that is marked as executable. | 215 """File that is marked as executable.""" |
223 """ | |
224 # i18n: "exec" is a keyword | 216 # i18n: "exec" is a keyword |
225 getargs(x, 0, 0, _(b"exec takes no arguments")) | 217 getargs(x, 0, 0, _(b"exec takes no arguments")) |
226 ctx = mctx.ctx | 218 ctx = mctx.ctx |
227 return mctx.predicate(lambda f: ctx.flags(f) == b'x', predrepr=b'exec') | 219 return mctx.predicate(lambda f: ctx.flags(f) == b'x', predrepr=b'exec') |
228 | 220 |
229 | 221 |
230 @predicate(b'symlink()') | 222 @predicate(b'symlink()') |
231 def symlink(mctx, x): | 223 def symlink(mctx, x): |
232 """File that is marked as a symlink. | 224 """File that is marked as a symlink.""" |
233 """ | |
234 # i18n: "symlink" is a keyword | 225 # i18n: "symlink" is a keyword |
235 getargs(x, 0, 0, _(b"symlink takes no arguments")) | 226 getargs(x, 0, 0, _(b"symlink takes no arguments")) |
236 ctx = mctx.ctx | 227 ctx = mctx.ctx |
237 return mctx.predicate(lambda f: ctx.flags(f) == b'l', predrepr=b'symlink') | 228 return mctx.predicate(lambda f: ctx.flags(f) == b'l', predrepr=b'symlink') |
238 | 229 |
239 | 230 |
240 @predicate(b'resolved()', weight=_WEIGHT_STATUS) | 231 @predicate(b'resolved()', weight=_WEIGHT_STATUS) |
241 def resolved(mctx, x): | 232 def resolved(mctx, x): |
242 """File that is marked resolved according to :hg:`resolve -l`. | 233 """File that is marked resolved according to :hg:`resolve -l`.""" |
243 """ | |
244 # i18n: "resolved" is a keyword | 234 # i18n: "resolved" is a keyword |
245 getargs(x, 0, 0, _(b"resolved takes no arguments")) | 235 getargs(x, 0, 0, _(b"resolved takes no arguments")) |
246 if mctx.ctx.rev() is not None: | 236 if mctx.ctx.rev() is not None: |
247 return mctx.never() | 237 return mctx.never() |
248 ms = mergestatemod.mergestate.read(mctx.ctx.repo()) | 238 ms = mergestatemod.mergestate.read(mctx.ctx.repo()) |
251 ) | 241 ) |
252 | 242 |
253 | 243 |
254 @predicate(b'unresolved()', weight=_WEIGHT_STATUS) | 244 @predicate(b'unresolved()', weight=_WEIGHT_STATUS) |
255 def unresolved(mctx, x): | 245 def unresolved(mctx, x): |
256 """File that is marked unresolved according to :hg:`resolve -l`. | 246 """File that is marked unresolved according to :hg:`resolve -l`.""" |
257 """ | |
258 # i18n: "unresolved" is a keyword | 247 # i18n: "unresolved" is a keyword |
259 getargs(x, 0, 0, _(b"unresolved takes no arguments")) | 248 getargs(x, 0, 0, _(b"unresolved takes no arguments")) |
260 if mctx.ctx.rev() is not None: | 249 if mctx.ctx.rev() is not None: |
261 return mctx.never() | 250 return mctx.never() |
262 ms = mergestatemod.mergestate.read(mctx.ctx.repo()) | 251 ms = mergestatemod.mergestate.read(mctx.ctx.repo()) |
265 ) | 254 ) |
266 | 255 |
267 | 256 |
268 @predicate(b'hgignore()', weight=_WEIGHT_STATUS) | 257 @predicate(b'hgignore()', weight=_WEIGHT_STATUS) |
269 def hgignore(mctx, x): | 258 def hgignore(mctx, x): |
270 """File that matches the active .hgignore pattern. | 259 """File that matches the active .hgignore pattern.""" |
271 """ | |
272 # i18n: "hgignore" is a keyword | 260 # i18n: "hgignore" is a keyword |
273 getargs(x, 0, 0, _(b"hgignore takes no arguments")) | 261 getargs(x, 0, 0, _(b"hgignore takes no arguments")) |
274 return mctx.ctx.repo().dirstate._ignore | 262 return mctx.ctx.repo().dirstate._ignore |
275 | 263 |
276 | 264 |
286 ) | 274 ) |
287 | 275 |
288 | 276 |
289 @predicate(b'grep(regex)', weight=_WEIGHT_READ_CONTENTS) | 277 @predicate(b'grep(regex)', weight=_WEIGHT_READ_CONTENTS) |
290 def grep(mctx, x): | 278 def grep(mctx, x): |
291 """File contains the given regular expression. | 279 """File contains the given regular expression.""" |
292 """ | |
293 try: | 280 try: |
294 # i18n: "grep" is a keyword | 281 # i18n: "grep" is a keyword |
295 r = re.compile(getstring(x, _(b"grep requires a pattern"))) | 282 r = re.compile(getstring(x, _(b"grep requires a pattern"))) |
296 except re.error as e: | 283 except re.error as e: |
297 raise error.ParseError( | 284 raise error.ParseError( |
412 return mctx.fpredicate(eolp, predrepr=(b'eol(%r)', enc), cache=True) | 399 return mctx.fpredicate(eolp, predrepr=(b'eol(%r)', enc), cache=True) |
413 | 400 |
414 | 401 |
415 @predicate(b'copied()') | 402 @predicate(b'copied()') |
416 def copied(mctx, x): | 403 def copied(mctx, x): |
417 """File that is recorded as being copied. | 404 """File that is recorded as being copied.""" |
418 """ | |
419 # i18n: "copied" is a keyword | 405 # i18n: "copied" is a keyword |
420 getargs(x, 0, 0, _(b"copied takes no arguments")) | 406 getargs(x, 0, 0, _(b"copied takes no arguments")) |
421 | 407 |
422 def copiedp(fctx): | 408 def copiedp(fctx): |
423 p = fctx.parents() | 409 p = fctx.parents() |
474 return getmatch(mc, x) | 460 return getmatch(mc, x) |
475 | 461 |
476 | 462 |
477 @predicate(b'subrepo([pattern])') | 463 @predicate(b'subrepo([pattern])') |
478 def subrepo(mctx, x): | 464 def subrepo(mctx, x): |
479 """Subrepositories whose paths match the given pattern. | 465 """Subrepositories whose paths match the given pattern.""" |
480 """ | |
481 # i18n: "subrepo" is a keyword | 466 # i18n: "subrepo" is a keyword |
482 getargs(x, 0, 1, _(b"subrepo takes at most one argument")) | 467 getargs(x, 0, 1, _(b"subrepo takes at most one argument")) |
483 ctx = mctx.ctx | 468 ctx = mctx.ctx |
484 sstate = ctx.substate | 469 sstate = ctx.substate |
485 if x: | 470 if x: |
626 mctx = matchctx(ctx.p1(), ctx, cwd, badfn=badfn) | 611 mctx = matchctx(ctx.p1(), ctx, cwd, badfn=badfn) |
627 return getmatch(mctx, tree) | 612 return getmatch(mctx, tree) |
628 | 613 |
629 | 614 |
630 def loadpredicate(ui, extname, registrarobj): | 615 def loadpredicate(ui, extname, registrarobj): |
631 """Load fileset predicates from specified registrarobj | 616 """Load fileset predicates from specified registrarobj""" |
632 """ | |
633 for name, func in pycompat.iteritems(registrarobj._table): | 617 for name, func in pycompat.iteritems(registrarobj._table): |
634 symbols[name] = func | 618 symbols[name] = func |
635 | 619 |
636 | 620 |
637 # tell hggettext to extract docstrings from these functions: | 621 # tell hggettext to extract docstrings from these functions: |