annotate mercurial/fileset.py @ 48676:3f618484eeb6 stable

transaction: add a way to know a transaction has been finalized This will be useful to fix the timing of the branchmap on disk caching. Differential Revision: https://phab.mercurial-scm.org/D12127
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 31 Jan 2022 19:28:58 +0100
parents d4ba4d51f85f
children 6000f5b25c9b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14511
30506b894359 filesets: introduce basic fileset expression parser
Matt Mackall <mpm@selenic.com>
parents: 14509
diff changeset
1 # fileset.py - file set queries for mercurial
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
2 #
46819
d4ba4d51f85f contributor: change mentions of mpm to olivia
Raphaël Gomès <rgomes@octobus.net>
parents: 45942
diff changeset
3 # Copyright 2010 Olivia Mackall <olivia@selenic.com>
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
4 #
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
5 # This software may be used and distributed according to the terms of the
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
6 # GNU General Public License version 2 or any later version.
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
7
25938
e194ada8d45f fileset: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25815
diff changeset
8 from __future__ import absolute_import
e194ada8d45f fileset: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25815
diff changeset
9
38684
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38613
diff changeset
10 import errno
20034
1e5b38a919dd cleanup: move stdlib imports to their own import statement
Augie Fackler <raf@durin42.com>
parents: 19470
diff changeset
11 import re
25938
e194ada8d45f fileset: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25815
diff changeset
12
e194ada8d45f fileset: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25815
diff changeset
13 from .i18n import _
43089
c59eb1560c44 py3: manually import getattr where it is needed
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43077
diff changeset
14 from .pycompat import getattr
25938
e194ada8d45f fileset: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25815
diff changeset
15 from . import (
e194ada8d45f fileset: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25815
diff changeset
16 error,
38805
b9162ea1b815 fileset: extract language processing part to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38804
diff changeset
17 filesetlang,
35739
9eb5c400f488 fileset: move import of match module to top
Yuya Nishihara <yuya@tcha.org>
parents: 35692
diff changeset
18 match as matchmod,
44856
b7808443ed6a mergestate: split out merge state handling code from main merge module
Augie Fackler <augie@google.com>
parents: 44009
diff changeset
19 mergestate as mergestatemod,
32523
1fb0a85fb20e py3: use pycompat.bytestr so that we don't get ascii values
Pulkit Goyal <7895pulkit@gmail.com>
parents: 32291
diff changeset
20 pycompat,
28448
7108834c76a2 fileset: replace predicate by filesetpredicate of registrar (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28447
diff changeset
21 registrar,
31193
4140d49d2efb fileset: add revs(revs, fileset) to evaluate set in working directory
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31192
diff changeset
22 scmutil,
25938
e194ada8d45f fileset: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25815
diff changeset
23 util,
e194ada8d45f fileset: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25815
diff changeset
24 )
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
25 from .utils import stringutil
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
26
38863
61ab546b71c3 fileset: introduce weight constants for readability
Yuya Nishihara <yuya@tcha.org>
parents: 38830
diff changeset
27 # common weight constants
61ab546b71c3 fileset: introduce weight constants for readability
Yuya Nishihara <yuya@tcha.org>
parents: 38830
diff changeset
28 _WEIGHT_CHECK_FILENAME = filesetlang.WEIGHT_CHECK_FILENAME
61ab546b71c3 fileset: introduce weight constants for readability
Yuya Nishihara <yuya@tcha.org>
parents: 38830
diff changeset
29 _WEIGHT_READ_CONTENTS = filesetlang.WEIGHT_READ_CONTENTS
61ab546b71c3 fileset: introduce weight constants for readability
Yuya Nishihara <yuya@tcha.org>
parents: 38830
diff changeset
30 _WEIGHT_STATUS = filesetlang.WEIGHT_STATUS
61ab546b71c3 fileset: introduce weight constants for readability
Yuya Nishihara <yuya@tcha.org>
parents: 38830
diff changeset
31 _WEIGHT_STATUS_THOROUGH = filesetlang.WEIGHT_STATUS_THOROUGH
61ab546b71c3 fileset: introduce weight constants for readability
Yuya Nishihara <yuya@tcha.org>
parents: 38830
diff changeset
32
38805
b9162ea1b815 fileset: extract language processing part to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38804
diff changeset
33 # helpers for processing parsed tree
b9162ea1b815 fileset: extract language processing part to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38804
diff changeset
34 getsymbol = filesetlang.getsymbol
b9162ea1b815 fileset: extract language processing part to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38804
diff changeset
35 getstring = filesetlang.getstring
b9162ea1b815 fileset: extract language processing part to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38804
diff changeset
36 _getkindpat = filesetlang.getkindpat
b9162ea1b815 fileset: extract language processing part to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38804
diff changeset
37 getpattern = filesetlang.getpattern
b9162ea1b815 fileset: extract language processing part to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38804
diff changeset
38 getargs = filesetlang.getargs
38598
d046bf37f1ba fileset: move helper functions to top
Yuya Nishihara <yuya@tcha.org>
parents: 38414
diff changeset
39
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
40
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
41 def getmatch(mctx, x):
14551
68d814a3cefd fileset: basic pattern and boolean support
Matt Mackall <mpm@selenic.com>
parents: 14513
diff changeset
42 if not x:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
43 raise error.ParseError(_(b"missing argument"))
14551
68d814a3cefd fileset: basic pattern and boolean support
Matt Mackall <mpm@selenic.com>
parents: 14513
diff changeset
44 return methods[x[0]](mctx, *x[1:])
68d814a3cefd fileset: basic pattern and boolean support
Matt Mackall <mpm@selenic.com>
parents: 14513
diff changeset
45
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
46
38879
e79a69af1593 fileset: insert hints where status should be computed
Yuya Nishihara <yuya@tcha.org>
parents: 38878
diff changeset
47 def getmatchwithstatus(mctx, x, hint):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
48 keys = set(getstring(hint, b'status hint must be a string').split())
38880
80fd7371f2d8 fileset: build status according to 'withstatus' hint
Yuya Nishihara <yuya@tcha.org>
parents: 38879
diff changeset
49 return getmatch(mctx.withstatus(keys), x)
38879
e79a69af1593 fileset: insert hints where status should be computed
Yuya Nishihara <yuya@tcha.org>
parents: 38878
diff changeset
50
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
51
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
52 def stringmatch(mctx, x):
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
53 return mctx.matcher([x])
14551
68d814a3cefd fileset: basic pattern and boolean support
Matt Mackall <mpm@selenic.com>
parents: 14513
diff changeset
54
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
55
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
56 def kindpatmatch(mctx, x, y):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
57 return stringmatch(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
58 mctx,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
59 _getkindpat(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
60 x, y, matchmod.allpatternkinds, _(b"pattern must be a string")
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
61 ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
62 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
63
35741
73432eee0ac4 fileset: add kind:pat operator
Yuya Nishihara <yuya@tcha.org>
parents: 35739
diff changeset
64
38865
899b4c74209c fileset: combine union of basic patterns into single matcher
Yuya Nishihara <yuya@tcha.org>
parents: 38863
diff changeset
65 def patternsmatch(mctx, *xs):
899b4c74209c fileset: combine union of basic patterns into single matcher
Yuya Nishihara <yuya@tcha.org>
parents: 38863
diff changeset
66 allkinds = matchmod.allpatternkinds
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
67 patterns = [
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
68 getpattern(x, allkinds, _(b"pattern must be a string")) for x in xs
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
69 ]
38865
899b4c74209c fileset: combine union of basic patterns into single matcher
Yuya Nishihara <yuya@tcha.org>
parents: 38863
diff changeset
70 return mctx.matcher(patterns)
899b4c74209c fileset: combine union of basic patterns into single matcher
Yuya Nishihara <yuya@tcha.org>
parents: 38863
diff changeset
71
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
72
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
73 def andmatch(mctx, x, y):
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
74 xm = getmatch(mctx, x)
38882
ff42ec7845e4 fileset: narrow status computation by left-hand-side of 'and' node
Yuya Nishihara <yuya@tcha.org>
parents: 38881
diff changeset
75 ym = getmatch(mctx.narrowed(xm), y)
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
76 return matchmod.intersectmatchers(xm, ym)
14551
68d814a3cefd fileset: basic pattern and boolean support
Matt Mackall <mpm@selenic.com>
parents: 14513
diff changeset
77
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
78
38804
d82c4d42b615 fileset: flatten 'or' nodes to unnest unionmatchers
Yuya Nishihara <yuya@tcha.org>
parents: 38803
diff changeset
79 def ormatch(mctx, *xs):
d82c4d42b615 fileset: flatten 'or' nodes to unnest unionmatchers
Yuya Nishihara <yuya@tcha.org>
parents: 38803
diff changeset
80 ms = [getmatch(mctx, x) for x in xs]
d82c4d42b615 fileset: flatten 'or' nodes to unnest unionmatchers
Yuya Nishihara <yuya@tcha.org>
parents: 38803
diff changeset
81 return matchmod.unionmatcher(ms)
14551
68d814a3cefd fileset: basic pattern and boolean support
Matt Mackall <mpm@selenic.com>
parents: 14513
diff changeset
82
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
83
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
84 def notmatch(mctx, x):
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
85 m = getmatch(mctx, x)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
86 return mctx.predicate(lambda f: not m(f), predrepr=(b'<not %r>', m))
14551
68d814a3cefd fileset: basic pattern and boolean support
Matt Mackall <mpm@selenic.com>
parents: 14513
diff changeset
87
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
88
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
89 def minusmatch(mctx, x, y):
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
90 xm = getmatch(mctx, x)
38882
ff42ec7845e4 fileset: narrow status computation by left-hand-side of 'and' node
Yuya Nishihara <yuya@tcha.org>
parents: 38881
diff changeset
91 ym = getmatch(mctx.narrowed(xm), y)
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
92 return matchmod.differencematcher(xm, ym)
17363
5d9e2031c0b1 fileset: actually implement 'minusset'
Patrick Mezard <patrick@mezard.eu>
parents: 16443
diff changeset
93
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
94
38803
4dc498d61d86 fileset: flatten arguments list
Yuya Nishihara <yuya@tcha.org>
parents: 38772
diff changeset
95 def listmatch(mctx, *xs):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
96 raise error.ParseError(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
97 _(b"can't use a list in this context"),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
98 hint=_(b'see \'hg help "filesets.x or y"\''),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
99 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
100
14551
68d814a3cefd fileset: basic pattern and boolean support
Matt Mackall <mpm@selenic.com>
parents: 14513
diff changeset
101
38598
d046bf37f1ba fileset: move helper functions to top
Yuya Nishihara <yuya@tcha.org>
parents: 38414
diff changeset
102 def func(mctx, a, b):
d046bf37f1ba fileset: move helper functions to top
Yuya Nishihara <yuya@tcha.org>
parents: 38414
diff changeset
103 funcname = getsymbol(a)
d046bf37f1ba fileset: move helper functions to top
Yuya Nishihara <yuya@tcha.org>
parents: 38414
diff changeset
104 if funcname in symbols:
38690
5d9749c598f0 fileset: remove callexisting flag and mctx.existing() (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38689
diff changeset
105 return symbols[funcname](mctx, b)
38598
d046bf37f1ba fileset: move helper functions to top
Yuya Nishihara <yuya@tcha.org>
parents: 38414
diff changeset
106
d046bf37f1ba fileset: move helper functions to top
Yuya Nishihara <yuya@tcha.org>
parents: 38414
diff changeset
107 keep = lambda fn: getattr(fn, '__doc__', None) is not None
d046bf37f1ba fileset: move helper functions to top
Yuya Nishihara <yuya@tcha.org>
parents: 38414
diff changeset
108
d046bf37f1ba fileset: move helper functions to top
Yuya Nishihara <yuya@tcha.org>
parents: 38414
diff changeset
109 syms = [s for (s, fn) in symbols.items() if keep(fn)]
d046bf37f1ba fileset: move helper functions to top
Yuya Nishihara <yuya@tcha.org>
parents: 38414
diff changeset
110 raise error.UnknownIdentifier(funcname, syms)
d046bf37f1ba fileset: move helper functions to top
Yuya Nishihara <yuya@tcha.org>
parents: 38414
diff changeset
111
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
112
27460
11286ac374f3 fileset: use decorator to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27459
diff changeset
113 # symbols are callable like:
11286ac374f3 fileset: use decorator to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27459
diff changeset
114 # fun(mctx, x)
11286ac374f3 fileset: use decorator to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27459
diff changeset
115 # with:
11286ac374f3 fileset: use decorator to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27459
diff changeset
116 # mctx - current matchctx instance
11286ac374f3 fileset: use decorator to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27459
diff changeset
117 # x - argument in tree form
38805
b9162ea1b815 fileset: extract language processing part to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38804
diff changeset
118 symbols = filesetlang.symbols
27460
11286ac374f3 fileset: use decorator to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27459
diff changeset
119
38927
aebfc4c5c855 fileset: load core predicates directly to symbols dict
Yuya Nishihara <yuya@tcha.org>
parents: 38926
diff changeset
120 predicate = registrar.filesetpredicate(symbols)
27460
11286ac374f3 fileset: use decorator to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27459
diff changeset
121
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
122
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
123 @predicate(b'modified()', callstatus=True, weight=_WEIGHT_STATUS)
14677
2a758ffc821e fileset: add support for file status predicates
Matt Mackall <mpm@selenic.com>
parents: 14676
diff changeset
124 def modified(mctx, x):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 44856
diff changeset
125 """File that is modified according to :hg:`status`."""
14785
0f0bd4d028d3 fileset: add i18n hints for keywords
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 14718
diff changeset
126 # i18n: "modified" is a keyword
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
127 getargs(x, 0, 0, _(b"modified takes no arguments"))
31697
992882cef7e1 fileset: perform membership test against set for status queries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31254
diff changeset
128 s = set(mctx.status().modified)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
129 return mctx.predicate(s.__contains__, predrepr=b'modified')
14677
2a758ffc821e fileset: add support for file status predicates
Matt Mackall <mpm@selenic.com>
parents: 14676
diff changeset
130
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
131
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
132 @predicate(b'added()', callstatus=True, weight=_WEIGHT_STATUS)
14677
2a758ffc821e fileset: add support for file status predicates
Matt Mackall <mpm@selenic.com>
parents: 14676
diff changeset
133 def added(mctx, x):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 44856
diff changeset
134 """File that is added according to :hg:`status`."""
14785
0f0bd4d028d3 fileset: add i18n hints for keywords
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 14718
diff changeset
135 # i18n: "added" is a keyword
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
136 getargs(x, 0, 0, _(b"added takes no arguments"))
31697
992882cef7e1 fileset: perform membership test against set for status queries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31254
diff changeset
137 s = set(mctx.status().added)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
138 return mctx.predicate(s.__contains__, predrepr=b'added')
14677
2a758ffc821e fileset: add support for file status predicates
Matt Mackall <mpm@selenic.com>
parents: 14676
diff changeset
139
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
140
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
141 @predicate(b'removed()', callstatus=True, weight=_WEIGHT_STATUS)
14677
2a758ffc821e fileset: add support for file status predicates
Matt Mackall <mpm@selenic.com>
parents: 14676
diff changeset
142 def removed(mctx, x):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 44856
diff changeset
143 """File that is removed according to :hg:`status`."""
14785
0f0bd4d028d3 fileset: add i18n hints for keywords
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 14718
diff changeset
144 # i18n: "removed" is a keyword
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
145 getargs(x, 0, 0, _(b"removed takes no arguments"))
31697
992882cef7e1 fileset: perform membership test against set for status queries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31254
diff changeset
146 s = set(mctx.status().removed)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
147 return mctx.predicate(s.__contains__, predrepr=b'removed')
14677
2a758ffc821e fileset: add support for file status predicates
Matt Mackall <mpm@selenic.com>
parents: 14676
diff changeset
148
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
149
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
150 @predicate(b'deleted()', callstatus=True, weight=_WEIGHT_STATUS)
14677
2a758ffc821e fileset: add support for file status predicates
Matt Mackall <mpm@selenic.com>
parents: 14676
diff changeset
151 def deleted(mctx, x):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 44856
diff changeset
152 """Alias for ``missing()``."""
14785
0f0bd4d028d3 fileset: add i18n hints for keywords
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 14718
diff changeset
153 # i18n: "deleted" is a keyword
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
154 getargs(x, 0, 0, _(b"deleted takes no arguments"))
31697
992882cef7e1 fileset: perform membership test against set for status queries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31254
diff changeset
155 s = set(mctx.status().deleted)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
156 return mctx.predicate(s.__contains__, predrepr=b'deleted')
14677
2a758ffc821e fileset: add support for file status predicates
Matt Mackall <mpm@selenic.com>
parents: 14676
diff changeset
157
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
158
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
159 @predicate(b'missing()', callstatus=True, weight=_WEIGHT_STATUS)
27024
ceef5fb14872 fileset: add missing() predicate (issue4925)
liscju <piotr.listkiewicz@gmail.com>
parents: 26995
diff changeset
160 def missing(mctx, x):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 44856
diff changeset
161 """File that is missing according to :hg:`status`."""
27024
ceef5fb14872 fileset: add missing() predicate (issue4925)
liscju <piotr.listkiewicz@gmail.com>
parents: 26995
diff changeset
162 # i18n: "missing" is a keyword
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
163 getargs(x, 0, 0, _(b"missing takes no arguments"))
31697
992882cef7e1 fileset: perform membership test against set for status queries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31254
diff changeset
164 s = set(mctx.status().deleted)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
165 return mctx.predicate(s.__contains__, predrepr=b'deleted')
27024
ceef5fb14872 fileset: add missing() predicate (issue4925)
liscju <piotr.listkiewicz@gmail.com>
parents: 26995
diff changeset
166
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
167
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
168 @predicate(b'unknown()', callstatus=True, weight=_WEIGHT_STATUS_THOROUGH)
14677
2a758ffc821e fileset: add support for file status predicates
Matt Mackall <mpm@selenic.com>
parents: 14676
diff changeset
169 def unknown(mctx, x):
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
170 """File that is unknown according to :hg:`status`."""
14785
0f0bd4d028d3 fileset: add i18n hints for keywords
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 14718
diff changeset
171 # i18n: "unknown" is a keyword
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
172 getargs(x, 0, 0, _(b"unknown takes no arguments"))
31697
992882cef7e1 fileset: perform membership test against set for status queries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31254
diff changeset
173 s = set(mctx.status().unknown)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
174 return mctx.predicate(s.__contains__, predrepr=b'unknown')
14677
2a758ffc821e fileset: add support for file status predicates
Matt Mackall <mpm@selenic.com>
parents: 14676
diff changeset
175
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
176
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
177 @predicate(b'ignored()', callstatus=True, weight=_WEIGHT_STATUS_THOROUGH)
14677
2a758ffc821e fileset: add support for file status predicates
Matt Mackall <mpm@selenic.com>
parents: 14676
diff changeset
178 def ignored(mctx, x):
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
179 """File that is ignored according to :hg:`status`."""
14785
0f0bd4d028d3 fileset: add i18n hints for keywords
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 14718
diff changeset
180 # i18n: "ignored" is a keyword
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
181 getargs(x, 0, 0, _(b"ignored takes no arguments"))
31697
992882cef7e1 fileset: perform membership test against set for status queries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31254
diff changeset
182 s = set(mctx.status().ignored)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
183 return mctx.predicate(s.__contains__, predrepr=b'ignored')
14677
2a758ffc821e fileset: add support for file status predicates
Matt Mackall <mpm@selenic.com>
parents: 14676
diff changeset
184
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
185
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
186 @predicate(b'clean()', callstatus=True, weight=_WEIGHT_STATUS)
14677
2a758ffc821e fileset: add support for file status predicates
Matt Mackall <mpm@selenic.com>
parents: 14676
diff changeset
187 def clean(mctx, x):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 44856
diff changeset
188 """File that is clean according to :hg:`status`."""
14785
0f0bd4d028d3 fileset: add i18n hints for keywords
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 14718
diff changeset
189 # i18n: "clean" is a keyword
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
190 getargs(x, 0, 0, _(b"clean takes no arguments"))
31697
992882cef7e1 fileset: perform membership test against set for status queries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31254
diff changeset
191 s = set(mctx.status().clean)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
192 return mctx.predicate(s.__contains__, predrepr=b'clean')
14677
2a758ffc821e fileset: add support for file status predicates
Matt Mackall <mpm@selenic.com>
parents: 14676
diff changeset
193
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
194
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
195 @predicate(b'tracked()')
38686
131aae58a316 fileset: add "tracked()" to explicitly select files in the revision
Yuya Nishihara <yuya@tcha.org>
parents: 38685
diff changeset
196 def tracked(mctx, x):
131aae58a316 fileset: add "tracked()" to explicitly select files in the revision
Yuya Nishihara <yuya@tcha.org>
parents: 38685
diff changeset
197 """File that is under Mercurial control."""
131aae58a316 fileset: add "tracked()" to explicitly select files in the revision
Yuya Nishihara <yuya@tcha.org>
parents: 38685
diff changeset
198 # i18n: "tracked" is a keyword
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
199 getargs(x, 0, 0, _(b"tracked takes no arguments"))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
200 return mctx.predicate(mctx.ctx.__contains__, predrepr=b'tracked')
38686
131aae58a316 fileset: add "tracked()" to explicitly select files in the revision
Yuya Nishihara <yuya@tcha.org>
parents: 38685
diff changeset
201
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
202
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
203 @predicate(b'binary()', weight=_WEIGHT_READ_CONTENTS)
14676
e80fa502b8cf fileset: add some basic predicates
Matt Mackall <mpm@selenic.com>
parents: 14673
diff changeset
204 def binary(mctx, x):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 44856
diff changeset
205 """File that appears to be binary (contains NUL bytes)."""
14785
0f0bd4d028d3 fileset: add i18n hints for keywords
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 14718
diff changeset
206 # i18n: "binary" is a keyword
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
207 getargs(x, 0, 0, _(b"binary takes no arguments"))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
208 return mctx.fpredicate(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
209 lambda fctx: fctx.isbinary(), predrepr=b'binary', cache=True
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
210 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
211
14676
e80fa502b8cf fileset: add some basic predicates
Matt Mackall <mpm@selenic.com>
parents: 14673
diff changeset
212
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
213 @predicate(b'exec()')
14676
e80fa502b8cf fileset: add some basic predicates
Matt Mackall <mpm@selenic.com>
parents: 14673
diff changeset
214 def exec_(mctx, x):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 44856
diff changeset
215 """File that is marked as executable."""
14785
0f0bd4d028d3 fileset: add i18n hints for keywords
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 14718
diff changeset
216 # i18n: "exec" is a keyword
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
217 getargs(x, 0, 0, _(b"exec takes no arguments"))
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
218 ctx = mctx.ctx
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
219 return mctx.predicate(lambda f: ctx.flags(f) == b'x', predrepr=b'exec')
14676
e80fa502b8cf fileset: add some basic predicates
Matt Mackall <mpm@selenic.com>
parents: 14673
diff changeset
220
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
221
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
222 @predicate(b'symlink()')
14676
e80fa502b8cf fileset: add some basic predicates
Matt Mackall <mpm@selenic.com>
parents: 14673
diff changeset
223 def symlink(mctx, x):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 44856
diff changeset
224 """File that is marked as a symlink."""
14785
0f0bd4d028d3 fileset: add i18n hints for keywords
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 14718
diff changeset
225 # i18n: "symlink" is a keyword
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
226 getargs(x, 0, 0, _(b"symlink takes no arguments"))
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
227 ctx = mctx.ctx
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
228 return mctx.predicate(lambda f: ctx.flags(f) == b'l', predrepr=b'symlink')
14676
e80fa502b8cf fileset: add some basic predicates
Matt Mackall <mpm@selenic.com>
parents: 14673
diff changeset
229
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
230
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
231 @predicate(b'resolved()', weight=_WEIGHT_STATUS)
14679
e141e1cee0cc fileset: add resolved and unresolved predicates
Matt Mackall <mpm@selenic.com>
parents: 14678
diff changeset
232 def resolved(mctx, x):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 44856
diff changeset
233 """File that is marked resolved according to :hg:`resolve -l`."""
14785
0f0bd4d028d3 fileset: add i18n hints for keywords
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 14718
diff changeset
234 # i18n: "resolved" is a keyword
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
235 getargs(x, 0, 0, _(b"resolved takes no arguments"))
14679
e141e1cee0cc fileset: add resolved and unresolved predicates
Matt Mackall <mpm@selenic.com>
parents: 14678
diff changeset
236 if mctx.ctx.rev() is not None:
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
237 return mctx.never()
44856
b7808443ed6a mergestate: split out merge state handling code from main merge module
Augie Fackler <augie@google.com>
parents: 44009
diff changeset
238 ms = mergestatemod.mergestate.read(mctx.ctx.repo())
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
239 return mctx.predicate(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
240 lambda f: f in ms and ms[f] == b'r', predrepr=b'resolved'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
241 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
242
14679
e141e1cee0cc fileset: add resolved and unresolved predicates
Matt Mackall <mpm@selenic.com>
parents: 14678
diff changeset
243
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
244 @predicate(b'unresolved()', weight=_WEIGHT_STATUS)
14679
e141e1cee0cc fileset: add resolved and unresolved predicates
Matt Mackall <mpm@selenic.com>
parents: 14678
diff changeset
245 def unresolved(mctx, x):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 44856
diff changeset
246 """File that is marked unresolved according to :hg:`resolve -l`."""
14785
0f0bd4d028d3 fileset: add i18n hints for keywords
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 14718
diff changeset
247 # i18n: "unresolved" is a keyword
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
248 getargs(x, 0, 0, _(b"unresolved takes no arguments"))
14679
e141e1cee0cc fileset: add resolved and unresolved predicates
Matt Mackall <mpm@selenic.com>
parents: 14678
diff changeset
249 if mctx.ctx.rev() is not None:
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
250 return mctx.never()
44856
b7808443ed6a mergestate: split out merge state handling code from main merge module
Augie Fackler <augie@google.com>
parents: 44009
diff changeset
251 ms = mergestatemod.mergestate.read(mctx.ctx.repo())
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
252 return mctx.predicate(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
253 lambda f: f in ms and ms[f] == b'u', predrepr=b'unresolved'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
254 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
255
14679
e141e1cee0cc fileset: add resolved and unresolved predicates
Matt Mackall <mpm@selenic.com>
parents: 14678
diff changeset
256
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
257 @predicate(b'hgignore()', weight=_WEIGHT_STATUS)
14680
49af5fa3809b fileset: add hgignore
Matt Mackall <mpm@selenic.com>
parents: 14679
diff changeset
258 def hgignore(mctx, x):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 44856
diff changeset
259 """File that matches the active .hgignore pattern."""
23113
c2dd79ad99cb i18n: add i18n comment to error messages of filesets predicates
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22924
diff changeset
260 # i18n: "hgignore" is a keyword
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
261 getargs(x, 0, 0, _(b"hgignore takes no arguments"))
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
262 return mctx.ctx.repo().dirstate._ignore
14680
49af5fa3809b fileset: add hgignore
Matt Mackall <mpm@selenic.com>
parents: 14679
diff changeset
263
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
264
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
265 @predicate(b'portable()', weight=_WEIGHT_CHECK_FILENAME)
24408
caa6b6c65dc3 fileset: add a fileset for portable filenames
Siddharth Agarwal <sid0@fb.com>
parents: 24334
diff changeset
266 def portable(mctx, x):
27460
11286ac374f3 fileset: use decorator to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27459
diff changeset
267 """File that has a portable name. (This doesn't include filenames with case
24408
caa6b6c65dc3 fileset: add a fileset for portable filenames
Siddharth Agarwal <sid0@fb.com>
parents: 24334
diff changeset
268 collisions.)
caa6b6c65dc3 fileset: add a fileset for portable filenames
Siddharth Agarwal <sid0@fb.com>
parents: 24334
diff changeset
269 """
caa6b6c65dc3 fileset: add a fileset for portable filenames
Siddharth Agarwal <sid0@fb.com>
parents: 24334
diff changeset
270 # i18n: "portable" is a keyword
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
271 getargs(x, 0, 0, _(b"portable takes no arguments"))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
272 return mctx.predicate(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
273 lambda f: util.checkwinfilename(f) is None, predrepr=b'portable'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
274 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
275
24408
caa6b6c65dc3 fileset: add a fileset for portable filenames
Siddharth Agarwal <sid0@fb.com>
parents: 24334
diff changeset
276
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
277 @predicate(b'grep(regex)', weight=_WEIGHT_READ_CONTENTS)
14682
8785fd757077 fileset: add grep predicate
Matt Mackall <mpm@selenic.com>
parents: 14681
diff changeset
278 def grep(mctx, x):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 44856
diff changeset
279 """File contains the given regular expression."""
17368
01cc267fc105 fileset: do not traceback on invalid grep pattern
Patrick Mezard <patrick@mezard.eu>
parents: 17367
diff changeset
280 try:
01cc267fc105 fileset: do not traceback on invalid grep pattern
Patrick Mezard <patrick@mezard.eu>
parents: 17367
diff changeset
281 # i18n: "grep" is a keyword
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
282 r = re.compile(getstring(x, _(b"grep requires a pattern")))
25660
328739ea70c3 global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25654
diff changeset
283 except re.error as e:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
284 raise error.ParseError(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
285 _(b'invalid match pattern: %s') % stringutil.forcebytestr(e)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
286 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
287 return mctx.fpredicate(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
288 lambda fctx: r.search(fctx.data()),
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
289 predrepr=(b'grep(%r)', r.pattern),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
290 cache=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
291 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
292
14682
8785fd757077 fileset: add grep predicate
Matt Mackall <mpm@selenic.com>
parents: 14681
diff changeset
293
14683
281102f37b24 fileset: add size() predicate
Matt Mackall <mpm@selenic.com>
parents: 14682
diff changeset
294 def _sizetomax(s):
281102f37b24 fileset: add size() predicate
Matt Mackall <mpm@selenic.com>
parents: 14682
diff changeset
295 try:
25925
23c4589fc678 filesets: ignore unit case in size() predicate for single value
Anton Shestakov <av6@dwimlabs.net>
parents: 25815
diff changeset
296 s = s.strip().lower()
19194
1d08df65cd3c util: migrate fileset._sizetoint to util.sizetoint
Bryan O'Sullivan <bryano@fb.com>
parents: 18842
diff changeset
297 for k, v in util._sizeunits:
14683
281102f37b24 fileset: add size() predicate
Matt Mackall <mpm@selenic.com>
parents: 14682
diff changeset
298 if s.endswith(k):
281102f37b24 fileset: add size() predicate
Matt Mackall <mpm@selenic.com>
parents: 14682
diff changeset
299 # max(4k) = 5k - 1, max(4.5k) = 4.6k - 1
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
300 n = s[: -len(k)]
14683
281102f37b24 fileset: add size() predicate
Matt Mackall <mpm@selenic.com>
parents: 14682
diff changeset
301 inc = 1.0
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
302 if b"." in n:
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
303 inc /= 10 ** len(n.split(b".")[1])
14683
281102f37b24 fileset: add size() predicate
Matt Mackall <mpm@selenic.com>
parents: 14682
diff changeset
304 return int((float(n) + inc) * v) - 1
281102f37b24 fileset: add size() predicate
Matt Mackall <mpm@selenic.com>
parents: 14682
diff changeset
305 # no extension, this is a precise value
281102f37b24 fileset: add size() predicate
Matt Mackall <mpm@selenic.com>
parents: 14682
diff changeset
306 return int(s)
281102f37b24 fileset: add size() predicate
Matt Mackall <mpm@selenic.com>
parents: 14682
diff changeset
307 except ValueError:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
308 raise error.ParseError(_(b"couldn't parse size: %s") % s)
14683
281102f37b24 fileset: add size() predicate
Matt Mackall <mpm@selenic.com>
parents: 14682
diff changeset
309
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
310
38687
1500cbe22d53 fileset: parse argument of size() by predicate function
Yuya Nishihara <yuya@tcha.org>
parents: 38686
diff changeset
311 def sizematcher(expr):
35615
0e369eca888f fileset: split the logic for matching a size expression to a separate method
Matt Harbison <matt_harbison@yahoo.com>
parents: 32523
diff changeset
312 """Return a function(size) -> bool from the ``size()`` expression"""
38687
1500cbe22d53 fileset: parse argument of size() by predicate function
Yuya Nishihara <yuya@tcha.org>
parents: 38686
diff changeset
313 expr = expr.strip()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
314 if b'-' in expr: # do we have a range?
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
315 a, b = expr.split(b'-', 1)
35615
0e369eca888f fileset: split the logic for matching a size expression to a separate method
Matt Harbison <matt_harbison@yahoo.com>
parents: 32523
diff changeset
316 a = util.sizetoint(a)
0e369eca888f fileset: split the logic for matching a size expression to a separate method
Matt Harbison <matt_harbison@yahoo.com>
parents: 32523
diff changeset
317 b = util.sizetoint(b)
0e369eca888f fileset: split the logic for matching a size expression to a separate method
Matt Harbison <matt_harbison@yahoo.com>
parents: 32523
diff changeset
318 return lambda x: x >= a and x <= b
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
319 elif expr.startswith(b"<="):
35615
0e369eca888f fileset: split the logic for matching a size expression to a separate method
Matt Harbison <matt_harbison@yahoo.com>
parents: 32523
diff changeset
320 a = util.sizetoint(expr[2:])
0e369eca888f fileset: split the logic for matching a size expression to a separate method
Matt Harbison <matt_harbison@yahoo.com>
parents: 32523
diff changeset
321 return lambda x: x <= a
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
322 elif expr.startswith(b"<"):
35615
0e369eca888f fileset: split the logic for matching a size expression to a separate method
Matt Harbison <matt_harbison@yahoo.com>
parents: 32523
diff changeset
323 a = util.sizetoint(expr[1:])
0e369eca888f fileset: split the logic for matching a size expression to a separate method
Matt Harbison <matt_harbison@yahoo.com>
parents: 32523
diff changeset
324 return lambda x: x < a
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
325 elif expr.startswith(b">="):
35615
0e369eca888f fileset: split the logic for matching a size expression to a separate method
Matt Harbison <matt_harbison@yahoo.com>
parents: 32523
diff changeset
326 a = util.sizetoint(expr[2:])
0e369eca888f fileset: split the logic for matching a size expression to a separate method
Matt Harbison <matt_harbison@yahoo.com>
parents: 32523
diff changeset
327 return lambda x: x >= a
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
328 elif expr.startswith(b">"):
35615
0e369eca888f fileset: split the logic for matching a size expression to a separate method
Matt Harbison <matt_harbison@yahoo.com>
parents: 32523
diff changeset
329 a = util.sizetoint(expr[1:])
0e369eca888f fileset: split the logic for matching a size expression to a separate method
Matt Harbison <matt_harbison@yahoo.com>
parents: 32523
diff changeset
330 return lambda x: x > a
36505
db33c5bc781f fileset: drop bad "elif:" trying to check invalid size expression
Yuya Nishihara <yuya@tcha.org>
parents: 36473
diff changeset
331 else:
35615
0e369eca888f fileset: split the logic for matching a size expression to a separate method
Matt Harbison <matt_harbison@yahoo.com>
parents: 32523
diff changeset
332 a = util.sizetoint(expr)
0e369eca888f fileset: split the logic for matching a size expression to a separate method
Matt Harbison <matt_harbison@yahoo.com>
parents: 32523
diff changeset
333 b = _sizetomax(expr)
0e369eca888f fileset: split the logic for matching a size expression to a separate method
Matt Harbison <matt_harbison@yahoo.com>
parents: 32523
diff changeset
334 return lambda x: x >= a and x <= b
0e369eca888f fileset: split the logic for matching a size expression to a separate method
Matt Harbison <matt_harbison@yahoo.com>
parents: 32523
diff changeset
335
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
336
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
337 @predicate(b'size(expression)', weight=_WEIGHT_STATUS)
14683
281102f37b24 fileset: add size() predicate
Matt Mackall <mpm@selenic.com>
parents: 14682
diff changeset
338 def size(mctx, x):
27460
11286ac374f3 fileset: use decorator to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27459
diff changeset
339 """File size matches the given expression. Examples:
14683
281102f37b24 fileset: add size() predicate
Matt Mackall <mpm@selenic.com>
parents: 14682
diff changeset
340
29987
d532ef155b0e help: clarify quotes are needed for filesets.size expressions
timeless <timeless@mozdev.org>
parents: 28448
diff changeset
341 - size('1k') - files from 1024 to 2047 bytes
d532ef155b0e help: clarify quotes are needed for filesets.size expressions
timeless <timeless@mozdev.org>
parents: 28448
diff changeset
342 - size('< 20k') - files less than 20480 bytes
d532ef155b0e help: clarify quotes are needed for filesets.size expressions
timeless <timeless@mozdev.org>
parents: 28448
diff changeset
343 - size('>= .5MB') - files at least 524288 bytes
d532ef155b0e help: clarify quotes are needed for filesets.size expressions
timeless <timeless@mozdev.org>
parents: 28448
diff changeset
344 - size('4k - 1MB') - files from 4096 bytes to 1048576 bytes
14683
281102f37b24 fileset: add size() predicate
Matt Mackall <mpm@selenic.com>
parents: 14682
diff changeset
345 """
38687
1500cbe22d53 fileset: parse argument of size() by predicate function
Yuya Nishihara <yuya@tcha.org>
parents: 38686
diff changeset
346 # i18n: "size" is a keyword
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
347 expr = getstring(x, _(b"size requires an expression"))
38687
1500cbe22d53 fileset: parse argument of size() by predicate function
Yuya Nishihara <yuya@tcha.org>
parents: 38686
diff changeset
348 m = sizematcher(expr)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
349 return mctx.fpredicate(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
350 lambda fctx: m(fctx.size()), predrepr=(b'size(%r)', expr), cache=True
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
351 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
352
14683
281102f37b24 fileset: add size() predicate
Matt Mackall <mpm@selenic.com>
parents: 14682
diff changeset
353
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
354 @predicate(b'encoding(name)', weight=_WEIGHT_READ_CONTENTS)
14684
87b9d6a7d807 fileset: add encoding() predicate
Matt Mackall <mpm@selenic.com>
parents: 14683
diff changeset
355 def encoding(mctx, x):
27460
11286ac374f3 fileset: use decorator to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27459
diff changeset
356 """File can be successfully decoded with the given character
14684
87b9d6a7d807 fileset: add encoding() predicate
Matt Mackall <mpm@selenic.com>
parents: 14683
diff changeset
357 encoding. May not be useful for encodings other than ASCII and
87b9d6a7d807 fileset: add encoding() predicate
Matt Mackall <mpm@selenic.com>
parents: 14683
diff changeset
358 UTF-8.
87b9d6a7d807 fileset: add encoding() predicate
Matt Mackall <mpm@selenic.com>
parents: 14683
diff changeset
359 """
87b9d6a7d807 fileset: add encoding() predicate
Matt Mackall <mpm@selenic.com>
parents: 14683
diff changeset
360
14785
0f0bd4d028d3 fileset: add i18n hints for keywords
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 14718
diff changeset
361 # i18n: "encoding" is a keyword
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
362 enc = getstring(x, _(b"encoding requires an encoding name"))
14684
87b9d6a7d807 fileset: add encoding() predicate
Matt Mackall <mpm@selenic.com>
parents: 14683
diff changeset
363
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
364 def encp(fctx):
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
365 d = fctx.data()
14684
87b9d6a7d807 fileset: add encoding() predicate
Matt Mackall <mpm@selenic.com>
parents: 14683
diff changeset
366 try:
38325
5cb39a368c80 py3: cast bytes encoding name to str in fileset.py
Yuya Nishihara <yuya@tcha.org>
parents: 38083
diff changeset
367 d.decode(pycompat.sysstr(enc))
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
368 return True
14684
87b9d6a7d807 fileset: add encoding() predicate
Matt Mackall <mpm@selenic.com>
parents: 14683
diff changeset
369 except LookupError:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
370 raise error.Abort(_(b"unknown encoding '%s'") % enc)
14684
87b9d6a7d807 fileset: add encoding() predicate
Matt Mackall <mpm@selenic.com>
parents: 14683
diff changeset
371 except UnicodeDecodeError:
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
372 return False
14684
87b9d6a7d807 fileset: add encoding() predicate
Matt Mackall <mpm@selenic.com>
parents: 14683
diff changeset
373
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
374 return mctx.fpredicate(encp, predrepr=(b'encoding(%r)', enc), cache=True)
14684
87b9d6a7d807 fileset: add encoding() predicate
Matt Mackall <mpm@selenic.com>
parents: 14683
diff changeset
375
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
376
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
377 @predicate(b'eol(style)', weight=_WEIGHT_READ_CONTENTS)
18842
3ce3f2b059a1 filesets: add eol predicate
Matt Mackall <mpm@selenic.com>
parents: 18364
diff changeset
378 def eol(mctx, x):
27460
11286ac374f3 fileset: use decorator to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27459
diff changeset
379 """File contains newlines of the given style (dos, unix, mac). Binary
18842
3ce3f2b059a1 filesets: add eol predicate
Matt Mackall <mpm@selenic.com>
parents: 18364
diff changeset
380 files are excluded, files with mixed line endings match multiple
3ce3f2b059a1 filesets: add eol predicate
Matt Mackall <mpm@selenic.com>
parents: 18364
diff changeset
381 styles.
3ce3f2b059a1 filesets: add eol predicate
Matt Mackall <mpm@selenic.com>
parents: 18364
diff changeset
382 """
3ce3f2b059a1 filesets: add eol predicate
Matt Mackall <mpm@selenic.com>
parents: 18364
diff changeset
383
28056
4f8ced23345e fileset: fix copy/paste in eol() error message
Matt Harbison <matt_harbison@yahoo.com>
parents: 27518
diff changeset
384 # i18n: "eol" is a keyword
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
385 enc = getstring(x, _(b"eol requires a style name"))
18842
3ce3f2b059a1 filesets: add eol predicate
Matt Mackall <mpm@selenic.com>
parents: 18364
diff changeset
386
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
387 def eolp(fctx):
38414
235d0bc11e1d fileset: use filectx.isbinary() to filter out binaries in eol()
Matt Harbison <matt_harbison@yahoo.com>
parents: 38326
diff changeset
388 if fctx.isbinary():
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
389 return False
38414
235d0bc11e1d fileset: use filectx.isbinary() to filter out binaries in eol()
Matt Harbison <matt_harbison@yahoo.com>
parents: 38326
diff changeset
390 d = fctx.data()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
391 if (enc == b'dos' or enc == b'win') and b'\r\n' in d:
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
392 return True
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
393 elif enc == b'unix' and re.search(b'(?<!\r)\n', d):
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
394 return True
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
395 elif enc == b'mac' and re.search(b'\r(?!\n)', d):
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
396 return True
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
397 return False
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
398
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
399 return mctx.fpredicate(eolp, predrepr=(b'eol(%r)', enc), cache=True)
18842
3ce3f2b059a1 filesets: add eol predicate
Matt Mackall <mpm@selenic.com>
parents: 18364
diff changeset
400
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
401
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
402 @predicate(b'copied()')
14685
394121d9f4fc fileset: add copied predicate
Matt Mackall <mpm@selenic.com>
parents: 14684
diff changeset
403 def copied(mctx, x):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 44856
diff changeset
404 """File that is recorded as being copied."""
14785
0f0bd4d028d3 fileset: add i18n hints for keywords
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 14718
diff changeset
405 # i18n: "copied" is a keyword
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
406 getargs(x, 0, 0, _(b"copied takes no arguments"))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
407
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
408 def copiedp(fctx):
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
409 p = fctx.parents()
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
410 return p and p[0].path() != fctx.path()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
411
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
412 return mctx.fpredicate(copiedp, predrepr=b'copied', cache=True)
14685
394121d9f4fc fileset: add copied predicate
Matt Mackall <mpm@selenic.com>
parents: 14684
diff changeset
413
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
414
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
415 @predicate(b'revs(revs, pattern)', weight=_WEIGHT_STATUS)
31193
4140d49d2efb fileset: add revs(revs, fileset) to evaluate set in working directory
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31192
diff changeset
416 def revs(mctx, x):
31254
2140e12d3258 fileset: drop false function signatures from revs() and status() docs
Yuya Nishihara <yuya@tcha.org>
parents: 31195
diff changeset
417 """Evaluate set in the specified revisions. If the revset match multiple
2140e12d3258 fileset: drop false function signatures from revs() and status() docs
Yuya Nishihara <yuya@tcha.org>
parents: 31195
diff changeset
418 revs, this will return file matching pattern in any of the revision.
31193
4140d49d2efb fileset: add revs(revs, fileset) to evaluate set in working directory
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31192
diff changeset
419 """
4140d49d2efb fileset: add revs(revs, fileset) to evaluate set in working directory
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31192
diff changeset
420 # i18n: "revs" is a keyword
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
421 r, x = getargs(x, 2, 2, _(b"revs takes two arguments"))
31193
4140d49d2efb fileset: add revs(revs, fileset) to evaluate set in working directory
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31192
diff changeset
422 # i18n: "revs" is a keyword
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
423 revspec = getstring(r, _(b"first argument to revs must be a revision"))
31193
4140d49d2efb fileset: add revs(revs, fileset) to evaluate set in working directory
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31192
diff changeset
424 repo = mctx.ctx.repo()
4140d49d2efb fileset: add revs(revs, fileset) to evaluate set in working directory
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31192
diff changeset
425 revs = scmutil.revrange(repo, [revspec])
4140d49d2efb fileset: add revs(revs, fileset) to evaluate set in working directory
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31192
diff changeset
426
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
427 matchers = []
31193
4140d49d2efb fileset: add revs(revs, fileset) to evaluate set in working directory
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31192
diff changeset
428 for r in revs:
4140d49d2efb fileset: add revs(revs, fileset) to evaluate set in working directory
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31192
diff changeset
429 ctx = repo[r]
38878
0f56d08e6271 fileset: move buildstatus() to matchctx method
Yuya Nishihara <yuya@tcha.org>
parents: 38877
diff changeset
430 mc = mctx.switch(ctx.p1(), ctx)
38876
da3bd2afd68d fileset: pass in basectx to _buildstatus()
Yuya Nishihara <yuya@tcha.org>
parents: 38865
diff changeset
431 matchers.append(getmatch(mc, x))
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
432 if not matchers:
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
433 return mctx.never()
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
434 if len(matchers) == 1:
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
435 return matchers[0]
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
436 return matchmod.unionmatcher(matchers)
31193
4140d49d2efb fileset: add revs(revs, fileset) to evaluate set in working directory
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31192
diff changeset
437
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
438
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
439 @predicate(b'status(base, rev, pattern)', weight=_WEIGHT_STATUS)
31195
6b098ac4542e fileset: add a 'status(...)' predicate to control evaluation context
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31194
diff changeset
440 def status(mctx, x):
31254
2140e12d3258 fileset: drop false function signatures from revs() and status() docs
Yuya Nishihara <yuya@tcha.org>
parents: 31195
diff changeset
441 """Evaluate predicate using status change between ``base`` and
31195
6b098ac4542e fileset: add a 'status(...)' predicate to control evaluation context
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31194
diff changeset
442 ``rev``. Examples:
6b098ac4542e fileset: add a 'status(...)' predicate to control evaluation context
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31194
diff changeset
443
6b098ac4542e fileset: add a 'status(...)' predicate to control evaluation context
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31194
diff changeset
444 - ``status(3, 7, added())`` - matches files added from "3" to "7"
6b098ac4542e fileset: add a 'status(...)' predicate to control evaluation context
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31194
diff changeset
445 """
6b098ac4542e fileset: add a 'status(...)' predicate to control evaluation context
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31194
diff changeset
446 repo = mctx.ctx.repo()
6b098ac4542e fileset: add a 'status(...)' predicate to control evaluation context
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31194
diff changeset
447 # i18n: "status" is a keyword
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
448 b, r, x = getargs(x, 3, 3, _(b"status takes three arguments"))
31195
6b098ac4542e fileset: add a 'status(...)' predicate to control evaluation context
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31194
diff changeset
449 # i18n: "status" is a keyword
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
450 baseerr = _(b"first argument to status must be a revision")
31195
6b098ac4542e fileset: add a 'status(...)' predicate to control evaluation context
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31194
diff changeset
451 baserevspec = getstring(b, baseerr)
6b098ac4542e fileset: add a 'status(...)' predicate to control evaluation context
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31194
diff changeset
452 if not baserevspec:
6b098ac4542e fileset: add a 'status(...)' predicate to control evaluation context
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31194
diff changeset
453 raise error.ParseError(baseerr)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
454 reverr = _(b"second argument to status must be a revision")
31195
6b098ac4542e fileset: add a 'status(...)' predicate to control evaluation context
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31194
diff changeset
455 revspec = getstring(r, reverr)
6b098ac4542e fileset: add a 'status(...)' predicate to control evaluation context
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31194
diff changeset
456 if not revspec:
6b098ac4542e fileset: add a 'status(...)' predicate to control evaluation context
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31194
diff changeset
457 raise error.ParseError(reverr)
37257
f290f130d7fc fileset: use context-returning revpair()
Martin von Zweigbergk <martinvonz@google.com>
parents: 37251
diff changeset
458 basectx, ctx = scmutil.revpair(repo, [baserevspec, revspec])
38878
0f56d08e6271 fileset: move buildstatus() to matchctx method
Yuya Nishihara <yuya@tcha.org>
parents: 38877
diff changeset
459 mc = mctx.switch(basectx, ctx)
38876
da3bd2afd68d fileset: pass in basectx to _buildstatus()
Yuya Nishihara <yuya@tcha.org>
parents: 38865
diff changeset
460 return getmatch(mc, x)
31195
6b098ac4542e fileset: add a 'status(...)' predicate to control evaluation context
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31194
diff changeset
461
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
462
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
463 @predicate(b'subrepo([pattern])')
16443
9e02e032b522 fileset: add "subrepo" fileset symbol
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 15963
diff changeset
464 def subrepo(mctx, x):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 44856
diff changeset
465 """Subrepositories whose paths match the given pattern."""
16443
9e02e032b522 fileset: add "subrepo" fileset symbol
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 15963
diff changeset
466 # i18n: "subrepo" is a keyword
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
467 getargs(x, 0, 1, _(b"subrepo takes at most one argument"))
16443
9e02e032b522 fileset: add "subrepo" fileset symbol
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 15963
diff changeset
468 ctx = mctx.ctx
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
469 sstate = ctx.substate
16443
9e02e032b522 fileset: add "subrepo" fileset symbol
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 15963
diff changeset
470 if x:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
471 pat = getpattern(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
472 x,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
473 matchmod.allpatternkinds,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
474 # i18n: "subrepo" is a keyword
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
475 _(b"subrepo requires a pattern or no arguments"),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
476 )
16443
9e02e032b522 fileset: add "subrepo" fileset symbol
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 15963
diff changeset
477 fast = not matchmod.patkind(pat)
9e02e032b522 fileset: add "subrepo" fileset symbol
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 15963
diff changeset
478 if fast:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
479
16443
9e02e032b522 fileset: add "subrepo" fileset symbol
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 15963
diff changeset
480 def m(s):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
481 return s == pat
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
482
16443
9e02e032b522 fileset: add "subrepo" fileset symbol
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 15963
diff changeset
483 else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
484 m = matchmod.match(ctx.repo().root, b'', [pat], ctx=ctx)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
485 return mctx.predicate(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
486 lambda f: f in sstate and m(f), predrepr=(b'subrepo(%r)', pat)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
487 )
16443
9e02e032b522 fileset: add "subrepo" fileset symbol
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 15963
diff changeset
488 else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
489 return mctx.predicate(sstate.__contains__, predrepr=b'subrepo')
16443
9e02e032b522 fileset: add "subrepo" fileset symbol
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 15963
diff changeset
490
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
491
14551
68d814a3cefd fileset: basic pattern and boolean support
Matt Mackall <mpm@selenic.com>
parents: 14513
diff changeset
492 methods = {
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
493 b'withstatus': getmatchwithstatus,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
494 b'string': stringmatch,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
495 b'symbol': stringmatch,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
496 b'kindpat': kindpatmatch,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
497 b'patterns': patternsmatch,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
498 b'and': andmatch,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
499 b'or': ormatch,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
500 b'minus': minusmatch,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
501 b'list': listmatch,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
502 b'not': notmatch,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
503 b'func': func,
14551
68d814a3cefd fileset: basic pattern and boolean support
Matt Mackall <mpm@selenic.com>
parents: 14513
diff changeset
504 }
68d814a3cefd fileset: basic pattern and boolean support
Matt Mackall <mpm@selenic.com>
parents: 14513
diff changeset
505
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
506
14551
68d814a3cefd fileset: basic pattern and boolean support
Matt Mackall <mpm@selenic.com>
parents: 14513
diff changeset
507 class matchctx(object):
44009
e685fac56693 match: resolve filesets against the passed `cwd`, not the current one
Matt Harbison <matt_harbison@yahoo.com>
parents: 43106
diff changeset
508 def __init__(self, basectx, ctx, cwd, badfn=None):
38877
8d6780f0b34d fileset: keep basectx by matchctx
Yuya Nishihara <yuya@tcha.org>
parents: 38876
diff changeset
509 self._basectx = basectx
14551
68d814a3cefd fileset: basic pattern and boolean support
Matt Mackall <mpm@selenic.com>
parents: 14513
diff changeset
510 self.ctx = ctx
38613
5cbcbe51d38d fileset: pass in badfn to inner matchers
Yuya Nishihara <yuya@tcha.org>
parents: 38612
diff changeset
511 self._badfn = badfn
38882
ff42ec7845e4 fileset: narrow status computation by left-hand-side of 'and' node
Yuya Nishihara <yuya@tcha.org>
parents: 38881
diff changeset
512 self._match = None
38878
0f56d08e6271 fileset: move buildstatus() to matchctx method
Yuya Nishihara <yuya@tcha.org>
parents: 38877
diff changeset
513 self._status = None
44009
e685fac56693 match: resolve filesets against the passed `cwd`, not the current one
Matt Harbison <matt_harbison@yahoo.com>
parents: 43106
diff changeset
514 self.cwd = cwd
38878
0f56d08e6271 fileset: move buildstatus() to matchctx method
Yuya Nishihara <yuya@tcha.org>
parents: 38877
diff changeset
515
38882
ff42ec7845e4 fileset: narrow status computation by left-hand-side of 'and' node
Yuya Nishihara <yuya@tcha.org>
parents: 38881
diff changeset
516 def narrowed(self, match):
ff42ec7845e4 fileset: narrow status computation by left-hand-side of 'and' node
Yuya Nishihara <yuya@tcha.org>
parents: 38881
diff changeset
517 """Create matchctx for a sub-tree narrowed by the given matcher"""
44009
e685fac56693 match: resolve filesets against the passed `cwd`, not the current one
Matt Harbison <matt_harbison@yahoo.com>
parents: 43106
diff changeset
518 mctx = matchctx(self._basectx, self.ctx, self.cwd, self._badfn)
38882
ff42ec7845e4 fileset: narrow status computation by left-hand-side of 'and' node
Yuya Nishihara <yuya@tcha.org>
parents: 38881
diff changeset
519 mctx._match = match
ff42ec7845e4 fileset: narrow status computation by left-hand-side of 'and' node
Yuya Nishihara <yuya@tcha.org>
parents: 38881
diff changeset
520 # leave wider status which we don't have to care
ff42ec7845e4 fileset: narrow status computation by left-hand-side of 'and' node
Yuya Nishihara <yuya@tcha.org>
parents: 38881
diff changeset
521 mctx._status = self._status
ff42ec7845e4 fileset: narrow status computation by left-hand-side of 'and' node
Yuya Nishihara <yuya@tcha.org>
parents: 38881
diff changeset
522 return mctx
ff42ec7845e4 fileset: narrow status computation by left-hand-side of 'and' node
Yuya Nishihara <yuya@tcha.org>
parents: 38881
diff changeset
523
38881
dec16c0cce50 fileset: move copy constructor of matchctx near __init__
Yuya Nishihara <yuya@tcha.org>
parents: 38880
diff changeset
524 def switch(self, basectx, ctx):
44009
e685fac56693 match: resolve filesets against the passed `cwd`, not the current one
Matt Harbison <matt_harbison@yahoo.com>
parents: 43106
diff changeset
525 mctx = matchctx(basectx, ctx, self.cwd, self._badfn)
38882
ff42ec7845e4 fileset: narrow status computation by left-hand-side of 'and' node
Yuya Nishihara <yuya@tcha.org>
parents: 38881
diff changeset
526 mctx._match = self._match
ff42ec7845e4 fileset: narrow status computation by left-hand-side of 'and' node
Yuya Nishihara <yuya@tcha.org>
parents: 38881
diff changeset
527 return mctx
38881
dec16c0cce50 fileset: move copy constructor of matchctx near __init__
Yuya Nishihara <yuya@tcha.org>
parents: 38880
diff changeset
528
38880
80fd7371f2d8 fileset: build status according to 'withstatus' hint
Yuya Nishihara <yuya@tcha.org>
parents: 38879
diff changeset
529 def withstatus(self, keys):
80fd7371f2d8 fileset: build status according to 'withstatus' hint
Yuya Nishihara <yuya@tcha.org>
parents: 38879
diff changeset
530 """Create matchctx which has precomputed status specified by the keys"""
44009
e685fac56693 match: resolve filesets against the passed `cwd`, not the current one
Matt Harbison <matt_harbison@yahoo.com>
parents: 43106
diff changeset
531 mctx = matchctx(self._basectx, self.ctx, self.cwd, self._badfn)
38882
ff42ec7845e4 fileset: narrow status computation by left-hand-side of 'and' node
Yuya Nishihara <yuya@tcha.org>
parents: 38881
diff changeset
532 mctx._match = self._match
38880
80fd7371f2d8 fileset: build status according to 'withstatus' hint
Yuya Nishihara <yuya@tcha.org>
parents: 38879
diff changeset
533 mctx._buildstatus(keys)
80fd7371f2d8 fileset: build status according to 'withstatus' hint
Yuya Nishihara <yuya@tcha.org>
parents: 38879
diff changeset
534 return mctx
80fd7371f2d8 fileset: build status according to 'withstatus' hint
Yuya Nishihara <yuya@tcha.org>
parents: 38879
diff changeset
535
80fd7371f2d8 fileset: build status according to 'withstatus' hint
Yuya Nishihara <yuya@tcha.org>
parents: 38879
diff changeset
536 def _buildstatus(self, keys):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
537 self._status = self._basectx.status(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
538 self.ctx,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
539 self._match,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
540 listignored=b'ignored' in keys,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
541 listclean=b'clean' in keys,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
542 listunknown=b'unknown' in keys,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
543 )
38690
5d9749c598f0 fileset: remove callexisting flag and mctx.existing() (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38689
diff changeset
544
14677
2a758ffc821e fileset: add support for file status predicates
Matt Mackall <mpm@selenic.com>
parents: 14676
diff changeset
545 def status(self):
2a758ffc821e fileset: add support for file status predicates
Matt Mackall <mpm@selenic.com>
parents: 14676
diff changeset
546 return self._status
38684
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38613
diff changeset
547
14673
b0566467c492 fileset: drop matchfn
Matt Mackall <mpm@selenic.com>
parents: 14554
diff changeset
548 def matcher(self, patterns):
44009
e685fac56693 match: resolve filesets against the passed `cwd`, not the current one
Matt Harbison <matt_harbison@yahoo.com>
parents: 43106
diff changeset
549 return self.ctx.match(patterns, badfn=self._badfn, cwd=self.cwd)
38684
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38613
diff changeset
550
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38613
diff changeset
551 def predicate(self, predfn, predrepr=None, cache=False):
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38613
diff changeset
552 """Create a matcher to select files by predfn(filename)"""
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38613
diff changeset
553 if cache:
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38613
diff changeset
554 predfn = util.cachefunc(predfn)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
555 return matchmod.predicatematcher(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
556 predfn, predrepr=predrepr, badfn=self._badfn
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
557 )
38684
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38613
diff changeset
558
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38613
diff changeset
559 def fpredicate(self, predfn, predrepr=None, cache=False):
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38613
diff changeset
560 """Create a matcher to select files by predfn(fctx) at the current
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38613
diff changeset
561 revision
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38613
diff changeset
562
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38613
diff changeset
563 Missing files are ignored.
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38613
diff changeset
564 """
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38613
diff changeset
565 ctx = self.ctx
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38613
diff changeset
566 if ctx.rev() is None:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
567
38684
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38613
diff changeset
568 def fctxpredfn(f):
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38613
diff changeset
569 try:
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38613
diff changeset
570 fctx = ctx[f]
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38613
diff changeset
571 except error.LookupError:
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38613
diff changeset
572 return False
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38613
diff changeset
573 try:
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38613
diff changeset
574 fctx.audit()
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38613
diff changeset
575 except error.Abort:
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38613
diff changeset
576 return False
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38613
diff changeset
577 try:
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38613
diff changeset
578 return predfn(fctx)
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38613
diff changeset
579 except (IOError, OSError) as e:
38758
774f92710a81 fileset: suppress EACCES while reading arbitrary paths via filectx API
Yuya Nishihara <yuya@tcha.org>
parents: 38692
diff changeset
580 # open()-ing a directory fails with EACCES on Windows
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
581 if e.errno in (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
582 errno.ENOENT,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
583 errno.EACCES,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
584 errno.ENOTDIR,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
585 errno.EISDIR,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
586 ):
38684
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38613
diff changeset
587 return False
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38613
diff changeset
588 raise
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
589
38684
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38613
diff changeset
590 else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
591
38684
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38613
diff changeset
592 def fctxpredfn(f):
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38613
diff changeset
593 try:
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38613
diff changeset
594 fctx = ctx[f]
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38613
diff changeset
595 except error.LookupError:
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38613
diff changeset
596 return False
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38613
diff changeset
597 return predfn(fctx)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
598
38684
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38613
diff changeset
599 return self.predicate(fctxpredfn, predrepr=predrepr, cache=cache)
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38613
diff changeset
600
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38613
diff changeset
601 def never(self):
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38613
diff changeset
602 """Create a matcher to select nothing"""
41676
0531dff73d0b match: delete unused root and cwd arguments from {always,never,exact}() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41675
diff changeset
603 return matchmod.never(badfn=self._badfn)
38684
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38613
diff changeset
604
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
605
44009
e685fac56693 match: resolve filesets against the passed `cwd`, not the current one
Matt Harbison <matt_harbison@yahoo.com>
parents: 43106
diff changeset
606 def match(ctx, cwd, expr, badfn=None):
38612
760cc5dc01e8 fileset: restrict getfileset() to not return a computed set (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38598
diff changeset
607 """Create a matcher for a single fileset expression"""
38805
b9162ea1b815 fileset: extract language processing part to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38804
diff changeset
608 tree = filesetlang.parse(expr)
38826
6371ab78c3b3 fileset: add phase to transform parsed tree
Yuya Nishihara <yuya@tcha.org>
parents: 38810
diff changeset
609 tree = filesetlang.analyze(tree)
38829
7e7e2b2ff284 fileset: add stub for weight-based optimization
Yuya Nishihara <yuya@tcha.org>
parents: 38828
diff changeset
610 tree = filesetlang.optimize(tree)
44009
e685fac56693 match: resolve filesets against the passed `cwd`, not the current one
Matt Harbison <matt_harbison@yahoo.com>
parents: 43106
diff changeset
611 mctx = matchctx(ctx.p1(), ctx, cwd, badfn=badfn)
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
612 return getmatch(mctx, tree)
14678
5ef7b87530f6 fileset: prescan parse tree to optimize status usage
Matt Mackall <mpm@selenic.com>
parents: 14677
diff changeset
613
14681
0744db5eb51c fileset: add some function help text
Matt Mackall <mpm@selenic.com>
parents: 14680
diff changeset
614
28447
4eb5496c2bd4 registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28056
diff changeset
615 def loadpredicate(ui, extname, registrarobj):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 44856
diff changeset
616 """Load fileset predicates from specified registrarobj"""
43106
d783f945a701 py3: finish porting iteritems() to pycompat and remove source transformer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43089
diff changeset
617 for name, func in pycompat.iteritems(registrarobj._table):
28447
4eb5496c2bd4 registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28056
diff changeset
618 symbols[name] = func
4eb5496c2bd4 registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28056
diff changeset
619
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
620
14681
0744db5eb51c fileset: add some function help text
Matt Mackall <mpm@selenic.com>
parents: 14680
diff changeset
621 # tell hggettext to extract docstrings from these functions:
0744db5eb51c fileset: add some function help text
Matt Mackall <mpm@selenic.com>
parents: 14680
diff changeset
622 i18nfunctions = symbols.values()