Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/fileset.py @ 31702:992882cef7e1
fileset: perform membership test against set for status queries
Previously, fileset functions operating on status items performed
membership tests against a list of items. When there are thousands
of items having a specific status, that test can be extremely
slow. Changing the membership test to a set makes this operation
substantially faster.
On the mozilla-central repo:
$ hg files -r d14cac631ecc 'set:added()'
before: 28.120s
after: 0.860s
$ hg status --change d14cac631ecc --added
0.690s
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Tue, 28 Mar 2017 14:40:13 -0700 |
parents | 2140e12d3258 |
children | 4240be02df79 |
comparison
equal
deleted
inserted
replaced
31701:9d3d56aa1a9f | 31702:992882cef7e1 |
---|---|
152 def modified(mctx, x): | 152 def modified(mctx, x): |
153 """File that is modified according to :hg:`status`. | 153 """File that is modified according to :hg:`status`. |
154 """ | 154 """ |
155 # i18n: "modified" is a keyword | 155 # i18n: "modified" is a keyword |
156 getargs(x, 0, 0, _("modified takes no arguments")) | 156 getargs(x, 0, 0, _("modified takes no arguments")) |
157 s = mctx.status().modified | 157 s = set(mctx.status().modified) |
158 return [f for f in mctx.subset if f in s] | 158 return [f for f in mctx.subset if f in s] |
159 | 159 |
160 @predicate('added()', callstatus=True) | 160 @predicate('added()', callstatus=True) |
161 def added(mctx, x): | 161 def added(mctx, x): |
162 """File that is added according to :hg:`status`. | 162 """File that is added according to :hg:`status`. |
163 """ | 163 """ |
164 # i18n: "added" is a keyword | 164 # i18n: "added" is a keyword |
165 getargs(x, 0, 0, _("added takes no arguments")) | 165 getargs(x, 0, 0, _("added takes no arguments")) |
166 s = mctx.status().added | 166 s = set(mctx.status().added) |
167 return [f for f in mctx.subset if f in s] | 167 return [f for f in mctx.subset if f in s] |
168 | 168 |
169 @predicate('removed()', callstatus=True) | 169 @predicate('removed()', callstatus=True) |
170 def removed(mctx, x): | 170 def removed(mctx, x): |
171 """File that is removed according to :hg:`status`. | 171 """File that is removed according to :hg:`status`. |
172 """ | 172 """ |
173 # i18n: "removed" is a keyword | 173 # i18n: "removed" is a keyword |
174 getargs(x, 0, 0, _("removed takes no arguments")) | 174 getargs(x, 0, 0, _("removed takes no arguments")) |
175 s = mctx.status().removed | 175 s = set(mctx.status().removed) |
176 return [f for f in mctx.subset if f in s] | 176 return [f for f in mctx.subset if f in s] |
177 | 177 |
178 @predicate('deleted()', callstatus=True) | 178 @predicate('deleted()', callstatus=True) |
179 def deleted(mctx, x): | 179 def deleted(mctx, x): |
180 """Alias for ``missing()``. | 180 """Alias for ``missing()``. |
181 """ | 181 """ |
182 # i18n: "deleted" is a keyword | 182 # i18n: "deleted" is a keyword |
183 getargs(x, 0, 0, _("deleted takes no arguments")) | 183 getargs(x, 0, 0, _("deleted takes no arguments")) |
184 s = mctx.status().deleted | 184 s = set(mctx.status().deleted) |
185 return [f for f in mctx.subset if f in s] | 185 return [f for f in mctx.subset if f in s] |
186 | 186 |
187 @predicate('missing()', callstatus=True) | 187 @predicate('missing()', callstatus=True) |
188 def missing(mctx, x): | 188 def missing(mctx, x): |
189 """File that is missing according to :hg:`status`. | 189 """File that is missing according to :hg:`status`. |
190 """ | 190 """ |
191 # i18n: "missing" is a keyword | 191 # i18n: "missing" is a keyword |
192 getargs(x, 0, 0, _("missing takes no arguments")) | 192 getargs(x, 0, 0, _("missing takes no arguments")) |
193 s = mctx.status().deleted | 193 s = set(mctx.status().deleted) |
194 return [f for f in mctx.subset if f in s] | 194 return [f for f in mctx.subset if f in s] |
195 | 195 |
196 @predicate('unknown()', callstatus=True) | 196 @predicate('unknown()', callstatus=True) |
197 def unknown(mctx, x): | 197 def unknown(mctx, x): |
198 """File that is unknown according to :hg:`status`. These files will only be | 198 """File that is unknown according to :hg:`status`. These files will only be |
199 considered if this predicate is used. | 199 considered if this predicate is used. |
200 """ | 200 """ |
201 # i18n: "unknown" is a keyword | 201 # i18n: "unknown" is a keyword |
202 getargs(x, 0, 0, _("unknown takes no arguments")) | 202 getargs(x, 0, 0, _("unknown takes no arguments")) |
203 s = mctx.status().unknown | 203 s = set(mctx.status().unknown) |
204 return [f for f in mctx.subset if f in s] | 204 return [f for f in mctx.subset if f in s] |
205 | 205 |
206 @predicate('ignored()', callstatus=True) | 206 @predicate('ignored()', callstatus=True) |
207 def ignored(mctx, x): | 207 def ignored(mctx, x): |
208 """File that is ignored according to :hg:`status`. These files will only be | 208 """File that is ignored according to :hg:`status`. These files will only be |
209 considered if this predicate is used. | 209 considered if this predicate is used. |
210 """ | 210 """ |
211 # i18n: "ignored" is a keyword | 211 # i18n: "ignored" is a keyword |
212 getargs(x, 0, 0, _("ignored takes no arguments")) | 212 getargs(x, 0, 0, _("ignored takes no arguments")) |
213 s = mctx.status().ignored | 213 s = set(mctx.status().ignored) |
214 return [f for f in mctx.subset if f in s] | 214 return [f for f in mctx.subset if f in s] |
215 | 215 |
216 @predicate('clean()', callstatus=True) | 216 @predicate('clean()', callstatus=True) |
217 def clean(mctx, x): | 217 def clean(mctx, x): |
218 """File that is clean according to :hg:`status`. | 218 """File that is clean according to :hg:`status`. |
219 """ | 219 """ |
220 # i18n: "clean" is a keyword | 220 # i18n: "clean" is a keyword |
221 getargs(x, 0, 0, _("clean takes no arguments")) | 221 getargs(x, 0, 0, _("clean takes no arguments")) |
222 s = mctx.status().clean | 222 s = set(mctx.status().clean) |
223 return [f for f in mctx.subset if f in s] | 223 return [f for f in mctx.subset if f in s] |
224 | 224 |
225 def func(mctx, a, b): | 225 def func(mctx, a, b): |
226 if a[0] == 'symbol' and a[1] in symbols: | 226 if a[0] == 'symbol' and a[1] in symbols: |
227 funcname = a[1] | 227 funcname = a[1] |