##// END OF EJS Templates
fileset: roughly adjust weights of functions...
Yuya Nishihara -
r38866:bfd5def3 default
parent child Browse files
Show More
@@ -88,7 +88,7 b' symbols = filesetlang.symbols'
88
88
89 predicate = registrar.filesetpredicate()
89 predicate = registrar.filesetpredicate()
90
90
91 @predicate('modified()', callstatus=True)
91 @predicate('modified()', callstatus=True, weight=10)
92 def modified(mctx, x):
92 def modified(mctx, x):
93 """File that is modified according to :hg:`status`.
93 """File that is modified according to :hg:`status`.
94 """
94 """
@@ -97,7 +97,7 b' def modified(mctx, x):'
97 s = set(mctx.status().modified)
97 s = set(mctx.status().modified)
98 return mctx.predicate(s.__contains__, predrepr='modified')
98 return mctx.predicate(s.__contains__, predrepr='modified')
99
99
100 @predicate('added()', callstatus=True)
100 @predicate('added()', callstatus=True, weight=10)
101 def added(mctx, x):
101 def added(mctx, x):
102 """File that is added according to :hg:`status`.
102 """File that is added according to :hg:`status`.
103 """
103 """
@@ -106,7 +106,7 b' def added(mctx, x):'
106 s = set(mctx.status().added)
106 s = set(mctx.status().added)
107 return mctx.predicate(s.__contains__, predrepr='added')
107 return mctx.predicate(s.__contains__, predrepr='added')
108
108
109 @predicate('removed()', callstatus=True)
109 @predicate('removed()', callstatus=True, weight=10)
110 def removed(mctx, x):
110 def removed(mctx, x):
111 """File that is removed according to :hg:`status`.
111 """File that is removed according to :hg:`status`.
112 """
112 """
@@ -115,7 +115,7 b' def removed(mctx, x):'
115 s = set(mctx.status().removed)
115 s = set(mctx.status().removed)
116 return mctx.predicate(s.__contains__, predrepr='removed')
116 return mctx.predicate(s.__contains__, predrepr='removed')
117
117
118 @predicate('deleted()', callstatus=True)
118 @predicate('deleted()', callstatus=True, weight=10)
119 def deleted(mctx, x):
119 def deleted(mctx, x):
120 """Alias for ``missing()``.
120 """Alias for ``missing()``.
121 """
121 """
@@ -124,7 +124,7 b' def deleted(mctx, x):'
124 s = set(mctx.status().deleted)
124 s = set(mctx.status().deleted)
125 return mctx.predicate(s.__contains__, predrepr='deleted')
125 return mctx.predicate(s.__contains__, predrepr='deleted')
126
126
127 @predicate('missing()', callstatus=True)
127 @predicate('missing()', callstatus=True, weight=10)
128 def missing(mctx, x):
128 def missing(mctx, x):
129 """File that is missing according to :hg:`status`.
129 """File that is missing according to :hg:`status`.
130 """
130 """
@@ -133,7 +133,7 b' def missing(mctx, x):'
133 s = set(mctx.status().deleted)
133 s = set(mctx.status().deleted)
134 return mctx.predicate(s.__contains__, predrepr='deleted')
134 return mctx.predicate(s.__contains__, predrepr='deleted')
135
135
136 @predicate('unknown()', callstatus=True)
136 @predicate('unknown()', callstatus=True, weight=50)
137 def unknown(mctx, x):
137 def unknown(mctx, x):
138 """File that is unknown according to :hg:`status`."""
138 """File that is unknown according to :hg:`status`."""
139 # i18n: "unknown" is a keyword
139 # i18n: "unknown" is a keyword
@@ -141,7 +141,7 b' def unknown(mctx, x):'
141 s = set(mctx.status().unknown)
141 s = set(mctx.status().unknown)
142 return mctx.predicate(s.__contains__, predrepr='unknown')
142 return mctx.predicate(s.__contains__, predrepr='unknown')
143
143
144 @predicate('ignored()', callstatus=True)
144 @predicate('ignored()', callstatus=True, weight=50)
145 def ignored(mctx, x):
145 def ignored(mctx, x):
146 """File that is ignored according to :hg:`status`."""
146 """File that is ignored according to :hg:`status`."""
147 # i18n: "ignored" is a keyword
147 # i18n: "ignored" is a keyword
@@ -149,7 +149,7 b' def ignored(mctx, x):'
149 s = set(mctx.status().ignored)
149 s = set(mctx.status().ignored)
150 return mctx.predicate(s.__contains__, predrepr='ignored')
150 return mctx.predicate(s.__contains__, predrepr='ignored')
151
151
152 @predicate('clean()', callstatus=True)
152 @predicate('clean()', callstatus=True, weight=10)
153 def clean(mctx, x):
153 def clean(mctx, x):
154 """File that is clean according to :hg:`status`.
154 """File that is clean according to :hg:`status`.
155 """
155 """
@@ -165,7 +165,7 b' def tracked(mctx, x):'
165 getargs(x, 0, 0, _("tracked takes no arguments"))
165 getargs(x, 0, 0, _("tracked takes no arguments"))
166 return mctx.predicate(mctx.ctx.__contains__, predrepr='tracked')
166 return mctx.predicate(mctx.ctx.__contains__, predrepr='tracked')
167
167
168 @predicate('binary()')
168 @predicate('binary()', weight=30)
169 def binary(mctx, x):
169 def binary(mctx, x):
170 """File that appears to be binary (contains NUL bytes).
170 """File that appears to be binary (contains NUL bytes).
171 """
171 """
@@ -192,7 +192,7 b' def symlink(mctx, x):'
192 ctx = mctx.ctx
192 ctx = mctx.ctx
193 return mctx.predicate(lambda f: ctx.flags(f) == 'l', predrepr='symlink')
193 return mctx.predicate(lambda f: ctx.flags(f) == 'l', predrepr='symlink')
194
194
195 @predicate('resolved()')
195 @predicate('resolved()', weight=10)
196 def resolved(mctx, x):
196 def resolved(mctx, x):
197 """File that is marked resolved according to :hg:`resolve -l`.
197 """File that is marked resolved according to :hg:`resolve -l`.
198 """
198 """
@@ -204,7 +204,7 b' def resolved(mctx, x):'
204 return mctx.predicate(lambda f: f in ms and ms[f] == 'r',
204 return mctx.predicate(lambda f: f in ms and ms[f] == 'r',
205 predrepr='resolved')
205 predrepr='resolved')
206
206
207 @predicate('unresolved()')
207 @predicate('unresolved()', weight=10)
208 def unresolved(mctx, x):
208 def unresolved(mctx, x):
209 """File that is marked unresolved according to :hg:`resolve -l`.
209 """File that is marked unresolved according to :hg:`resolve -l`.
210 """
210 """
@@ -216,7 +216,7 b' def unresolved(mctx, x):'
216 return mctx.predicate(lambda f: f in ms and ms[f] == 'u',
216 return mctx.predicate(lambda f: f in ms and ms[f] == 'u',
217 predrepr='unresolved')
217 predrepr='unresolved')
218
218
219 @predicate('hgignore()')
219 @predicate('hgignore()', weight=10)
220 def hgignore(mctx, x):
220 def hgignore(mctx, x):
221 """File that matches the active .hgignore pattern.
221 """File that matches the active .hgignore pattern.
222 """
222 """
@@ -224,7 +224,7 b' def hgignore(mctx, x):'
224 getargs(x, 0, 0, _("hgignore takes no arguments"))
224 getargs(x, 0, 0, _("hgignore takes no arguments"))
225 return mctx.ctx.repo().dirstate._ignore
225 return mctx.ctx.repo().dirstate._ignore
226
226
227 @predicate('portable()')
227 @predicate('portable()', weight=0.5)
228 def portable(mctx, x):
228 def portable(mctx, x):
229 """File that has a portable name. (This doesn't include filenames with case
229 """File that has a portable name. (This doesn't include filenames with case
230 collisions.)
230 collisions.)
@@ -234,7 +234,7 b' def portable(mctx, x):'
234 return mctx.predicate(lambda f: util.checkwinfilename(f) is None,
234 return mctx.predicate(lambda f: util.checkwinfilename(f) is None,
235 predrepr='portable')
235 predrepr='portable')
236
236
237 @predicate('grep(regex)')
237 @predicate('grep(regex)', weight=30)
238 def grep(mctx, x):
238 def grep(mctx, x):
239 """File contains the given regular expression.
239 """File contains the given regular expression.
240 """
240 """
@@ -288,7 +288,7 b' def sizematcher(expr):'
288 b = _sizetomax(expr)
288 b = _sizetomax(expr)
289 return lambda x: x >= a and x <= b
289 return lambda x: x >= a and x <= b
290
290
291 @predicate('size(expression)')
291 @predicate('size(expression)', weight=10)
292 def size(mctx, x):
292 def size(mctx, x):
293 """File size matches the given expression. Examples:
293 """File size matches the given expression. Examples:
294
294
@@ -303,7 +303,7 b' def size(mctx, x):'
303 return mctx.fpredicate(lambda fctx: m(fctx.size()),
303 return mctx.fpredicate(lambda fctx: m(fctx.size()),
304 predrepr=('size(%r)', expr), cache=True)
304 predrepr=('size(%r)', expr), cache=True)
305
305
306 @predicate('encoding(name)')
306 @predicate('encoding(name)', weight=30)
307 def encoding(mctx, x):
307 def encoding(mctx, x):
308 """File can be successfully decoded with the given character
308 """File can be successfully decoded with the given character
309 encoding. May not be useful for encodings other than ASCII and
309 encoding. May not be useful for encodings other than ASCII and
@@ -325,7 +325,7 b' def encoding(mctx, x):'
325
325
326 return mctx.fpredicate(encp, predrepr=('encoding(%r)', enc), cache=True)
326 return mctx.fpredicate(encp, predrepr=('encoding(%r)', enc), cache=True)
327
327
328 @predicate('eol(style)')
328 @predicate('eol(style)', weight=30)
329 def eol(mctx, x):
329 def eol(mctx, x):
330 """File contains newlines of the given style (dos, unix, mac). Binary
330 """File contains newlines of the given style (dos, unix, mac). Binary
331 files are excluded, files with mixed line endings match multiple
331 files are excluded, files with mixed line endings match multiple
@@ -359,7 +359,7 b' def copied(mctx, x):'
359 return p and p[0].path() != fctx.path()
359 return p and p[0].path() != fctx.path()
360 return mctx.fpredicate(copiedp, predrepr='copied', cache=True)
360 return mctx.fpredicate(copiedp, predrepr='copied', cache=True)
361
361
362 @predicate('revs(revs, pattern)')
362 @predicate('revs(revs, pattern)', weight=10)
363 def revs(mctx, x):
363 def revs(mctx, x):
364 """Evaluate set in the specified revisions. If the revset match multiple
364 """Evaluate set in the specified revisions. If the revset match multiple
365 revs, this will return file matching pattern in any of the revision.
365 revs, this will return file matching pattern in any of the revision.
@@ -381,7 +381,7 b' def revs(mctx, x):'
381 return matchers[0]
381 return matchers[0]
382 return matchmod.unionmatcher(matchers)
382 return matchmod.unionmatcher(matchers)
383
383
384 @predicate('status(base, rev, pattern)')
384 @predicate('status(base, rev, pattern)', weight=10)
385 def status(mctx, x):
385 def status(mctx, x):
386 """Evaluate predicate using status change between ``base`` and
386 """Evaluate predicate using status change between ``base`` and
387 ``rev``. Examples:
387 ``rev``. Examples:
@@ -250,6 +250,15 b' class filesetpredicate(_funcregistrarbas'
250 Optional argument 'weight' indicates the estimated run-time cost, useful
250 Optional argument 'weight' indicates the estimated run-time cost, useful
251 for static optimization, default is 1. Higher weight means more expensive.
251 for static optimization, default is 1. Higher weight means more expensive.
252
252
253 ====== =============================================================
254 Weight Description and examples
255 ====== =============================================================
256 0.5 basic match patterns (e.g. a symbol)
257 10 computing status (e.g. added()) or accessing a few files
258 30 reading file content for each (e.g. grep())
259 50 scanning working directory (ignored())
260 ====== =============================================================
261
253 'filesetpredicate' instance in example above can be used to
262 'filesetpredicate' instance in example above can be used to
254 decorate multiple functions.
263 decorate multiple functions.
255
264
General Comments 0
You need to be logged in to leave comments. Login now