Show More
@@ -1,2232 +1,2225 | |||||
1 | # revset.py - revision set queries for mercurial |
|
1 | # revset.py - revision set queries for mercurial | |
2 | # |
|
2 | # | |
3 | # Copyright 2010 Matt Mackall <mpm@selenic.com> |
|
3 | # Copyright 2010 Matt Mackall <mpm@selenic.com> | |
4 | # |
|
4 | # | |
5 | # This software may be used and distributed according to the terms of the |
|
5 | # This software may be used and distributed according to the terms of the | |
6 | # GNU General Public License version 2 or any later version. |
|
6 | # GNU General Public License version 2 or any later version. | |
7 |
|
7 | |||
8 | from __future__ import absolute_import |
|
8 | from __future__ import absolute_import | |
9 |
|
9 | |||
10 | import re |
|
10 | import re | |
11 |
|
11 | |||
12 | from .i18n import _ |
|
12 | from .i18n import _ | |
13 | from . import ( |
|
13 | from . import ( | |
14 | dagop, |
|
14 | dagop, | |
15 | destutil, |
|
15 | destutil, | |
16 | encoding, |
|
16 | encoding, | |
17 | error, |
|
17 | error, | |
18 | hbisect, |
|
18 | hbisect, | |
19 | match as matchmod, |
|
19 | match as matchmod, | |
20 | node, |
|
20 | node, | |
21 | obsolete as obsmod, |
|
21 | obsolete as obsmod, | |
22 | obsutil, |
|
22 | obsutil, | |
23 | pathutil, |
|
23 | pathutil, | |
24 | phases, |
|
24 | phases, | |
25 | registrar, |
|
25 | registrar, | |
26 | repoview, |
|
26 | repoview, | |
27 | revsetlang, |
|
27 | revsetlang, | |
28 | scmutil, |
|
28 | scmutil, | |
29 | smartset, |
|
29 | smartset, | |
30 | util, |
|
30 | util, | |
31 | ) |
|
31 | ) | |
32 |
|
32 | |||
33 | # helpers for processing parsed tree |
|
33 | # helpers for processing parsed tree | |
34 | getsymbol = revsetlang.getsymbol |
|
34 | getsymbol = revsetlang.getsymbol | |
35 | getstring = revsetlang.getstring |
|
35 | getstring = revsetlang.getstring | |
36 | getinteger = revsetlang.getinteger |
|
36 | getinteger = revsetlang.getinteger | |
37 | getboolean = revsetlang.getboolean |
|
37 | getboolean = revsetlang.getboolean | |
38 | getlist = revsetlang.getlist |
|
38 | getlist = revsetlang.getlist | |
39 | getrange = revsetlang.getrange |
|
39 | getrange = revsetlang.getrange | |
40 | getargs = revsetlang.getargs |
|
40 | getargs = revsetlang.getargs | |
41 | getargsdict = revsetlang.getargsdict |
|
41 | getargsdict = revsetlang.getargsdict | |
42 |
|
42 | |||
43 | baseset = smartset.baseset |
|
43 | baseset = smartset.baseset | |
44 | generatorset = smartset.generatorset |
|
44 | generatorset = smartset.generatorset | |
45 | spanset = smartset.spanset |
|
45 | spanset = smartset.spanset | |
46 | fullreposet = smartset.fullreposet |
|
46 | fullreposet = smartset.fullreposet | |
47 |
|
47 | |||
48 | # Constants for ordering requirement, used in getset(): |
|
48 | # Constants for ordering requirement, used in getset(): | |
49 | # |
|
49 | # | |
50 | # If 'define', any nested functions and operations MAY change the ordering of |
|
50 | # If 'define', any nested functions and operations MAY change the ordering of | |
51 | # the entries in the set (but if changes the ordering, it MUST ALWAYS change |
|
51 | # the entries in the set (but if changes the ordering, it MUST ALWAYS change | |
52 | # it). If 'follow', any nested functions and operations MUST take the ordering |
|
52 | # it). If 'follow', any nested functions and operations MUST take the ordering | |
53 | # specified by the first operand to the '&' operator. |
|
53 | # specified by the first operand to the '&' operator. | |
54 | # |
|
54 | # | |
55 | # For instance, |
|
55 | # For instance, | |
56 | # |
|
56 | # | |
57 | # X & (Y | Z) |
|
57 | # X & (Y | Z) | |
58 | # ^ ^^^^^^^ |
|
58 | # ^ ^^^^^^^ | |
59 | # | follow |
|
59 | # | follow | |
60 | # define |
|
60 | # define | |
61 | # |
|
61 | # | |
62 | # will be evaluated as 'or(y(x()), z(x()))', where 'x()' can change the order |
|
62 | # will be evaluated as 'or(y(x()), z(x()))', where 'x()' can change the order | |
63 | # of the entries in the set, but 'y()', 'z()' and 'or()' shouldn't. |
|
63 | # of the entries in the set, but 'y()', 'z()' and 'or()' shouldn't. | |
64 | # |
|
64 | # | |
65 | # 'any' means the order doesn't matter. For instance, |
|
65 | # 'any' means the order doesn't matter. For instance, | |
66 | # |
|
66 | # | |
67 | # (X & !Y) | ancestors(Z) |
|
67 | # (X & !Y) | ancestors(Z) | |
68 | # ^ ^ |
|
68 | # ^ ^ | |
69 | # any any |
|
69 | # any any | |
70 | # |
|
70 | # | |
71 | # For 'X & !Y', 'X' decides the order and 'Y' is subtracted from 'X', so the |
|
71 | # For 'X & !Y', 'X' decides the order and 'Y' is subtracted from 'X', so the | |
72 | # order of 'Y' does not matter. For 'ancestors(Z)', Z's order does not matter |
|
72 | # order of 'Y' does not matter. For 'ancestors(Z)', Z's order does not matter | |
73 | # since 'ancestors' does not care about the order of its argument. |
|
73 | # since 'ancestors' does not care about the order of its argument. | |
74 | # |
|
74 | # | |
75 | # Currently, most revsets do not care about the order, so 'define' is |
|
75 | # Currently, most revsets do not care about the order, so 'define' is | |
76 | # equivalent to 'follow' for them, and the resulting order is based on the |
|
76 | # equivalent to 'follow' for them, and the resulting order is based on the | |
77 | # 'subset' parameter passed down to them: |
|
77 | # 'subset' parameter passed down to them: | |
78 | # |
|
78 | # | |
79 | # m = revset.match(...) |
|
79 | # m = revset.match(...) | |
80 | # m(repo, subset, order=defineorder) |
|
80 | # m(repo, subset, order=defineorder) | |
81 | # ^^^^^^ |
|
81 | # ^^^^^^ | |
82 | # For most revsets, 'define' means using the order this subset provides |
|
82 | # For most revsets, 'define' means using the order this subset provides | |
83 | # |
|
83 | # | |
84 | # There are a few revsets that always redefine the order if 'define' is |
|
84 | # There are a few revsets that always redefine the order if 'define' is | |
85 | # specified: 'sort(X)', 'reverse(X)', 'x:y'. |
|
85 | # specified: 'sort(X)', 'reverse(X)', 'x:y'. | |
86 | anyorder = 'any' # don't care the order, could be even random-shuffled |
|
86 | anyorder = 'any' # don't care the order, could be even random-shuffled | |
87 | defineorder = 'define' # ALWAYS redefine, or ALWAYS follow the current order |
|
87 | defineorder = 'define' # ALWAYS redefine, or ALWAYS follow the current order | |
88 | followorder = 'follow' # MUST follow the current order |
|
88 | followorder = 'follow' # MUST follow the current order | |
89 |
|
89 | |||
90 | # helpers |
|
90 | # helpers | |
91 |
|
91 | |||
92 | def getset(repo, subset, x, order=defineorder): |
|
92 | def getset(repo, subset, x, order=defineorder): | |
93 | if not x: |
|
93 | if not x: | |
94 | raise error.ParseError(_("missing argument")) |
|
94 | raise error.ParseError(_("missing argument")) | |
95 | return methods[x[0]](repo, subset, *x[1:], order=order) |
|
95 | return methods[x[0]](repo, subset, *x[1:], order=order) | |
96 |
|
96 | |||
97 | def _getrevsource(repo, r): |
|
97 | def _getrevsource(repo, r): | |
98 | extra = repo[r].extra() |
|
98 | extra = repo[r].extra() | |
99 | for label in ('source', 'transplant_source', 'rebase_source'): |
|
99 | for label in ('source', 'transplant_source', 'rebase_source'): | |
100 | if label in extra: |
|
100 | if label in extra: | |
101 | try: |
|
101 | try: | |
102 | return repo[extra[label]].rev() |
|
102 | return repo[extra[label]].rev() | |
103 | except error.RepoLookupError: |
|
103 | except error.RepoLookupError: | |
104 | pass |
|
104 | pass | |
105 | return None |
|
105 | return None | |
106 |
|
106 | |||
107 | # operator methods |
|
107 | # operator methods | |
108 |
|
108 | |||
109 | def stringset(repo, subset, x, order): |
|
109 | def stringset(repo, subset, x, order): | |
110 | x = scmutil.intrev(repo[x]) |
|
110 | x = scmutil.intrev(repo[x]) | |
111 | if (x in subset |
|
111 | if (x in subset | |
112 | or x == node.nullrev and isinstance(subset, fullreposet)): |
|
112 | or x == node.nullrev and isinstance(subset, fullreposet)): | |
113 | return baseset([x]) |
|
113 | return baseset([x]) | |
114 | return baseset() |
|
114 | return baseset() | |
115 |
|
115 | |||
116 | def rangeset(repo, subset, x, y, order): |
|
116 | def rangeset(repo, subset, x, y, order): | |
117 | m = getset(repo, fullreposet(repo), x) |
|
117 | m = getset(repo, fullreposet(repo), x) | |
118 | n = getset(repo, fullreposet(repo), y) |
|
118 | n = getset(repo, fullreposet(repo), y) | |
119 |
|
119 | |||
120 | if not m or not n: |
|
120 | if not m or not n: | |
121 | return baseset() |
|
121 | return baseset() | |
122 | return _makerangeset(repo, subset, m.first(), n.last(), order) |
|
122 | return _makerangeset(repo, subset, m.first(), n.last(), order) | |
123 |
|
123 | |||
124 | def rangeall(repo, subset, x, order): |
|
124 | def rangeall(repo, subset, x, order): | |
125 | assert x is None |
|
125 | assert x is None | |
126 | return _makerangeset(repo, subset, 0, len(repo) - 1, order) |
|
126 | return _makerangeset(repo, subset, 0, len(repo) - 1, order) | |
127 |
|
127 | |||
128 | def rangepre(repo, subset, y, order): |
|
128 | def rangepre(repo, subset, y, order): | |
129 | # ':y' can't be rewritten to '0:y' since '0' may be hidden |
|
129 | # ':y' can't be rewritten to '0:y' since '0' may be hidden | |
130 | n = getset(repo, fullreposet(repo), y) |
|
130 | n = getset(repo, fullreposet(repo), y) | |
131 | if not n: |
|
131 | if not n: | |
132 | return baseset() |
|
132 | return baseset() | |
133 | return _makerangeset(repo, subset, 0, n.last(), order) |
|
133 | return _makerangeset(repo, subset, 0, n.last(), order) | |
134 |
|
134 | |||
135 | def rangepost(repo, subset, x, order): |
|
135 | def rangepost(repo, subset, x, order): | |
136 | m = getset(repo, fullreposet(repo), x) |
|
136 | m = getset(repo, fullreposet(repo), x) | |
137 | if not m: |
|
137 | if not m: | |
138 | return baseset() |
|
138 | return baseset() | |
139 | return _makerangeset(repo, subset, m.first(), len(repo) - 1, order) |
|
139 | return _makerangeset(repo, subset, m.first(), len(repo) - 1, order) | |
140 |
|
140 | |||
141 | def _makerangeset(repo, subset, m, n, order): |
|
141 | def _makerangeset(repo, subset, m, n, order): | |
142 | if m == n: |
|
142 | if m == n: | |
143 | r = baseset([m]) |
|
143 | r = baseset([m]) | |
144 | elif n == node.wdirrev: |
|
144 | elif n == node.wdirrev: | |
145 | r = spanset(repo, m, len(repo)) + baseset([n]) |
|
145 | r = spanset(repo, m, len(repo)) + baseset([n]) | |
146 | elif m == node.wdirrev: |
|
146 | elif m == node.wdirrev: | |
147 | r = baseset([m]) + spanset(repo, len(repo) - 1, n - 1) |
|
147 | r = baseset([m]) + spanset(repo, len(repo) - 1, n - 1) | |
148 | elif m < n: |
|
148 | elif m < n: | |
149 | r = spanset(repo, m, n + 1) |
|
149 | r = spanset(repo, m, n + 1) | |
150 | else: |
|
150 | else: | |
151 | r = spanset(repo, m, n - 1) |
|
151 | r = spanset(repo, m, n - 1) | |
152 |
|
152 | |||
153 | if order == defineorder: |
|
153 | if order == defineorder: | |
154 | return r & subset |
|
154 | return r & subset | |
155 | else: |
|
155 | else: | |
156 | # carrying the sorting over when possible would be more efficient |
|
156 | # carrying the sorting over when possible would be more efficient | |
157 | return subset & r |
|
157 | return subset & r | |
158 |
|
158 | |||
159 | def dagrange(repo, subset, x, y, order): |
|
159 | def dagrange(repo, subset, x, y, order): | |
160 | r = fullreposet(repo) |
|
160 | r = fullreposet(repo) | |
161 | xs = dagop.reachableroots(repo, getset(repo, r, x), getset(repo, r, y), |
|
161 | xs = dagop.reachableroots(repo, getset(repo, r, x), getset(repo, r, y), | |
162 | includepath=True) |
|
162 | includepath=True) | |
163 | return subset & xs |
|
163 | return subset & xs | |
164 |
|
164 | |||
165 | def andset(repo, subset, x, y, order): |
|
165 | def andset(repo, subset, x, y, order): | |
166 | if order == anyorder: |
|
166 | if order == anyorder: | |
167 | yorder = anyorder |
|
167 | yorder = anyorder | |
168 | else: |
|
168 | else: | |
169 | yorder = followorder |
|
169 | yorder = followorder | |
170 | return getset(repo, getset(repo, subset, x, order), y, yorder) |
|
170 | return getset(repo, getset(repo, subset, x, order), y, yorder) | |
171 |
|
171 | |||
172 | def andsmallyset(repo, subset, x, y, order): |
|
172 | def andsmallyset(repo, subset, x, y, order): | |
173 | # 'andsmally(x, y)' is equivalent to 'and(x, y)', but faster when y is small |
|
173 | # 'andsmally(x, y)' is equivalent to 'and(x, y)', but faster when y is small | |
174 | if order == anyorder: |
|
174 | if order == anyorder: | |
175 | yorder = anyorder |
|
175 | yorder = anyorder | |
176 | else: |
|
176 | else: | |
177 | yorder = followorder |
|
177 | yorder = followorder | |
178 | return getset(repo, getset(repo, subset, y, yorder), x, order) |
|
178 | return getset(repo, getset(repo, subset, y, yorder), x, order) | |
179 |
|
179 | |||
180 | def differenceset(repo, subset, x, y, order): |
|
180 | def differenceset(repo, subset, x, y, order): | |
181 | return getset(repo, subset, x, order) - getset(repo, subset, y, anyorder) |
|
181 | return getset(repo, subset, x, order) - getset(repo, subset, y, anyorder) | |
182 |
|
182 | |||
183 | def _orsetlist(repo, subset, xs, order): |
|
183 | def _orsetlist(repo, subset, xs, order): | |
184 | assert xs |
|
184 | assert xs | |
185 | if len(xs) == 1: |
|
185 | if len(xs) == 1: | |
186 | return getset(repo, subset, xs[0], order) |
|
186 | return getset(repo, subset, xs[0], order) | |
187 | p = len(xs) // 2 |
|
187 | p = len(xs) // 2 | |
188 | a = _orsetlist(repo, subset, xs[:p], order) |
|
188 | a = _orsetlist(repo, subset, xs[:p], order) | |
189 | b = _orsetlist(repo, subset, xs[p:], order) |
|
189 | b = _orsetlist(repo, subset, xs[p:], order) | |
190 | return a + b |
|
190 | return a + b | |
191 |
|
191 | |||
192 | def orset(repo, subset, x, order): |
|
192 | def orset(repo, subset, x, order): | |
193 | xs = getlist(x) |
|
193 | xs = getlist(x) | |
194 | if order == followorder: |
|
194 | if order == followorder: | |
195 | # slow path to take the subset order |
|
195 | # slow path to take the subset order | |
196 | return subset & _orsetlist(repo, fullreposet(repo), xs, anyorder) |
|
196 | return subset & _orsetlist(repo, fullreposet(repo), xs, anyorder) | |
197 | else: |
|
197 | else: | |
198 | return _orsetlist(repo, subset, xs, order) |
|
198 | return _orsetlist(repo, subset, xs, order) | |
199 |
|
199 | |||
200 | def notset(repo, subset, x, order): |
|
200 | def notset(repo, subset, x, order): | |
201 | return subset - getset(repo, subset, x, anyorder) |
|
201 | return subset - getset(repo, subset, x, anyorder) | |
202 |
|
202 | |||
203 | def relationset(repo, subset, x, y, order): |
|
203 | def relationset(repo, subset, x, y, order): | |
204 | raise error.ParseError(_("can't use a relation in this context")) |
|
204 | raise error.ParseError(_("can't use a relation in this context")) | |
205 |
|
205 | |||
206 | def relsubscriptset(repo, subset, x, y, z, order): |
|
206 | def relsubscriptset(repo, subset, x, y, z, order): | |
207 | # this is pretty basic implementation of 'x#y[z]' operator, still |
|
207 | # this is pretty basic implementation of 'x#y[z]' operator, still | |
208 | # experimental so undocumented. see the wiki for further ideas. |
|
208 | # experimental so undocumented. see the wiki for further ideas. | |
209 | # https://www.mercurial-scm.org/wiki/RevsetOperatorPlan |
|
209 | # https://www.mercurial-scm.org/wiki/RevsetOperatorPlan | |
210 | rel = getsymbol(y) |
|
210 | rel = getsymbol(y) | |
211 | n = getinteger(z, _("relation subscript must be an integer")) |
|
211 | n = getinteger(z, _("relation subscript must be an integer")) | |
212 |
|
212 | |||
213 | # TODO: perhaps this should be a table of relation functions |
|
213 | # TODO: perhaps this should be a table of relation functions | |
214 | if rel in ('g', 'generations'): |
|
214 | if rel in ('g', 'generations'): | |
215 | # TODO: support range, rewrite tests, and drop startdepth argument |
|
215 | # TODO: support range, rewrite tests, and drop startdepth argument | |
216 | # from ancestors() and descendants() predicates |
|
216 | # from ancestors() and descendants() predicates | |
217 | if n <= 0: |
|
217 | if n <= 0: | |
218 | n = -n |
|
218 | n = -n | |
219 | return _ancestors(repo, subset, x, startdepth=n, stopdepth=n + 1) |
|
219 | return _ancestors(repo, subset, x, startdepth=n, stopdepth=n + 1) | |
220 | else: |
|
220 | else: | |
221 | return _descendants(repo, subset, x, startdepth=n, stopdepth=n + 1) |
|
221 | return _descendants(repo, subset, x, startdepth=n, stopdepth=n + 1) | |
222 |
|
222 | |||
223 | raise error.UnknownIdentifier(rel, ['generations']) |
|
223 | raise error.UnknownIdentifier(rel, ['generations']) | |
224 |
|
224 | |||
225 | def subscriptset(repo, subset, x, y, order): |
|
225 | def subscriptset(repo, subset, x, y, order): | |
226 | raise error.ParseError(_("can't use a subscript in this context")) |
|
226 | raise error.ParseError(_("can't use a subscript in this context")) | |
227 |
|
227 | |||
228 | def listset(repo, subset, *xs, **opts): |
|
228 | def listset(repo, subset, *xs, **opts): | |
229 | raise error.ParseError(_("can't use a list in this context"), |
|
229 | raise error.ParseError(_("can't use a list in this context"), | |
230 | hint=_('see hg help "revsets.x or y"')) |
|
230 | hint=_('see hg help "revsets.x or y"')) | |
231 |
|
231 | |||
232 | def keyvaluepair(repo, subset, k, v, order): |
|
232 | def keyvaluepair(repo, subset, k, v, order): | |
233 | raise error.ParseError(_("can't use a key-value pair in this context")) |
|
233 | raise error.ParseError(_("can't use a key-value pair in this context")) | |
234 |
|
234 | |||
235 | def func(repo, subset, a, b, order): |
|
235 | def func(repo, subset, a, b, order): | |
236 | f = getsymbol(a) |
|
236 | f = getsymbol(a) | |
237 | if f in symbols: |
|
237 | if f in symbols: | |
238 | func = symbols[f] |
|
238 | func = symbols[f] | |
239 | if getattr(func, '_takeorder', False): |
|
239 | if getattr(func, '_takeorder', False): | |
240 | return func(repo, subset, b, order) |
|
240 | return func(repo, subset, b, order) | |
241 | return func(repo, subset, b) |
|
241 | return func(repo, subset, b) | |
242 |
|
242 | |||
243 | keep = lambda fn: getattr(fn, '__doc__', None) is not None |
|
243 | keep = lambda fn: getattr(fn, '__doc__', None) is not None | |
244 |
|
244 | |||
245 | syms = [s for (s, fn) in symbols.items() if keep(fn)] |
|
245 | syms = [s for (s, fn) in symbols.items() if keep(fn)] | |
246 | raise error.UnknownIdentifier(f, syms) |
|
246 | raise error.UnknownIdentifier(f, syms) | |
247 |
|
247 | |||
248 | # functions |
|
248 | # functions | |
249 |
|
249 | |||
250 | # symbols are callables like: |
|
250 | # symbols are callables like: | |
251 | # fn(repo, subset, x) |
|
251 | # fn(repo, subset, x) | |
252 | # with: |
|
252 | # with: | |
253 | # repo - current repository instance |
|
253 | # repo - current repository instance | |
254 | # subset - of revisions to be examined |
|
254 | # subset - of revisions to be examined | |
255 | # x - argument in tree form |
|
255 | # x - argument in tree form | |
256 | symbols = revsetlang.symbols |
|
256 | symbols = revsetlang.symbols | |
257 |
|
257 | |||
258 | # symbols which can't be used for a DoS attack for any given input |
|
258 | # symbols which can't be used for a DoS attack for any given input | |
259 | # (e.g. those which accept regexes as plain strings shouldn't be included) |
|
259 | # (e.g. those which accept regexes as plain strings shouldn't be included) | |
260 | # functions that just return a lot of changesets (like all) don't count here |
|
260 | # functions that just return a lot of changesets (like all) don't count here | |
261 | safesymbols = set() |
|
261 | safesymbols = set() | |
262 |
|
262 | |||
263 | predicate = registrar.revsetpredicate() |
|
263 | predicate = registrar.revsetpredicate() | |
264 |
|
264 | |||
265 | @predicate('_destupdate') |
|
265 | @predicate('_destupdate') | |
266 | def _destupdate(repo, subset, x): |
|
266 | def _destupdate(repo, subset, x): | |
267 | # experimental revset for update destination |
|
267 | # experimental revset for update destination | |
268 | args = getargsdict(x, 'limit', 'clean') |
|
268 | args = getargsdict(x, 'limit', 'clean') | |
269 | return subset & baseset([destutil.destupdate(repo, **args)[0]]) |
|
269 | return subset & baseset([destutil.destupdate(repo, **args)[0]]) | |
270 |
|
270 | |||
271 | @predicate('_destmerge') |
|
271 | @predicate('_destmerge') | |
272 | def _destmerge(repo, subset, x): |
|
272 | def _destmerge(repo, subset, x): | |
273 | # experimental revset for merge destination |
|
273 | # experimental revset for merge destination | |
274 | sourceset = None |
|
274 | sourceset = None | |
275 | if x is not None: |
|
275 | if x is not None: | |
276 | sourceset = getset(repo, fullreposet(repo), x) |
|
276 | sourceset = getset(repo, fullreposet(repo), x) | |
277 | return subset & baseset([destutil.destmerge(repo, sourceset=sourceset)]) |
|
277 | return subset & baseset([destutil.destmerge(repo, sourceset=sourceset)]) | |
278 |
|
278 | |||
279 | @predicate('adds(pattern)', safe=True, weight=30) |
|
279 | @predicate('adds(pattern)', safe=True, weight=30) | |
280 | def adds(repo, subset, x): |
|
280 | def adds(repo, subset, x): | |
281 | """Changesets that add a file matching pattern. |
|
281 | """Changesets that add a file matching pattern. | |
282 |
|
282 | |||
283 | The pattern without explicit kind like ``glob:`` is expected to be |
|
283 | The pattern without explicit kind like ``glob:`` is expected to be | |
284 | relative to the current directory and match against a file or a |
|
284 | relative to the current directory and match against a file or a | |
285 | directory. |
|
285 | directory. | |
286 | """ |
|
286 | """ | |
287 | # i18n: "adds" is a keyword |
|
287 | # i18n: "adds" is a keyword | |
288 | pat = getstring(x, _("adds requires a pattern")) |
|
288 | pat = getstring(x, _("adds requires a pattern")) | |
289 | return checkstatus(repo, subset, pat, 1) |
|
289 | return checkstatus(repo, subset, pat, 1) | |
290 |
|
290 | |||
291 | @predicate('ancestor(*changeset)', safe=True, weight=0.5) |
|
291 | @predicate('ancestor(*changeset)', safe=True, weight=0.5) | |
292 | def ancestor(repo, subset, x): |
|
292 | def ancestor(repo, subset, x): | |
293 | """A greatest common ancestor of the changesets. |
|
293 | """A greatest common ancestor of the changesets. | |
294 |
|
294 | |||
295 | Accepts 0 or more changesets. |
|
295 | Accepts 0 or more changesets. | |
296 | Will return empty list when passed no args. |
|
296 | Will return empty list when passed no args. | |
297 | Greatest common ancestor of a single changeset is that changeset. |
|
297 | Greatest common ancestor of a single changeset is that changeset. | |
298 | """ |
|
298 | """ | |
299 | # i18n: "ancestor" is a keyword |
|
299 | # i18n: "ancestor" is a keyword | |
300 | l = getlist(x) |
|
300 | l = getlist(x) | |
301 | rl = fullreposet(repo) |
|
301 | rl = fullreposet(repo) | |
302 | anc = None |
|
302 | anc = None | |
303 |
|
303 | |||
304 | # (getset(repo, rl, i) for i in l) generates a list of lists |
|
304 | # (getset(repo, rl, i) for i in l) generates a list of lists | |
305 | for revs in (getset(repo, rl, i) for i in l): |
|
305 | for revs in (getset(repo, rl, i) for i in l): | |
306 | for r in revs: |
|
306 | for r in revs: | |
307 | if anc is None: |
|
307 | if anc is None: | |
308 | anc = repo[r] |
|
308 | anc = repo[r] | |
309 | else: |
|
309 | else: | |
310 | anc = anc.ancestor(repo[r]) |
|
310 | anc = anc.ancestor(repo[r]) | |
311 |
|
311 | |||
312 | if anc is not None and anc.rev() in subset: |
|
312 | if anc is not None and anc.rev() in subset: | |
313 | return baseset([anc.rev()]) |
|
313 | return baseset([anc.rev()]) | |
314 | return baseset() |
|
314 | return baseset() | |
315 |
|
315 | |||
316 | def _ancestors(repo, subset, x, followfirst=False, startdepth=None, |
|
316 | def _ancestors(repo, subset, x, followfirst=False, startdepth=None, | |
317 | stopdepth=None): |
|
317 | stopdepth=None): | |
318 | heads = getset(repo, fullreposet(repo), x) |
|
318 | heads = getset(repo, fullreposet(repo), x) | |
319 | if not heads: |
|
319 | if not heads: | |
320 | return baseset() |
|
320 | return baseset() | |
321 | s = dagop.revancestors(repo, heads, followfirst, startdepth, stopdepth) |
|
321 | s = dagop.revancestors(repo, heads, followfirst, startdepth, stopdepth) | |
322 | return subset & s |
|
322 | return subset & s | |
323 |
|
323 | |||
324 | @predicate('ancestors(set[, depth])', safe=True) |
|
324 | @predicate('ancestors(set[, depth])', safe=True) | |
325 | def ancestors(repo, subset, x): |
|
325 | def ancestors(repo, subset, x): | |
326 | """Changesets that are ancestors of changesets in set, including the |
|
326 | """Changesets that are ancestors of changesets in set, including the | |
327 | given changesets themselves. |
|
327 | given changesets themselves. | |
328 |
|
328 | |||
329 | If depth is specified, the result only includes changesets up to |
|
329 | If depth is specified, the result only includes changesets up to | |
330 | the specified generation. |
|
330 | the specified generation. | |
331 | """ |
|
331 | """ | |
332 | # startdepth is for internal use only until we can decide the UI |
|
332 | # startdepth is for internal use only until we can decide the UI | |
333 | args = getargsdict(x, 'ancestors', 'set depth startdepth') |
|
333 | args = getargsdict(x, 'ancestors', 'set depth startdepth') | |
334 | if 'set' not in args: |
|
334 | if 'set' not in args: | |
335 | # i18n: "ancestors" is a keyword |
|
335 | # i18n: "ancestors" is a keyword | |
336 | raise error.ParseError(_('ancestors takes at least 1 argument')) |
|
336 | raise error.ParseError(_('ancestors takes at least 1 argument')) | |
337 | startdepth = stopdepth = None |
|
337 | startdepth = stopdepth = None | |
338 | if 'startdepth' in args: |
|
338 | if 'startdepth' in args: | |
339 | n = getinteger(args['startdepth'], |
|
339 | n = getinteger(args['startdepth'], | |
340 | "ancestors expects an integer startdepth") |
|
340 | "ancestors expects an integer startdepth") | |
341 | if n < 0: |
|
341 | if n < 0: | |
342 | raise error.ParseError("negative startdepth") |
|
342 | raise error.ParseError("negative startdepth") | |
343 | startdepth = n |
|
343 | startdepth = n | |
344 | if 'depth' in args: |
|
344 | if 'depth' in args: | |
345 | # i18n: "ancestors" is a keyword |
|
345 | # i18n: "ancestors" is a keyword | |
346 | n = getinteger(args['depth'], _("ancestors expects an integer depth")) |
|
346 | n = getinteger(args['depth'], _("ancestors expects an integer depth")) | |
347 | if n < 0: |
|
347 | if n < 0: | |
348 | raise error.ParseError(_("negative depth")) |
|
348 | raise error.ParseError(_("negative depth")) | |
349 | stopdepth = n + 1 |
|
349 | stopdepth = n + 1 | |
350 | return _ancestors(repo, subset, args['set'], |
|
350 | return _ancestors(repo, subset, args['set'], | |
351 | startdepth=startdepth, stopdepth=stopdepth) |
|
351 | startdepth=startdepth, stopdepth=stopdepth) | |
352 |
|
352 | |||
353 | @predicate('_firstancestors', safe=True) |
|
353 | @predicate('_firstancestors', safe=True) | |
354 | def _firstancestors(repo, subset, x): |
|
354 | def _firstancestors(repo, subset, x): | |
355 | # ``_firstancestors(set)`` |
|
355 | # ``_firstancestors(set)`` | |
356 | # Like ``ancestors(set)`` but follows only the first parents. |
|
356 | # Like ``ancestors(set)`` but follows only the first parents. | |
357 | return _ancestors(repo, subset, x, followfirst=True) |
|
357 | return _ancestors(repo, subset, x, followfirst=True) | |
358 |
|
358 | |||
359 | def _childrenspec(repo, subset, x, n, order): |
|
359 | def _childrenspec(repo, subset, x, n, order): | |
360 | """Changesets that are the Nth child of a changeset |
|
360 | """Changesets that are the Nth child of a changeset | |
361 | in set. |
|
361 | in set. | |
362 | """ |
|
362 | """ | |
363 | cs = set() |
|
363 | cs = set() | |
364 | for r in getset(repo, fullreposet(repo), x): |
|
364 | for r in getset(repo, fullreposet(repo), x): | |
365 | for i in range(n): |
|
365 | for i in range(n): | |
366 | c = repo[r].children() |
|
366 | c = repo[r].children() | |
367 | if len(c) == 0: |
|
367 | if len(c) == 0: | |
368 | break |
|
368 | break | |
369 | if len(c) > 1: |
|
369 | if len(c) > 1: | |
370 | raise error.RepoLookupError( |
|
370 | raise error.RepoLookupError( | |
371 | _("revision in set has more than one child")) |
|
371 | _("revision in set has more than one child")) | |
372 | r = c[0].rev() |
|
372 | r = c[0].rev() | |
373 | else: |
|
373 | else: | |
374 | cs.add(r) |
|
374 | cs.add(r) | |
375 | return subset & cs |
|
375 | return subset & cs | |
376 |
|
376 | |||
377 | def ancestorspec(repo, subset, x, n, order): |
|
377 | def ancestorspec(repo, subset, x, n, order): | |
378 | """``set~n`` |
|
378 | """``set~n`` | |
379 | Changesets that are the Nth ancestor (first parents only) of a changeset |
|
379 | Changesets that are the Nth ancestor (first parents only) of a changeset | |
380 | in set. |
|
380 | in set. | |
381 | """ |
|
381 | """ | |
382 | n = getinteger(n, _("~ expects a number")) |
|
382 | n = getinteger(n, _("~ expects a number")) | |
383 | if n < 0: |
|
383 | if n < 0: | |
384 | # children lookup |
|
384 | # children lookup | |
385 | return _childrenspec(repo, subset, x, -n, order) |
|
385 | return _childrenspec(repo, subset, x, -n, order) | |
386 | ps = set() |
|
386 | ps = set() | |
387 | cl = repo.changelog |
|
387 | cl = repo.changelog | |
388 | for r in getset(repo, fullreposet(repo), x): |
|
388 | for r in getset(repo, fullreposet(repo), x): | |
389 | for i in range(n): |
|
389 | for i in range(n): | |
390 | try: |
|
390 | try: | |
391 | r = cl.parentrevs(r)[0] |
|
391 | r = cl.parentrevs(r)[0] | |
392 | except error.WdirUnsupported: |
|
392 | except error.WdirUnsupported: | |
393 | r = repo[r].parents()[0].rev() |
|
393 | r = repo[r].parents()[0].rev() | |
394 | ps.add(r) |
|
394 | ps.add(r) | |
395 | return subset & ps |
|
395 | return subset & ps | |
396 |
|
396 | |||
397 | @predicate('author(string)', safe=True, weight=10) |
|
397 | @predicate('author(string)', safe=True, weight=10) | |
398 | def author(repo, subset, x): |
|
398 | def author(repo, subset, x): | |
399 | """Alias for ``user(string)``. |
|
399 | """Alias for ``user(string)``. | |
400 | """ |
|
400 | """ | |
401 | # i18n: "author" is a keyword |
|
401 | # i18n: "author" is a keyword | |
402 | n = getstring(x, _("author requires a string")) |
|
402 | n = getstring(x, _("author requires a string")) | |
403 | kind, pattern, matcher = _substringmatcher(n, casesensitive=False) |
|
403 | kind, pattern, matcher = _substringmatcher(n, casesensitive=False) | |
404 | return subset.filter(lambda x: matcher(repo[x].user()), |
|
404 | return subset.filter(lambda x: matcher(repo[x].user()), | |
405 | condrepr=('<user %r>', n)) |
|
405 | condrepr=('<user %r>', n)) | |
406 |
|
406 | |||
407 | @predicate('bisect(string)', safe=True) |
|
407 | @predicate('bisect(string)', safe=True) | |
408 | def bisect(repo, subset, x): |
|
408 | def bisect(repo, subset, x): | |
409 | """Changesets marked in the specified bisect status: |
|
409 | """Changesets marked in the specified bisect status: | |
410 |
|
410 | |||
411 | - ``good``, ``bad``, ``skip``: csets explicitly marked as good/bad/skip |
|
411 | - ``good``, ``bad``, ``skip``: csets explicitly marked as good/bad/skip | |
412 | - ``goods``, ``bads`` : csets topologically good/bad |
|
412 | - ``goods``, ``bads`` : csets topologically good/bad | |
413 | - ``range`` : csets taking part in the bisection |
|
413 | - ``range`` : csets taking part in the bisection | |
414 | - ``pruned`` : csets that are goods, bads or skipped |
|
414 | - ``pruned`` : csets that are goods, bads or skipped | |
415 | - ``untested`` : csets whose fate is yet unknown |
|
415 | - ``untested`` : csets whose fate is yet unknown | |
416 | - ``ignored`` : csets ignored due to DAG topology |
|
416 | - ``ignored`` : csets ignored due to DAG topology | |
417 | - ``current`` : the cset currently being bisected |
|
417 | - ``current`` : the cset currently being bisected | |
418 | """ |
|
418 | """ | |
419 | # i18n: "bisect" is a keyword |
|
419 | # i18n: "bisect" is a keyword | |
420 | status = getstring(x, _("bisect requires a string")).lower() |
|
420 | status = getstring(x, _("bisect requires a string")).lower() | |
421 | state = set(hbisect.get(repo, status)) |
|
421 | state = set(hbisect.get(repo, status)) | |
422 | return subset & state |
|
422 | return subset & state | |
423 |
|
423 | |||
424 | # Backward-compatibility |
|
424 | # Backward-compatibility | |
425 | # - no help entry so that we do not advertise it any more |
|
425 | # - no help entry so that we do not advertise it any more | |
426 | @predicate('bisected', safe=True) |
|
426 | @predicate('bisected', safe=True) | |
427 | def bisected(repo, subset, x): |
|
427 | def bisected(repo, subset, x): | |
428 | return bisect(repo, subset, x) |
|
428 | return bisect(repo, subset, x) | |
429 |
|
429 | |||
430 | @predicate('bookmark([name])', safe=True) |
|
430 | @predicate('bookmark([name])', safe=True) | |
431 | def bookmark(repo, subset, x): |
|
431 | def bookmark(repo, subset, x): | |
432 | """The named bookmark or all bookmarks. |
|
432 | """The named bookmark or all bookmarks. | |
433 |
|
433 | |||
434 | Pattern matching is supported for `name`. See :hg:`help revisions.patterns`. |
|
434 | Pattern matching is supported for `name`. See :hg:`help revisions.patterns`. | |
435 | """ |
|
435 | """ | |
436 | # i18n: "bookmark" is a keyword |
|
436 | # i18n: "bookmark" is a keyword | |
437 | args = getargs(x, 0, 1, _('bookmark takes one or no arguments')) |
|
437 | args = getargs(x, 0, 1, _('bookmark takes one or no arguments')) | |
438 | if args: |
|
438 | if args: | |
439 | bm = getstring(args[0], |
|
439 | bm = getstring(args[0], | |
440 | # i18n: "bookmark" is a keyword |
|
440 | # i18n: "bookmark" is a keyword | |
441 | _('the argument to bookmark must be a string')) |
|
441 | _('the argument to bookmark must be a string')) | |
442 | kind, pattern, matcher = util.stringmatcher(bm) |
|
442 | kind, pattern, matcher = util.stringmatcher(bm) | |
443 | bms = set() |
|
443 | bms = set() | |
444 | if kind == 'literal': |
|
444 | if kind == 'literal': | |
445 | bmrev = repo._bookmarks.get(pattern, None) |
|
445 | bmrev = repo._bookmarks.get(pattern, None) | |
446 | if not bmrev: |
|
446 | if not bmrev: | |
447 | raise error.RepoLookupError(_("bookmark '%s' does not exist") |
|
447 | raise error.RepoLookupError(_("bookmark '%s' does not exist") | |
448 | % pattern) |
|
448 | % pattern) | |
449 | bms.add(repo[bmrev].rev()) |
|
449 | bms.add(repo[bmrev].rev()) | |
450 | else: |
|
450 | else: | |
451 | matchrevs = set() |
|
451 | matchrevs = set() | |
452 | for name, bmrev in repo._bookmarks.iteritems(): |
|
452 | for name, bmrev in repo._bookmarks.iteritems(): | |
453 | if matcher(name): |
|
453 | if matcher(name): | |
454 | matchrevs.add(bmrev) |
|
454 | matchrevs.add(bmrev) | |
455 | if not matchrevs: |
|
455 | if not matchrevs: | |
456 | raise error.RepoLookupError(_("no bookmarks exist" |
|
456 | raise error.RepoLookupError(_("no bookmarks exist" | |
457 | " that match '%s'") % pattern) |
|
457 | " that match '%s'") % pattern) | |
458 | for bmrev in matchrevs: |
|
458 | for bmrev in matchrevs: | |
459 | bms.add(repo[bmrev].rev()) |
|
459 | bms.add(repo[bmrev].rev()) | |
460 | else: |
|
460 | else: | |
461 | bms = {repo[r].rev() for r in repo._bookmarks.values()} |
|
461 | bms = {repo[r].rev() for r in repo._bookmarks.values()} | |
462 | bms -= {node.nullrev} |
|
462 | bms -= {node.nullrev} | |
463 | return subset & bms |
|
463 | return subset & bms | |
464 |
|
464 | |||
465 | @predicate('branch(string or set)', safe=True, weight=10) |
|
465 | @predicate('branch(string or set)', safe=True, weight=10) | |
466 | def branch(repo, subset, x): |
|
466 | def branch(repo, subset, x): | |
467 | """ |
|
467 | """ | |
468 | All changesets belonging to the given branch or the branches of the given |
|
468 | All changesets belonging to the given branch or the branches of the given | |
469 | changesets. |
|
469 | changesets. | |
470 |
|
470 | |||
471 | Pattern matching is supported for `string`. See |
|
471 | Pattern matching is supported for `string`. See | |
472 | :hg:`help revisions.patterns`. |
|
472 | :hg:`help revisions.patterns`. | |
473 | """ |
|
473 | """ | |
474 | getbi = repo.revbranchcache().branchinfo |
|
474 | getbi = repo.revbranchcache().branchinfo | |
475 | def getbranch(r): |
|
475 | def getbranch(r): | |
476 | try: |
|
476 | try: | |
477 | return getbi(r)[0] |
|
477 | return getbi(r)[0] | |
478 | except error.WdirUnsupported: |
|
478 | except error.WdirUnsupported: | |
479 | return repo[r].branch() |
|
479 | return repo[r].branch() | |
480 |
|
480 | |||
481 | try: |
|
481 | try: | |
482 | b = getstring(x, '') |
|
482 | b = getstring(x, '') | |
483 | except error.ParseError: |
|
483 | except error.ParseError: | |
484 | # not a string, but another revspec, e.g. tip() |
|
484 | # not a string, but another revspec, e.g. tip() | |
485 | pass |
|
485 | pass | |
486 | else: |
|
486 | else: | |
487 | kind, pattern, matcher = util.stringmatcher(b) |
|
487 | kind, pattern, matcher = util.stringmatcher(b) | |
488 | if kind == 'literal': |
|
488 | if kind == 'literal': | |
489 | # note: falls through to the revspec case if no branch with |
|
489 | # note: falls through to the revspec case if no branch with | |
490 | # this name exists and pattern kind is not specified explicitly |
|
490 | # this name exists and pattern kind is not specified explicitly | |
491 | if pattern in repo.branchmap(): |
|
491 | if pattern in repo.branchmap(): | |
492 | return subset.filter(lambda r: matcher(getbranch(r)), |
|
492 | return subset.filter(lambda r: matcher(getbranch(r)), | |
493 | condrepr=('<branch %r>', b)) |
|
493 | condrepr=('<branch %r>', b)) | |
494 | if b.startswith('literal:'): |
|
494 | if b.startswith('literal:'): | |
495 | raise error.RepoLookupError(_("branch '%s' does not exist") |
|
495 | raise error.RepoLookupError(_("branch '%s' does not exist") | |
496 | % pattern) |
|
496 | % pattern) | |
497 | else: |
|
497 | else: | |
498 | return subset.filter(lambda r: matcher(getbranch(r)), |
|
498 | return subset.filter(lambda r: matcher(getbranch(r)), | |
499 | condrepr=('<branch %r>', b)) |
|
499 | condrepr=('<branch %r>', b)) | |
500 |
|
500 | |||
501 | s = getset(repo, fullreposet(repo), x) |
|
501 | s = getset(repo, fullreposet(repo), x) | |
502 | b = set() |
|
502 | b = set() | |
503 | for r in s: |
|
503 | for r in s: | |
504 | b.add(getbranch(r)) |
|
504 | b.add(getbranch(r)) | |
505 | c = s.__contains__ |
|
505 | c = s.__contains__ | |
506 | return subset.filter(lambda r: c(r) or getbranch(r) in b, |
|
506 | return subset.filter(lambda r: c(r) or getbranch(r) in b, | |
507 | condrepr=lambda: '<branch %r>' % sorted(b)) |
|
507 | condrepr=lambda: '<branch %r>' % sorted(b)) | |
508 |
|
508 | |||
509 | @predicate('bumped()', safe=True) |
|
509 | @predicate('bumped()', safe=True) | |
510 | def bumped(repo, subset, x): |
|
510 | def bumped(repo, subset, x): | |
511 | msg = ("'bumped()' is deprecated, " |
|
511 | msg = ("'bumped()' is deprecated, " | |
512 | "use 'phasedivergent()'") |
|
512 | "use 'phasedivergent()'") | |
513 | repo.ui.deprecwarn(msg, '4.4') |
|
513 | repo.ui.deprecwarn(msg, '4.4') | |
514 |
|
514 | |||
515 | return phasedivergent(repo, subset, x) |
|
515 | return phasedivergent(repo, subset, x) | |
516 |
|
516 | |||
517 | @predicate('phasedivergent()', safe=True) |
|
517 | @predicate('phasedivergent()', safe=True) | |
518 | def phasedivergent(repo, subset, x): |
|
518 | def phasedivergent(repo, subset, x): | |
519 | """Mutable changesets marked as successors of public changesets. |
|
519 | """Mutable changesets marked as successors of public changesets. | |
520 |
|
520 | |||
521 | Only non-public and non-obsolete changesets can be `phasedivergent`. |
|
521 | Only non-public and non-obsolete changesets can be `phasedivergent`. | |
522 | (EXPERIMENTAL) |
|
522 | (EXPERIMENTAL) | |
523 | """ |
|
523 | """ | |
524 | # i18n: "phasedivergent" is a keyword |
|
524 | # i18n: "phasedivergent" is a keyword | |
525 | getargs(x, 0, 0, _("phasedivergent takes no arguments")) |
|
525 | getargs(x, 0, 0, _("phasedivergent takes no arguments")) | |
526 | phasedivergent = obsmod.getrevs(repo, 'phasedivergent') |
|
526 | phasedivergent = obsmod.getrevs(repo, 'phasedivergent') | |
527 | return subset & phasedivergent |
|
527 | return subset & phasedivergent | |
528 |
|
528 | |||
529 | @predicate('bundle()', safe=True) |
|
529 | @predicate('bundle()', safe=True) | |
530 | def bundle(repo, subset, x): |
|
530 | def bundle(repo, subset, x): | |
531 | """Changesets in the bundle. |
|
531 | """Changesets in the bundle. | |
532 |
|
532 | |||
533 | Bundle must be specified by the -R option.""" |
|
533 | Bundle must be specified by the -R option.""" | |
534 |
|
534 | |||
535 | try: |
|
535 | try: | |
536 | bundlerevs = repo.changelog.bundlerevs |
|
536 | bundlerevs = repo.changelog.bundlerevs | |
537 | except AttributeError: |
|
537 | except AttributeError: | |
538 | raise error.Abort(_("no bundle provided - specify with -R")) |
|
538 | raise error.Abort(_("no bundle provided - specify with -R")) | |
539 | return subset & bundlerevs |
|
539 | return subset & bundlerevs | |
540 |
|
540 | |||
541 | def checkstatus(repo, subset, pat, field): |
|
541 | def checkstatus(repo, subset, pat, field): | |
542 | hasset = matchmod.patkind(pat) == 'set' |
|
542 | hasset = matchmod.patkind(pat) == 'set' | |
543 |
|
543 | |||
544 | mcache = [None] |
|
544 | mcache = [None] | |
545 | def matches(x): |
|
545 | def matches(x): | |
546 | c = repo[x] |
|
546 | c = repo[x] | |
547 | if not mcache[0] or hasset: |
|
547 | if not mcache[0] or hasset: | |
548 | mcache[0] = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=c) |
|
548 | mcache[0] = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=c) | |
549 | m = mcache[0] |
|
549 | m = mcache[0] | |
550 | fname = None |
|
550 | fname = None | |
551 | if not m.anypats() and len(m.files()) == 1: |
|
551 | if not m.anypats() and len(m.files()) == 1: | |
552 | fname = m.files()[0] |
|
552 | fname = m.files()[0] | |
553 | if fname is not None: |
|
553 | if fname is not None: | |
554 | if fname not in c.files(): |
|
554 | if fname not in c.files(): | |
555 | return False |
|
555 | return False | |
556 | else: |
|
556 | else: | |
557 | for f in c.files(): |
|
557 | for f in c.files(): | |
558 | if m(f): |
|
558 | if m(f): | |
559 | break |
|
559 | break | |
560 | else: |
|
560 | else: | |
561 | return False |
|
561 | return False | |
562 | files = repo.status(c.p1().node(), c.node())[field] |
|
562 | files = repo.status(c.p1().node(), c.node())[field] | |
563 | if fname is not None: |
|
563 | if fname is not None: | |
564 | if fname in files: |
|
564 | if fname in files: | |
565 | return True |
|
565 | return True | |
566 | else: |
|
566 | else: | |
567 | for f in files: |
|
567 | for f in files: | |
568 | if m(f): |
|
568 | if m(f): | |
569 | return True |
|
569 | return True | |
570 |
|
570 | |||
571 | return subset.filter(matches, condrepr=('<status[%r] %r>', field, pat)) |
|
571 | return subset.filter(matches, condrepr=('<status[%r] %r>', field, pat)) | |
572 |
|
572 | |||
573 | def _children(repo, subset, parentset): |
|
573 | def _children(repo, subset, parentset): | |
574 | if not parentset: |
|
574 | if not parentset: | |
575 | return baseset() |
|
575 | return baseset() | |
576 | cs = set() |
|
576 | cs = set() | |
577 | pr = repo.changelog.parentrevs |
|
577 | pr = repo.changelog.parentrevs | |
578 | minrev = parentset.min() |
|
578 | minrev = parentset.min() | |
579 | nullrev = node.nullrev |
|
579 | nullrev = node.nullrev | |
580 | for r in subset: |
|
580 | for r in subset: | |
581 | if r <= minrev: |
|
581 | if r <= minrev: | |
582 | continue |
|
582 | continue | |
583 | p1, p2 = pr(r) |
|
583 | p1, p2 = pr(r) | |
584 | if p1 in parentset: |
|
584 | if p1 in parentset: | |
585 | cs.add(r) |
|
585 | cs.add(r) | |
586 | if p2 != nullrev and p2 in parentset: |
|
586 | if p2 != nullrev and p2 in parentset: | |
587 | cs.add(r) |
|
587 | cs.add(r) | |
588 | return baseset(cs) |
|
588 | return baseset(cs) | |
589 |
|
589 | |||
590 | @predicate('children(set)', safe=True) |
|
590 | @predicate('children(set)', safe=True) | |
591 | def children(repo, subset, x): |
|
591 | def children(repo, subset, x): | |
592 | """Child changesets of changesets in set. |
|
592 | """Child changesets of changesets in set. | |
593 | """ |
|
593 | """ | |
594 | s = getset(repo, fullreposet(repo), x) |
|
594 | s = getset(repo, fullreposet(repo), x) | |
595 | cs = _children(repo, subset, s) |
|
595 | cs = _children(repo, subset, s) | |
596 | return subset & cs |
|
596 | return subset & cs | |
597 |
|
597 | |||
598 | @predicate('closed()', safe=True, weight=10) |
|
598 | @predicate('closed()', safe=True, weight=10) | |
599 | def closed(repo, subset, x): |
|
599 | def closed(repo, subset, x): | |
600 | """Changeset is closed. |
|
600 | """Changeset is closed. | |
601 | """ |
|
601 | """ | |
602 | # i18n: "closed" is a keyword |
|
602 | # i18n: "closed" is a keyword | |
603 | getargs(x, 0, 0, _("closed takes no arguments")) |
|
603 | getargs(x, 0, 0, _("closed takes no arguments")) | |
604 | return subset.filter(lambda r: repo[r].closesbranch(), |
|
604 | return subset.filter(lambda r: repo[r].closesbranch(), | |
605 | condrepr='<branch closed>') |
|
605 | condrepr='<branch closed>') | |
606 |
|
606 | |||
607 | @predicate('contains(pattern)', weight=100) |
|
607 | @predicate('contains(pattern)', weight=100) | |
608 | def contains(repo, subset, x): |
|
608 | def contains(repo, subset, x): | |
609 | """The revision's manifest contains a file matching pattern (but might not |
|
609 | """The revision's manifest contains a file matching pattern (but might not | |
610 | modify it). See :hg:`help patterns` for information about file patterns. |
|
610 | modify it). See :hg:`help patterns` for information about file patterns. | |
611 |
|
611 | |||
612 | The pattern without explicit kind like ``glob:`` is expected to be |
|
612 | The pattern without explicit kind like ``glob:`` is expected to be | |
613 | relative to the current directory and match against a file exactly |
|
613 | relative to the current directory and match against a file exactly | |
614 | for efficiency. |
|
614 | for efficiency. | |
615 | """ |
|
615 | """ | |
616 | # i18n: "contains" is a keyword |
|
616 | # i18n: "contains" is a keyword | |
617 | pat = getstring(x, _("contains requires a pattern")) |
|
617 | pat = getstring(x, _("contains requires a pattern")) | |
618 |
|
618 | |||
619 | def matches(x): |
|
619 | def matches(x): | |
620 | if not matchmod.patkind(pat): |
|
620 | if not matchmod.patkind(pat): | |
621 | pats = pathutil.canonpath(repo.root, repo.getcwd(), pat) |
|
621 | pats = pathutil.canonpath(repo.root, repo.getcwd(), pat) | |
622 | if pats in repo[x]: |
|
622 | if pats in repo[x]: | |
623 | return True |
|
623 | return True | |
624 | else: |
|
624 | else: | |
625 | c = repo[x] |
|
625 | c = repo[x] | |
626 | m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=c) |
|
626 | m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=c) | |
627 | for f in c.manifest(): |
|
627 | for f in c.manifest(): | |
628 | if m(f): |
|
628 | if m(f): | |
629 | return True |
|
629 | return True | |
630 | return False |
|
630 | return False | |
631 |
|
631 | |||
632 | return subset.filter(matches, condrepr=('<contains %r>', pat)) |
|
632 | return subset.filter(matches, condrepr=('<contains %r>', pat)) | |
633 |
|
633 | |||
634 | @predicate('converted([id])', safe=True) |
|
634 | @predicate('converted([id])', safe=True) | |
635 | def converted(repo, subset, x): |
|
635 | def converted(repo, subset, x): | |
636 | """Changesets converted from the given identifier in the old repository if |
|
636 | """Changesets converted from the given identifier in the old repository if | |
637 | present, or all converted changesets if no identifier is specified. |
|
637 | present, or all converted changesets if no identifier is specified. | |
638 | """ |
|
638 | """ | |
639 |
|
639 | |||
640 | # There is exactly no chance of resolving the revision, so do a simple |
|
640 | # There is exactly no chance of resolving the revision, so do a simple | |
641 | # string compare and hope for the best |
|
641 | # string compare and hope for the best | |
642 |
|
642 | |||
643 | rev = None |
|
643 | rev = None | |
644 | # i18n: "converted" is a keyword |
|
644 | # i18n: "converted" is a keyword | |
645 | l = getargs(x, 0, 1, _('converted takes one or no arguments')) |
|
645 | l = getargs(x, 0, 1, _('converted takes one or no arguments')) | |
646 | if l: |
|
646 | if l: | |
647 | # i18n: "converted" is a keyword |
|
647 | # i18n: "converted" is a keyword | |
648 | rev = getstring(l[0], _('converted requires a revision')) |
|
648 | rev = getstring(l[0], _('converted requires a revision')) | |
649 |
|
649 | |||
650 | def _matchvalue(r): |
|
650 | def _matchvalue(r): | |
651 | source = repo[r].extra().get('convert_revision', None) |
|
651 | source = repo[r].extra().get('convert_revision', None) | |
652 | return source is not None and (rev is None or source.startswith(rev)) |
|
652 | return source is not None and (rev is None or source.startswith(rev)) | |
653 |
|
653 | |||
654 | return subset.filter(lambda r: _matchvalue(r), |
|
654 | return subset.filter(lambda r: _matchvalue(r), | |
655 | condrepr=('<converted %r>', rev)) |
|
655 | condrepr=('<converted %r>', rev)) | |
656 |
|
656 | |||
657 | @predicate('date(interval)', safe=True, weight=10) |
|
657 | @predicate('date(interval)', safe=True, weight=10) | |
658 | def date(repo, subset, x): |
|
658 | def date(repo, subset, x): | |
659 | """Changesets within the interval, see :hg:`help dates`. |
|
659 | """Changesets within the interval, see :hg:`help dates`. | |
660 | """ |
|
660 | """ | |
661 | # i18n: "date" is a keyword |
|
661 | # i18n: "date" is a keyword | |
662 | ds = getstring(x, _("date requires a string")) |
|
662 | ds = getstring(x, _("date requires a string")) | |
663 | dm = util.matchdate(ds) |
|
663 | dm = util.matchdate(ds) | |
664 | return subset.filter(lambda x: dm(repo[x].date()[0]), |
|
664 | return subset.filter(lambda x: dm(repo[x].date()[0]), | |
665 | condrepr=('<date %r>', ds)) |
|
665 | condrepr=('<date %r>', ds)) | |
666 |
|
666 | |||
667 | @predicate('desc(string)', safe=True, weight=10) |
|
667 | @predicate('desc(string)', safe=True, weight=10) | |
668 | def desc(repo, subset, x): |
|
668 | def desc(repo, subset, x): | |
669 | """Search commit message for string. The match is case-insensitive. |
|
669 | """Search commit message for string. The match is case-insensitive. | |
670 |
|
670 | |||
671 | Pattern matching is supported for `string`. See |
|
671 | Pattern matching is supported for `string`. See | |
672 | :hg:`help revisions.patterns`. |
|
672 | :hg:`help revisions.patterns`. | |
673 | """ |
|
673 | """ | |
674 | # i18n: "desc" is a keyword |
|
674 | # i18n: "desc" is a keyword | |
675 | ds = getstring(x, _("desc requires a string")) |
|
675 | ds = getstring(x, _("desc requires a string")) | |
676 |
|
676 | |||
677 | kind, pattern, matcher = _substringmatcher(ds, casesensitive=False) |
|
677 | kind, pattern, matcher = _substringmatcher(ds, casesensitive=False) | |
678 |
|
678 | |||
679 | return subset.filter(lambda r: matcher(repo[r].description()), |
|
679 | return subset.filter(lambda r: matcher(repo[r].description()), | |
680 | condrepr=('<desc %r>', ds)) |
|
680 | condrepr=('<desc %r>', ds)) | |
681 |
|
681 | |||
682 | def _descendants(repo, subset, x, followfirst=False, startdepth=None, |
|
682 | def _descendants(repo, subset, x, followfirst=False, startdepth=None, | |
683 | stopdepth=None): |
|
683 | stopdepth=None): | |
684 | roots = getset(repo, fullreposet(repo), x) |
|
684 | roots = getset(repo, fullreposet(repo), x) | |
685 | if not roots: |
|
685 | if not roots: | |
686 | return baseset() |
|
686 | return baseset() | |
687 | s = dagop.revdescendants(repo, roots, followfirst, startdepth, stopdepth) |
|
687 | s = dagop.revdescendants(repo, roots, followfirst, startdepth, stopdepth) | |
688 | return subset & s |
|
688 | return subset & s | |
689 |
|
689 | |||
690 | @predicate('descendants(set[, depth])', safe=True) |
|
690 | @predicate('descendants(set[, depth])', safe=True) | |
691 | def descendants(repo, subset, x): |
|
691 | def descendants(repo, subset, x): | |
692 | """Changesets which are descendants of changesets in set, including the |
|
692 | """Changesets which are descendants of changesets in set, including the | |
693 | given changesets themselves. |
|
693 | given changesets themselves. | |
694 |
|
694 | |||
695 | If depth is specified, the result only includes changesets up to |
|
695 | If depth is specified, the result only includes changesets up to | |
696 | the specified generation. |
|
696 | the specified generation. | |
697 | """ |
|
697 | """ | |
698 | # startdepth is for internal use only until we can decide the UI |
|
698 | # startdepth is for internal use only until we can decide the UI | |
699 | args = getargsdict(x, 'descendants', 'set depth startdepth') |
|
699 | args = getargsdict(x, 'descendants', 'set depth startdepth') | |
700 | if 'set' not in args: |
|
700 | if 'set' not in args: | |
701 | # i18n: "descendants" is a keyword |
|
701 | # i18n: "descendants" is a keyword | |
702 | raise error.ParseError(_('descendants takes at least 1 argument')) |
|
702 | raise error.ParseError(_('descendants takes at least 1 argument')) | |
703 | startdepth = stopdepth = None |
|
703 | startdepth = stopdepth = None | |
704 | if 'startdepth' in args: |
|
704 | if 'startdepth' in args: | |
705 | n = getinteger(args['startdepth'], |
|
705 | n = getinteger(args['startdepth'], | |
706 | "descendants expects an integer startdepth") |
|
706 | "descendants expects an integer startdepth") | |
707 | if n < 0: |
|
707 | if n < 0: | |
708 | raise error.ParseError("negative startdepth") |
|
708 | raise error.ParseError("negative startdepth") | |
709 | startdepth = n |
|
709 | startdepth = n | |
710 | if 'depth' in args: |
|
710 | if 'depth' in args: | |
711 | # i18n: "descendants" is a keyword |
|
711 | # i18n: "descendants" is a keyword | |
712 | n = getinteger(args['depth'], _("descendants expects an integer depth")) |
|
712 | n = getinteger(args['depth'], _("descendants expects an integer depth")) | |
713 | if n < 0: |
|
713 | if n < 0: | |
714 | raise error.ParseError(_("negative depth")) |
|
714 | raise error.ParseError(_("negative depth")) | |
715 | stopdepth = n + 1 |
|
715 | stopdepth = n + 1 | |
716 | return _descendants(repo, subset, args['set'], |
|
716 | return _descendants(repo, subset, args['set'], | |
717 | startdepth=startdepth, stopdepth=stopdepth) |
|
717 | startdepth=startdepth, stopdepth=stopdepth) | |
718 |
|
718 | |||
719 | @predicate('_firstdescendants', safe=True) |
|
719 | @predicate('_firstdescendants', safe=True) | |
720 | def _firstdescendants(repo, subset, x): |
|
720 | def _firstdescendants(repo, subset, x): | |
721 | # ``_firstdescendants(set)`` |
|
721 | # ``_firstdescendants(set)`` | |
722 | # Like ``descendants(set)`` but follows only the first parents. |
|
722 | # Like ``descendants(set)`` but follows only the first parents. | |
723 | return _descendants(repo, subset, x, followfirst=True) |
|
723 | return _descendants(repo, subset, x, followfirst=True) | |
724 |
|
724 | |||
725 | @predicate('destination([set])', safe=True, weight=10) |
|
725 | @predicate('destination([set])', safe=True, weight=10) | |
726 | def destination(repo, subset, x): |
|
726 | def destination(repo, subset, x): | |
727 | """Changesets that were created by a graft, transplant or rebase operation, |
|
727 | """Changesets that were created by a graft, transplant or rebase operation, | |
728 | with the given revisions specified as the source. Omitting the optional set |
|
728 | with the given revisions specified as the source. Omitting the optional set | |
729 | is the same as passing all(). |
|
729 | is the same as passing all(). | |
730 | """ |
|
730 | """ | |
731 | if x is not None: |
|
731 | if x is not None: | |
732 | sources = getset(repo, fullreposet(repo), x) |
|
732 | sources = getset(repo, fullreposet(repo), x) | |
733 | else: |
|
733 | else: | |
734 | sources = fullreposet(repo) |
|
734 | sources = fullreposet(repo) | |
735 |
|
735 | |||
736 | dests = set() |
|
736 | dests = set() | |
737 |
|
737 | |||
738 | # subset contains all of the possible destinations that can be returned, so |
|
738 | # subset contains all of the possible destinations that can be returned, so | |
739 | # iterate over them and see if their source(s) were provided in the arg set. |
|
739 | # iterate over them and see if their source(s) were provided in the arg set. | |
740 | # Even if the immediate src of r is not in the arg set, src's source (or |
|
740 | # Even if the immediate src of r is not in the arg set, src's source (or | |
741 | # further back) may be. Scanning back further than the immediate src allows |
|
741 | # further back) may be. Scanning back further than the immediate src allows | |
742 | # transitive transplants and rebases to yield the same results as transitive |
|
742 | # transitive transplants and rebases to yield the same results as transitive | |
743 | # grafts. |
|
743 | # grafts. | |
744 | for r in subset: |
|
744 | for r in subset: | |
745 | src = _getrevsource(repo, r) |
|
745 | src = _getrevsource(repo, r) | |
746 | lineage = None |
|
746 | lineage = None | |
747 |
|
747 | |||
748 | while src is not None: |
|
748 | while src is not None: | |
749 | if lineage is None: |
|
749 | if lineage is None: | |
750 | lineage = list() |
|
750 | lineage = list() | |
751 |
|
751 | |||
752 | lineage.append(r) |
|
752 | lineage.append(r) | |
753 |
|
753 | |||
754 | # The visited lineage is a match if the current source is in the arg |
|
754 | # The visited lineage is a match if the current source is in the arg | |
755 | # set. Since every candidate dest is visited by way of iterating |
|
755 | # set. Since every candidate dest is visited by way of iterating | |
756 | # subset, any dests further back in the lineage will be tested by a |
|
756 | # subset, any dests further back in the lineage will be tested by a | |
757 | # different iteration over subset. Likewise, if the src was already |
|
757 | # different iteration over subset. Likewise, if the src was already | |
758 | # selected, the current lineage can be selected without going back |
|
758 | # selected, the current lineage can be selected without going back | |
759 | # further. |
|
759 | # further. | |
760 | if src in sources or src in dests: |
|
760 | if src in sources or src in dests: | |
761 | dests.update(lineage) |
|
761 | dests.update(lineage) | |
762 | break |
|
762 | break | |
763 |
|
763 | |||
764 | r = src |
|
764 | r = src | |
765 | src = _getrevsource(repo, r) |
|
765 | src = _getrevsource(repo, r) | |
766 |
|
766 | |||
767 | return subset.filter(dests.__contains__, |
|
767 | return subset.filter(dests.__contains__, | |
768 | condrepr=lambda: '<destination %r>' % sorted(dests)) |
|
768 | condrepr=lambda: '<destination %r>' % sorted(dests)) | |
769 |
|
769 | |||
770 | @predicate('divergent()', safe=True) |
|
770 | @predicate('divergent()', safe=True) | |
771 | def divergent(repo, subset, x): |
|
771 | def divergent(repo, subset, x): | |
772 | msg = ("'divergent()' is deprecated, " |
|
772 | msg = ("'divergent()' is deprecated, " | |
773 | "use 'contentdivergent()'") |
|
773 | "use 'contentdivergent()'") | |
774 | repo.ui.deprecwarn(msg, '4.4') |
|
774 | repo.ui.deprecwarn(msg, '4.4') | |
775 |
|
775 | |||
776 | return contentdivergent(repo, subset, x) |
|
776 | return contentdivergent(repo, subset, x) | |
777 |
|
777 | |||
778 | @predicate('contentdivergent()', safe=True) |
|
778 | @predicate('contentdivergent()', safe=True) | |
779 | def contentdivergent(repo, subset, x): |
|
779 | def contentdivergent(repo, subset, x): | |
780 | """ |
|
780 | """ | |
781 | Final successors of changesets with an alternative set of final |
|
781 | Final successors of changesets with an alternative set of final | |
782 | successors. (EXPERIMENTAL) |
|
782 | successors. (EXPERIMENTAL) | |
783 | """ |
|
783 | """ | |
784 | # i18n: "contentdivergent" is a keyword |
|
784 | # i18n: "contentdivergent" is a keyword | |
785 | getargs(x, 0, 0, _("contentdivergent takes no arguments")) |
|
785 | getargs(x, 0, 0, _("contentdivergent takes no arguments")) | |
786 | contentdivergent = obsmod.getrevs(repo, 'contentdivergent') |
|
786 | contentdivergent = obsmod.getrevs(repo, 'contentdivergent') | |
787 | return subset & contentdivergent |
|
787 | return subset & contentdivergent | |
788 |
|
788 | |||
789 | @predicate('extdata(source)', safe=False, weight=100) |
|
789 | @predicate('extdata(source)', safe=False, weight=100) | |
790 | def extdata(repo, subset, x): |
|
790 | def extdata(repo, subset, x): | |
791 | """Changesets in the specified extdata source. (EXPERIMENTAL)""" |
|
791 | """Changesets in the specified extdata source. (EXPERIMENTAL)""" | |
792 | # i18n: "extdata" is a keyword |
|
792 | # i18n: "extdata" is a keyword | |
793 | args = getargsdict(x, 'extdata', 'source') |
|
793 | args = getargsdict(x, 'extdata', 'source') | |
794 | source = getstring(args.get('source'), |
|
794 | source = getstring(args.get('source'), | |
795 | # i18n: "extdata" is a keyword |
|
795 | # i18n: "extdata" is a keyword | |
796 | _('extdata takes at least 1 string argument')) |
|
796 | _('extdata takes at least 1 string argument')) | |
797 | data = scmutil.extdatasource(repo, source) |
|
797 | data = scmutil.extdatasource(repo, source) | |
798 | return subset & baseset(data) |
|
798 | return subset & baseset(data) | |
799 |
|
799 | |||
800 | @predicate('extinct()', safe=True) |
|
800 | @predicate('extinct()', safe=True) | |
801 | def extinct(repo, subset, x): |
|
801 | def extinct(repo, subset, x): | |
802 | """Obsolete changesets with obsolete descendants only. |
|
802 | """Obsolete changesets with obsolete descendants only. | |
803 | """ |
|
803 | """ | |
804 | # i18n: "extinct" is a keyword |
|
804 | # i18n: "extinct" is a keyword | |
805 | getargs(x, 0, 0, _("extinct takes no arguments")) |
|
805 | getargs(x, 0, 0, _("extinct takes no arguments")) | |
806 | extincts = obsmod.getrevs(repo, 'extinct') |
|
806 | extincts = obsmod.getrevs(repo, 'extinct') | |
807 | return subset & extincts |
|
807 | return subset & extincts | |
808 |
|
808 | |||
809 | @predicate('extra(label, [value])', safe=True) |
|
809 | @predicate('extra(label, [value])', safe=True) | |
810 | def extra(repo, subset, x): |
|
810 | def extra(repo, subset, x): | |
811 | """Changesets with the given label in the extra metadata, with the given |
|
811 | """Changesets with the given label in the extra metadata, with the given | |
812 | optional value. |
|
812 | optional value. | |
813 |
|
813 | |||
814 | Pattern matching is supported for `value`. See |
|
814 | Pattern matching is supported for `value`. See | |
815 | :hg:`help revisions.patterns`. |
|
815 | :hg:`help revisions.patterns`. | |
816 | """ |
|
816 | """ | |
817 | args = getargsdict(x, 'extra', 'label value') |
|
817 | args = getargsdict(x, 'extra', 'label value') | |
818 | if 'label' not in args: |
|
818 | if 'label' not in args: | |
819 | # i18n: "extra" is a keyword |
|
819 | # i18n: "extra" is a keyword | |
820 | raise error.ParseError(_('extra takes at least 1 argument')) |
|
820 | raise error.ParseError(_('extra takes at least 1 argument')) | |
821 | # i18n: "extra" is a keyword |
|
821 | # i18n: "extra" is a keyword | |
822 | label = getstring(args['label'], _('first argument to extra must be ' |
|
822 | label = getstring(args['label'], _('first argument to extra must be ' | |
823 | 'a string')) |
|
823 | 'a string')) | |
824 | value = None |
|
824 | value = None | |
825 |
|
825 | |||
826 | if 'value' in args: |
|
826 | if 'value' in args: | |
827 | # i18n: "extra" is a keyword |
|
827 | # i18n: "extra" is a keyword | |
828 | value = getstring(args['value'], _('second argument to extra must be ' |
|
828 | value = getstring(args['value'], _('second argument to extra must be ' | |
829 | 'a string')) |
|
829 | 'a string')) | |
830 | kind, value, matcher = util.stringmatcher(value) |
|
830 | kind, value, matcher = util.stringmatcher(value) | |
831 |
|
831 | |||
832 | def _matchvalue(r): |
|
832 | def _matchvalue(r): | |
833 | extra = repo[r].extra() |
|
833 | extra = repo[r].extra() | |
834 | return label in extra and (value is None or matcher(extra[label])) |
|
834 | return label in extra and (value is None or matcher(extra[label])) | |
835 |
|
835 | |||
836 | return subset.filter(lambda r: _matchvalue(r), |
|
836 | return subset.filter(lambda r: _matchvalue(r), | |
837 | condrepr=('<extra[%r] %r>', label, value)) |
|
837 | condrepr=('<extra[%r] %r>', label, value)) | |
838 |
|
838 | |||
839 | @predicate('filelog(pattern)', safe=True) |
|
839 | @predicate('filelog(pattern)', safe=True) | |
840 | def filelog(repo, subset, x): |
|
840 | def filelog(repo, subset, x): | |
841 | """Changesets connected to the specified filelog. |
|
841 | """Changesets connected to the specified filelog. | |
842 |
|
842 | |||
843 | For performance reasons, visits only revisions mentioned in the file-level |
|
843 | For performance reasons, visits only revisions mentioned in the file-level | |
844 | filelog, rather than filtering through all changesets (much faster, but |
|
844 | filelog, rather than filtering through all changesets (much faster, but | |
845 | doesn't include deletes or duplicate changes). For a slower, more accurate |
|
845 | doesn't include deletes or duplicate changes). For a slower, more accurate | |
846 | result, use ``file()``. |
|
846 | result, use ``file()``. | |
847 |
|
847 | |||
848 | The pattern without explicit kind like ``glob:`` is expected to be |
|
848 | The pattern without explicit kind like ``glob:`` is expected to be | |
849 | relative to the current directory and match against a file exactly |
|
849 | relative to the current directory and match against a file exactly | |
850 | for efficiency. |
|
850 | for efficiency. | |
851 |
|
851 | |||
852 | If some linkrev points to revisions filtered by the current repoview, we'll |
|
852 | If some linkrev points to revisions filtered by the current repoview, we'll | |
853 | work around it to return a non-filtered value. |
|
853 | work around it to return a non-filtered value. | |
854 | """ |
|
854 | """ | |
855 |
|
855 | |||
856 | # i18n: "filelog" is a keyword |
|
856 | # i18n: "filelog" is a keyword | |
857 | pat = getstring(x, _("filelog requires a pattern")) |
|
857 | pat = getstring(x, _("filelog requires a pattern")) | |
858 | s = set() |
|
858 | s = set() | |
859 | cl = repo.changelog |
|
859 | cl = repo.changelog | |
860 |
|
860 | |||
861 | if not matchmod.patkind(pat): |
|
861 | if not matchmod.patkind(pat): | |
862 | f = pathutil.canonpath(repo.root, repo.getcwd(), pat) |
|
862 | f = pathutil.canonpath(repo.root, repo.getcwd(), pat) | |
863 | files = [f] |
|
863 | files = [f] | |
864 | else: |
|
864 | else: | |
865 | m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=repo[None]) |
|
865 | m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=repo[None]) | |
866 | files = (f for f in repo[None] if m(f)) |
|
866 | files = (f for f in repo[None] if m(f)) | |
867 |
|
867 | |||
868 | for f in files: |
|
868 | for f in files: | |
869 | fl = repo.file(f) |
|
869 | fl = repo.file(f) | |
870 | known = {} |
|
870 | known = {} | |
871 | scanpos = 0 |
|
871 | scanpos = 0 | |
872 | for fr in list(fl): |
|
872 | for fr in list(fl): | |
873 | fn = fl.node(fr) |
|
873 | fn = fl.node(fr) | |
874 | if fn in known: |
|
874 | if fn in known: | |
875 | s.add(known[fn]) |
|
875 | s.add(known[fn]) | |
876 | continue |
|
876 | continue | |
877 |
|
877 | |||
878 | lr = fl.linkrev(fr) |
|
878 | lr = fl.linkrev(fr) | |
879 | if lr in cl: |
|
879 | if lr in cl: | |
880 | s.add(lr) |
|
880 | s.add(lr) | |
881 | elif scanpos is not None: |
|
881 | elif scanpos is not None: | |
882 | # lowest matching changeset is filtered, scan further |
|
882 | # lowest matching changeset is filtered, scan further | |
883 | # ahead in changelog |
|
883 | # ahead in changelog | |
884 | start = max(lr, scanpos) + 1 |
|
884 | start = max(lr, scanpos) + 1 | |
885 | scanpos = None |
|
885 | scanpos = None | |
886 | for r in cl.revs(start): |
|
886 | for r in cl.revs(start): | |
887 | # minimize parsing of non-matching entries |
|
887 | # minimize parsing of non-matching entries | |
888 | if f in cl.revision(r) and f in cl.readfiles(r): |
|
888 | if f in cl.revision(r) and f in cl.readfiles(r): | |
889 | try: |
|
889 | try: | |
890 | # try to use manifest delta fastpath |
|
890 | # try to use manifest delta fastpath | |
891 | n = repo[r].filenode(f) |
|
891 | n = repo[r].filenode(f) | |
892 | if n not in known: |
|
892 | if n not in known: | |
893 | if n == fn: |
|
893 | if n == fn: | |
894 | s.add(r) |
|
894 | s.add(r) | |
895 | scanpos = r |
|
895 | scanpos = r | |
896 | break |
|
896 | break | |
897 | else: |
|
897 | else: | |
898 | known[n] = r |
|
898 | known[n] = r | |
899 | except error.ManifestLookupError: |
|
899 | except error.ManifestLookupError: | |
900 | # deletion in changelog |
|
900 | # deletion in changelog | |
901 | continue |
|
901 | continue | |
902 |
|
902 | |||
903 | return subset & s |
|
903 | return subset & s | |
904 |
|
904 | |||
905 | @predicate('first(set, [n])', safe=True, takeorder=True, weight=0) |
|
905 | @predicate('first(set, [n])', safe=True, takeorder=True, weight=0) | |
906 | def first(repo, subset, x, order): |
|
906 | def first(repo, subset, x, order): | |
907 | """An alias for limit(). |
|
907 | """An alias for limit(). | |
908 | """ |
|
908 | """ | |
909 | return limit(repo, subset, x, order) |
|
909 | return limit(repo, subset, x, order) | |
910 |
|
910 | |||
911 | def _follow(repo, subset, x, name, followfirst=False): |
|
911 | def _follow(repo, subset, x, name, followfirst=False): | |
912 | l = getargs(x, 0, 2, _("%s takes no arguments or a pattern " |
|
912 | l = getargs(x, 0, 2, _("%s takes no arguments or a pattern " | |
913 | "and an optional revset") % name) |
|
913 | "and an optional revset") % name) | |
914 | c = repo['.'] |
|
914 | c = repo['.'] | |
915 | if l: |
|
915 | if l: | |
916 | x = getstring(l[0], _("%s expected a pattern") % name) |
|
916 | x = getstring(l[0], _("%s expected a pattern") % name) | |
917 | rev = None |
|
917 | rev = None | |
918 | if len(l) >= 2: |
|
918 | if len(l) >= 2: | |
919 | revs = getset(repo, fullreposet(repo), l[1]) |
|
919 | revs = getset(repo, fullreposet(repo), l[1]) | |
920 | if len(revs) != 1: |
|
920 | if len(revs) != 1: | |
921 | raise error.RepoLookupError( |
|
921 | raise error.RepoLookupError( | |
922 | _("%s expected one starting revision") % name) |
|
922 | _("%s expected one starting revision") % name) | |
923 | rev = revs.last() |
|
923 | rev = revs.last() | |
924 | c = repo[rev] |
|
924 | c = repo[rev] | |
925 | matcher = matchmod.match(repo.root, repo.getcwd(), [x], |
|
925 | matcher = matchmod.match(repo.root, repo.getcwd(), [x], | |
926 | ctx=repo[rev], default='path') |
|
926 | ctx=repo[rev], default='path') | |
927 |
|
927 | |||
928 | files = c.manifest().walk(matcher) |
|
928 | files = c.manifest().walk(matcher) | |
929 |
|
929 | |||
930 | s = set() |
|
930 | s = set() | |
931 | for fname in files: |
|
931 | for fname in files: | |
932 | fctx = c[fname] |
|
932 | fctx = c[fname] | |
933 | s = s.union(set(c.rev() for c in fctx.ancestors(followfirst))) |
|
933 | s = s.union(set(c.rev() for c in fctx.ancestors(followfirst))) | |
934 | # include the revision responsible for the most recent version |
|
934 | # include the revision responsible for the most recent version | |
935 | s.add(fctx.introrev()) |
|
935 | s.add(fctx.introrev()) | |
936 | else: |
|
936 | else: | |
937 | s = dagop.revancestors(repo, baseset([c.rev()]), followfirst) |
|
937 | s = dagop.revancestors(repo, baseset([c.rev()]), followfirst) | |
938 |
|
938 | |||
939 | return subset & s |
|
939 | return subset & s | |
940 |
|
940 | |||
941 | @predicate('follow([pattern[, startrev]])', safe=True) |
|
941 | @predicate('follow([pattern[, startrev]])', safe=True) | |
942 | def follow(repo, subset, x): |
|
942 | def follow(repo, subset, x): | |
943 | """ |
|
943 | """ | |
944 | An alias for ``::.`` (ancestors of the working directory's first parent). |
|
944 | An alias for ``::.`` (ancestors of the working directory's first parent). | |
945 | If pattern is specified, the histories of files matching given |
|
945 | If pattern is specified, the histories of files matching given | |
946 | pattern in the revision given by startrev are followed, including copies. |
|
946 | pattern in the revision given by startrev are followed, including copies. | |
947 | """ |
|
947 | """ | |
948 | return _follow(repo, subset, x, 'follow') |
|
948 | return _follow(repo, subset, x, 'follow') | |
949 |
|
949 | |||
950 | @predicate('_followfirst', safe=True) |
|
950 | @predicate('_followfirst', safe=True) | |
951 | def _followfirst(repo, subset, x): |
|
951 | def _followfirst(repo, subset, x): | |
952 | # ``followfirst([pattern[, startrev]])`` |
|
952 | # ``followfirst([pattern[, startrev]])`` | |
953 | # Like ``follow([pattern[, startrev]])`` but follows only the first parent |
|
953 | # Like ``follow([pattern[, startrev]])`` but follows only the first parent | |
954 | # of every revisions or files revisions. |
|
954 | # of every revisions or files revisions. | |
955 | return _follow(repo, subset, x, '_followfirst', followfirst=True) |
|
955 | return _follow(repo, subset, x, '_followfirst', followfirst=True) | |
956 |
|
956 | |||
957 | @predicate('followlines(file, fromline:toline[, startrev=., descend=False])', |
|
957 | @predicate('followlines(file, fromline:toline[, startrev=., descend=False])', | |
958 | safe=True) |
|
958 | safe=True) | |
959 | def followlines(repo, subset, x): |
|
959 | def followlines(repo, subset, x): | |
960 | """Changesets modifying `file` in line range ('fromline', 'toline'). |
|
960 | """Changesets modifying `file` in line range ('fromline', 'toline'). | |
961 |
|
961 | |||
962 | Line range corresponds to 'file' content at 'startrev' and should hence be |
|
962 | Line range corresponds to 'file' content at 'startrev' and should hence be | |
963 | consistent with file size. If startrev is not specified, working directory's |
|
963 | consistent with file size. If startrev is not specified, working directory's | |
964 | parent is used. |
|
964 | parent is used. | |
965 |
|
965 | |||
966 | By default, ancestors of 'startrev' are returned. If 'descend' is True, |
|
966 | By default, ancestors of 'startrev' are returned. If 'descend' is True, | |
967 | descendants of 'startrev' are returned though renames are (currently) not |
|
967 | descendants of 'startrev' are returned though renames are (currently) not | |
968 | followed in this direction. |
|
968 | followed in this direction. | |
969 | """ |
|
969 | """ | |
970 | args = getargsdict(x, 'followlines', 'file *lines startrev descend') |
|
970 | args = getargsdict(x, 'followlines', 'file *lines startrev descend') | |
971 | if len(args['lines']) != 1: |
|
971 | if len(args['lines']) != 1: | |
972 | raise error.ParseError(_("followlines requires a line range")) |
|
972 | raise error.ParseError(_("followlines requires a line range")) | |
973 |
|
973 | |||
974 | rev = '.' |
|
974 | rev = '.' | |
975 | if 'startrev' in args: |
|
975 | if 'startrev' in args: | |
976 | revs = getset(repo, fullreposet(repo), args['startrev']) |
|
976 | revs = getset(repo, fullreposet(repo), args['startrev']) | |
977 | if len(revs) != 1: |
|
977 | if len(revs) != 1: | |
978 | raise error.ParseError( |
|
978 | raise error.ParseError( | |
979 | # i18n: "followlines" is a keyword |
|
979 | # i18n: "followlines" is a keyword | |
980 | _("followlines expects exactly one revision")) |
|
980 | _("followlines expects exactly one revision")) | |
981 | rev = revs.last() |
|
981 | rev = revs.last() | |
982 |
|
982 | |||
983 | pat = getstring(args['file'], _("followlines requires a pattern")) |
|
983 | pat = getstring(args['file'], _("followlines requires a pattern")) | |
984 | if not matchmod.patkind(pat): |
|
|||
985 | fname = pathutil.canonpath(repo.root, repo.getcwd(), pat) |
|
|||
986 | else: |
|
|||
987 | m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=repo[rev]) |
|
|||
988 | files = [f for f in repo[rev] if m(f)] |
|
|||
989 | if len(files) != 1: |
|
|||
990 |
|
|
984 | # i18n: "followlines" is a keyword | |
991 |
|
|
985 | msg = _("followlines expects exactly one file") | |
992 | fname = files[0] |
|
986 | fname = scmutil.parsefollowlinespattern(repo, rev, pat, msg) | |
993 |
|
||||
994 | # i18n: "followlines" is a keyword |
|
987 | # i18n: "followlines" is a keyword | |
995 | lr = getrange(args['lines'][0], _("followlines expects a line range")) |
|
988 | lr = getrange(args['lines'][0], _("followlines expects a line range")) | |
996 | fromline, toline = [getinteger(a, _("line range bounds must be integers")) |
|
989 | fromline, toline = [getinteger(a, _("line range bounds must be integers")) | |
997 | for a in lr] |
|
990 | for a in lr] | |
998 | fromline, toline = util.processlinerange(fromline, toline) |
|
991 | fromline, toline = util.processlinerange(fromline, toline) | |
999 |
|
992 | |||
1000 | fctx = repo[rev].filectx(fname) |
|
993 | fctx = repo[rev].filectx(fname) | |
1001 | descend = False |
|
994 | descend = False | |
1002 | if 'descend' in args: |
|
995 | if 'descend' in args: | |
1003 | descend = getboolean(args['descend'], |
|
996 | descend = getboolean(args['descend'], | |
1004 | # i18n: "descend" is a keyword |
|
997 | # i18n: "descend" is a keyword | |
1005 | _("descend argument must be a boolean")) |
|
998 | _("descend argument must be a boolean")) | |
1006 | if descend: |
|
999 | if descend: | |
1007 | rs = generatorset( |
|
1000 | rs = generatorset( | |
1008 | (c.rev() for c, _linerange |
|
1001 | (c.rev() for c, _linerange | |
1009 | in dagop.blockdescendants(fctx, fromline, toline)), |
|
1002 | in dagop.blockdescendants(fctx, fromline, toline)), | |
1010 | iterasc=True) |
|
1003 | iterasc=True) | |
1011 | else: |
|
1004 | else: | |
1012 | rs = generatorset( |
|
1005 | rs = generatorset( | |
1013 | (c.rev() for c, _linerange |
|
1006 | (c.rev() for c, _linerange | |
1014 | in dagop.blockancestors(fctx, fromline, toline)), |
|
1007 | in dagop.blockancestors(fctx, fromline, toline)), | |
1015 | iterasc=False) |
|
1008 | iterasc=False) | |
1016 | return subset & rs |
|
1009 | return subset & rs | |
1017 |
|
1010 | |||
1018 | @predicate('all()', safe=True) |
|
1011 | @predicate('all()', safe=True) | |
1019 | def getall(repo, subset, x): |
|
1012 | def getall(repo, subset, x): | |
1020 | """All changesets, the same as ``0:tip``. |
|
1013 | """All changesets, the same as ``0:tip``. | |
1021 | """ |
|
1014 | """ | |
1022 | # i18n: "all" is a keyword |
|
1015 | # i18n: "all" is a keyword | |
1023 | getargs(x, 0, 0, _("all takes no arguments")) |
|
1016 | getargs(x, 0, 0, _("all takes no arguments")) | |
1024 | return subset & spanset(repo) # drop "null" if any |
|
1017 | return subset & spanset(repo) # drop "null" if any | |
1025 |
|
1018 | |||
1026 | @predicate('grep(regex)', weight=10) |
|
1019 | @predicate('grep(regex)', weight=10) | |
1027 | def grep(repo, subset, x): |
|
1020 | def grep(repo, subset, x): | |
1028 | """Like ``keyword(string)`` but accepts a regex. Use ``grep(r'...')`` |
|
1021 | """Like ``keyword(string)`` but accepts a regex. Use ``grep(r'...')`` | |
1029 | to ensure special escape characters are handled correctly. Unlike |
|
1022 | to ensure special escape characters are handled correctly. Unlike | |
1030 | ``keyword(string)``, the match is case-sensitive. |
|
1023 | ``keyword(string)``, the match is case-sensitive. | |
1031 | """ |
|
1024 | """ | |
1032 | try: |
|
1025 | try: | |
1033 | # i18n: "grep" is a keyword |
|
1026 | # i18n: "grep" is a keyword | |
1034 | gr = re.compile(getstring(x, _("grep requires a string"))) |
|
1027 | gr = re.compile(getstring(x, _("grep requires a string"))) | |
1035 | except re.error as e: |
|
1028 | except re.error as e: | |
1036 | raise error.ParseError(_('invalid match pattern: %s') % e) |
|
1029 | raise error.ParseError(_('invalid match pattern: %s') % e) | |
1037 |
|
1030 | |||
1038 | def matches(x): |
|
1031 | def matches(x): | |
1039 | c = repo[x] |
|
1032 | c = repo[x] | |
1040 | for e in c.files() + [c.user(), c.description()]: |
|
1033 | for e in c.files() + [c.user(), c.description()]: | |
1041 | if gr.search(e): |
|
1034 | if gr.search(e): | |
1042 | return True |
|
1035 | return True | |
1043 | return False |
|
1036 | return False | |
1044 |
|
1037 | |||
1045 | return subset.filter(matches, condrepr=('<grep %r>', gr.pattern)) |
|
1038 | return subset.filter(matches, condrepr=('<grep %r>', gr.pattern)) | |
1046 |
|
1039 | |||
1047 | @predicate('_matchfiles', safe=True) |
|
1040 | @predicate('_matchfiles', safe=True) | |
1048 | def _matchfiles(repo, subset, x): |
|
1041 | def _matchfiles(repo, subset, x): | |
1049 | # _matchfiles takes a revset list of prefixed arguments: |
|
1042 | # _matchfiles takes a revset list of prefixed arguments: | |
1050 | # |
|
1043 | # | |
1051 | # [p:foo, i:bar, x:baz] |
|
1044 | # [p:foo, i:bar, x:baz] | |
1052 | # |
|
1045 | # | |
1053 | # builds a match object from them and filters subset. Allowed |
|
1046 | # builds a match object from them and filters subset. Allowed | |
1054 | # prefixes are 'p:' for regular patterns, 'i:' for include |
|
1047 | # prefixes are 'p:' for regular patterns, 'i:' for include | |
1055 | # patterns and 'x:' for exclude patterns. Use 'r:' prefix to pass |
|
1048 | # patterns and 'x:' for exclude patterns. Use 'r:' prefix to pass | |
1056 | # a revision identifier, or the empty string to reference the |
|
1049 | # a revision identifier, or the empty string to reference the | |
1057 | # working directory, from which the match object is |
|
1050 | # working directory, from which the match object is | |
1058 | # initialized. Use 'd:' to set the default matching mode, default |
|
1051 | # initialized. Use 'd:' to set the default matching mode, default | |
1059 | # to 'glob'. At most one 'r:' and 'd:' argument can be passed. |
|
1052 | # to 'glob'. At most one 'r:' and 'd:' argument can be passed. | |
1060 |
|
1053 | |||
1061 | l = getargs(x, 1, -1, "_matchfiles requires at least one argument") |
|
1054 | l = getargs(x, 1, -1, "_matchfiles requires at least one argument") | |
1062 | pats, inc, exc = [], [], [] |
|
1055 | pats, inc, exc = [], [], [] | |
1063 | rev, default = None, None |
|
1056 | rev, default = None, None | |
1064 | for arg in l: |
|
1057 | for arg in l: | |
1065 | s = getstring(arg, "_matchfiles requires string arguments") |
|
1058 | s = getstring(arg, "_matchfiles requires string arguments") | |
1066 | prefix, value = s[:2], s[2:] |
|
1059 | prefix, value = s[:2], s[2:] | |
1067 | if prefix == 'p:': |
|
1060 | if prefix == 'p:': | |
1068 | pats.append(value) |
|
1061 | pats.append(value) | |
1069 | elif prefix == 'i:': |
|
1062 | elif prefix == 'i:': | |
1070 | inc.append(value) |
|
1063 | inc.append(value) | |
1071 | elif prefix == 'x:': |
|
1064 | elif prefix == 'x:': | |
1072 | exc.append(value) |
|
1065 | exc.append(value) | |
1073 | elif prefix == 'r:': |
|
1066 | elif prefix == 'r:': | |
1074 | if rev is not None: |
|
1067 | if rev is not None: | |
1075 | raise error.ParseError('_matchfiles expected at most one ' |
|
1068 | raise error.ParseError('_matchfiles expected at most one ' | |
1076 | 'revision') |
|
1069 | 'revision') | |
1077 | if value != '': # empty means working directory; leave rev as None |
|
1070 | if value != '': # empty means working directory; leave rev as None | |
1078 | rev = value |
|
1071 | rev = value | |
1079 | elif prefix == 'd:': |
|
1072 | elif prefix == 'd:': | |
1080 | if default is not None: |
|
1073 | if default is not None: | |
1081 | raise error.ParseError('_matchfiles expected at most one ' |
|
1074 | raise error.ParseError('_matchfiles expected at most one ' | |
1082 | 'default mode') |
|
1075 | 'default mode') | |
1083 | default = value |
|
1076 | default = value | |
1084 | else: |
|
1077 | else: | |
1085 | raise error.ParseError('invalid _matchfiles prefix: %s' % prefix) |
|
1078 | raise error.ParseError('invalid _matchfiles prefix: %s' % prefix) | |
1086 | if not default: |
|
1079 | if not default: | |
1087 | default = 'glob' |
|
1080 | default = 'glob' | |
1088 |
|
1081 | |||
1089 | m = matchmod.match(repo.root, repo.getcwd(), pats, include=inc, |
|
1082 | m = matchmod.match(repo.root, repo.getcwd(), pats, include=inc, | |
1090 | exclude=exc, ctx=repo[rev], default=default) |
|
1083 | exclude=exc, ctx=repo[rev], default=default) | |
1091 |
|
1084 | |||
1092 | # This directly read the changelog data as creating changectx for all |
|
1085 | # This directly read the changelog data as creating changectx for all | |
1093 | # revisions is quite expensive. |
|
1086 | # revisions is quite expensive. | |
1094 | getfiles = repo.changelog.readfiles |
|
1087 | getfiles = repo.changelog.readfiles | |
1095 | wdirrev = node.wdirrev |
|
1088 | wdirrev = node.wdirrev | |
1096 | def matches(x): |
|
1089 | def matches(x): | |
1097 | if x == wdirrev: |
|
1090 | if x == wdirrev: | |
1098 | files = repo[x].files() |
|
1091 | files = repo[x].files() | |
1099 | else: |
|
1092 | else: | |
1100 | files = getfiles(x) |
|
1093 | files = getfiles(x) | |
1101 | for f in files: |
|
1094 | for f in files: | |
1102 | if m(f): |
|
1095 | if m(f): | |
1103 | return True |
|
1096 | return True | |
1104 | return False |
|
1097 | return False | |
1105 |
|
1098 | |||
1106 | return subset.filter(matches, |
|
1099 | return subset.filter(matches, | |
1107 | condrepr=('<matchfiles patterns=%r, include=%r ' |
|
1100 | condrepr=('<matchfiles patterns=%r, include=%r ' | |
1108 | 'exclude=%r, default=%r, rev=%r>', |
|
1101 | 'exclude=%r, default=%r, rev=%r>', | |
1109 | pats, inc, exc, default, rev)) |
|
1102 | pats, inc, exc, default, rev)) | |
1110 |
|
1103 | |||
1111 | @predicate('file(pattern)', safe=True, weight=10) |
|
1104 | @predicate('file(pattern)', safe=True, weight=10) | |
1112 | def hasfile(repo, subset, x): |
|
1105 | def hasfile(repo, subset, x): | |
1113 | """Changesets affecting files matched by pattern. |
|
1106 | """Changesets affecting files matched by pattern. | |
1114 |
|
1107 | |||
1115 | For a faster but less accurate result, consider using ``filelog()`` |
|
1108 | For a faster but less accurate result, consider using ``filelog()`` | |
1116 | instead. |
|
1109 | instead. | |
1117 |
|
1110 | |||
1118 | This predicate uses ``glob:`` as the default kind of pattern. |
|
1111 | This predicate uses ``glob:`` as the default kind of pattern. | |
1119 | """ |
|
1112 | """ | |
1120 | # i18n: "file" is a keyword |
|
1113 | # i18n: "file" is a keyword | |
1121 | pat = getstring(x, _("file requires a pattern")) |
|
1114 | pat = getstring(x, _("file requires a pattern")) | |
1122 | return _matchfiles(repo, subset, ('string', 'p:' + pat)) |
|
1115 | return _matchfiles(repo, subset, ('string', 'p:' + pat)) | |
1123 |
|
1116 | |||
1124 | @predicate('head()', safe=True) |
|
1117 | @predicate('head()', safe=True) | |
1125 | def head(repo, subset, x): |
|
1118 | def head(repo, subset, x): | |
1126 | """Changeset is a named branch head. |
|
1119 | """Changeset is a named branch head. | |
1127 | """ |
|
1120 | """ | |
1128 | # i18n: "head" is a keyword |
|
1121 | # i18n: "head" is a keyword | |
1129 | getargs(x, 0, 0, _("head takes no arguments")) |
|
1122 | getargs(x, 0, 0, _("head takes no arguments")) | |
1130 | hs = set() |
|
1123 | hs = set() | |
1131 | cl = repo.changelog |
|
1124 | cl = repo.changelog | |
1132 | for ls in repo.branchmap().itervalues(): |
|
1125 | for ls in repo.branchmap().itervalues(): | |
1133 | hs.update(cl.rev(h) for h in ls) |
|
1126 | hs.update(cl.rev(h) for h in ls) | |
1134 | return subset & baseset(hs) |
|
1127 | return subset & baseset(hs) | |
1135 |
|
1128 | |||
1136 | @predicate('heads(set)', safe=True) |
|
1129 | @predicate('heads(set)', safe=True) | |
1137 | def heads(repo, subset, x): |
|
1130 | def heads(repo, subset, x): | |
1138 | """Members of set with no children in set. |
|
1131 | """Members of set with no children in set. | |
1139 | """ |
|
1132 | """ | |
1140 | s = getset(repo, subset, x) |
|
1133 | s = getset(repo, subset, x) | |
1141 | ps = parents(repo, subset, x) |
|
1134 | ps = parents(repo, subset, x) | |
1142 | return s - ps |
|
1135 | return s - ps | |
1143 |
|
1136 | |||
1144 | @predicate('hidden()', safe=True) |
|
1137 | @predicate('hidden()', safe=True) | |
1145 | def hidden(repo, subset, x): |
|
1138 | def hidden(repo, subset, x): | |
1146 | """Hidden changesets. |
|
1139 | """Hidden changesets. | |
1147 | """ |
|
1140 | """ | |
1148 | # i18n: "hidden" is a keyword |
|
1141 | # i18n: "hidden" is a keyword | |
1149 | getargs(x, 0, 0, _("hidden takes no arguments")) |
|
1142 | getargs(x, 0, 0, _("hidden takes no arguments")) | |
1150 | hiddenrevs = repoview.filterrevs(repo, 'visible') |
|
1143 | hiddenrevs = repoview.filterrevs(repo, 'visible') | |
1151 | return subset & hiddenrevs |
|
1144 | return subset & hiddenrevs | |
1152 |
|
1145 | |||
1153 | @predicate('keyword(string)', safe=True, weight=10) |
|
1146 | @predicate('keyword(string)', safe=True, weight=10) | |
1154 | def keyword(repo, subset, x): |
|
1147 | def keyword(repo, subset, x): | |
1155 | """Search commit message, user name, and names of changed files for |
|
1148 | """Search commit message, user name, and names of changed files for | |
1156 | string. The match is case-insensitive. |
|
1149 | string. The match is case-insensitive. | |
1157 |
|
1150 | |||
1158 | For a regular expression or case sensitive search of these fields, use |
|
1151 | For a regular expression or case sensitive search of these fields, use | |
1159 | ``grep(regex)``. |
|
1152 | ``grep(regex)``. | |
1160 | """ |
|
1153 | """ | |
1161 | # i18n: "keyword" is a keyword |
|
1154 | # i18n: "keyword" is a keyword | |
1162 | kw = encoding.lower(getstring(x, _("keyword requires a string"))) |
|
1155 | kw = encoding.lower(getstring(x, _("keyword requires a string"))) | |
1163 |
|
1156 | |||
1164 | def matches(r): |
|
1157 | def matches(r): | |
1165 | c = repo[r] |
|
1158 | c = repo[r] | |
1166 | return any(kw in encoding.lower(t) |
|
1159 | return any(kw in encoding.lower(t) | |
1167 | for t in c.files() + [c.user(), c.description()]) |
|
1160 | for t in c.files() + [c.user(), c.description()]) | |
1168 |
|
1161 | |||
1169 | return subset.filter(matches, condrepr=('<keyword %r>', kw)) |
|
1162 | return subset.filter(matches, condrepr=('<keyword %r>', kw)) | |
1170 |
|
1163 | |||
1171 | @predicate('limit(set[, n[, offset]])', safe=True, takeorder=True, weight=0) |
|
1164 | @predicate('limit(set[, n[, offset]])', safe=True, takeorder=True, weight=0) | |
1172 | def limit(repo, subset, x, order): |
|
1165 | def limit(repo, subset, x, order): | |
1173 | """First n members of set, defaulting to 1, starting from offset. |
|
1166 | """First n members of set, defaulting to 1, starting from offset. | |
1174 | """ |
|
1167 | """ | |
1175 | args = getargsdict(x, 'limit', 'set n offset') |
|
1168 | args = getargsdict(x, 'limit', 'set n offset') | |
1176 | if 'set' not in args: |
|
1169 | if 'set' not in args: | |
1177 | # i18n: "limit" is a keyword |
|
1170 | # i18n: "limit" is a keyword | |
1178 | raise error.ParseError(_("limit requires one to three arguments")) |
|
1171 | raise error.ParseError(_("limit requires one to three arguments")) | |
1179 | # i18n: "limit" is a keyword |
|
1172 | # i18n: "limit" is a keyword | |
1180 | lim = getinteger(args.get('n'), _("limit expects a number"), default=1) |
|
1173 | lim = getinteger(args.get('n'), _("limit expects a number"), default=1) | |
1181 | if lim < 0: |
|
1174 | if lim < 0: | |
1182 | raise error.ParseError(_("negative number to select")) |
|
1175 | raise error.ParseError(_("negative number to select")) | |
1183 | # i18n: "limit" is a keyword |
|
1176 | # i18n: "limit" is a keyword | |
1184 | ofs = getinteger(args.get('offset'), _("limit expects a number"), default=0) |
|
1177 | ofs = getinteger(args.get('offset'), _("limit expects a number"), default=0) | |
1185 | if ofs < 0: |
|
1178 | if ofs < 0: | |
1186 | raise error.ParseError(_("negative offset")) |
|
1179 | raise error.ParseError(_("negative offset")) | |
1187 | os = getset(repo, fullreposet(repo), args['set']) |
|
1180 | os = getset(repo, fullreposet(repo), args['set']) | |
1188 | ls = os.slice(ofs, ofs + lim) |
|
1181 | ls = os.slice(ofs, ofs + lim) | |
1189 | if order == followorder and lim > 1: |
|
1182 | if order == followorder and lim > 1: | |
1190 | return subset & ls |
|
1183 | return subset & ls | |
1191 | return ls & subset |
|
1184 | return ls & subset | |
1192 |
|
1185 | |||
1193 | @predicate('last(set, [n])', safe=True, takeorder=True) |
|
1186 | @predicate('last(set, [n])', safe=True, takeorder=True) | |
1194 | def last(repo, subset, x, order): |
|
1187 | def last(repo, subset, x, order): | |
1195 | """Last n members of set, defaulting to 1. |
|
1188 | """Last n members of set, defaulting to 1. | |
1196 | """ |
|
1189 | """ | |
1197 | # i18n: "last" is a keyword |
|
1190 | # i18n: "last" is a keyword | |
1198 | l = getargs(x, 1, 2, _("last requires one or two arguments")) |
|
1191 | l = getargs(x, 1, 2, _("last requires one or two arguments")) | |
1199 | lim = 1 |
|
1192 | lim = 1 | |
1200 | if len(l) == 2: |
|
1193 | if len(l) == 2: | |
1201 | # i18n: "last" is a keyword |
|
1194 | # i18n: "last" is a keyword | |
1202 | lim = getinteger(l[1], _("last expects a number")) |
|
1195 | lim = getinteger(l[1], _("last expects a number")) | |
1203 | if lim < 0: |
|
1196 | if lim < 0: | |
1204 | raise error.ParseError(_("negative number to select")) |
|
1197 | raise error.ParseError(_("negative number to select")) | |
1205 | os = getset(repo, fullreposet(repo), l[0]) |
|
1198 | os = getset(repo, fullreposet(repo), l[0]) | |
1206 | os.reverse() |
|
1199 | os.reverse() | |
1207 | ls = os.slice(0, lim) |
|
1200 | ls = os.slice(0, lim) | |
1208 | if order == followorder and lim > 1: |
|
1201 | if order == followorder and lim > 1: | |
1209 | return subset & ls |
|
1202 | return subset & ls | |
1210 | ls.reverse() |
|
1203 | ls.reverse() | |
1211 | return ls & subset |
|
1204 | return ls & subset | |
1212 |
|
1205 | |||
1213 | @predicate('max(set)', safe=True) |
|
1206 | @predicate('max(set)', safe=True) | |
1214 | def maxrev(repo, subset, x): |
|
1207 | def maxrev(repo, subset, x): | |
1215 | """Changeset with highest revision number in set. |
|
1208 | """Changeset with highest revision number in set. | |
1216 | """ |
|
1209 | """ | |
1217 | os = getset(repo, fullreposet(repo), x) |
|
1210 | os = getset(repo, fullreposet(repo), x) | |
1218 | try: |
|
1211 | try: | |
1219 | m = os.max() |
|
1212 | m = os.max() | |
1220 | if m in subset: |
|
1213 | if m in subset: | |
1221 | return baseset([m], datarepr=('<max %r, %r>', subset, os)) |
|
1214 | return baseset([m], datarepr=('<max %r, %r>', subset, os)) | |
1222 | except ValueError: |
|
1215 | except ValueError: | |
1223 | # os.max() throws a ValueError when the collection is empty. |
|
1216 | # os.max() throws a ValueError when the collection is empty. | |
1224 | # Same as python's max(). |
|
1217 | # Same as python's max(). | |
1225 | pass |
|
1218 | pass | |
1226 | return baseset(datarepr=('<max %r, %r>', subset, os)) |
|
1219 | return baseset(datarepr=('<max %r, %r>', subset, os)) | |
1227 |
|
1220 | |||
1228 | @predicate('merge()', safe=True) |
|
1221 | @predicate('merge()', safe=True) | |
1229 | def merge(repo, subset, x): |
|
1222 | def merge(repo, subset, x): | |
1230 | """Changeset is a merge changeset. |
|
1223 | """Changeset is a merge changeset. | |
1231 | """ |
|
1224 | """ | |
1232 | # i18n: "merge" is a keyword |
|
1225 | # i18n: "merge" is a keyword | |
1233 | getargs(x, 0, 0, _("merge takes no arguments")) |
|
1226 | getargs(x, 0, 0, _("merge takes no arguments")) | |
1234 | cl = repo.changelog |
|
1227 | cl = repo.changelog | |
1235 | return subset.filter(lambda r: cl.parentrevs(r)[1] != -1, |
|
1228 | return subset.filter(lambda r: cl.parentrevs(r)[1] != -1, | |
1236 | condrepr='<merge>') |
|
1229 | condrepr='<merge>') | |
1237 |
|
1230 | |||
1238 | @predicate('branchpoint()', safe=True) |
|
1231 | @predicate('branchpoint()', safe=True) | |
1239 | def branchpoint(repo, subset, x): |
|
1232 | def branchpoint(repo, subset, x): | |
1240 | """Changesets with more than one child. |
|
1233 | """Changesets with more than one child. | |
1241 | """ |
|
1234 | """ | |
1242 | # i18n: "branchpoint" is a keyword |
|
1235 | # i18n: "branchpoint" is a keyword | |
1243 | getargs(x, 0, 0, _("branchpoint takes no arguments")) |
|
1236 | getargs(x, 0, 0, _("branchpoint takes no arguments")) | |
1244 | cl = repo.changelog |
|
1237 | cl = repo.changelog | |
1245 | if not subset: |
|
1238 | if not subset: | |
1246 | return baseset() |
|
1239 | return baseset() | |
1247 | # XXX this should be 'parentset.min()' assuming 'parentset' is a smartset |
|
1240 | # XXX this should be 'parentset.min()' assuming 'parentset' is a smartset | |
1248 | # (and if it is not, it should.) |
|
1241 | # (and if it is not, it should.) | |
1249 | baserev = min(subset) |
|
1242 | baserev = min(subset) | |
1250 | parentscount = [0]*(len(repo) - baserev) |
|
1243 | parentscount = [0]*(len(repo) - baserev) | |
1251 | for r in cl.revs(start=baserev + 1): |
|
1244 | for r in cl.revs(start=baserev + 1): | |
1252 | for p in cl.parentrevs(r): |
|
1245 | for p in cl.parentrevs(r): | |
1253 | if p >= baserev: |
|
1246 | if p >= baserev: | |
1254 | parentscount[p - baserev] += 1 |
|
1247 | parentscount[p - baserev] += 1 | |
1255 | return subset.filter(lambda r: parentscount[r - baserev] > 1, |
|
1248 | return subset.filter(lambda r: parentscount[r - baserev] > 1, | |
1256 | condrepr='<branchpoint>') |
|
1249 | condrepr='<branchpoint>') | |
1257 |
|
1250 | |||
1258 | @predicate('min(set)', safe=True) |
|
1251 | @predicate('min(set)', safe=True) | |
1259 | def minrev(repo, subset, x): |
|
1252 | def minrev(repo, subset, x): | |
1260 | """Changeset with lowest revision number in set. |
|
1253 | """Changeset with lowest revision number in set. | |
1261 | """ |
|
1254 | """ | |
1262 | os = getset(repo, fullreposet(repo), x) |
|
1255 | os = getset(repo, fullreposet(repo), x) | |
1263 | try: |
|
1256 | try: | |
1264 | m = os.min() |
|
1257 | m = os.min() | |
1265 | if m in subset: |
|
1258 | if m in subset: | |
1266 | return baseset([m], datarepr=('<min %r, %r>', subset, os)) |
|
1259 | return baseset([m], datarepr=('<min %r, %r>', subset, os)) | |
1267 | except ValueError: |
|
1260 | except ValueError: | |
1268 | # os.min() throws a ValueError when the collection is empty. |
|
1261 | # os.min() throws a ValueError when the collection is empty. | |
1269 | # Same as python's min(). |
|
1262 | # Same as python's min(). | |
1270 | pass |
|
1263 | pass | |
1271 | return baseset(datarepr=('<min %r, %r>', subset, os)) |
|
1264 | return baseset(datarepr=('<min %r, %r>', subset, os)) | |
1272 |
|
1265 | |||
1273 | @predicate('modifies(pattern)', safe=True, weight=30) |
|
1266 | @predicate('modifies(pattern)', safe=True, weight=30) | |
1274 | def modifies(repo, subset, x): |
|
1267 | def modifies(repo, subset, x): | |
1275 | """Changesets modifying files matched by pattern. |
|
1268 | """Changesets modifying files matched by pattern. | |
1276 |
|
1269 | |||
1277 | The pattern without explicit kind like ``glob:`` is expected to be |
|
1270 | The pattern without explicit kind like ``glob:`` is expected to be | |
1278 | relative to the current directory and match against a file or a |
|
1271 | relative to the current directory and match against a file or a | |
1279 | directory. |
|
1272 | directory. | |
1280 | """ |
|
1273 | """ | |
1281 | # i18n: "modifies" is a keyword |
|
1274 | # i18n: "modifies" is a keyword | |
1282 | pat = getstring(x, _("modifies requires a pattern")) |
|
1275 | pat = getstring(x, _("modifies requires a pattern")) | |
1283 | return checkstatus(repo, subset, pat, 0) |
|
1276 | return checkstatus(repo, subset, pat, 0) | |
1284 |
|
1277 | |||
1285 | @predicate('named(namespace)') |
|
1278 | @predicate('named(namespace)') | |
1286 | def named(repo, subset, x): |
|
1279 | def named(repo, subset, x): | |
1287 | """The changesets in a given namespace. |
|
1280 | """The changesets in a given namespace. | |
1288 |
|
1281 | |||
1289 | Pattern matching is supported for `namespace`. See |
|
1282 | Pattern matching is supported for `namespace`. See | |
1290 | :hg:`help revisions.patterns`. |
|
1283 | :hg:`help revisions.patterns`. | |
1291 | """ |
|
1284 | """ | |
1292 | # i18n: "named" is a keyword |
|
1285 | # i18n: "named" is a keyword | |
1293 | args = getargs(x, 1, 1, _('named requires a namespace argument')) |
|
1286 | args = getargs(x, 1, 1, _('named requires a namespace argument')) | |
1294 |
|
1287 | |||
1295 | ns = getstring(args[0], |
|
1288 | ns = getstring(args[0], | |
1296 | # i18n: "named" is a keyword |
|
1289 | # i18n: "named" is a keyword | |
1297 | _('the argument to named must be a string')) |
|
1290 | _('the argument to named must be a string')) | |
1298 | kind, pattern, matcher = util.stringmatcher(ns) |
|
1291 | kind, pattern, matcher = util.stringmatcher(ns) | |
1299 | namespaces = set() |
|
1292 | namespaces = set() | |
1300 | if kind == 'literal': |
|
1293 | if kind == 'literal': | |
1301 | if pattern not in repo.names: |
|
1294 | if pattern not in repo.names: | |
1302 | raise error.RepoLookupError(_("namespace '%s' does not exist") |
|
1295 | raise error.RepoLookupError(_("namespace '%s' does not exist") | |
1303 | % ns) |
|
1296 | % ns) | |
1304 | namespaces.add(repo.names[pattern]) |
|
1297 | namespaces.add(repo.names[pattern]) | |
1305 | else: |
|
1298 | else: | |
1306 | for name, ns in repo.names.iteritems(): |
|
1299 | for name, ns in repo.names.iteritems(): | |
1307 | if matcher(name): |
|
1300 | if matcher(name): | |
1308 | namespaces.add(ns) |
|
1301 | namespaces.add(ns) | |
1309 | if not namespaces: |
|
1302 | if not namespaces: | |
1310 | raise error.RepoLookupError(_("no namespace exists" |
|
1303 | raise error.RepoLookupError(_("no namespace exists" | |
1311 | " that match '%s'") % pattern) |
|
1304 | " that match '%s'") % pattern) | |
1312 |
|
1305 | |||
1313 | names = set() |
|
1306 | names = set() | |
1314 | for ns in namespaces: |
|
1307 | for ns in namespaces: | |
1315 | for name in ns.listnames(repo): |
|
1308 | for name in ns.listnames(repo): | |
1316 | if name not in ns.deprecated: |
|
1309 | if name not in ns.deprecated: | |
1317 | names.update(repo[n].rev() for n in ns.nodes(repo, name)) |
|
1310 | names.update(repo[n].rev() for n in ns.nodes(repo, name)) | |
1318 |
|
1311 | |||
1319 | names -= {node.nullrev} |
|
1312 | names -= {node.nullrev} | |
1320 | return subset & names |
|
1313 | return subset & names | |
1321 |
|
1314 | |||
1322 | @predicate('id(string)', safe=True) |
|
1315 | @predicate('id(string)', safe=True) | |
1323 | def node_(repo, subset, x): |
|
1316 | def node_(repo, subset, x): | |
1324 | """Revision non-ambiguously specified by the given hex string prefix. |
|
1317 | """Revision non-ambiguously specified by the given hex string prefix. | |
1325 | """ |
|
1318 | """ | |
1326 | # i18n: "id" is a keyword |
|
1319 | # i18n: "id" is a keyword | |
1327 | l = getargs(x, 1, 1, _("id requires one argument")) |
|
1320 | l = getargs(x, 1, 1, _("id requires one argument")) | |
1328 | # i18n: "id" is a keyword |
|
1321 | # i18n: "id" is a keyword | |
1329 | n = getstring(l[0], _("id requires a string")) |
|
1322 | n = getstring(l[0], _("id requires a string")) | |
1330 | if len(n) == 40: |
|
1323 | if len(n) == 40: | |
1331 | try: |
|
1324 | try: | |
1332 | rn = repo.changelog.rev(node.bin(n)) |
|
1325 | rn = repo.changelog.rev(node.bin(n)) | |
1333 | except error.WdirUnsupported: |
|
1326 | except error.WdirUnsupported: | |
1334 | rn = node.wdirrev |
|
1327 | rn = node.wdirrev | |
1335 | except (LookupError, TypeError): |
|
1328 | except (LookupError, TypeError): | |
1336 | rn = None |
|
1329 | rn = None | |
1337 | else: |
|
1330 | else: | |
1338 | rn = None |
|
1331 | rn = None | |
1339 | try: |
|
1332 | try: | |
1340 | pm = repo.changelog._partialmatch(n) |
|
1333 | pm = repo.changelog._partialmatch(n) | |
1341 | if pm is not None: |
|
1334 | if pm is not None: | |
1342 | rn = repo.changelog.rev(pm) |
|
1335 | rn = repo.changelog.rev(pm) | |
1343 | except error.WdirUnsupported: |
|
1336 | except error.WdirUnsupported: | |
1344 | rn = node.wdirrev |
|
1337 | rn = node.wdirrev | |
1345 |
|
1338 | |||
1346 | if rn is None: |
|
1339 | if rn is None: | |
1347 | return baseset() |
|
1340 | return baseset() | |
1348 | result = baseset([rn]) |
|
1341 | result = baseset([rn]) | |
1349 | return result & subset |
|
1342 | return result & subset | |
1350 |
|
1343 | |||
1351 | @predicate('obsolete()', safe=True) |
|
1344 | @predicate('obsolete()', safe=True) | |
1352 | def obsolete(repo, subset, x): |
|
1345 | def obsolete(repo, subset, x): | |
1353 | """Mutable changeset with a newer version.""" |
|
1346 | """Mutable changeset with a newer version.""" | |
1354 | # i18n: "obsolete" is a keyword |
|
1347 | # i18n: "obsolete" is a keyword | |
1355 | getargs(x, 0, 0, _("obsolete takes no arguments")) |
|
1348 | getargs(x, 0, 0, _("obsolete takes no arguments")) | |
1356 | obsoletes = obsmod.getrevs(repo, 'obsolete') |
|
1349 | obsoletes = obsmod.getrevs(repo, 'obsolete') | |
1357 | return subset & obsoletes |
|
1350 | return subset & obsoletes | |
1358 |
|
1351 | |||
1359 | @predicate('only(set, [set])', safe=True) |
|
1352 | @predicate('only(set, [set])', safe=True) | |
1360 | def only(repo, subset, x): |
|
1353 | def only(repo, subset, x): | |
1361 | """Changesets that are ancestors of the first set that are not ancestors |
|
1354 | """Changesets that are ancestors of the first set that are not ancestors | |
1362 | of any other head in the repo. If a second set is specified, the result |
|
1355 | of any other head in the repo. If a second set is specified, the result | |
1363 | is ancestors of the first set that are not ancestors of the second set |
|
1356 | is ancestors of the first set that are not ancestors of the second set | |
1364 | (i.e. ::<set1> - ::<set2>). |
|
1357 | (i.e. ::<set1> - ::<set2>). | |
1365 | """ |
|
1358 | """ | |
1366 | cl = repo.changelog |
|
1359 | cl = repo.changelog | |
1367 | # i18n: "only" is a keyword |
|
1360 | # i18n: "only" is a keyword | |
1368 | args = getargs(x, 1, 2, _('only takes one or two arguments')) |
|
1361 | args = getargs(x, 1, 2, _('only takes one or two arguments')) | |
1369 | include = getset(repo, fullreposet(repo), args[0]) |
|
1362 | include = getset(repo, fullreposet(repo), args[0]) | |
1370 | if len(args) == 1: |
|
1363 | if len(args) == 1: | |
1371 | if not include: |
|
1364 | if not include: | |
1372 | return baseset() |
|
1365 | return baseset() | |
1373 |
|
1366 | |||
1374 | descendants = set(dagop.revdescendants(repo, include, False)) |
|
1367 | descendants = set(dagop.revdescendants(repo, include, False)) | |
1375 | exclude = [rev for rev in cl.headrevs() |
|
1368 | exclude = [rev for rev in cl.headrevs() | |
1376 | if not rev in descendants and not rev in include] |
|
1369 | if not rev in descendants and not rev in include] | |
1377 | else: |
|
1370 | else: | |
1378 | exclude = getset(repo, fullreposet(repo), args[1]) |
|
1371 | exclude = getset(repo, fullreposet(repo), args[1]) | |
1379 |
|
1372 | |||
1380 | results = set(cl.findmissingrevs(common=exclude, heads=include)) |
|
1373 | results = set(cl.findmissingrevs(common=exclude, heads=include)) | |
1381 | # XXX we should turn this into a baseset instead of a set, smartset may do |
|
1374 | # XXX we should turn this into a baseset instead of a set, smartset may do | |
1382 | # some optimizations from the fact this is a baseset. |
|
1375 | # some optimizations from the fact this is a baseset. | |
1383 | return subset & results |
|
1376 | return subset & results | |
1384 |
|
1377 | |||
1385 | @predicate('origin([set])', safe=True) |
|
1378 | @predicate('origin([set])', safe=True) | |
1386 | def origin(repo, subset, x): |
|
1379 | def origin(repo, subset, x): | |
1387 | """ |
|
1380 | """ | |
1388 | Changesets that were specified as a source for the grafts, transplants or |
|
1381 | Changesets that were specified as a source for the grafts, transplants or | |
1389 | rebases that created the given revisions. Omitting the optional set is the |
|
1382 | rebases that created the given revisions. Omitting the optional set is the | |
1390 | same as passing all(). If a changeset created by these operations is itself |
|
1383 | same as passing all(). If a changeset created by these operations is itself | |
1391 | specified as a source for one of these operations, only the source changeset |
|
1384 | specified as a source for one of these operations, only the source changeset | |
1392 | for the first operation is selected. |
|
1385 | for the first operation is selected. | |
1393 | """ |
|
1386 | """ | |
1394 | if x is not None: |
|
1387 | if x is not None: | |
1395 | dests = getset(repo, fullreposet(repo), x) |
|
1388 | dests = getset(repo, fullreposet(repo), x) | |
1396 | else: |
|
1389 | else: | |
1397 | dests = fullreposet(repo) |
|
1390 | dests = fullreposet(repo) | |
1398 |
|
1391 | |||
1399 | def _firstsrc(rev): |
|
1392 | def _firstsrc(rev): | |
1400 | src = _getrevsource(repo, rev) |
|
1393 | src = _getrevsource(repo, rev) | |
1401 | if src is None: |
|
1394 | if src is None: | |
1402 | return None |
|
1395 | return None | |
1403 |
|
1396 | |||
1404 | while True: |
|
1397 | while True: | |
1405 | prev = _getrevsource(repo, src) |
|
1398 | prev = _getrevsource(repo, src) | |
1406 |
|
1399 | |||
1407 | if prev is None: |
|
1400 | if prev is None: | |
1408 | return src |
|
1401 | return src | |
1409 | src = prev |
|
1402 | src = prev | |
1410 |
|
1403 | |||
1411 | o = {_firstsrc(r) for r in dests} |
|
1404 | o = {_firstsrc(r) for r in dests} | |
1412 | o -= {None} |
|
1405 | o -= {None} | |
1413 | # XXX we should turn this into a baseset instead of a set, smartset may do |
|
1406 | # XXX we should turn this into a baseset instead of a set, smartset may do | |
1414 | # some optimizations from the fact this is a baseset. |
|
1407 | # some optimizations from the fact this is a baseset. | |
1415 | return subset & o |
|
1408 | return subset & o | |
1416 |
|
1409 | |||
1417 | @predicate('outgoing([path])', safe=False, weight=10) |
|
1410 | @predicate('outgoing([path])', safe=False, weight=10) | |
1418 | def outgoing(repo, subset, x): |
|
1411 | def outgoing(repo, subset, x): | |
1419 | """Changesets not found in the specified destination repository, or the |
|
1412 | """Changesets not found in the specified destination repository, or the | |
1420 | default push location. |
|
1413 | default push location. | |
1421 | """ |
|
1414 | """ | |
1422 | # Avoid cycles. |
|
1415 | # Avoid cycles. | |
1423 | from . import ( |
|
1416 | from . import ( | |
1424 | discovery, |
|
1417 | discovery, | |
1425 | hg, |
|
1418 | hg, | |
1426 | ) |
|
1419 | ) | |
1427 | # i18n: "outgoing" is a keyword |
|
1420 | # i18n: "outgoing" is a keyword | |
1428 | l = getargs(x, 0, 1, _("outgoing takes one or no arguments")) |
|
1421 | l = getargs(x, 0, 1, _("outgoing takes one or no arguments")) | |
1429 | # i18n: "outgoing" is a keyword |
|
1422 | # i18n: "outgoing" is a keyword | |
1430 | dest = l and getstring(l[0], _("outgoing requires a repository path")) or '' |
|
1423 | dest = l and getstring(l[0], _("outgoing requires a repository path")) or '' | |
1431 | dest = repo.ui.expandpath(dest or 'default-push', dest or 'default') |
|
1424 | dest = repo.ui.expandpath(dest or 'default-push', dest or 'default') | |
1432 | dest, branches = hg.parseurl(dest) |
|
1425 | dest, branches = hg.parseurl(dest) | |
1433 | revs, checkout = hg.addbranchrevs(repo, repo, branches, []) |
|
1426 | revs, checkout = hg.addbranchrevs(repo, repo, branches, []) | |
1434 | if revs: |
|
1427 | if revs: | |
1435 | revs = [repo.lookup(rev) for rev in revs] |
|
1428 | revs = [repo.lookup(rev) for rev in revs] | |
1436 | other = hg.peer(repo, {}, dest) |
|
1429 | other = hg.peer(repo, {}, dest) | |
1437 | repo.ui.pushbuffer() |
|
1430 | repo.ui.pushbuffer() | |
1438 | outgoing = discovery.findcommonoutgoing(repo, other, onlyheads=revs) |
|
1431 | outgoing = discovery.findcommonoutgoing(repo, other, onlyheads=revs) | |
1439 | repo.ui.popbuffer() |
|
1432 | repo.ui.popbuffer() | |
1440 | cl = repo.changelog |
|
1433 | cl = repo.changelog | |
1441 | o = {cl.rev(r) for r in outgoing.missing} |
|
1434 | o = {cl.rev(r) for r in outgoing.missing} | |
1442 | return subset & o |
|
1435 | return subset & o | |
1443 |
|
1436 | |||
1444 | @predicate('p1([set])', safe=True) |
|
1437 | @predicate('p1([set])', safe=True) | |
1445 | def p1(repo, subset, x): |
|
1438 | def p1(repo, subset, x): | |
1446 | """First parent of changesets in set, or the working directory. |
|
1439 | """First parent of changesets in set, or the working directory. | |
1447 | """ |
|
1440 | """ | |
1448 | if x is None: |
|
1441 | if x is None: | |
1449 | p = repo[x].p1().rev() |
|
1442 | p = repo[x].p1().rev() | |
1450 | if p >= 0: |
|
1443 | if p >= 0: | |
1451 | return subset & baseset([p]) |
|
1444 | return subset & baseset([p]) | |
1452 | return baseset() |
|
1445 | return baseset() | |
1453 |
|
1446 | |||
1454 | ps = set() |
|
1447 | ps = set() | |
1455 | cl = repo.changelog |
|
1448 | cl = repo.changelog | |
1456 | for r in getset(repo, fullreposet(repo), x): |
|
1449 | for r in getset(repo, fullreposet(repo), x): | |
1457 | try: |
|
1450 | try: | |
1458 | ps.add(cl.parentrevs(r)[0]) |
|
1451 | ps.add(cl.parentrevs(r)[0]) | |
1459 | except error.WdirUnsupported: |
|
1452 | except error.WdirUnsupported: | |
1460 | ps.add(repo[r].parents()[0].rev()) |
|
1453 | ps.add(repo[r].parents()[0].rev()) | |
1461 | ps -= {node.nullrev} |
|
1454 | ps -= {node.nullrev} | |
1462 | # XXX we should turn this into a baseset instead of a set, smartset may do |
|
1455 | # XXX we should turn this into a baseset instead of a set, smartset may do | |
1463 | # some optimizations from the fact this is a baseset. |
|
1456 | # some optimizations from the fact this is a baseset. | |
1464 | return subset & ps |
|
1457 | return subset & ps | |
1465 |
|
1458 | |||
1466 | @predicate('p2([set])', safe=True) |
|
1459 | @predicate('p2([set])', safe=True) | |
1467 | def p2(repo, subset, x): |
|
1460 | def p2(repo, subset, x): | |
1468 | """Second parent of changesets in set, or the working directory. |
|
1461 | """Second parent of changesets in set, or the working directory. | |
1469 | """ |
|
1462 | """ | |
1470 | if x is None: |
|
1463 | if x is None: | |
1471 | ps = repo[x].parents() |
|
1464 | ps = repo[x].parents() | |
1472 | try: |
|
1465 | try: | |
1473 | p = ps[1].rev() |
|
1466 | p = ps[1].rev() | |
1474 | if p >= 0: |
|
1467 | if p >= 0: | |
1475 | return subset & baseset([p]) |
|
1468 | return subset & baseset([p]) | |
1476 | return baseset() |
|
1469 | return baseset() | |
1477 | except IndexError: |
|
1470 | except IndexError: | |
1478 | return baseset() |
|
1471 | return baseset() | |
1479 |
|
1472 | |||
1480 | ps = set() |
|
1473 | ps = set() | |
1481 | cl = repo.changelog |
|
1474 | cl = repo.changelog | |
1482 | for r in getset(repo, fullreposet(repo), x): |
|
1475 | for r in getset(repo, fullreposet(repo), x): | |
1483 | try: |
|
1476 | try: | |
1484 | ps.add(cl.parentrevs(r)[1]) |
|
1477 | ps.add(cl.parentrevs(r)[1]) | |
1485 | except error.WdirUnsupported: |
|
1478 | except error.WdirUnsupported: | |
1486 | parents = repo[r].parents() |
|
1479 | parents = repo[r].parents() | |
1487 | if len(parents) == 2: |
|
1480 | if len(parents) == 2: | |
1488 | ps.add(parents[1]) |
|
1481 | ps.add(parents[1]) | |
1489 | ps -= {node.nullrev} |
|
1482 | ps -= {node.nullrev} | |
1490 | # XXX we should turn this into a baseset instead of a set, smartset may do |
|
1483 | # XXX we should turn this into a baseset instead of a set, smartset may do | |
1491 | # some optimizations from the fact this is a baseset. |
|
1484 | # some optimizations from the fact this is a baseset. | |
1492 | return subset & ps |
|
1485 | return subset & ps | |
1493 |
|
1486 | |||
1494 | def parentpost(repo, subset, x, order): |
|
1487 | def parentpost(repo, subset, x, order): | |
1495 | return p1(repo, subset, x) |
|
1488 | return p1(repo, subset, x) | |
1496 |
|
1489 | |||
1497 | @predicate('parents([set])', safe=True) |
|
1490 | @predicate('parents([set])', safe=True) | |
1498 | def parents(repo, subset, x): |
|
1491 | def parents(repo, subset, x): | |
1499 | """ |
|
1492 | """ | |
1500 | The set of all parents for all changesets in set, or the working directory. |
|
1493 | The set of all parents for all changesets in set, or the working directory. | |
1501 | """ |
|
1494 | """ | |
1502 | if x is None: |
|
1495 | if x is None: | |
1503 | ps = set(p.rev() for p in repo[x].parents()) |
|
1496 | ps = set(p.rev() for p in repo[x].parents()) | |
1504 | else: |
|
1497 | else: | |
1505 | ps = set() |
|
1498 | ps = set() | |
1506 | cl = repo.changelog |
|
1499 | cl = repo.changelog | |
1507 | up = ps.update |
|
1500 | up = ps.update | |
1508 | parentrevs = cl.parentrevs |
|
1501 | parentrevs = cl.parentrevs | |
1509 | for r in getset(repo, fullreposet(repo), x): |
|
1502 | for r in getset(repo, fullreposet(repo), x): | |
1510 | try: |
|
1503 | try: | |
1511 | up(parentrevs(r)) |
|
1504 | up(parentrevs(r)) | |
1512 | except error.WdirUnsupported: |
|
1505 | except error.WdirUnsupported: | |
1513 | up(p.rev() for p in repo[r].parents()) |
|
1506 | up(p.rev() for p in repo[r].parents()) | |
1514 | ps -= {node.nullrev} |
|
1507 | ps -= {node.nullrev} | |
1515 | return subset & ps |
|
1508 | return subset & ps | |
1516 |
|
1509 | |||
1517 | def _phase(repo, subset, *targets): |
|
1510 | def _phase(repo, subset, *targets): | |
1518 | """helper to select all rev in <targets> phases""" |
|
1511 | """helper to select all rev in <targets> phases""" | |
1519 | s = repo._phasecache.getrevset(repo, targets) |
|
1512 | s = repo._phasecache.getrevset(repo, targets) | |
1520 | return subset & s |
|
1513 | return subset & s | |
1521 |
|
1514 | |||
1522 | @predicate('draft()', safe=True) |
|
1515 | @predicate('draft()', safe=True) | |
1523 | def draft(repo, subset, x): |
|
1516 | def draft(repo, subset, x): | |
1524 | """Changeset in draft phase.""" |
|
1517 | """Changeset in draft phase.""" | |
1525 | # i18n: "draft" is a keyword |
|
1518 | # i18n: "draft" is a keyword | |
1526 | getargs(x, 0, 0, _("draft takes no arguments")) |
|
1519 | getargs(x, 0, 0, _("draft takes no arguments")) | |
1527 | target = phases.draft |
|
1520 | target = phases.draft | |
1528 | return _phase(repo, subset, target) |
|
1521 | return _phase(repo, subset, target) | |
1529 |
|
1522 | |||
1530 | @predicate('secret()', safe=True) |
|
1523 | @predicate('secret()', safe=True) | |
1531 | def secret(repo, subset, x): |
|
1524 | def secret(repo, subset, x): | |
1532 | """Changeset in secret phase.""" |
|
1525 | """Changeset in secret phase.""" | |
1533 | # i18n: "secret" is a keyword |
|
1526 | # i18n: "secret" is a keyword | |
1534 | getargs(x, 0, 0, _("secret takes no arguments")) |
|
1527 | getargs(x, 0, 0, _("secret takes no arguments")) | |
1535 | target = phases.secret |
|
1528 | target = phases.secret | |
1536 | return _phase(repo, subset, target) |
|
1529 | return _phase(repo, subset, target) | |
1537 |
|
1530 | |||
1538 | def parentspec(repo, subset, x, n, order): |
|
1531 | def parentspec(repo, subset, x, n, order): | |
1539 | """``set^0`` |
|
1532 | """``set^0`` | |
1540 | The set. |
|
1533 | The set. | |
1541 | ``set^1`` (or ``set^``), ``set^2`` |
|
1534 | ``set^1`` (or ``set^``), ``set^2`` | |
1542 | First or second parent, respectively, of all changesets in set. |
|
1535 | First or second parent, respectively, of all changesets in set. | |
1543 | """ |
|
1536 | """ | |
1544 | try: |
|
1537 | try: | |
1545 | n = int(n[1]) |
|
1538 | n = int(n[1]) | |
1546 | if n not in (0, 1, 2): |
|
1539 | if n not in (0, 1, 2): | |
1547 | raise ValueError |
|
1540 | raise ValueError | |
1548 | except (TypeError, ValueError): |
|
1541 | except (TypeError, ValueError): | |
1549 | raise error.ParseError(_("^ expects a number 0, 1, or 2")) |
|
1542 | raise error.ParseError(_("^ expects a number 0, 1, or 2")) | |
1550 | ps = set() |
|
1543 | ps = set() | |
1551 | cl = repo.changelog |
|
1544 | cl = repo.changelog | |
1552 | for r in getset(repo, fullreposet(repo), x): |
|
1545 | for r in getset(repo, fullreposet(repo), x): | |
1553 | if n == 0: |
|
1546 | if n == 0: | |
1554 | ps.add(r) |
|
1547 | ps.add(r) | |
1555 | elif n == 1: |
|
1548 | elif n == 1: | |
1556 | try: |
|
1549 | try: | |
1557 | ps.add(cl.parentrevs(r)[0]) |
|
1550 | ps.add(cl.parentrevs(r)[0]) | |
1558 | except error.WdirUnsupported: |
|
1551 | except error.WdirUnsupported: | |
1559 | ps.add(repo[r].parents()[0].rev()) |
|
1552 | ps.add(repo[r].parents()[0].rev()) | |
1560 | else: |
|
1553 | else: | |
1561 | try: |
|
1554 | try: | |
1562 | parents = cl.parentrevs(r) |
|
1555 | parents = cl.parentrevs(r) | |
1563 | if parents[1] != node.nullrev: |
|
1556 | if parents[1] != node.nullrev: | |
1564 | ps.add(parents[1]) |
|
1557 | ps.add(parents[1]) | |
1565 | except error.WdirUnsupported: |
|
1558 | except error.WdirUnsupported: | |
1566 | parents = repo[r].parents() |
|
1559 | parents = repo[r].parents() | |
1567 | if len(parents) == 2: |
|
1560 | if len(parents) == 2: | |
1568 | ps.add(parents[1].rev()) |
|
1561 | ps.add(parents[1].rev()) | |
1569 | return subset & ps |
|
1562 | return subset & ps | |
1570 |
|
1563 | |||
1571 | @predicate('present(set)', safe=True, takeorder=True) |
|
1564 | @predicate('present(set)', safe=True, takeorder=True) | |
1572 | def present(repo, subset, x, order): |
|
1565 | def present(repo, subset, x, order): | |
1573 | """An empty set, if any revision in set isn't found; otherwise, |
|
1566 | """An empty set, if any revision in set isn't found; otherwise, | |
1574 | all revisions in set. |
|
1567 | all revisions in set. | |
1575 |
|
1568 | |||
1576 | If any of specified revisions is not present in the local repository, |
|
1569 | If any of specified revisions is not present in the local repository, | |
1577 | the query is normally aborted. But this predicate allows the query |
|
1570 | the query is normally aborted. But this predicate allows the query | |
1578 | to continue even in such cases. |
|
1571 | to continue even in such cases. | |
1579 | """ |
|
1572 | """ | |
1580 | try: |
|
1573 | try: | |
1581 | return getset(repo, subset, x, order) |
|
1574 | return getset(repo, subset, x, order) | |
1582 | except error.RepoLookupError: |
|
1575 | except error.RepoLookupError: | |
1583 | return baseset() |
|
1576 | return baseset() | |
1584 |
|
1577 | |||
1585 | # for internal use |
|
1578 | # for internal use | |
1586 | @predicate('_notpublic', safe=True) |
|
1579 | @predicate('_notpublic', safe=True) | |
1587 | def _notpublic(repo, subset, x): |
|
1580 | def _notpublic(repo, subset, x): | |
1588 | getargs(x, 0, 0, "_notpublic takes no arguments") |
|
1581 | getargs(x, 0, 0, "_notpublic takes no arguments") | |
1589 | return _phase(repo, subset, phases.draft, phases.secret) |
|
1582 | return _phase(repo, subset, phases.draft, phases.secret) | |
1590 |
|
1583 | |||
1591 | # for internal use |
|
1584 | # for internal use | |
1592 | @predicate('_phaseandancestors(phasename, set)', safe=True) |
|
1585 | @predicate('_phaseandancestors(phasename, set)', safe=True) | |
1593 | def _phaseandancestors(repo, subset, x): |
|
1586 | def _phaseandancestors(repo, subset, x): | |
1594 | # equivalent to (phasename() & ancestors(set)) but more efficient |
|
1587 | # equivalent to (phasename() & ancestors(set)) but more efficient | |
1595 | # phasename could be one of 'draft', 'secret', or '_notpublic' |
|
1588 | # phasename could be one of 'draft', 'secret', or '_notpublic' | |
1596 | args = getargs(x, 2, 2, "_phaseandancestors requires two arguments") |
|
1589 | args = getargs(x, 2, 2, "_phaseandancestors requires two arguments") | |
1597 | phasename = getsymbol(args[0]) |
|
1590 | phasename = getsymbol(args[0]) | |
1598 | s = getset(repo, fullreposet(repo), args[1]) |
|
1591 | s = getset(repo, fullreposet(repo), args[1]) | |
1599 |
|
1592 | |||
1600 | draft = phases.draft |
|
1593 | draft = phases.draft | |
1601 | secret = phases.secret |
|
1594 | secret = phases.secret | |
1602 | phasenamemap = { |
|
1595 | phasenamemap = { | |
1603 | '_notpublic': draft, |
|
1596 | '_notpublic': draft, | |
1604 | 'draft': draft, # follow secret's ancestors |
|
1597 | 'draft': draft, # follow secret's ancestors | |
1605 | 'secret': secret, |
|
1598 | 'secret': secret, | |
1606 | } |
|
1599 | } | |
1607 | if phasename not in phasenamemap: |
|
1600 | if phasename not in phasenamemap: | |
1608 | raise error.ParseError('%r is not a valid phasename' % phasename) |
|
1601 | raise error.ParseError('%r is not a valid phasename' % phasename) | |
1609 |
|
1602 | |||
1610 | minimalphase = phasenamemap[phasename] |
|
1603 | minimalphase = phasenamemap[phasename] | |
1611 | getphase = repo._phasecache.phase |
|
1604 | getphase = repo._phasecache.phase | |
1612 |
|
1605 | |||
1613 | def cutfunc(rev): |
|
1606 | def cutfunc(rev): | |
1614 | return getphase(repo, rev) < minimalphase |
|
1607 | return getphase(repo, rev) < minimalphase | |
1615 |
|
1608 | |||
1616 | revs = dagop.revancestors(repo, s, cutfunc=cutfunc) |
|
1609 | revs = dagop.revancestors(repo, s, cutfunc=cutfunc) | |
1617 |
|
1610 | |||
1618 | if phasename == 'draft': # need to remove secret changesets |
|
1611 | if phasename == 'draft': # need to remove secret changesets | |
1619 | revs = revs.filter(lambda r: getphase(repo, r) == draft) |
|
1612 | revs = revs.filter(lambda r: getphase(repo, r) == draft) | |
1620 | return subset & revs |
|
1613 | return subset & revs | |
1621 |
|
1614 | |||
1622 | @predicate('public()', safe=True) |
|
1615 | @predicate('public()', safe=True) | |
1623 | def public(repo, subset, x): |
|
1616 | def public(repo, subset, x): | |
1624 | """Changeset in public phase.""" |
|
1617 | """Changeset in public phase.""" | |
1625 | # i18n: "public" is a keyword |
|
1618 | # i18n: "public" is a keyword | |
1626 | getargs(x, 0, 0, _("public takes no arguments")) |
|
1619 | getargs(x, 0, 0, _("public takes no arguments")) | |
1627 | phase = repo._phasecache.phase |
|
1620 | phase = repo._phasecache.phase | |
1628 | target = phases.public |
|
1621 | target = phases.public | |
1629 | condition = lambda r: phase(repo, r) == target |
|
1622 | condition = lambda r: phase(repo, r) == target | |
1630 | return subset.filter(condition, condrepr=('<phase %r>', target), |
|
1623 | return subset.filter(condition, condrepr=('<phase %r>', target), | |
1631 | cache=False) |
|
1624 | cache=False) | |
1632 |
|
1625 | |||
1633 | @predicate('remote([id [,path]])', safe=False) |
|
1626 | @predicate('remote([id [,path]])', safe=False) | |
1634 | def remote(repo, subset, x): |
|
1627 | def remote(repo, subset, x): | |
1635 | """Local revision that corresponds to the given identifier in a |
|
1628 | """Local revision that corresponds to the given identifier in a | |
1636 | remote repository, if present. Here, the '.' identifier is a |
|
1629 | remote repository, if present. Here, the '.' identifier is a | |
1637 | synonym for the current local branch. |
|
1630 | synonym for the current local branch. | |
1638 | """ |
|
1631 | """ | |
1639 |
|
1632 | |||
1640 | from . import hg # avoid start-up nasties |
|
1633 | from . import hg # avoid start-up nasties | |
1641 | # i18n: "remote" is a keyword |
|
1634 | # i18n: "remote" is a keyword | |
1642 | l = getargs(x, 0, 2, _("remote takes zero, one, or two arguments")) |
|
1635 | l = getargs(x, 0, 2, _("remote takes zero, one, or two arguments")) | |
1643 |
|
1636 | |||
1644 | q = '.' |
|
1637 | q = '.' | |
1645 | if len(l) > 0: |
|
1638 | if len(l) > 0: | |
1646 | # i18n: "remote" is a keyword |
|
1639 | # i18n: "remote" is a keyword | |
1647 | q = getstring(l[0], _("remote requires a string id")) |
|
1640 | q = getstring(l[0], _("remote requires a string id")) | |
1648 | if q == '.': |
|
1641 | if q == '.': | |
1649 | q = repo['.'].branch() |
|
1642 | q = repo['.'].branch() | |
1650 |
|
1643 | |||
1651 | dest = '' |
|
1644 | dest = '' | |
1652 | if len(l) > 1: |
|
1645 | if len(l) > 1: | |
1653 | # i18n: "remote" is a keyword |
|
1646 | # i18n: "remote" is a keyword | |
1654 | dest = getstring(l[1], _("remote requires a repository path")) |
|
1647 | dest = getstring(l[1], _("remote requires a repository path")) | |
1655 | dest = repo.ui.expandpath(dest or 'default') |
|
1648 | dest = repo.ui.expandpath(dest or 'default') | |
1656 | dest, branches = hg.parseurl(dest) |
|
1649 | dest, branches = hg.parseurl(dest) | |
1657 | revs, checkout = hg.addbranchrevs(repo, repo, branches, []) |
|
1650 | revs, checkout = hg.addbranchrevs(repo, repo, branches, []) | |
1658 | if revs: |
|
1651 | if revs: | |
1659 | revs = [repo.lookup(rev) for rev in revs] |
|
1652 | revs = [repo.lookup(rev) for rev in revs] | |
1660 | other = hg.peer(repo, {}, dest) |
|
1653 | other = hg.peer(repo, {}, dest) | |
1661 | n = other.lookup(q) |
|
1654 | n = other.lookup(q) | |
1662 | if n in repo: |
|
1655 | if n in repo: | |
1663 | r = repo[n].rev() |
|
1656 | r = repo[n].rev() | |
1664 | if r in subset: |
|
1657 | if r in subset: | |
1665 | return baseset([r]) |
|
1658 | return baseset([r]) | |
1666 | return baseset() |
|
1659 | return baseset() | |
1667 |
|
1660 | |||
1668 | @predicate('removes(pattern)', safe=True, weight=30) |
|
1661 | @predicate('removes(pattern)', safe=True, weight=30) | |
1669 | def removes(repo, subset, x): |
|
1662 | def removes(repo, subset, x): | |
1670 | """Changesets which remove files matching pattern. |
|
1663 | """Changesets which remove files matching pattern. | |
1671 |
|
1664 | |||
1672 | The pattern without explicit kind like ``glob:`` is expected to be |
|
1665 | The pattern without explicit kind like ``glob:`` is expected to be | |
1673 | relative to the current directory and match against a file or a |
|
1666 | relative to the current directory and match against a file or a | |
1674 | directory. |
|
1667 | directory. | |
1675 | """ |
|
1668 | """ | |
1676 | # i18n: "removes" is a keyword |
|
1669 | # i18n: "removes" is a keyword | |
1677 | pat = getstring(x, _("removes requires a pattern")) |
|
1670 | pat = getstring(x, _("removes requires a pattern")) | |
1678 | return checkstatus(repo, subset, pat, 2) |
|
1671 | return checkstatus(repo, subset, pat, 2) | |
1679 |
|
1672 | |||
1680 | @predicate('rev(number)', safe=True) |
|
1673 | @predicate('rev(number)', safe=True) | |
1681 | def rev(repo, subset, x): |
|
1674 | def rev(repo, subset, x): | |
1682 | """Revision with the given numeric identifier. |
|
1675 | """Revision with the given numeric identifier. | |
1683 | """ |
|
1676 | """ | |
1684 | # i18n: "rev" is a keyword |
|
1677 | # i18n: "rev" is a keyword | |
1685 | l = getargs(x, 1, 1, _("rev requires one argument")) |
|
1678 | l = getargs(x, 1, 1, _("rev requires one argument")) | |
1686 | try: |
|
1679 | try: | |
1687 | # i18n: "rev" is a keyword |
|
1680 | # i18n: "rev" is a keyword | |
1688 | l = int(getstring(l[0], _("rev requires a number"))) |
|
1681 | l = int(getstring(l[0], _("rev requires a number"))) | |
1689 | except (TypeError, ValueError): |
|
1682 | except (TypeError, ValueError): | |
1690 | # i18n: "rev" is a keyword |
|
1683 | # i18n: "rev" is a keyword | |
1691 | raise error.ParseError(_("rev expects a number")) |
|
1684 | raise error.ParseError(_("rev expects a number")) | |
1692 | if l not in repo.changelog and l not in (node.nullrev, node.wdirrev): |
|
1685 | if l not in repo.changelog and l not in (node.nullrev, node.wdirrev): | |
1693 | return baseset() |
|
1686 | return baseset() | |
1694 | return subset & baseset([l]) |
|
1687 | return subset & baseset([l]) | |
1695 |
|
1688 | |||
1696 | @predicate('matching(revision [, field])', safe=True) |
|
1689 | @predicate('matching(revision [, field])', safe=True) | |
1697 | def matching(repo, subset, x): |
|
1690 | def matching(repo, subset, x): | |
1698 | """Changesets in which a given set of fields match the set of fields in the |
|
1691 | """Changesets in which a given set of fields match the set of fields in the | |
1699 | selected revision or set. |
|
1692 | selected revision or set. | |
1700 |
|
1693 | |||
1701 | To match more than one field pass the list of fields to match separated |
|
1694 | To match more than one field pass the list of fields to match separated | |
1702 | by spaces (e.g. ``author description``). |
|
1695 | by spaces (e.g. ``author description``). | |
1703 |
|
1696 | |||
1704 | Valid fields are most regular revision fields and some special fields. |
|
1697 | Valid fields are most regular revision fields and some special fields. | |
1705 |
|
1698 | |||
1706 | Regular revision fields are ``description``, ``author``, ``branch``, |
|
1699 | Regular revision fields are ``description``, ``author``, ``branch``, | |
1707 | ``date``, ``files``, ``phase``, ``parents``, ``substate``, ``user`` |
|
1700 | ``date``, ``files``, ``phase``, ``parents``, ``substate``, ``user`` | |
1708 | and ``diff``. |
|
1701 | and ``diff``. | |
1709 | Note that ``author`` and ``user`` are synonyms. ``diff`` refers to the |
|
1702 | Note that ``author`` and ``user`` are synonyms. ``diff`` refers to the | |
1710 | contents of the revision. Two revisions matching their ``diff`` will |
|
1703 | contents of the revision. Two revisions matching their ``diff`` will | |
1711 | also match their ``files``. |
|
1704 | also match their ``files``. | |
1712 |
|
1705 | |||
1713 | Special fields are ``summary`` and ``metadata``: |
|
1706 | Special fields are ``summary`` and ``metadata``: | |
1714 | ``summary`` matches the first line of the description. |
|
1707 | ``summary`` matches the first line of the description. | |
1715 | ``metadata`` is equivalent to matching ``description user date`` |
|
1708 | ``metadata`` is equivalent to matching ``description user date`` | |
1716 | (i.e. it matches the main metadata fields). |
|
1709 | (i.e. it matches the main metadata fields). | |
1717 |
|
1710 | |||
1718 | ``metadata`` is the default field which is used when no fields are |
|
1711 | ``metadata`` is the default field which is used when no fields are | |
1719 | specified. You can match more than one field at a time. |
|
1712 | specified. You can match more than one field at a time. | |
1720 | """ |
|
1713 | """ | |
1721 | # i18n: "matching" is a keyword |
|
1714 | # i18n: "matching" is a keyword | |
1722 | l = getargs(x, 1, 2, _("matching takes 1 or 2 arguments")) |
|
1715 | l = getargs(x, 1, 2, _("matching takes 1 or 2 arguments")) | |
1723 |
|
1716 | |||
1724 | revs = getset(repo, fullreposet(repo), l[0]) |
|
1717 | revs = getset(repo, fullreposet(repo), l[0]) | |
1725 |
|
1718 | |||
1726 | fieldlist = ['metadata'] |
|
1719 | fieldlist = ['metadata'] | |
1727 | if len(l) > 1: |
|
1720 | if len(l) > 1: | |
1728 | fieldlist = getstring(l[1], |
|
1721 | fieldlist = getstring(l[1], | |
1729 | # i18n: "matching" is a keyword |
|
1722 | # i18n: "matching" is a keyword | |
1730 | _("matching requires a string " |
|
1723 | _("matching requires a string " | |
1731 | "as its second argument")).split() |
|
1724 | "as its second argument")).split() | |
1732 |
|
1725 | |||
1733 | # Make sure that there are no repeated fields, |
|
1726 | # Make sure that there are no repeated fields, | |
1734 | # expand the 'special' 'metadata' field type |
|
1727 | # expand the 'special' 'metadata' field type | |
1735 | # and check the 'files' whenever we check the 'diff' |
|
1728 | # and check the 'files' whenever we check the 'diff' | |
1736 | fields = [] |
|
1729 | fields = [] | |
1737 | for field in fieldlist: |
|
1730 | for field in fieldlist: | |
1738 | if field == 'metadata': |
|
1731 | if field == 'metadata': | |
1739 | fields += ['user', 'description', 'date'] |
|
1732 | fields += ['user', 'description', 'date'] | |
1740 | elif field == 'diff': |
|
1733 | elif field == 'diff': | |
1741 | # a revision matching the diff must also match the files |
|
1734 | # a revision matching the diff must also match the files | |
1742 | # since matching the diff is very costly, make sure to |
|
1735 | # since matching the diff is very costly, make sure to | |
1743 | # also match the files first |
|
1736 | # also match the files first | |
1744 | fields += ['files', 'diff'] |
|
1737 | fields += ['files', 'diff'] | |
1745 | else: |
|
1738 | else: | |
1746 | if field == 'author': |
|
1739 | if field == 'author': | |
1747 | field = 'user' |
|
1740 | field = 'user' | |
1748 | fields.append(field) |
|
1741 | fields.append(field) | |
1749 | fields = set(fields) |
|
1742 | fields = set(fields) | |
1750 | if 'summary' in fields and 'description' in fields: |
|
1743 | if 'summary' in fields and 'description' in fields: | |
1751 | # If a revision matches its description it also matches its summary |
|
1744 | # If a revision matches its description it also matches its summary | |
1752 | fields.discard('summary') |
|
1745 | fields.discard('summary') | |
1753 |
|
1746 | |||
1754 | # We may want to match more than one field |
|
1747 | # We may want to match more than one field | |
1755 | # Not all fields take the same amount of time to be matched |
|
1748 | # Not all fields take the same amount of time to be matched | |
1756 | # Sort the selected fields in order of increasing matching cost |
|
1749 | # Sort the selected fields in order of increasing matching cost | |
1757 | fieldorder = ['phase', 'parents', 'user', 'date', 'branch', 'summary', |
|
1750 | fieldorder = ['phase', 'parents', 'user', 'date', 'branch', 'summary', | |
1758 | 'files', 'description', 'substate', 'diff'] |
|
1751 | 'files', 'description', 'substate', 'diff'] | |
1759 | def fieldkeyfunc(f): |
|
1752 | def fieldkeyfunc(f): | |
1760 | try: |
|
1753 | try: | |
1761 | return fieldorder.index(f) |
|
1754 | return fieldorder.index(f) | |
1762 | except ValueError: |
|
1755 | except ValueError: | |
1763 | # assume an unknown field is very costly |
|
1756 | # assume an unknown field is very costly | |
1764 | return len(fieldorder) |
|
1757 | return len(fieldorder) | |
1765 | fields = list(fields) |
|
1758 | fields = list(fields) | |
1766 | fields.sort(key=fieldkeyfunc) |
|
1759 | fields.sort(key=fieldkeyfunc) | |
1767 |
|
1760 | |||
1768 | # Each field will be matched with its own "getfield" function |
|
1761 | # Each field will be matched with its own "getfield" function | |
1769 | # which will be added to the getfieldfuncs array of functions |
|
1762 | # which will be added to the getfieldfuncs array of functions | |
1770 | getfieldfuncs = [] |
|
1763 | getfieldfuncs = [] | |
1771 | _funcs = { |
|
1764 | _funcs = { | |
1772 | 'user': lambda r: repo[r].user(), |
|
1765 | 'user': lambda r: repo[r].user(), | |
1773 | 'branch': lambda r: repo[r].branch(), |
|
1766 | 'branch': lambda r: repo[r].branch(), | |
1774 | 'date': lambda r: repo[r].date(), |
|
1767 | 'date': lambda r: repo[r].date(), | |
1775 | 'description': lambda r: repo[r].description(), |
|
1768 | 'description': lambda r: repo[r].description(), | |
1776 | 'files': lambda r: repo[r].files(), |
|
1769 | 'files': lambda r: repo[r].files(), | |
1777 | 'parents': lambda r: repo[r].parents(), |
|
1770 | 'parents': lambda r: repo[r].parents(), | |
1778 | 'phase': lambda r: repo[r].phase(), |
|
1771 | 'phase': lambda r: repo[r].phase(), | |
1779 | 'substate': lambda r: repo[r].substate, |
|
1772 | 'substate': lambda r: repo[r].substate, | |
1780 | 'summary': lambda r: repo[r].description().splitlines()[0], |
|
1773 | 'summary': lambda r: repo[r].description().splitlines()[0], | |
1781 | 'diff': lambda r: list(repo[r].diff(git=True),) |
|
1774 | 'diff': lambda r: list(repo[r].diff(git=True),) | |
1782 | } |
|
1775 | } | |
1783 | for info in fields: |
|
1776 | for info in fields: | |
1784 | getfield = _funcs.get(info, None) |
|
1777 | getfield = _funcs.get(info, None) | |
1785 | if getfield is None: |
|
1778 | if getfield is None: | |
1786 | raise error.ParseError( |
|
1779 | raise error.ParseError( | |
1787 | # i18n: "matching" is a keyword |
|
1780 | # i18n: "matching" is a keyword | |
1788 | _("unexpected field name passed to matching: %s") % info) |
|
1781 | _("unexpected field name passed to matching: %s") % info) | |
1789 | getfieldfuncs.append(getfield) |
|
1782 | getfieldfuncs.append(getfield) | |
1790 | # convert the getfield array of functions into a "getinfo" function |
|
1783 | # convert the getfield array of functions into a "getinfo" function | |
1791 | # which returns an array of field values (or a single value if there |
|
1784 | # which returns an array of field values (or a single value if there | |
1792 | # is only one field to match) |
|
1785 | # is only one field to match) | |
1793 | getinfo = lambda r: [f(r) for f in getfieldfuncs] |
|
1786 | getinfo = lambda r: [f(r) for f in getfieldfuncs] | |
1794 |
|
1787 | |||
1795 | def matches(x): |
|
1788 | def matches(x): | |
1796 | for rev in revs: |
|
1789 | for rev in revs: | |
1797 | target = getinfo(rev) |
|
1790 | target = getinfo(rev) | |
1798 | match = True |
|
1791 | match = True | |
1799 | for n, f in enumerate(getfieldfuncs): |
|
1792 | for n, f in enumerate(getfieldfuncs): | |
1800 | if target[n] != f(x): |
|
1793 | if target[n] != f(x): | |
1801 | match = False |
|
1794 | match = False | |
1802 | if match: |
|
1795 | if match: | |
1803 | return True |
|
1796 | return True | |
1804 | return False |
|
1797 | return False | |
1805 |
|
1798 | |||
1806 | return subset.filter(matches, condrepr=('<matching%r %r>', fields, revs)) |
|
1799 | return subset.filter(matches, condrepr=('<matching%r %r>', fields, revs)) | |
1807 |
|
1800 | |||
1808 | @predicate('reverse(set)', safe=True, takeorder=True, weight=0) |
|
1801 | @predicate('reverse(set)', safe=True, takeorder=True, weight=0) | |
1809 | def reverse(repo, subset, x, order): |
|
1802 | def reverse(repo, subset, x, order): | |
1810 | """Reverse order of set. |
|
1803 | """Reverse order of set. | |
1811 | """ |
|
1804 | """ | |
1812 | l = getset(repo, subset, x, order) |
|
1805 | l = getset(repo, subset, x, order) | |
1813 | if order == defineorder: |
|
1806 | if order == defineorder: | |
1814 | l.reverse() |
|
1807 | l.reverse() | |
1815 | return l |
|
1808 | return l | |
1816 |
|
1809 | |||
1817 | @predicate('roots(set)', safe=True) |
|
1810 | @predicate('roots(set)', safe=True) | |
1818 | def roots(repo, subset, x): |
|
1811 | def roots(repo, subset, x): | |
1819 | """Changesets in set with no parent changeset in set. |
|
1812 | """Changesets in set with no parent changeset in set. | |
1820 | """ |
|
1813 | """ | |
1821 | s = getset(repo, fullreposet(repo), x) |
|
1814 | s = getset(repo, fullreposet(repo), x) | |
1822 | parents = repo.changelog.parentrevs |
|
1815 | parents = repo.changelog.parentrevs | |
1823 | def filter(r): |
|
1816 | def filter(r): | |
1824 | for p in parents(r): |
|
1817 | for p in parents(r): | |
1825 | if 0 <= p and p in s: |
|
1818 | if 0 <= p and p in s: | |
1826 | return False |
|
1819 | return False | |
1827 | return True |
|
1820 | return True | |
1828 | return subset & s.filter(filter, condrepr='<roots>') |
|
1821 | return subset & s.filter(filter, condrepr='<roots>') | |
1829 |
|
1822 | |||
1830 | _sortkeyfuncs = { |
|
1823 | _sortkeyfuncs = { | |
1831 | 'rev': lambda c: c.rev(), |
|
1824 | 'rev': lambda c: c.rev(), | |
1832 | 'branch': lambda c: c.branch(), |
|
1825 | 'branch': lambda c: c.branch(), | |
1833 | 'desc': lambda c: c.description(), |
|
1826 | 'desc': lambda c: c.description(), | |
1834 | 'user': lambda c: c.user(), |
|
1827 | 'user': lambda c: c.user(), | |
1835 | 'author': lambda c: c.user(), |
|
1828 | 'author': lambda c: c.user(), | |
1836 | 'date': lambda c: c.date()[0], |
|
1829 | 'date': lambda c: c.date()[0], | |
1837 | } |
|
1830 | } | |
1838 |
|
1831 | |||
1839 | def _getsortargs(x): |
|
1832 | def _getsortargs(x): | |
1840 | """Parse sort options into (set, [(key, reverse)], opts)""" |
|
1833 | """Parse sort options into (set, [(key, reverse)], opts)""" | |
1841 | args = getargsdict(x, 'sort', 'set keys topo.firstbranch') |
|
1834 | args = getargsdict(x, 'sort', 'set keys topo.firstbranch') | |
1842 | if 'set' not in args: |
|
1835 | if 'set' not in args: | |
1843 | # i18n: "sort" is a keyword |
|
1836 | # i18n: "sort" is a keyword | |
1844 | raise error.ParseError(_('sort requires one or two arguments')) |
|
1837 | raise error.ParseError(_('sort requires one or two arguments')) | |
1845 | keys = "rev" |
|
1838 | keys = "rev" | |
1846 | if 'keys' in args: |
|
1839 | if 'keys' in args: | |
1847 | # i18n: "sort" is a keyword |
|
1840 | # i18n: "sort" is a keyword | |
1848 | keys = getstring(args['keys'], _("sort spec must be a string")) |
|
1841 | keys = getstring(args['keys'], _("sort spec must be a string")) | |
1849 |
|
1842 | |||
1850 | keyflags = [] |
|
1843 | keyflags = [] | |
1851 | for k in keys.split(): |
|
1844 | for k in keys.split(): | |
1852 | fk = k |
|
1845 | fk = k | |
1853 | reverse = (k[0] == '-') |
|
1846 | reverse = (k[0] == '-') | |
1854 | if reverse: |
|
1847 | if reverse: | |
1855 | k = k[1:] |
|
1848 | k = k[1:] | |
1856 | if k not in _sortkeyfuncs and k != 'topo': |
|
1849 | if k not in _sortkeyfuncs and k != 'topo': | |
1857 | raise error.ParseError(_("unknown sort key %r") % fk) |
|
1850 | raise error.ParseError(_("unknown sort key %r") % fk) | |
1858 | keyflags.append((k, reverse)) |
|
1851 | keyflags.append((k, reverse)) | |
1859 |
|
1852 | |||
1860 | if len(keyflags) > 1 and any(k == 'topo' for k, reverse in keyflags): |
|
1853 | if len(keyflags) > 1 and any(k == 'topo' for k, reverse in keyflags): | |
1861 | # i18n: "topo" is a keyword |
|
1854 | # i18n: "topo" is a keyword | |
1862 | raise error.ParseError(_('topo sort order cannot be combined ' |
|
1855 | raise error.ParseError(_('topo sort order cannot be combined ' | |
1863 | 'with other sort keys')) |
|
1856 | 'with other sort keys')) | |
1864 |
|
1857 | |||
1865 | opts = {} |
|
1858 | opts = {} | |
1866 | if 'topo.firstbranch' in args: |
|
1859 | if 'topo.firstbranch' in args: | |
1867 | if any(k == 'topo' for k, reverse in keyflags): |
|
1860 | if any(k == 'topo' for k, reverse in keyflags): | |
1868 | opts['topo.firstbranch'] = args['topo.firstbranch'] |
|
1861 | opts['topo.firstbranch'] = args['topo.firstbranch'] | |
1869 | else: |
|
1862 | else: | |
1870 | # i18n: "topo" and "topo.firstbranch" are keywords |
|
1863 | # i18n: "topo" and "topo.firstbranch" are keywords | |
1871 | raise error.ParseError(_('topo.firstbranch can only be used ' |
|
1864 | raise error.ParseError(_('topo.firstbranch can only be used ' | |
1872 | 'when using the topo sort key')) |
|
1865 | 'when using the topo sort key')) | |
1873 |
|
1866 | |||
1874 | return args['set'], keyflags, opts |
|
1867 | return args['set'], keyflags, opts | |
1875 |
|
1868 | |||
1876 | @predicate('sort(set[, [-]key... [, ...]])', safe=True, takeorder=True, |
|
1869 | @predicate('sort(set[, [-]key... [, ...]])', safe=True, takeorder=True, | |
1877 | weight=10) |
|
1870 | weight=10) | |
1878 | def sort(repo, subset, x, order): |
|
1871 | def sort(repo, subset, x, order): | |
1879 | """Sort set by keys. The default sort order is ascending, specify a key |
|
1872 | """Sort set by keys. The default sort order is ascending, specify a key | |
1880 | as ``-key`` to sort in descending order. |
|
1873 | as ``-key`` to sort in descending order. | |
1881 |
|
1874 | |||
1882 | The keys can be: |
|
1875 | The keys can be: | |
1883 |
|
1876 | |||
1884 | - ``rev`` for the revision number, |
|
1877 | - ``rev`` for the revision number, | |
1885 | - ``branch`` for the branch name, |
|
1878 | - ``branch`` for the branch name, | |
1886 | - ``desc`` for the commit message (description), |
|
1879 | - ``desc`` for the commit message (description), | |
1887 | - ``user`` for user name (``author`` can be used as an alias), |
|
1880 | - ``user`` for user name (``author`` can be used as an alias), | |
1888 | - ``date`` for the commit date |
|
1881 | - ``date`` for the commit date | |
1889 | - ``topo`` for a reverse topographical sort |
|
1882 | - ``topo`` for a reverse topographical sort | |
1890 |
|
1883 | |||
1891 | The ``topo`` sort order cannot be combined with other sort keys. This sort |
|
1884 | The ``topo`` sort order cannot be combined with other sort keys. This sort | |
1892 | takes one optional argument, ``topo.firstbranch``, which takes a revset that |
|
1885 | takes one optional argument, ``topo.firstbranch``, which takes a revset that | |
1893 | specifies what topographical branches to prioritize in the sort. |
|
1886 | specifies what topographical branches to prioritize in the sort. | |
1894 |
|
1887 | |||
1895 | """ |
|
1888 | """ | |
1896 | s, keyflags, opts = _getsortargs(x) |
|
1889 | s, keyflags, opts = _getsortargs(x) | |
1897 | revs = getset(repo, subset, s, order) |
|
1890 | revs = getset(repo, subset, s, order) | |
1898 |
|
1891 | |||
1899 | if not keyflags or order != defineorder: |
|
1892 | if not keyflags or order != defineorder: | |
1900 | return revs |
|
1893 | return revs | |
1901 | if len(keyflags) == 1 and keyflags[0][0] == "rev": |
|
1894 | if len(keyflags) == 1 and keyflags[0][0] == "rev": | |
1902 | revs.sort(reverse=keyflags[0][1]) |
|
1895 | revs.sort(reverse=keyflags[0][1]) | |
1903 | return revs |
|
1896 | return revs | |
1904 | elif keyflags[0][0] == "topo": |
|
1897 | elif keyflags[0][0] == "topo": | |
1905 | firstbranch = () |
|
1898 | firstbranch = () | |
1906 | if 'topo.firstbranch' in opts: |
|
1899 | if 'topo.firstbranch' in opts: | |
1907 | firstbranch = getset(repo, subset, opts['topo.firstbranch']) |
|
1900 | firstbranch = getset(repo, subset, opts['topo.firstbranch']) | |
1908 | revs = baseset(dagop.toposort(revs, repo.changelog.parentrevs, |
|
1901 | revs = baseset(dagop.toposort(revs, repo.changelog.parentrevs, | |
1909 | firstbranch), |
|
1902 | firstbranch), | |
1910 | istopo=True) |
|
1903 | istopo=True) | |
1911 | if keyflags[0][1]: |
|
1904 | if keyflags[0][1]: | |
1912 | revs.reverse() |
|
1905 | revs.reverse() | |
1913 | return revs |
|
1906 | return revs | |
1914 |
|
1907 | |||
1915 | # sort() is guaranteed to be stable |
|
1908 | # sort() is guaranteed to be stable | |
1916 | ctxs = [repo[r] for r in revs] |
|
1909 | ctxs = [repo[r] for r in revs] | |
1917 | for k, reverse in reversed(keyflags): |
|
1910 | for k, reverse in reversed(keyflags): | |
1918 | ctxs.sort(key=_sortkeyfuncs[k], reverse=reverse) |
|
1911 | ctxs.sort(key=_sortkeyfuncs[k], reverse=reverse) | |
1919 | return baseset([c.rev() for c in ctxs]) |
|
1912 | return baseset([c.rev() for c in ctxs]) | |
1920 |
|
1913 | |||
1921 | @predicate('subrepo([pattern])') |
|
1914 | @predicate('subrepo([pattern])') | |
1922 | def subrepo(repo, subset, x): |
|
1915 | def subrepo(repo, subset, x): | |
1923 | """Changesets that add, modify or remove the given subrepo. If no subrepo |
|
1916 | """Changesets that add, modify or remove the given subrepo. If no subrepo | |
1924 | pattern is named, any subrepo changes are returned. |
|
1917 | pattern is named, any subrepo changes are returned. | |
1925 | """ |
|
1918 | """ | |
1926 | # i18n: "subrepo" is a keyword |
|
1919 | # i18n: "subrepo" is a keyword | |
1927 | args = getargs(x, 0, 1, _('subrepo takes at most one argument')) |
|
1920 | args = getargs(x, 0, 1, _('subrepo takes at most one argument')) | |
1928 | pat = None |
|
1921 | pat = None | |
1929 | if len(args) != 0: |
|
1922 | if len(args) != 0: | |
1930 | pat = getstring(args[0], _("subrepo requires a pattern")) |
|
1923 | pat = getstring(args[0], _("subrepo requires a pattern")) | |
1931 |
|
1924 | |||
1932 | m = matchmod.exact(repo.root, repo.root, ['.hgsubstate']) |
|
1925 | m = matchmod.exact(repo.root, repo.root, ['.hgsubstate']) | |
1933 |
|
1926 | |||
1934 | def submatches(names): |
|
1927 | def submatches(names): | |
1935 | k, p, m = util.stringmatcher(pat) |
|
1928 | k, p, m = util.stringmatcher(pat) | |
1936 | for name in names: |
|
1929 | for name in names: | |
1937 | if m(name): |
|
1930 | if m(name): | |
1938 | yield name |
|
1931 | yield name | |
1939 |
|
1932 | |||
1940 | def matches(x): |
|
1933 | def matches(x): | |
1941 | c = repo[x] |
|
1934 | c = repo[x] | |
1942 | s = repo.status(c.p1().node(), c.node(), match=m) |
|
1935 | s = repo.status(c.p1().node(), c.node(), match=m) | |
1943 |
|
1936 | |||
1944 | if pat is None: |
|
1937 | if pat is None: | |
1945 | return s.added or s.modified or s.removed |
|
1938 | return s.added or s.modified or s.removed | |
1946 |
|
1939 | |||
1947 | if s.added: |
|
1940 | if s.added: | |
1948 | return any(submatches(c.substate.keys())) |
|
1941 | return any(submatches(c.substate.keys())) | |
1949 |
|
1942 | |||
1950 | if s.modified: |
|
1943 | if s.modified: | |
1951 | subs = set(c.p1().substate.keys()) |
|
1944 | subs = set(c.p1().substate.keys()) | |
1952 | subs.update(c.substate.keys()) |
|
1945 | subs.update(c.substate.keys()) | |
1953 |
|
1946 | |||
1954 | for path in submatches(subs): |
|
1947 | for path in submatches(subs): | |
1955 | if c.p1().substate.get(path) != c.substate.get(path): |
|
1948 | if c.p1().substate.get(path) != c.substate.get(path): | |
1956 | return True |
|
1949 | return True | |
1957 |
|
1950 | |||
1958 | if s.removed: |
|
1951 | if s.removed: | |
1959 | return any(submatches(c.p1().substate.keys())) |
|
1952 | return any(submatches(c.p1().substate.keys())) | |
1960 |
|
1953 | |||
1961 | return False |
|
1954 | return False | |
1962 |
|
1955 | |||
1963 | return subset.filter(matches, condrepr=('<subrepo %r>', pat)) |
|
1956 | return subset.filter(matches, condrepr=('<subrepo %r>', pat)) | |
1964 |
|
1957 | |||
1965 | def _mapbynodefunc(repo, s, f): |
|
1958 | def _mapbynodefunc(repo, s, f): | |
1966 | """(repo, smartset, [node] -> [node]) -> smartset |
|
1959 | """(repo, smartset, [node] -> [node]) -> smartset | |
1967 |
|
1960 | |||
1968 | Helper method to map a smartset to another smartset given a function only |
|
1961 | Helper method to map a smartset to another smartset given a function only | |
1969 | talking about nodes. Handles converting between rev numbers and nodes, and |
|
1962 | talking about nodes. Handles converting between rev numbers and nodes, and | |
1970 | filtering. |
|
1963 | filtering. | |
1971 | """ |
|
1964 | """ | |
1972 | cl = repo.unfiltered().changelog |
|
1965 | cl = repo.unfiltered().changelog | |
1973 | torev = cl.rev |
|
1966 | torev = cl.rev | |
1974 | tonode = cl.node |
|
1967 | tonode = cl.node | |
1975 | nodemap = cl.nodemap |
|
1968 | nodemap = cl.nodemap | |
1976 | result = set(torev(n) for n in f(tonode(r) for r in s) if n in nodemap) |
|
1969 | result = set(torev(n) for n in f(tonode(r) for r in s) if n in nodemap) | |
1977 | return smartset.baseset(result - repo.changelog.filteredrevs) |
|
1970 | return smartset.baseset(result - repo.changelog.filteredrevs) | |
1978 |
|
1971 | |||
1979 | @predicate('successors(set)', safe=True) |
|
1972 | @predicate('successors(set)', safe=True) | |
1980 | def successors(repo, subset, x): |
|
1973 | def successors(repo, subset, x): | |
1981 | """All successors for set, including the given set themselves""" |
|
1974 | """All successors for set, including the given set themselves""" | |
1982 | s = getset(repo, fullreposet(repo), x) |
|
1975 | s = getset(repo, fullreposet(repo), x) | |
1983 | f = lambda nodes: obsutil.allsuccessors(repo.obsstore, nodes) |
|
1976 | f = lambda nodes: obsutil.allsuccessors(repo.obsstore, nodes) | |
1984 | d = _mapbynodefunc(repo, s, f) |
|
1977 | d = _mapbynodefunc(repo, s, f) | |
1985 | return subset & d |
|
1978 | return subset & d | |
1986 |
|
1979 | |||
1987 | def _substringmatcher(pattern, casesensitive=True): |
|
1980 | def _substringmatcher(pattern, casesensitive=True): | |
1988 | kind, pattern, matcher = util.stringmatcher(pattern, |
|
1981 | kind, pattern, matcher = util.stringmatcher(pattern, | |
1989 | casesensitive=casesensitive) |
|
1982 | casesensitive=casesensitive) | |
1990 | if kind == 'literal': |
|
1983 | if kind == 'literal': | |
1991 | if not casesensitive: |
|
1984 | if not casesensitive: | |
1992 | pattern = encoding.lower(pattern) |
|
1985 | pattern = encoding.lower(pattern) | |
1993 | matcher = lambda s: pattern in encoding.lower(s) |
|
1986 | matcher = lambda s: pattern in encoding.lower(s) | |
1994 | else: |
|
1987 | else: | |
1995 | matcher = lambda s: pattern in s |
|
1988 | matcher = lambda s: pattern in s | |
1996 | return kind, pattern, matcher |
|
1989 | return kind, pattern, matcher | |
1997 |
|
1990 | |||
1998 | @predicate('tag([name])', safe=True) |
|
1991 | @predicate('tag([name])', safe=True) | |
1999 | def tag(repo, subset, x): |
|
1992 | def tag(repo, subset, x): | |
2000 | """The specified tag by name, or all tagged revisions if no name is given. |
|
1993 | """The specified tag by name, or all tagged revisions if no name is given. | |
2001 |
|
1994 | |||
2002 | Pattern matching is supported for `name`. See |
|
1995 | Pattern matching is supported for `name`. See | |
2003 | :hg:`help revisions.patterns`. |
|
1996 | :hg:`help revisions.patterns`. | |
2004 | """ |
|
1997 | """ | |
2005 | # i18n: "tag" is a keyword |
|
1998 | # i18n: "tag" is a keyword | |
2006 | args = getargs(x, 0, 1, _("tag takes one or no arguments")) |
|
1999 | args = getargs(x, 0, 1, _("tag takes one or no arguments")) | |
2007 | cl = repo.changelog |
|
2000 | cl = repo.changelog | |
2008 | if args: |
|
2001 | if args: | |
2009 | pattern = getstring(args[0], |
|
2002 | pattern = getstring(args[0], | |
2010 | # i18n: "tag" is a keyword |
|
2003 | # i18n: "tag" is a keyword | |
2011 | _('the argument to tag must be a string')) |
|
2004 | _('the argument to tag must be a string')) | |
2012 | kind, pattern, matcher = util.stringmatcher(pattern) |
|
2005 | kind, pattern, matcher = util.stringmatcher(pattern) | |
2013 | if kind == 'literal': |
|
2006 | if kind == 'literal': | |
2014 | # avoid resolving all tags |
|
2007 | # avoid resolving all tags | |
2015 | tn = repo._tagscache.tags.get(pattern, None) |
|
2008 | tn = repo._tagscache.tags.get(pattern, None) | |
2016 | if tn is None: |
|
2009 | if tn is None: | |
2017 | raise error.RepoLookupError(_("tag '%s' does not exist") |
|
2010 | raise error.RepoLookupError(_("tag '%s' does not exist") | |
2018 | % pattern) |
|
2011 | % pattern) | |
2019 | s = {repo[tn].rev()} |
|
2012 | s = {repo[tn].rev()} | |
2020 | else: |
|
2013 | else: | |
2021 | s = {cl.rev(n) for t, n in repo.tagslist() if matcher(t)} |
|
2014 | s = {cl.rev(n) for t, n in repo.tagslist() if matcher(t)} | |
2022 | else: |
|
2015 | else: | |
2023 | s = {cl.rev(n) for t, n in repo.tagslist() if t != 'tip'} |
|
2016 | s = {cl.rev(n) for t, n in repo.tagslist() if t != 'tip'} | |
2024 | return subset & s |
|
2017 | return subset & s | |
2025 |
|
2018 | |||
2026 | @predicate('tagged', safe=True) |
|
2019 | @predicate('tagged', safe=True) | |
2027 | def tagged(repo, subset, x): |
|
2020 | def tagged(repo, subset, x): | |
2028 | return tag(repo, subset, x) |
|
2021 | return tag(repo, subset, x) | |
2029 |
|
2022 | |||
2030 | @predicate('unstable()', safe=True) |
|
2023 | @predicate('unstable()', safe=True) | |
2031 | def unstable(repo, subset, x): |
|
2024 | def unstable(repo, subset, x): | |
2032 | msg = ("'unstable()' is deprecated, " |
|
2025 | msg = ("'unstable()' is deprecated, " | |
2033 | "use 'orphan()'") |
|
2026 | "use 'orphan()'") | |
2034 | repo.ui.deprecwarn(msg, '4.4') |
|
2027 | repo.ui.deprecwarn(msg, '4.4') | |
2035 |
|
2028 | |||
2036 | return orphan(repo, subset, x) |
|
2029 | return orphan(repo, subset, x) | |
2037 |
|
2030 | |||
2038 | @predicate('orphan()', safe=True) |
|
2031 | @predicate('orphan()', safe=True) | |
2039 | def orphan(repo, subset, x): |
|
2032 | def orphan(repo, subset, x): | |
2040 | """Non-obsolete changesets with obsolete ancestors. (EXPERIMENTAL) |
|
2033 | """Non-obsolete changesets with obsolete ancestors. (EXPERIMENTAL) | |
2041 | """ |
|
2034 | """ | |
2042 | # i18n: "orphan" is a keyword |
|
2035 | # i18n: "orphan" is a keyword | |
2043 | getargs(x, 0, 0, _("orphan takes no arguments")) |
|
2036 | getargs(x, 0, 0, _("orphan takes no arguments")) | |
2044 | orphan = obsmod.getrevs(repo, 'orphan') |
|
2037 | orphan = obsmod.getrevs(repo, 'orphan') | |
2045 | return subset & orphan |
|
2038 | return subset & orphan | |
2046 |
|
2039 | |||
2047 |
|
2040 | |||
2048 | @predicate('user(string)', safe=True, weight=10) |
|
2041 | @predicate('user(string)', safe=True, weight=10) | |
2049 | def user(repo, subset, x): |
|
2042 | def user(repo, subset, x): | |
2050 | """User name contains string. The match is case-insensitive. |
|
2043 | """User name contains string. The match is case-insensitive. | |
2051 |
|
2044 | |||
2052 | Pattern matching is supported for `string`. See |
|
2045 | Pattern matching is supported for `string`. See | |
2053 | :hg:`help revisions.patterns`. |
|
2046 | :hg:`help revisions.patterns`. | |
2054 | """ |
|
2047 | """ | |
2055 | return author(repo, subset, x) |
|
2048 | return author(repo, subset, x) | |
2056 |
|
2049 | |||
2057 | @predicate('wdir()', safe=True, weight=0) |
|
2050 | @predicate('wdir()', safe=True, weight=0) | |
2058 | def wdir(repo, subset, x): |
|
2051 | def wdir(repo, subset, x): | |
2059 | """Working directory. (EXPERIMENTAL)""" |
|
2052 | """Working directory. (EXPERIMENTAL)""" | |
2060 | # i18n: "wdir" is a keyword |
|
2053 | # i18n: "wdir" is a keyword | |
2061 | getargs(x, 0, 0, _("wdir takes no arguments")) |
|
2054 | getargs(x, 0, 0, _("wdir takes no arguments")) | |
2062 | if node.wdirrev in subset or isinstance(subset, fullreposet): |
|
2055 | if node.wdirrev in subset or isinstance(subset, fullreposet): | |
2063 | return baseset([node.wdirrev]) |
|
2056 | return baseset([node.wdirrev]) | |
2064 | return baseset() |
|
2057 | return baseset() | |
2065 |
|
2058 | |||
2066 | def _orderedlist(repo, subset, x): |
|
2059 | def _orderedlist(repo, subset, x): | |
2067 | s = getstring(x, "internal error") |
|
2060 | s = getstring(x, "internal error") | |
2068 | if not s: |
|
2061 | if not s: | |
2069 | return baseset() |
|
2062 | return baseset() | |
2070 | # remove duplicates here. it's difficult for caller to deduplicate sets |
|
2063 | # remove duplicates here. it's difficult for caller to deduplicate sets | |
2071 | # because different symbols can point to the same rev. |
|
2064 | # because different symbols can point to the same rev. | |
2072 | cl = repo.changelog |
|
2065 | cl = repo.changelog | |
2073 | ls = [] |
|
2066 | ls = [] | |
2074 | seen = set() |
|
2067 | seen = set() | |
2075 | for t in s.split('\0'): |
|
2068 | for t in s.split('\0'): | |
2076 | try: |
|
2069 | try: | |
2077 | # fast path for integer revision |
|
2070 | # fast path for integer revision | |
2078 | r = int(t) |
|
2071 | r = int(t) | |
2079 | if str(r) != t or r not in cl: |
|
2072 | if str(r) != t or r not in cl: | |
2080 | raise ValueError |
|
2073 | raise ValueError | |
2081 | revs = [r] |
|
2074 | revs = [r] | |
2082 | except ValueError: |
|
2075 | except ValueError: | |
2083 | revs = stringset(repo, subset, t, defineorder) |
|
2076 | revs = stringset(repo, subset, t, defineorder) | |
2084 |
|
2077 | |||
2085 | for r in revs: |
|
2078 | for r in revs: | |
2086 | if r in seen: |
|
2079 | if r in seen: | |
2087 | continue |
|
2080 | continue | |
2088 | if (r in subset |
|
2081 | if (r in subset | |
2089 | or r == node.nullrev and isinstance(subset, fullreposet)): |
|
2082 | or r == node.nullrev and isinstance(subset, fullreposet)): | |
2090 | ls.append(r) |
|
2083 | ls.append(r) | |
2091 | seen.add(r) |
|
2084 | seen.add(r) | |
2092 | return baseset(ls) |
|
2085 | return baseset(ls) | |
2093 |
|
2086 | |||
2094 | # for internal use |
|
2087 | # for internal use | |
2095 | @predicate('_list', safe=True, takeorder=True) |
|
2088 | @predicate('_list', safe=True, takeorder=True) | |
2096 | def _list(repo, subset, x, order): |
|
2089 | def _list(repo, subset, x, order): | |
2097 | if order == followorder: |
|
2090 | if order == followorder: | |
2098 | # slow path to take the subset order |
|
2091 | # slow path to take the subset order | |
2099 | return subset & _orderedlist(repo, fullreposet(repo), x) |
|
2092 | return subset & _orderedlist(repo, fullreposet(repo), x) | |
2100 | else: |
|
2093 | else: | |
2101 | return _orderedlist(repo, subset, x) |
|
2094 | return _orderedlist(repo, subset, x) | |
2102 |
|
2095 | |||
2103 | def _orderedintlist(repo, subset, x): |
|
2096 | def _orderedintlist(repo, subset, x): | |
2104 | s = getstring(x, "internal error") |
|
2097 | s = getstring(x, "internal error") | |
2105 | if not s: |
|
2098 | if not s: | |
2106 | return baseset() |
|
2099 | return baseset() | |
2107 | ls = [int(r) for r in s.split('\0')] |
|
2100 | ls = [int(r) for r in s.split('\0')] | |
2108 | s = subset |
|
2101 | s = subset | |
2109 | return baseset([r for r in ls if r in s]) |
|
2102 | return baseset([r for r in ls if r in s]) | |
2110 |
|
2103 | |||
2111 | # for internal use |
|
2104 | # for internal use | |
2112 | @predicate('_intlist', safe=True, takeorder=True, weight=0) |
|
2105 | @predicate('_intlist', safe=True, takeorder=True, weight=0) | |
2113 | def _intlist(repo, subset, x, order): |
|
2106 | def _intlist(repo, subset, x, order): | |
2114 | if order == followorder: |
|
2107 | if order == followorder: | |
2115 | # slow path to take the subset order |
|
2108 | # slow path to take the subset order | |
2116 | return subset & _orderedintlist(repo, fullreposet(repo), x) |
|
2109 | return subset & _orderedintlist(repo, fullreposet(repo), x) | |
2117 | else: |
|
2110 | else: | |
2118 | return _orderedintlist(repo, subset, x) |
|
2111 | return _orderedintlist(repo, subset, x) | |
2119 |
|
2112 | |||
2120 | def _orderedhexlist(repo, subset, x): |
|
2113 | def _orderedhexlist(repo, subset, x): | |
2121 | s = getstring(x, "internal error") |
|
2114 | s = getstring(x, "internal error") | |
2122 | if not s: |
|
2115 | if not s: | |
2123 | return baseset() |
|
2116 | return baseset() | |
2124 | cl = repo.changelog |
|
2117 | cl = repo.changelog | |
2125 | ls = [cl.rev(node.bin(r)) for r in s.split('\0')] |
|
2118 | ls = [cl.rev(node.bin(r)) for r in s.split('\0')] | |
2126 | s = subset |
|
2119 | s = subset | |
2127 | return baseset([r for r in ls if r in s]) |
|
2120 | return baseset([r for r in ls if r in s]) | |
2128 |
|
2121 | |||
2129 | # for internal use |
|
2122 | # for internal use | |
2130 | @predicate('_hexlist', safe=True, takeorder=True) |
|
2123 | @predicate('_hexlist', safe=True, takeorder=True) | |
2131 | def _hexlist(repo, subset, x, order): |
|
2124 | def _hexlist(repo, subset, x, order): | |
2132 | if order == followorder: |
|
2125 | if order == followorder: | |
2133 | # slow path to take the subset order |
|
2126 | # slow path to take the subset order | |
2134 | return subset & _orderedhexlist(repo, fullreposet(repo), x) |
|
2127 | return subset & _orderedhexlist(repo, fullreposet(repo), x) | |
2135 | else: |
|
2128 | else: | |
2136 | return _orderedhexlist(repo, subset, x) |
|
2129 | return _orderedhexlist(repo, subset, x) | |
2137 |
|
2130 | |||
2138 | methods = { |
|
2131 | methods = { | |
2139 | "range": rangeset, |
|
2132 | "range": rangeset, | |
2140 | "rangeall": rangeall, |
|
2133 | "rangeall": rangeall, | |
2141 | "rangepre": rangepre, |
|
2134 | "rangepre": rangepre, | |
2142 | "rangepost": rangepost, |
|
2135 | "rangepost": rangepost, | |
2143 | "dagrange": dagrange, |
|
2136 | "dagrange": dagrange, | |
2144 | "string": stringset, |
|
2137 | "string": stringset, | |
2145 | "symbol": stringset, |
|
2138 | "symbol": stringset, | |
2146 | "and": andset, |
|
2139 | "and": andset, | |
2147 | "andsmally": andsmallyset, |
|
2140 | "andsmally": andsmallyset, | |
2148 | "or": orset, |
|
2141 | "or": orset, | |
2149 | "not": notset, |
|
2142 | "not": notset, | |
2150 | "difference": differenceset, |
|
2143 | "difference": differenceset, | |
2151 | "relation": relationset, |
|
2144 | "relation": relationset, | |
2152 | "relsubscript": relsubscriptset, |
|
2145 | "relsubscript": relsubscriptset, | |
2153 | "subscript": subscriptset, |
|
2146 | "subscript": subscriptset, | |
2154 | "list": listset, |
|
2147 | "list": listset, | |
2155 | "keyvalue": keyvaluepair, |
|
2148 | "keyvalue": keyvaluepair, | |
2156 | "func": func, |
|
2149 | "func": func, | |
2157 | "ancestor": ancestorspec, |
|
2150 | "ancestor": ancestorspec, | |
2158 | "parent": parentspec, |
|
2151 | "parent": parentspec, | |
2159 | "parentpost": parentpost, |
|
2152 | "parentpost": parentpost, | |
2160 | } |
|
2153 | } | |
2161 |
|
2154 | |||
2162 | def posttreebuilthook(tree, repo): |
|
2155 | def posttreebuilthook(tree, repo): | |
2163 | # hook for extensions to execute code on the optimized tree |
|
2156 | # hook for extensions to execute code on the optimized tree | |
2164 | pass |
|
2157 | pass | |
2165 |
|
2158 | |||
2166 | def match(ui, spec, repo=None): |
|
2159 | def match(ui, spec, repo=None): | |
2167 | """Create a matcher for a single revision spec""" |
|
2160 | """Create a matcher for a single revision spec""" | |
2168 | return matchany(ui, [spec], repo=repo) |
|
2161 | return matchany(ui, [spec], repo=repo) | |
2169 |
|
2162 | |||
2170 | def matchany(ui, specs, repo=None, localalias=None): |
|
2163 | def matchany(ui, specs, repo=None, localalias=None): | |
2171 | """Create a matcher that will include any revisions matching one of the |
|
2164 | """Create a matcher that will include any revisions matching one of the | |
2172 | given specs |
|
2165 | given specs | |
2173 |
|
2166 | |||
2174 | If localalias is not None, it is a dict {name: definitionstring}. It takes |
|
2167 | If localalias is not None, it is a dict {name: definitionstring}. It takes | |
2175 | precedence over [revsetalias] config section. |
|
2168 | precedence over [revsetalias] config section. | |
2176 | """ |
|
2169 | """ | |
2177 | if not specs: |
|
2170 | if not specs: | |
2178 | def mfunc(repo, subset=None): |
|
2171 | def mfunc(repo, subset=None): | |
2179 | return baseset() |
|
2172 | return baseset() | |
2180 | return mfunc |
|
2173 | return mfunc | |
2181 | if not all(specs): |
|
2174 | if not all(specs): | |
2182 | raise error.ParseError(_("empty query")) |
|
2175 | raise error.ParseError(_("empty query")) | |
2183 | lookup = None |
|
2176 | lookup = None | |
2184 | if repo: |
|
2177 | if repo: | |
2185 | lookup = repo.__contains__ |
|
2178 | lookup = repo.__contains__ | |
2186 | if len(specs) == 1: |
|
2179 | if len(specs) == 1: | |
2187 | tree = revsetlang.parse(specs[0], lookup) |
|
2180 | tree = revsetlang.parse(specs[0], lookup) | |
2188 | else: |
|
2181 | else: | |
2189 | tree = ('or', |
|
2182 | tree = ('or', | |
2190 | ('list',) + tuple(revsetlang.parse(s, lookup) for s in specs)) |
|
2183 | ('list',) + tuple(revsetlang.parse(s, lookup) for s in specs)) | |
2191 |
|
2184 | |||
2192 | aliases = [] |
|
2185 | aliases = [] | |
2193 | warn = None |
|
2186 | warn = None | |
2194 | if ui: |
|
2187 | if ui: | |
2195 | aliases.extend(ui.configitems('revsetalias')) |
|
2188 | aliases.extend(ui.configitems('revsetalias')) | |
2196 | warn = ui.warn |
|
2189 | warn = ui.warn | |
2197 | if localalias: |
|
2190 | if localalias: | |
2198 | aliases.extend(localalias.items()) |
|
2191 | aliases.extend(localalias.items()) | |
2199 | if aliases: |
|
2192 | if aliases: | |
2200 | tree = revsetlang.expandaliases(tree, aliases, warn=warn) |
|
2193 | tree = revsetlang.expandaliases(tree, aliases, warn=warn) | |
2201 | tree = revsetlang.foldconcat(tree) |
|
2194 | tree = revsetlang.foldconcat(tree) | |
2202 | tree = revsetlang.analyze(tree) |
|
2195 | tree = revsetlang.analyze(tree) | |
2203 | tree = revsetlang.optimize(tree) |
|
2196 | tree = revsetlang.optimize(tree) | |
2204 | posttreebuilthook(tree, repo) |
|
2197 | posttreebuilthook(tree, repo) | |
2205 | return makematcher(tree) |
|
2198 | return makematcher(tree) | |
2206 |
|
2199 | |||
2207 | def makematcher(tree): |
|
2200 | def makematcher(tree): | |
2208 | """Create a matcher from an evaluatable tree""" |
|
2201 | """Create a matcher from an evaluatable tree""" | |
2209 | def mfunc(repo, subset=None, order=None): |
|
2202 | def mfunc(repo, subset=None, order=None): | |
2210 | if order is None: |
|
2203 | if order is None: | |
2211 | if subset is None: |
|
2204 | if subset is None: | |
2212 | order = defineorder # 'x' |
|
2205 | order = defineorder # 'x' | |
2213 | else: |
|
2206 | else: | |
2214 | order = followorder # 'subset & x' |
|
2207 | order = followorder # 'subset & x' | |
2215 | if subset is None: |
|
2208 | if subset is None: | |
2216 | subset = fullreposet(repo) |
|
2209 | subset = fullreposet(repo) | |
2217 | return getset(repo, subset, tree, order) |
|
2210 | return getset(repo, subset, tree, order) | |
2218 | return mfunc |
|
2211 | return mfunc | |
2219 |
|
2212 | |||
2220 | def loadpredicate(ui, extname, registrarobj): |
|
2213 | def loadpredicate(ui, extname, registrarobj): | |
2221 | """Load revset predicates from specified registrarobj |
|
2214 | """Load revset predicates from specified registrarobj | |
2222 | """ |
|
2215 | """ | |
2223 | for name, func in registrarobj._table.iteritems(): |
|
2216 | for name, func in registrarobj._table.iteritems(): | |
2224 | symbols[name] = func |
|
2217 | symbols[name] = func | |
2225 | if func._safe: |
|
2218 | if func._safe: | |
2226 | safesymbols.add(name) |
|
2219 | safesymbols.add(name) | |
2227 |
|
2220 | |||
2228 | # load built-in predicates explicitly to setup safesymbols |
|
2221 | # load built-in predicates explicitly to setup safesymbols | |
2229 | loadpredicate(None, None, predicate) |
|
2222 | loadpredicate(None, None, predicate) | |
2230 |
|
2223 | |||
2231 | # tell hggettext to extract docstrings from these functions: |
|
2224 | # tell hggettext to extract docstrings from these functions: | |
2232 | i18nfunctions = symbols.values() |
|
2225 | i18nfunctions = symbols.values() |
@@ -1,1259 +1,1273 | |||||
1 | # scmutil.py - Mercurial core utility functions |
|
1 | # scmutil.py - Mercurial core utility functions | |
2 | # |
|
2 | # | |
3 | # Copyright Matt Mackall <mpm@selenic.com> |
|
3 | # Copyright Matt Mackall <mpm@selenic.com> | |
4 | # |
|
4 | # | |
5 | # This software may be used and distributed according to the terms of the |
|
5 | # This software may be used and distributed according to the terms of the | |
6 | # GNU General Public License version 2 or any later version. |
|
6 | # GNU General Public License version 2 or any later version. | |
7 |
|
7 | |||
8 | from __future__ import absolute_import |
|
8 | from __future__ import absolute_import | |
9 |
|
9 | |||
10 | import errno |
|
10 | import errno | |
11 | import glob |
|
11 | import glob | |
12 | import hashlib |
|
12 | import hashlib | |
13 | import os |
|
13 | import os | |
14 | import re |
|
14 | import re | |
15 | import socket |
|
15 | import socket | |
16 | import subprocess |
|
16 | import subprocess | |
17 | import weakref |
|
17 | import weakref | |
18 |
|
18 | |||
19 | from .i18n import _ |
|
19 | from .i18n import _ | |
20 | from .node import ( |
|
20 | from .node import ( | |
21 | hex, |
|
21 | hex, | |
22 | nullid, |
|
22 | nullid, | |
23 | short, |
|
23 | short, | |
24 | wdirid, |
|
24 | wdirid, | |
25 | wdirrev, |
|
25 | wdirrev, | |
26 | ) |
|
26 | ) | |
27 |
|
27 | |||
28 | from . import ( |
|
28 | from . import ( | |
29 | encoding, |
|
29 | encoding, | |
30 | error, |
|
30 | error, | |
31 | match as matchmod, |
|
31 | match as matchmod, | |
32 | obsolete, |
|
32 | obsolete, | |
33 | obsutil, |
|
33 | obsutil, | |
34 | pathutil, |
|
34 | pathutil, | |
35 | phases, |
|
35 | phases, | |
36 | pycompat, |
|
36 | pycompat, | |
37 | revsetlang, |
|
37 | revsetlang, | |
38 | similar, |
|
38 | similar, | |
39 | url, |
|
39 | url, | |
40 | util, |
|
40 | util, | |
41 | vfs, |
|
41 | vfs, | |
42 | ) |
|
42 | ) | |
43 |
|
43 | |||
44 | if pycompat.iswindows: |
|
44 | if pycompat.iswindows: | |
45 | from . import scmwindows as scmplatform |
|
45 | from . import scmwindows as scmplatform | |
46 | else: |
|
46 | else: | |
47 | from . import scmposix as scmplatform |
|
47 | from . import scmposix as scmplatform | |
48 |
|
48 | |||
49 | termsize = scmplatform.termsize |
|
49 | termsize = scmplatform.termsize | |
50 |
|
50 | |||
51 | class status(tuple): |
|
51 | class status(tuple): | |
52 | '''Named tuple with a list of files per status. The 'deleted', 'unknown' |
|
52 | '''Named tuple with a list of files per status. The 'deleted', 'unknown' | |
53 | and 'ignored' properties are only relevant to the working copy. |
|
53 | and 'ignored' properties are only relevant to the working copy. | |
54 | ''' |
|
54 | ''' | |
55 |
|
55 | |||
56 | __slots__ = () |
|
56 | __slots__ = () | |
57 |
|
57 | |||
58 | def __new__(cls, modified, added, removed, deleted, unknown, ignored, |
|
58 | def __new__(cls, modified, added, removed, deleted, unknown, ignored, | |
59 | clean): |
|
59 | clean): | |
60 | return tuple.__new__(cls, (modified, added, removed, deleted, unknown, |
|
60 | return tuple.__new__(cls, (modified, added, removed, deleted, unknown, | |
61 | ignored, clean)) |
|
61 | ignored, clean)) | |
62 |
|
62 | |||
63 | @property |
|
63 | @property | |
64 | def modified(self): |
|
64 | def modified(self): | |
65 | '''files that have been modified''' |
|
65 | '''files that have been modified''' | |
66 | return self[0] |
|
66 | return self[0] | |
67 |
|
67 | |||
68 | @property |
|
68 | @property | |
69 | def added(self): |
|
69 | def added(self): | |
70 | '''files that have been added''' |
|
70 | '''files that have been added''' | |
71 | return self[1] |
|
71 | return self[1] | |
72 |
|
72 | |||
73 | @property |
|
73 | @property | |
74 | def removed(self): |
|
74 | def removed(self): | |
75 | '''files that have been removed''' |
|
75 | '''files that have been removed''' | |
76 | return self[2] |
|
76 | return self[2] | |
77 |
|
77 | |||
78 | @property |
|
78 | @property | |
79 | def deleted(self): |
|
79 | def deleted(self): | |
80 | '''files that are in the dirstate, but have been deleted from the |
|
80 | '''files that are in the dirstate, but have been deleted from the | |
81 | working copy (aka "missing") |
|
81 | working copy (aka "missing") | |
82 | ''' |
|
82 | ''' | |
83 | return self[3] |
|
83 | return self[3] | |
84 |
|
84 | |||
85 | @property |
|
85 | @property | |
86 | def unknown(self): |
|
86 | def unknown(self): | |
87 | '''files not in the dirstate that are not ignored''' |
|
87 | '''files not in the dirstate that are not ignored''' | |
88 | return self[4] |
|
88 | return self[4] | |
89 |
|
89 | |||
90 | @property |
|
90 | @property | |
91 | def ignored(self): |
|
91 | def ignored(self): | |
92 | '''files not in the dirstate that are ignored (by _dirignore())''' |
|
92 | '''files not in the dirstate that are ignored (by _dirignore())''' | |
93 | return self[5] |
|
93 | return self[5] | |
94 |
|
94 | |||
95 | @property |
|
95 | @property | |
96 | def clean(self): |
|
96 | def clean(self): | |
97 | '''files that have not been modified''' |
|
97 | '''files that have not been modified''' | |
98 | return self[6] |
|
98 | return self[6] | |
99 |
|
99 | |||
100 | def __repr__(self, *args, **kwargs): |
|
100 | def __repr__(self, *args, **kwargs): | |
101 | return (('<status modified=%r, added=%r, removed=%r, deleted=%r, ' |
|
101 | return (('<status modified=%r, added=%r, removed=%r, deleted=%r, ' | |
102 | 'unknown=%r, ignored=%r, clean=%r>') % self) |
|
102 | 'unknown=%r, ignored=%r, clean=%r>') % self) | |
103 |
|
103 | |||
104 | def itersubrepos(ctx1, ctx2): |
|
104 | def itersubrepos(ctx1, ctx2): | |
105 | """find subrepos in ctx1 or ctx2""" |
|
105 | """find subrepos in ctx1 or ctx2""" | |
106 | # Create a (subpath, ctx) mapping where we prefer subpaths from |
|
106 | # Create a (subpath, ctx) mapping where we prefer subpaths from | |
107 | # ctx1. The subpaths from ctx2 are important when the .hgsub file |
|
107 | # ctx1. The subpaths from ctx2 are important when the .hgsub file | |
108 | # has been modified (in ctx2) but not yet committed (in ctx1). |
|
108 | # has been modified (in ctx2) but not yet committed (in ctx1). | |
109 | subpaths = dict.fromkeys(ctx2.substate, ctx2) |
|
109 | subpaths = dict.fromkeys(ctx2.substate, ctx2) | |
110 | subpaths.update(dict.fromkeys(ctx1.substate, ctx1)) |
|
110 | subpaths.update(dict.fromkeys(ctx1.substate, ctx1)) | |
111 |
|
111 | |||
112 | missing = set() |
|
112 | missing = set() | |
113 |
|
113 | |||
114 | for subpath in ctx2.substate: |
|
114 | for subpath in ctx2.substate: | |
115 | if subpath not in ctx1.substate: |
|
115 | if subpath not in ctx1.substate: | |
116 | del subpaths[subpath] |
|
116 | del subpaths[subpath] | |
117 | missing.add(subpath) |
|
117 | missing.add(subpath) | |
118 |
|
118 | |||
119 | for subpath, ctx in sorted(subpaths.iteritems()): |
|
119 | for subpath, ctx in sorted(subpaths.iteritems()): | |
120 | yield subpath, ctx.sub(subpath) |
|
120 | yield subpath, ctx.sub(subpath) | |
121 |
|
121 | |||
122 | # Yield an empty subrepo based on ctx1 for anything only in ctx2. That way, |
|
122 | # Yield an empty subrepo based on ctx1 for anything only in ctx2. That way, | |
123 | # status and diff will have an accurate result when it does |
|
123 | # status and diff will have an accurate result when it does | |
124 | # 'sub.{status|diff}(rev2)'. Otherwise, the ctx2 subrepo is compared |
|
124 | # 'sub.{status|diff}(rev2)'. Otherwise, the ctx2 subrepo is compared | |
125 | # against itself. |
|
125 | # against itself. | |
126 | for subpath in missing: |
|
126 | for subpath in missing: | |
127 | yield subpath, ctx2.nullsub(subpath, ctx1) |
|
127 | yield subpath, ctx2.nullsub(subpath, ctx1) | |
128 |
|
128 | |||
129 | def nochangesfound(ui, repo, excluded=None): |
|
129 | def nochangesfound(ui, repo, excluded=None): | |
130 | '''Report no changes for push/pull, excluded is None or a list of |
|
130 | '''Report no changes for push/pull, excluded is None or a list of | |
131 | nodes excluded from the push/pull. |
|
131 | nodes excluded from the push/pull. | |
132 | ''' |
|
132 | ''' | |
133 | secretlist = [] |
|
133 | secretlist = [] | |
134 | if excluded: |
|
134 | if excluded: | |
135 | for n in excluded: |
|
135 | for n in excluded: | |
136 | ctx = repo[n] |
|
136 | ctx = repo[n] | |
137 | if ctx.phase() >= phases.secret and not ctx.extinct(): |
|
137 | if ctx.phase() >= phases.secret and not ctx.extinct(): | |
138 | secretlist.append(n) |
|
138 | secretlist.append(n) | |
139 |
|
139 | |||
140 | if secretlist: |
|
140 | if secretlist: | |
141 | ui.status(_("no changes found (ignored %d secret changesets)\n") |
|
141 | ui.status(_("no changes found (ignored %d secret changesets)\n") | |
142 | % len(secretlist)) |
|
142 | % len(secretlist)) | |
143 | else: |
|
143 | else: | |
144 | ui.status(_("no changes found\n")) |
|
144 | ui.status(_("no changes found\n")) | |
145 |
|
145 | |||
146 | def callcatch(ui, func): |
|
146 | def callcatch(ui, func): | |
147 | """call func() with global exception handling |
|
147 | """call func() with global exception handling | |
148 |
|
148 | |||
149 | return func() if no exception happens. otherwise do some error handling |
|
149 | return func() if no exception happens. otherwise do some error handling | |
150 | and return an exit code accordingly. does not handle all exceptions. |
|
150 | and return an exit code accordingly. does not handle all exceptions. | |
151 | """ |
|
151 | """ | |
152 | try: |
|
152 | try: | |
153 | try: |
|
153 | try: | |
154 | return func() |
|
154 | return func() | |
155 | except: # re-raises |
|
155 | except: # re-raises | |
156 | ui.traceback() |
|
156 | ui.traceback() | |
157 | raise |
|
157 | raise | |
158 | # Global exception handling, alphabetically |
|
158 | # Global exception handling, alphabetically | |
159 | # Mercurial-specific first, followed by built-in and library exceptions |
|
159 | # Mercurial-specific first, followed by built-in and library exceptions | |
160 | except error.LockHeld as inst: |
|
160 | except error.LockHeld as inst: | |
161 | if inst.errno == errno.ETIMEDOUT: |
|
161 | if inst.errno == errno.ETIMEDOUT: | |
162 | reason = _('timed out waiting for lock held by %r') % inst.locker |
|
162 | reason = _('timed out waiting for lock held by %r') % inst.locker | |
163 | else: |
|
163 | else: | |
164 | reason = _('lock held by %r') % inst.locker |
|
164 | reason = _('lock held by %r') % inst.locker | |
165 | ui.warn(_("abort: %s: %s\n") % (inst.desc or inst.filename, reason)) |
|
165 | ui.warn(_("abort: %s: %s\n") % (inst.desc or inst.filename, reason)) | |
166 | if not inst.locker: |
|
166 | if not inst.locker: | |
167 | ui.warn(_("(lock might be very busy)\n")) |
|
167 | ui.warn(_("(lock might be very busy)\n")) | |
168 | except error.LockUnavailable as inst: |
|
168 | except error.LockUnavailable as inst: | |
169 | ui.warn(_("abort: could not lock %s: %s\n") % |
|
169 | ui.warn(_("abort: could not lock %s: %s\n") % | |
170 | (inst.desc or inst.filename, |
|
170 | (inst.desc or inst.filename, | |
171 | encoding.strtolocal(inst.strerror))) |
|
171 | encoding.strtolocal(inst.strerror))) | |
172 | except error.OutOfBandError as inst: |
|
172 | except error.OutOfBandError as inst: | |
173 | if inst.args: |
|
173 | if inst.args: | |
174 | msg = _("abort: remote error:\n") |
|
174 | msg = _("abort: remote error:\n") | |
175 | else: |
|
175 | else: | |
176 | msg = _("abort: remote error\n") |
|
176 | msg = _("abort: remote error\n") | |
177 | ui.warn(msg) |
|
177 | ui.warn(msg) | |
178 | if inst.args: |
|
178 | if inst.args: | |
179 | ui.warn(''.join(inst.args)) |
|
179 | ui.warn(''.join(inst.args)) | |
180 | if inst.hint: |
|
180 | if inst.hint: | |
181 | ui.warn('(%s)\n' % inst.hint) |
|
181 | ui.warn('(%s)\n' % inst.hint) | |
182 | except error.RepoError as inst: |
|
182 | except error.RepoError as inst: | |
183 | ui.warn(_("abort: %s!\n") % inst) |
|
183 | ui.warn(_("abort: %s!\n") % inst) | |
184 | if inst.hint: |
|
184 | if inst.hint: | |
185 | ui.warn(_("(%s)\n") % inst.hint) |
|
185 | ui.warn(_("(%s)\n") % inst.hint) | |
186 | except error.ResponseError as inst: |
|
186 | except error.ResponseError as inst: | |
187 | ui.warn(_("abort: %s") % inst.args[0]) |
|
187 | ui.warn(_("abort: %s") % inst.args[0]) | |
188 | if not isinstance(inst.args[1], basestring): |
|
188 | if not isinstance(inst.args[1], basestring): | |
189 | ui.warn(" %r\n" % (inst.args[1],)) |
|
189 | ui.warn(" %r\n" % (inst.args[1],)) | |
190 | elif not inst.args[1]: |
|
190 | elif not inst.args[1]: | |
191 | ui.warn(_(" empty string\n")) |
|
191 | ui.warn(_(" empty string\n")) | |
192 | else: |
|
192 | else: | |
193 | ui.warn("\n%r\n" % util.ellipsis(inst.args[1])) |
|
193 | ui.warn("\n%r\n" % util.ellipsis(inst.args[1])) | |
194 | except error.CensoredNodeError as inst: |
|
194 | except error.CensoredNodeError as inst: | |
195 | ui.warn(_("abort: file censored %s!\n") % inst) |
|
195 | ui.warn(_("abort: file censored %s!\n") % inst) | |
196 | except error.RevlogError as inst: |
|
196 | except error.RevlogError as inst: | |
197 | ui.warn(_("abort: %s!\n") % inst) |
|
197 | ui.warn(_("abort: %s!\n") % inst) | |
198 | except error.InterventionRequired as inst: |
|
198 | except error.InterventionRequired as inst: | |
199 | ui.warn("%s\n" % inst) |
|
199 | ui.warn("%s\n" % inst) | |
200 | if inst.hint: |
|
200 | if inst.hint: | |
201 | ui.warn(_("(%s)\n") % inst.hint) |
|
201 | ui.warn(_("(%s)\n") % inst.hint) | |
202 | return 1 |
|
202 | return 1 | |
203 | except error.WdirUnsupported: |
|
203 | except error.WdirUnsupported: | |
204 | ui.warn(_("abort: working directory revision cannot be specified\n")) |
|
204 | ui.warn(_("abort: working directory revision cannot be specified\n")) | |
205 | except error.Abort as inst: |
|
205 | except error.Abort as inst: | |
206 | ui.warn(_("abort: %s\n") % inst) |
|
206 | ui.warn(_("abort: %s\n") % inst) | |
207 | if inst.hint: |
|
207 | if inst.hint: | |
208 | ui.warn(_("(%s)\n") % inst.hint) |
|
208 | ui.warn(_("(%s)\n") % inst.hint) | |
209 | except ImportError as inst: |
|
209 | except ImportError as inst: | |
210 | ui.warn(_("abort: %s!\n") % inst) |
|
210 | ui.warn(_("abort: %s!\n") % inst) | |
211 | m = str(inst).split()[-1] |
|
211 | m = str(inst).split()[-1] | |
212 | if m in "mpatch bdiff".split(): |
|
212 | if m in "mpatch bdiff".split(): | |
213 | ui.warn(_("(did you forget to compile extensions?)\n")) |
|
213 | ui.warn(_("(did you forget to compile extensions?)\n")) | |
214 | elif m in "zlib".split(): |
|
214 | elif m in "zlib".split(): | |
215 | ui.warn(_("(is your Python install correct?)\n")) |
|
215 | ui.warn(_("(is your Python install correct?)\n")) | |
216 | except IOError as inst: |
|
216 | except IOError as inst: | |
217 | if util.safehasattr(inst, "code"): |
|
217 | if util.safehasattr(inst, "code"): | |
218 | ui.warn(_("abort: %s\n") % inst) |
|
218 | ui.warn(_("abort: %s\n") % inst) | |
219 | elif util.safehasattr(inst, "reason"): |
|
219 | elif util.safehasattr(inst, "reason"): | |
220 | try: # usually it is in the form (errno, strerror) |
|
220 | try: # usually it is in the form (errno, strerror) | |
221 | reason = inst.reason.args[1] |
|
221 | reason = inst.reason.args[1] | |
222 | except (AttributeError, IndexError): |
|
222 | except (AttributeError, IndexError): | |
223 | # it might be anything, for example a string |
|
223 | # it might be anything, for example a string | |
224 | reason = inst.reason |
|
224 | reason = inst.reason | |
225 | if isinstance(reason, unicode): |
|
225 | if isinstance(reason, unicode): | |
226 | # SSLError of Python 2.7.9 contains a unicode |
|
226 | # SSLError of Python 2.7.9 contains a unicode | |
227 | reason = encoding.unitolocal(reason) |
|
227 | reason = encoding.unitolocal(reason) | |
228 | ui.warn(_("abort: error: %s\n") % reason) |
|
228 | ui.warn(_("abort: error: %s\n") % reason) | |
229 | elif (util.safehasattr(inst, "args") |
|
229 | elif (util.safehasattr(inst, "args") | |
230 | and inst.args and inst.args[0] == errno.EPIPE): |
|
230 | and inst.args and inst.args[0] == errno.EPIPE): | |
231 | pass |
|
231 | pass | |
232 | elif getattr(inst, "strerror", None): |
|
232 | elif getattr(inst, "strerror", None): | |
233 | if getattr(inst, "filename", None): |
|
233 | if getattr(inst, "filename", None): | |
234 | ui.warn(_("abort: %s: %s\n") % ( |
|
234 | ui.warn(_("abort: %s: %s\n") % ( | |
235 | encoding.strtolocal(inst.strerror), inst.filename)) |
|
235 | encoding.strtolocal(inst.strerror), inst.filename)) | |
236 | else: |
|
236 | else: | |
237 | ui.warn(_("abort: %s\n") % encoding.strtolocal(inst.strerror)) |
|
237 | ui.warn(_("abort: %s\n") % encoding.strtolocal(inst.strerror)) | |
238 | else: |
|
238 | else: | |
239 | raise |
|
239 | raise | |
240 | except OSError as inst: |
|
240 | except OSError as inst: | |
241 | if getattr(inst, "filename", None) is not None: |
|
241 | if getattr(inst, "filename", None) is not None: | |
242 | ui.warn(_("abort: %s: '%s'\n") % ( |
|
242 | ui.warn(_("abort: %s: '%s'\n") % ( | |
243 | encoding.strtolocal(inst.strerror), inst.filename)) |
|
243 | encoding.strtolocal(inst.strerror), inst.filename)) | |
244 | else: |
|
244 | else: | |
245 | ui.warn(_("abort: %s\n") % encoding.strtolocal(inst.strerror)) |
|
245 | ui.warn(_("abort: %s\n") % encoding.strtolocal(inst.strerror)) | |
246 | except MemoryError: |
|
246 | except MemoryError: | |
247 | ui.warn(_("abort: out of memory\n")) |
|
247 | ui.warn(_("abort: out of memory\n")) | |
248 | except SystemExit as inst: |
|
248 | except SystemExit as inst: | |
249 | # Commands shouldn't sys.exit directly, but give a return code. |
|
249 | # Commands shouldn't sys.exit directly, but give a return code. | |
250 | # Just in case catch this and and pass exit code to caller. |
|
250 | # Just in case catch this and and pass exit code to caller. | |
251 | return inst.code |
|
251 | return inst.code | |
252 | except socket.error as inst: |
|
252 | except socket.error as inst: | |
253 | ui.warn(_("abort: %s\n") % inst.args[-1]) |
|
253 | ui.warn(_("abort: %s\n") % inst.args[-1]) | |
254 |
|
254 | |||
255 | return -1 |
|
255 | return -1 | |
256 |
|
256 | |||
257 | def checknewlabel(repo, lbl, kind): |
|
257 | def checknewlabel(repo, lbl, kind): | |
258 | # Do not use the "kind" parameter in ui output. |
|
258 | # Do not use the "kind" parameter in ui output. | |
259 | # It makes strings difficult to translate. |
|
259 | # It makes strings difficult to translate. | |
260 | if lbl in ['tip', '.', 'null']: |
|
260 | if lbl in ['tip', '.', 'null']: | |
261 | raise error.Abort(_("the name '%s' is reserved") % lbl) |
|
261 | raise error.Abort(_("the name '%s' is reserved") % lbl) | |
262 | for c in (':', '\0', '\n', '\r'): |
|
262 | for c in (':', '\0', '\n', '\r'): | |
263 | if c in lbl: |
|
263 | if c in lbl: | |
264 | raise error.Abort(_("%r cannot be used in a name") % c) |
|
264 | raise error.Abort(_("%r cannot be used in a name") % c) | |
265 | try: |
|
265 | try: | |
266 | int(lbl) |
|
266 | int(lbl) | |
267 | raise error.Abort(_("cannot use an integer as a name")) |
|
267 | raise error.Abort(_("cannot use an integer as a name")) | |
268 | except ValueError: |
|
268 | except ValueError: | |
269 | pass |
|
269 | pass | |
270 |
|
270 | |||
271 | def checkfilename(f): |
|
271 | def checkfilename(f): | |
272 | '''Check that the filename f is an acceptable filename for a tracked file''' |
|
272 | '''Check that the filename f is an acceptable filename for a tracked file''' | |
273 | if '\r' in f or '\n' in f: |
|
273 | if '\r' in f or '\n' in f: | |
274 | raise error.Abort(_("'\\n' and '\\r' disallowed in filenames: %r") % f) |
|
274 | raise error.Abort(_("'\\n' and '\\r' disallowed in filenames: %r") % f) | |
275 |
|
275 | |||
276 | def checkportable(ui, f): |
|
276 | def checkportable(ui, f): | |
277 | '''Check if filename f is portable and warn or abort depending on config''' |
|
277 | '''Check if filename f is portable and warn or abort depending on config''' | |
278 | checkfilename(f) |
|
278 | checkfilename(f) | |
279 | abort, warn = checkportabilityalert(ui) |
|
279 | abort, warn = checkportabilityalert(ui) | |
280 | if abort or warn: |
|
280 | if abort or warn: | |
281 | msg = util.checkwinfilename(f) |
|
281 | msg = util.checkwinfilename(f) | |
282 | if msg: |
|
282 | if msg: | |
283 | msg = "%s: %s" % (msg, util.shellquote(f)) |
|
283 | msg = "%s: %s" % (msg, util.shellquote(f)) | |
284 | if abort: |
|
284 | if abort: | |
285 | raise error.Abort(msg) |
|
285 | raise error.Abort(msg) | |
286 | ui.warn(_("warning: %s\n") % msg) |
|
286 | ui.warn(_("warning: %s\n") % msg) | |
287 |
|
287 | |||
288 | def checkportabilityalert(ui): |
|
288 | def checkportabilityalert(ui): | |
289 | '''check if the user's config requests nothing, a warning, or abort for |
|
289 | '''check if the user's config requests nothing, a warning, or abort for | |
290 | non-portable filenames''' |
|
290 | non-portable filenames''' | |
291 | val = ui.config('ui', 'portablefilenames') |
|
291 | val = ui.config('ui', 'portablefilenames') | |
292 | lval = val.lower() |
|
292 | lval = val.lower() | |
293 | bval = util.parsebool(val) |
|
293 | bval = util.parsebool(val) | |
294 | abort = pycompat.iswindows or lval == 'abort' |
|
294 | abort = pycompat.iswindows or lval == 'abort' | |
295 | warn = bval or lval == 'warn' |
|
295 | warn = bval or lval == 'warn' | |
296 | if bval is None and not (warn or abort or lval == 'ignore'): |
|
296 | if bval is None and not (warn or abort or lval == 'ignore'): | |
297 | raise error.ConfigError( |
|
297 | raise error.ConfigError( | |
298 | _("ui.portablefilenames value is invalid ('%s')") % val) |
|
298 | _("ui.portablefilenames value is invalid ('%s')") % val) | |
299 | return abort, warn |
|
299 | return abort, warn | |
300 |
|
300 | |||
301 | class casecollisionauditor(object): |
|
301 | class casecollisionauditor(object): | |
302 | def __init__(self, ui, abort, dirstate): |
|
302 | def __init__(self, ui, abort, dirstate): | |
303 | self._ui = ui |
|
303 | self._ui = ui | |
304 | self._abort = abort |
|
304 | self._abort = abort | |
305 | allfiles = '\0'.join(dirstate._map) |
|
305 | allfiles = '\0'.join(dirstate._map) | |
306 | self._loweredfiles = set(encoding.lower(allfiles).split('\0')) |
|
306 | self._loweredfiles = set(encoding.lower(allfiles).split('\0')) | |
307 | self._dirstate = dirstate |
|
307 | self._dirstate = dirstate | |
308 | # The purpose of _newfiles is so that we don't complain about |
|
308 | # The purpose of _newfiles is so that we don't complain about | |
309 | # case collisions if someone were to call this object with the |
|
309 | # case collisions if someone were to call this object with the | |
310 | # same filename twice. |
|
310 | # same filename twice. | |
311 | self._newfiles = set() |
|
311 | self._newfiles = set() | |
312 |
|
312 | |||
313 | def __call__(self, f): |
|
313 | def __call__(self, f): | |
314 | if f in self._newfiles: |
|
314 | if f in self._newfiles: | |
315 | return |
|
315 | return | |
316 | fl = encoding.lower(f) |
|
316 | fl = encoding.lower(f) | |
317 | if fl in self._loweredfiles and f not in self._dirstate: |
|
317 | if fl in self._loweredfiles and f not in self._dirstate: | |
318 | msg = _('possible case-folding collision for %s') % f |
|
318 | msg = _('possible case-folding collision for %s') % f | |
319 | if self._abort: |
|
319 | if self._abort: | |
320 | raise error.Abort(msg) |
|
320 | raise error.Abort(msg) | |
321 | self._ui.warn(_("warning: %s\n") % msg) |
|
321 | self._ui.warn(_("warning: %s\n") % msg) | |
322 | self._loweredfiles.add(fl) |
|
322 | self._loweredfiles.add(fl) | |
323 | self._newfiles.add(f) |
|
323 | self._newfiles.add(f) | |
324 |
|
324 | |||
325 | def filteredhash(repo, maxrev): |
|
325 | def filteredhash(repo, maxrev): | |
326 | """build hash of filtered revisions in the current repoview. |
|
326 | """build hash of filtered revisions in the current repoview. | |
327 |
|
327 | |||
328 | Multiple caches perform up-to-date validation by checking that the |
|
328 | Multiple caches perform up-to-date validation by checking that the | |
329 | tiprev and tipnode stored in the cache file match the current repository. |
|
329 | tiprev and tipnode stored in the cache file match the current repository. | |
330 | However, this is not sufficient for validating repoviews because the set |
|
330 | However, this is not sufficient for validating repoviews because the set | |
331 | of revisions in the view may change without the repository tiprev and |
|
331 | of revisions in the view may change without the repository tiprev and | |
332 | tipnode changing. |
|
332 | tipnode changing. | |
333 |
|
333 | |||
334 | This function hashes all the revs filtered from the view and returns |
|
334 | This function hashes all the revs filtered from the view and returns | |
335 | that SHA-1 digest. |
|
335 | that SHA-1 digest. | |
336 | """ |
|
336 | """ | |
337 | cl = repo.changelog |
|
337 | cl = repo.changelog | |
338 | if not cl.filteredrevs: |
|
338 | if not cl.filteredrevs: | |
339 | return None |
|
339 | return None | |
340 | key = None |
|
340 | key = None | |
341 | revs = sorted(r for r in cl.filteredrevs if r <= maxrev) |
|
341 | revs = sorted(r for r in cl.filteredrevs if r <= maxrev) | |
342 | if revs: |
|
342 | if revs: | |
343 | s = hashlib.sha1() |
|
343 | s = hashlib.sha1() | |
344 | for rev in revs: |
|
344 | for rev in revs: | |
345 | s.update('%d;' % rev) |
|
345 | s.update('%d;' % rev) | |
346 | key = s.digest() |
|
346 | key = s.digest() | |
347 | return key |
|
347 | return key | |
348 |
|
348 | |||
349 | def walkrepos(path, followsym=False, seen_dirs=None, recurse=False): |
|
349 | def walkrepos(path, followsym=False, seen_dirs=None, recurse=False): | |
350 | '''yield every hg repository under path, always recursively. |
|
350 | '''yield every hg repository under path, always recursively. | |
351 | The recurse flag will only control recursion into repo working dirs''' |
|
351 | The recurse flag will only control recursion into repo working dirs''' | |
352 | def errhandler(err): |
|
352 | def errhandler(err): | |
353 | if err.filename == path: |
|
353 | if err.filename == path: | |
354 | raise err |
|
354 | raise err | |
355 | samestat = getattr(os.path, 'samestat', None) |
|
355 | samestat = getattr(os.path, 'samestat', None) | |
356 | if followsym and samestat is not None: |
|
356 | if followsym and samestat is not None: | |
357 | def adddir(dirlst, dirname): |
|
357 | def adddir(dirlst, dirname): | |
358 | match = False |
|
358 | match = False | |
359 | dirstat = os.stat(dirname) |
|
359 | dirstat = os.stat(dirname) | |
360 | for lstdirstat in dirlst: |
|
360 | for lstdirstat in dirlst: | |
361 | if samestat(dirstat, lstdirstat): |
|
361 | if samestat(dirstat, lstdirstat): | |
362 | match = True |
|
362 | match = True | |
363 | break |
|
363 | break | |
364 | if not match: |
|
364 | if not match: | |
365 | dirlst.append(dirstat) |
|
365 | dirlst.append(dirstat) | |
366 | return not match |
|
366 | return not match | |
367 | else: |
|
367 | else: | |
368 | followsym = False |
|
368 | followsym = False | |
369 |
|
369 | |||
370 | if (seen_dirs is None) and followsym: |
|
370 | if (seen_dirs is None) and followsym: | |
371 | seen_dirs = [] |
|
371 | seen_dirs = [] | |
372 | adddir(seen_dirs, path) |
|
372 | adddir(seen_dirs, path) | |
373 | for root, dirs, files in os.walk(path, topdown=True, onerror=errhandler): |
|
373 | for root, dirs, files in os.walk(path, topdown=True, onerror=errhandler): | |
374 | dirs.sort() |
|
374 | dirs.sort() | |
375 | if '.hg' in dirs: |
|
375 | if '.hg' in dirs: | |
376 | yield root # found a repository |
|
376 | yield root # found a repository | |
377 | qroot = os.path.join(root, '.hg', 'patches') |
|
377 | qroot = os.path.join(root, '.hg', 'patches') | |
378 | if os.path.isdir(os.path.join(qroot, '.hg')): |
|
378 | if os.path.isdir(os.path.join(qroot, '.hg')): | |
379 | yield qroot # we have a patch queue repo here |
|
379 | yield qroot # we have a patch queue repo here | |
380 | if recurse: |
|
380 | if recurse: | |
381 | # avoid recursing inside the .hg directory |
|
381 | # avoid recursing inside the .hg directory | |
382 | dirs.remove('.hg') |
|
382 | dirs.remove('.hg') | |
383 | else: |
|
383 | else: | |
384 | dirs[:] = [] # don't descend further |
|
384 | dirs[:] = [] # don't descend further | |
385 | elif followsym: |
|
385 | elif followsym: | |
386 | newdirs = [] |
|
386 | newdirs = [] | |
387 | for d in dirs: |
|
387 | for d in dirs: | |
388 | fname = os.path.join(root, d) |
|
388 | fname = os.path.join(root, d) | |
389 | if adddir(seen_dirs, fname): |
|
389 | if adddir(seen_dirs, fname): | |
390 | if os.path.islink(fname): |
|
390 | if os.path.islink(fname): | |
391 | for hgname in walkrepos(fname, True, seen_dirs): |
|
391 | for hgname in walkrepos(fname, True, seen_dirs): | |
392 | yield hgname |
|
392 | yield hgname | |
393 | else: |
|
393 | else: | |
394 | newdirs.append(d) |
|
394 | newdirs.append(d) | |
395 | dirs[:] = newdirs |
|
395 | dirs[:] = newdirs | |
396 |
|
396 | |||
397 | def binnode(ctx): |
|
397 | def binnode(ctx): | |
398 | """Return binary node id for a given basectx""" |
|
398 | """Return binary node id for a given basectx""" | |
399 | node = ctx.node() |
|
399 | node = ctx.node() | |
400 | if node is None: |
|
400 | if node is None: | |
401 | return wdirid |
|
401 | return wdirid | |
402 | return node |
|
402 | return node | |
403 |
|
403 | |||
404 | def intrev(ctx): |
|
404 | def intrev(ctx): | |
405 | """Return integer for a given basectx that can be used in comparison or |
|
405 | """Return integer for a given basectx that can be used in comparison or | |
406 | arithmetic operation""" |
|
406 | arithmetic operation""" | |
407 | rev = ctx.rev() |
|
407 | rev = ctx.rev() | |
408 | if rev is None: |
|
408 | if rev is None: | |
409 | return wdirrev |
|
409 | return wdirrev | |
410 | return rev |
|
410 | return rev | |
411 |
|
411 | |||
412 | def formatchangeid(ctx): |
|
412 | def formatchangeid(ctx): | |
413 | """Format changectx as '{rev}:{node|formatnode}', which is the default |
|
413 | """Format changectx as '{rev}:{node|formatnode}', which is the default | |
414 | template provided by cmdutil.changeset_templater""" |
|
414 | template provided by cmdutil.changeset_templater""" | |
415 | repo = ctx.repo() |
|
415 | repo = ctx.repo() | |
416 | return formatrevnode(repo.ui, intrev(ctx), binnode(ctx)) |
|
416 | return formatrevnode(repo.ui, intrev(ctx), binnode(ctx)) | |
417 |
|
417 | |||
418 | def formatrevnode(ui, rev, node): |
|
418 | def formatrevnode(ui, rev, node): | |
419 | """Format given revision and node depending on the current verbosity""" |
|
419 | """Format given revision and node depending on the current verbosity""" | |
420 | if ui.debugflag: |
|
420 | if ui.debugflag: | |
421 | hexfunc = hex |
|
421 | hexfunc = hex | |
422 | else: |
|
422 | else: | |
423 | hexfunc = short |
|
423 | hexfunc = short | |
424 | return '%d:%s' % (rev, hexfunc(node)) |
|
424 | return '%d:%s' % (rev, hexfunc(node)) | |
425 |
|
425 | |||
426 | def revsingle(repo, revspec, default='.', localalias=None): |
|
426 | def revsingle(repo, revspec, default='.', localalias=None): | |
427 | if not revspec and revspec != 0: |
|
427 | if not revspec and revspec != 0: | |
428 | return repo[default] |
|
428 | return repo[default] | |
429 |
|
429 | |||
430 | l = revrange(repo, [revspec], localalias=localalias) |
|
430 | l = revrange(repo, [revspec], localalias=localalias) | |
431 | if not l: |
|
431 | if not l: | |
432 | raise error.Abort(_('empty revision set')) |
|
432 | raise error.Abort(_('empty revision set')) | |
433 | return repo[l.last()] |
|
433 | return repo[l.last()] | |
434 |
|
434 | |||
435 | def _pairspec(revspec): |
|
435 | def _pairspec(revspec): | |
436 | tree = revsetlang.parse(revspec) |
|
436 | tree = revsetlang.parse(revspec) | |
437 | return tree and tree[0] in ('range', 'rangepre', 'rangepost', 'rangeall') |
|
437 | return tree and tree[0] in ('range', 'rangepre', 'rangepost', 'rangeall') | |
438 |
|
438 | |||
439 | def revpair(repo, revs): |
|
439 | def revpair(repo, revs): | |
440 | if not revs: |
|
440 | if not revs: | |
441 | return repo.dirstate.p1(), None |
|
441 | return repo.dirstate.p1(), None | |
442 |
|
442 | |||
443 | l = revrange(repo, revs) |
|
443 | l = revrange(repo, revs) | |
444 |
|
444 | |||
445 | if not l: |
|
445 | if not l: | |
446 | first = second = None |
|
446 | first = second = None | |
447 | elif l.isascending(): |
|
447 | elif l.isascending(): | |
448 | first = l.min() |
|
448 | first = l.min() | |
449 | second = l.max() |
|
449 | second = l.max() | |
450 | elif l.isdescending(): |
|
450 | elif l.isdescending(): | |
451 | first = l.max() |
|
451 | first = l.max() | |
452 | second = l.min() |
|
452 | second = l.min() | |
453 | else: |
|
453 | else: | |
454 | first = l.first() |
|
454 | first = l.first() | |
455 | second = l.last() |
|
455 | second = l.last() | |
456 |
|
456 | |||
457 | if first is None: |
|
457 | if first is None: | |
458 | raise error.Abort(_('empty revision range')) |
|
458 | raise error.Abort(_('empty revision range')) | |
459 | if (first == second and len(revs) >= 2 |
|
459 | if (first == second and len(revs) >= 2 | |
460 | and not all(revrange(repo, [r]) for r in revs)): |
|
460 | and not all(revrange(repo, [r]) for r in revs)): | |
461 | raise error.Abort(_('empty revision on one side of range')) |
|
461 | raise error.Abort(_('empty revision on one side of range')) | |
462 |
|
462 | |||
463 | # if top-level is range expression, the result must always be a pair |
|
463 | # if top-level is range expression, the result must always be a pair | |
464 | if first == second and len(revs) == 1 and not _pairspec(revs[0]): |
|
464 | if first == second and len(revs) == 1 and not _pairspec(revs[0]): | |
465 | return repo.lookup(first), None |
|
465 | return repo.lookup(first), None | |
466 |
|
466 | |||
467 | return repo.lookup(first), repo.lookup(second) |
|
467 | return repo.lookup(first), repo.lookup(second) | |
468 |
|
468 | |||
469 | def revrange(repo, specs, localalias=None): |
|
469 | def revrange(repo, specs, localalias=None): | |
470 | """Execute 1 to many revsets and return the union. |
|
470 | """Execute 1 to many revsets and return the union. | |
471 |
|
471 | |||
472 | This is the preferred mechanism for executing revsets using user-specified |
|
472 | This is the preferred mechanism for executing revsets using user-specified | |
473 | config options, such as revset aliases. |
|
473 | config options, such as revset aliases. | |
474 |
|
474 | |||
475 | The revsets specified by ``specs`` will be executed via a chained ``OR`` |
|
475 | The revsets specified by ``specs`` will be executed via a chained ``OR`` | |
476 | expression. If ``specs`` is empty, an empty result is returned. |
|
476 | expression. If ``specs`` is empty, an empty result is returned. | |
477 |
|
477 | |||
478 | ``specs`` can contain integers, in which case they are assumed to be |
|
478 | ``specs`` can contain integers, in which case they are assumed to be | |
479 | revision numbers. |
|
479 | revision numbers. | |
480 |
|
480 | |||
481 | It is assumed the revsets are already formatted. If you have arguments |
|
481 | It is assumed the revsets are already formatted. If you have arguments | |
482 | that need to be expanded in the revset, call ``revsetlang.formatspec()`` |
|
482 | that need to be expanded in the revset, call ``revsetlang.formatspec()`` | |
483 | and pass the result as an element of ``specs``. |
|
483 | and pass the result as an element of ``specs``. | |
484 |
|
484 | |||
485 | Specifying a single revset is allowed. |
|
485 | Specifying a single revset is allowed. | |
486 |
|
486 | |||
487 | Returns a ``revset.abstractsmartset`` which is a list-like interface over |
|
487 | Returns a ``revset.abstractsmartset`` which is a list-like interface over | |
488 | integer revisions. |
|
488 | integer revisions. | |
489 | """ |
|
489 | """ | |
490 | allspecs = [] |
|
490 | allspecs = [] | |
491 | for spec in specs: |
|
491 | for spec in specs: | |
492 | if isinstance(spec, int): |
|
492 | if isinstance(spec, int): | |
493 | spec = revsetlang.formatspec('rev(%d)', spec) |
|
493 | spec = revsetlang.formatspec('rev(%d)', spec) | |
494 | allspecs.append(spec) |
|
494 | allspecs.append(spec) | |
495 | return repo.anyrevs(allspecs, user=True, localalias=localalias) |
|
495 | return repo.anyrevs(allspecs, user=True, localalias=localalias) | |
496 |
|
496 | |||
497 | def meaningfulparents(repo, ctx): |
|
497 | def meaningfulparents(repo, ctx): | |
498 | """Return list of meaningful (or all if debug) parentrevs for rev. |
|
498 | """Return list of meaningful (or all if debug) parentrevs for rev. | |
499 |
|
499 | |||
500 | For merges (two non-nullrev revisions) both parents are meaningful. |
|
500 | For merges (two non-nullrev revisions) both parents are meaningful. | |
501 | Otherwise the first parent revision is considered meaningful if it |
|
501 | Otherwise the first parent revision is considered meaningful if it | |
502 | is not the preceding revision. |
|
502 | is not the preceding revision. | |
503 | """ |
|
503 | """ | |
504 | parents = ctx.parents() |
|
504 | parents = ctx.parents() | |
505 | if len(parents) > 1: |
|
505 | if len(parents) > 1: | |
506 | return parents |
|
506 | return parents | |
507 | if repo.ui.debugflag: |
|
507 | if repo.ui.debugflag: | |
508 | return [parents[0], repo['null']] |
|
508 | return [parents[0], repo['null']] | |
509 | if parents[0].rev() >= intrev(ctx) - 1: |
|
509 | if parents[0].rev() >= intrev(ctx) - 1: | |
510 | return [] |
|
510 | return [] | |
511 | return parents |
|
511 | return parents | |
512 |
|
512 | |||
513 | def expandpats(pats): |
|
513 | def expandpats(pats): | |
514 | '''Expand bare globs when running on windows. |
|
514 | '''Expand bare globs when running on windows. | |
515 | On posix we assume it already has already been done by sh.''' |
|
515 | On posix we assume it already has already been done by sh.''' | |
516 | if not util.expandglobs: |
|
516 | if not util.expandglobs: | |
517 | return list(pats) |
|
517 | return list(pats) | |
518 | ret = [] |
|
518 | ret = [] | |
519 | for kindpat in pats: |
|
519 | for kindpat in pats: | |
520 | kind, pat = matchmod._patsplit(kindpat, None) |
|
520 | kind, pat = matchmod._patsplit(kindpat, None) | |
521 | if kind is None: |
|
521 | if kind is None: | |
522 | try: |
|
522 | try: | |
523 | globbed = glob.glob(pat) |
|
523 | globbed = glob.glob(pat) | |
524 | except re.error: |
|
524 | except re.error: | |
525 | globbed = [pat] |
|
525 | globbed = [pat] | |
526 | if globbed: |
|
526 | if globbed: | |
527 | ret.extend(globbed) |
|
527 | ret.extend(globbed) | |
528 | continue |
|
528 | continue | |
529 | ret.append(kindpat) |
|
529 | ret.append(kindpat) | |
530 | return ret |
|
530 | return ret | |
531 |
|
531 | |||
532 | def matchandpats(ctx, pats=(), opts=None, globbed=False, default='relpath', |
|
532 | def matchandpats(ctx, pats=(), opts=None, globbed=False, default='relpath', | |
533 | badfn=None): |
|
533 | badfn=None): | |
534 | '''Return a matcher and the patterns that were used. |
|
534 | '''Return a matcher and the patterns that were used. | |
535 | The matcher will warn about bad matches, unless an alternate badfn callback |
|
535 | The matcher will warn about bad matches, unless an alternate badfn callback | |
536 | is provided.''' |
|
536 | is provided.''' | |
537 | if pats == ("",): |
|
537 | if pats == ("",): | |
538 | pats = [] |
|
538 | pats = [] | |
539 | if opts is None: |
|
539 | if opts is None: | |
540 | opts = {} |
|
540 | opts = {} | |
541 | if not globbed and default == 'relpath': |
|
541 | if not globbed and default == 'relpath': | |
542 | pats = expandpats(pats or []) |
|
542 | pats = expandpats(pats or []) | |
543 |
|
543 | |||
544 | def bad(f, msg): |
|
544 | def bad(f, msg): | |
545 | ctx.repo().ui.warn("%s: %s\n" % (m.rel(f), msg)) |
|
545 | ctx.repo().ui.warn("%s: %s\n" % (m.rel(f), msg)) | |
546 |
|
546 | |||
547 | if badfn is None: |
|
547 | if badfn is None: | |
548 | badfn = bad |
|
548 | badfn = bad | |
549 |
|
549 | |||
550 | m = ctx.match(pats, opts.get('include'), opts.get('exclude'), |
|
550 | m = ctx.match(pats, opts.get('include'), opts.get('exclude'), | |
551 | default, listsubrepos=opts.get('subrepos'), badfn=badfn) |
|
551 | default, listsubrepos=opts.get('subrepos'), badfn=badfn) | |
552 |
|
552 | |||
553 | if m.always(): |
|
553 | if m.always(): | |
554 | pats = [] |
|
554 | pats = [] | |
555 | return m, pats |
|
555 | return m, pats | |
556 |
|
556 | |||
557 | def match(ctx, pats=(), opts=None, globbed=False, default='relpath', |
|
557 | def match(ctx, pats=(), opts=None, globbed=False, default='relpath', | |
558 | badfn=None): |
|
558 | badfn=None): | |
559 | '''Return a matcher that will warn about bad matches.''' |
|
559 | '''Return a matcher that will warn about bad matches.''' | |
560 | return matchandpats(ctx, pats, opts, globbed, default, badfn=badfn)[0] |
|
560 | return matchandpats(ctx, pats, opts, globbed, default, badfn=badfn)[0] | |
561 |
|
561 | |||
562 | def matchall(repo): |
|
562 | def matchall(repo): | |
563 | '''Return a matcher that will efficiently match everything.''' |
|
563 | '''Return a matcher that will efficiently match everything.''' | |
564 | return matchmod.always(repo.root, repo.getcwd()) |
|
564 | return matchmod.always(repo.root, repo.getcwd()) | |
565 |
|
565 | |||
566 | def matchfiles(repo, files, badfn=None): |
|
566 | def matchfiles(repo, files, badfn=None): | |
567 | '''Return a matcher that will efficiently match exactly these files.''' |
|
567 | '''Return a matcher that will efficiently match exactly these files.''' | |
568 | return matchmod.exact(repo.root, repo.getcwd(), files, badfn=badfn) |
|
568 | return matchmod.exact(repo.root, repo.getcwd(), files, badfn=badfn) | |
569 |
|
569 | |||
|
570 | def parsefollowlinespattern(repo, rev, pat, msg): | |||
|
571 | """Return a file name from `pat` pattern suitable for usage in followlines | |||
|
572 | logic. | |||
|
573 | """ | |||
|
574 | if not matchmod.patkind(pat): | |||
|
575 | return pathutil.canonpath(repo.root, repo.getcwd(), pat) | |||
|
576 | else: | |||
|
577 | ctx = repo[rev] | |||
|
578 | m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=ctx) | |||
|
579 | files = [f for f in ctx if m(f)] | |||
|
580 | if len(files) != 1: | |||
|
581 | raise error.ParseError(msg) | |||
|
582 | return files[0] | |||
|
583 | ||||
570 | def origpath(ui, repo, filepath): |
|
584 | def origpath(ui, repo, filepath): | |
571 | '''customize where .orig files are created |
|
585 | '''customize where .orig files are created | |
572 |
|
586 | |||
573 | Fetch user defined path from config file: [ui] origbackuppath = <path> |
|
587 | Fetch user defined path from config file: [ui] origbackuppath = <path> | |
574 | Fall back to default (filepath with .orig suffix) if not specified |
|
588 | Fall back to default (filepath with .orig suffix) if not specified | |
575 | ''' |
|
589 | ''' | |
576 | origbackuppath = ui.config('ui', 'origbackuppath') |
|
590 | origbackuppath = ui.config('ui', 'origbackuppath') | |
577 | if not origbackuppath: |
|
591 | if not origbackuppath: | |
578 | return filepath + ".orig" |
|
592 | return filepath + ".orig" | |
579 |
|
593 | |||
580 | # Convert filepath from an absolute path into a path inside the repo. |
|
594 | # Convert filepath from an absolute path into a path inside the repo. | |
581 | filepathfromroot = util.normpath(os.path.relpath(filepath, |
|
595 | filepathfromroot = util.normpath(os.path.relpath(filepath, | |
582 | start=repo.root)) |
|
596 | start=repo.root)) | |
583 |
|
597 | |||
584 | origvfs = vfs.vfs(repo.wjoin(origbackuppath)) |
|
598 | origvfs = vfs.vfs(repo.wjoin(origbackuppath)) | |
585 | origbackupdir = origvfs.dirname(filepathfromroot) |
|
599 | origbackupdir = origvfs.dirname(filepathfromroot) | |
586 | if not origvfs.isdir(origbackupdir) or origvfs.islink(origbackupdir): |
|
600 | if not origvfs.isdir(origbackupdir) or origvfs.islink(origbackupdir): | |
587 | ui.note(_('creating directory: %s\n') % origvfs.join(origbackupdir)) |
|
601 | ui.note(_('creating directory: %s\n') % origvfs.join(origbackupdir)) | |
588 |
|
602 | |||
589 | # Remove any files that conflict with the backup file's path |
|
603 | # Remove any files that conflict with the backup file's path | |
590 | for f in reversed(list(util.finddirs(filepathfromroot))): |
|
604 | for f in reversed(list(util.finddirs(filepathfromroot))): | |
591 | if origvfs.isfileorlink(f): |
|
605 | if origvfs.isfileorlink(f): | |
592 | ui.note(_('removing conflicting file: %s\n') |
|
606 | ui.note(_('removing conflicting file: %s\n') | |
593 | % origvfs.join(f)) |
|
607 | % origvfs.join(f)) | |
594 | origvfs.unlink(f) |
|
608 | origvfs.unlink(f) | |
595 | break |
|
609 | break | |
596 |
|
610 | |||
597 | origvfs.makedirs(origbackupdir) |
|
611 | origvfs.makedirs(origbackupdir) | |
598 |
|
612 | |||
599 | if origvfs.isdir(filepathfromroot): |
|
613 | if origvfs.isdir(filepathfromroot): | |
600 | ui.note(_('removing conflicting directory: %s\n') |
|
614 | ui.note(_('removing conflicting directory: %s\n') | |
601 | % origvfs.join(filepathfromroot)) |
|
615 | % origvfs.join(filepathfromroot)) | |
602 | origvfs.rmtree(filepathfromroot, forcibly=True) |
|
616 | origvfs.rmtree(filepathfromroot, forcibly=True) | |
603 |
|
617 | |||
604 | return origvfs.join(filepathfromroot) |
|
618 | return origvfs.join(filepathfromroot) | |
605 |
|
619 | |||
606 | class _containsnode(object): |
|
620 | class _containsnode(object): | |
607 | """proxy __contains__(node) to container.__contains__ which accepts revs""" |
|
621 | """proxy __contains__(node) to container.__contains__ which accepts revs""" | |
608 |
|
622 | |||
609 | def __init__(self, repo, revcontainer): |
|
623 | def __init__(self, repo, revcontainer): | |
610 | self._torev = repo.changelog.rev |
|
624 | self._torev = repo.changelog.rev | |
611 | self._revcontains = revcontainer.__contains__ |
|
625 | self._revcontains = revcontainer.__contains__ | |
612 |
|
626 | |||
613 | def __contains__(self, node): |
|
627 | def __contains__(self, node): | |
614 | return self._revcontains(self._torev(node)) |
|
628 | return self._revcontains(self._torev(node)) | |
615 |
|
629 | |||
616 | def cleanupnodes(repo, replacements, operation, moves=None, metadata=None): |
|
630 | def cleanupnodes(repo, replacements, operation, moves=None, metadata=None): | |
617 | """do common cleanups when old nodes are replaced by new nodes |
|
631 | """do common cleanups when old nodes are replaced by new nodes | |
618 |
|
632 | |||
619 | That includes writing obsmarkers or stripping nodes, and moving bookmarks. |
|
633 | That includes writing obsmarkers or stripping nodes, and moving bookmarks. | |
620 | (we might also want to move working directory parent in the future) |
|
634 | (we might also want to move working directory parent in the future) | |
621 |
|
635 | |||
622 | By default, bookmark moves are calculated automatically from 'replacements', |
|
636 | By default, bookmark moves are calculated automatically from 'replacements', | |
623 | but 'moves' can be used to override that. Also, 'moves' may include |
|
637 | but 'moves' can be used to override that. Also, 'moves' may include | |
624 | additional bookmark moves that should not have associated obsmarkers. |
|
638 | additional bookmark moves that should not have associated obsmarkers. | |
625 |
|
639 | |||
626 | replacements is {oldnode: [newnode]} or a iterable of nodes if they do not |
|
640 | replacements is {oldnode: [newnode]} or a iterable of nodes if they do not | |
627 | have replacements. operation is a string, like "rebase". |
|
641 | have replacements. operation is a string, like "rebase". | |
628 |
|
642 | |||
629 | metadata is dictionary containing metadata to be stored in obsmarker if |
|
643 | metadata is dictionary containing metadata to be stored in obsmarker if | |
630 | obsolescence is enabled. |
|
644 | obsolescence is enabled. | |
631 | """ |
|
645 | """ | |
632 | if not replacements and not moves: |
|
646 | if not replacements and not moves: | |
633 | return |
|
647 | return | |
634 |
|
648 | |||
635 | # translate mapping's other forms |
|
649 | # translate mapping's other forms | |
636 | if not util.safehasattr(replacements, 'items'): |
|
650 | if not util.safehasattr(replacements, 'items'): | |
637 | replacements = {n: () for n in replacements} |
|
651 | replacements = {n: () for n in replacements} | |
638 |
|
652 | |||
639 | # Calculate bookmark movements |
|
653 | # Calculate bookmark movements | |
640 | if moves is None: |
|
654 | if moves is None: | |
641 | moves = {} |
|
655 | moves = {} | |
642 | # Unfiltered repo is needed since nodes in replacements might be hidden. |
|
656 | # Unfiltered repo is needed since nodes in replacements might be hidden. | |
643 | unfi = repo.unfiltered() |
|
657 | unfi = repo.unfiltered() | |
644 | for oldnode, newnodes in replacements.items(): |
|
658 | for oldnode, newnodes in replacements.items(): | |
645 | if oldnode in moves: |
|
659 | if oldnode in moves: | |
646 | continue |
|
660 | continue | |
647 | if len(newnodes) > 1: |
|
661 | if len(newnodes) > 1: | |
648 | # usually a split, take the one with biggest rev number |
|
662 | # usually a split, take the one with biggest rev number | |
649 | newnode = next(unfi.set('max(%ln)', newnodes)).node() |
|
663 | newnode = next(unfi.set('max(%ln)', newnodes)).node() | |
650 | elif len(newnodes) == 0: |
|
664 | elif len(newnodes) == 0: | |
651 | # move bookmark backwards |
|
665 | # move bookmark backwards | |
652 | roots = list(unfi.set('max((::%n) - %ln)', oldnode, |
|
666 | roots = list(unfi.set('max((::%n) - %ln)', oldnode, | |
653 | list(replacements))) |
|
667 | list(replacements))) | |
654 | if roots: |
|
668 | if roots: | |
655 | newnode = roots[0].node() |
|
669 | newnode = roots[0].node() | |
656 | else: |
|
670 | else: | |
657 | newnode = nullid |
|
671 | newnode = nullid | |
658 | else: |
|
672 | else: | |
659 | newnode = newnodes[0] |
|
673 | newnode = newnodes[0] | |
660 | moves[oldnode] = newnode |
|
674 | moves[oldnode] = newnode | |
661 |
|
675 | |||
662 | with repo.transaction('cleanup') as tr: |
|
676 | with repo.transaction('cleanup') as tr: | |
663 | # Move bookmarks |
|
677 | # Move bookmarks | |
664 | bmarks = repo._bookmarks |
|
678 | bmarks = repo._bookmarks | |
665 | bmarkchanges = [] |
|
679 | bmarkchanges = [] | |
666 | allnewnodes = [n for ns in replacements.values() for n in ns] |
|
680 | allnewnodes = [n for ns in replacements.values() for n in ns] | |
667 | for oldnode, newnode in moves.items(): |
|
681 | for oldnode, newnode in moves.items(): | |
668 | oldbmarks = repo.nodebookmarks(oldnode) |
|
682 | oldbmarks = repo.nodebookmarks(oldnode) | |
669 | if not oldbmarks: |
|
683 | if not oldbmarks: | |
670 | continue |
|
684 | continue | |
671 | from . import bookmarks # avoid import cycle |
|
685 | from . import bookmarks # avoid import cycle | |
672 | repo.ui.debug('moving bookmarks %r from %s to %s\n' % |
|
686 | repo.ui.debug('moving bookmarks %r from %s to %s\n' % | |
673 | (oldbmarks, hex(oldnode), hex(newnode))) |
|
687 | (oldbmarks, hex(oldnode), hex(newnode))) | |
674 | # Delete divergent bookmarks being parents of related newnodes |
|
688 | # Delete divergent bookmarks being parents of related newnodes | |
675 | deleterevs = repo.revs('parents(roots(%ln & (::%n))) - parents(%n)', |
|
689 | deleterevs = repo.revs('parents(roots(%ln & (::%n))) - parents(%n)', | |
676 | allnewnodes, newnode, oldnode) |
|
690 | allnewnodes, newnode, oldnode) | |
677 | deletenodes = _containsnode(repo, deleterevs) |
|
691 | deletenodes = _containsnode(repo, deleterevs) | |
678 | for name in oldbmarks: |
|
692 | for name in oldbmarks: | |
679 | bmarkchanges.append((name, newnode)) |
|
693 | bmarkchanges.append((name, newnode)) | |
680 | for b in bookmarks.divergent2delete(repo, deletenodes, name): |
|
694 | for b in bookmarks.divergent2delete(repo, deletenodes, name): | |
681 | bmarkchanges.append((b, None)) |
|
695 | bmarkchanges.append((b, None)) | |
682 |
|
696 | |||
683 | if bmarkchanges: |
|
697 | if bmarkchanges: | |
684 | bmarks.applychanges(repo, tr, bmarkchanges) |
|
698 | bmarks.applychanges(repo, tr, bmarkchanges) | |
685 |
|
699 | |||
686 | # Obsolete or strip nodes |
|
700 | # Obsolete or strip nodes | |
687 | if obsolete.isenabled(repo, obsolete.createmarkersopt): |
|
701 | if obsolete.isenabled(repo, obsolete.createmarkersopt): | |
688 | # If a node is already obsoleted, and we want to obsolete it |
|
702 | # If a node is already obsoleted, and we want to obsolete it | |
689 | # without a successor, skip that obssolete request since it's |
|
703 | # without a successor, skip that obssolete request since it's | |
690 | # unnecessary. That's the "if s or not isobs(n)" check below. |
|
704 | # unnecessary. That's the "if s or not isobs(n)" check below. | |
691 | # Also sort the node in topology order, that might be useful for |
|
705 | # Also sort the node in topology order, that might be useful for | |
692 | # some obsstore logic. |
|
706 | # some obsstore logic. | |
693 | # NOTE: the filtering and sorting might belong to createmarkers. |
|
707 | # NOTE: the filtering and sorting might belong to createmarkers. | |
694 | isobs = unfi.obsstore.successors.__contains__ |
|
708 | isobs = unfi.obsstore.successors.__contains__ | |
695 | torev = unfi.changelog.rev |
|
709 | torev = unfi.changelog.rev | |
696 | sortfunc = lambda ns: torev(ns[0]) |
|
710 | sortfunc = lambda ns: torev(ns[0]) | |
697 | rels = [(unfi[n], tuple(unfi[m] for m in s)) |
|
711 | rels = [(unfi[n], tuple(unfi[m] for m in s)) | |
698 | for n, s in sorted(replacements.items(), key=sortfunc) |
|
712 | for n, s in sorted(replacements.items(), key=sortfunc) | |
699 | if s or not isobs(n)] |
|
713 | if s or not isobs(n)] | |
700 | if rels: |
|
714 | if rels: | |
701 | obsolete.createmarkers(repo, rels, operation=operation, |
|
715 | obsolete.createmarkers(repo, rels, operation=operation, | |
702 | metadata=metadata) |
|
716 | metadata=metadata) | |
703 | else: |
|
717 | else: | |
704 | from . import repair # avoid import cycle |
|
718 | from . import repair # avoid import cycle | |
705 | tostrip = list(replacements) |
|
719 | tostrip = list(replacements) | |
706 | if tostrip: |
|
720 | if tostrip: | |
707 | repair.delayedstrip(repo.ui, repo, tostrip, operation) |
|
721 | repair.delayedstrip(repo.ui, repo, tostrip, operation) | |
708 |
|
722 | |||
709 | def addremove(repo, matcher, prefix, opts=None, dry_run=None, similarity=None): |
|
723 | def addremove(repo, matcher, prefix, opts=None, dry_run=None, similarity=None): | |
710 | if opts is None: |
|
724 | if opts is None: | |
711 | opts = {} |
|
725 | opts = {} | |
712 | m = matcher |
|
726 | m = matcher | |
713 | if dry_run is None: |
|
727 | if dry_run is None: | |
714 | dry_run = opts.get('dry_run') |
|
728 | dry_run = opts.get('dry_run') | |
715 | if similarity is None: |
|
729 | if similarity is None: | |
716 | similarity = float(opts.get('similarity') or 0) |
|
730 | similarity = float(opts.get('similarity') or 0) | |
717 |
|
731 | |||
718 | ret = 0 |
|
732 | ret = 0 | |
719 | join = lambda f: os.path.join(prefix, f) |
|
733 | join = lambda f: os.path.join(prefix, f) | |
720 |
|
734 | |||
721 | wctx = repo[None] |
|
735 | wctx = repo[None] | |
722 | for subpath in sorted(wctx.substate): |
|
736 | for subpath in sorted(wctx.substate): | |
723 | submatch = matchmod.subdirmatcher(subpath, m) |
|
737 | submatch = matchmod.subdirmatcher(subpath, m) | |
724 | if opts.get('subrepos') or m.exact(subpath) or any(submatch.files()): |
|
738 | if opts.get('subrepos') or m.exact(subpath) or any(submatch.files()): | |
725 | sub = wctx.sub(subpath) |
|
739 | sub = wctx.sub(subpath) | |
726 | try: |
|
740 | try: | |
727 | if sub.addremove(submatch, prefix, opts, dry_run, similarity): |
|
741 | if sub.addremove(submatch, prefix, opts, dry_run, similarity): | |
728 | ret = 1 |
|
742 | ret = 1 | |
729 | except error.LookupError: |
|
743 | except error.LookupError: | |
730 | repo.ui.status(_("skipping missing subrepository: %s\n") |
|
744 | repo.ui.status(_("skipping missing subrepository: %s\n") | |
731 | % join(subpath)) |
|
745 | % join(subpath)) | |
732 |
|
746 | |||
733 | rejected = [] |
|
747 | rejected = [] | |
734 | def badfn(f, msg): |
|
748 | def badfn(f, msg): | |
735 | if f in m.files(): |
|
749 | if f in m.files(): | |
736 | m.bad(f, msg) |
|
750 | m.bad(f, msg) | |
737 | rejected.append(f) |
|
751 | rejected.append(f) | |
738 |
|
752 | |||
739 | badmatch = matchmod.badmatch(m, badfn) |
|
753 | badmatch = matchmod.badmatch(m, badfn) | |
740 | added, unknown, deleted, removed, forgotten = _interestingfiles(repo, |
|
754 | added, unknown, deleted, removed, forgotten = _interestingfiles(repo, | |
741 | badmatch) |
|
755 | badmatch) | |
742 |
|
756 | |||
743 | unknownset = set(unknown + forgotten) |
|
757 | unknownset = set(unknown + forgotten) | |
744 | toprint = unknownset.copy() |
|
758 | toprint = unknownset.copy() | |
745 | toprint.update(deleted) |
|
759 | toprint.update(deleted) | |
746 | for abs in sorted(toprint): |
|
760 | for abs in sorted(toprint): | |
747 | if repo.ui.verbose or not m.exact(abs): |
|
761 | if repo.ui.verbose or not m.exact(abs): | |
748 | if abs in unknownset: |
|
762 | if abs in unknownset: | |
749 | status = _('adding %s\n') % m.uipath(abs) |
|
763 | status = _('adding %s\n') % m.uipath(abs) | |
750 | else: |
|
764 | else: | |
751 | status = _('removing %s\n') % m.uipath(abs) |
|
765 | status = _('removing %s\n') % m.uipath(abs) | |
752 | repo.ui.status(status) |
|
766 | repo.ui.status(status) | |
753 |
|
767 | |||
754 | renames = _findrenames(repo, m, added + unknown, removed + deleted, |
|
768 | renames = _findrenames(repo, m, added + unknown, removed + deleted, | |
755 | similarity) |
|
769 | similarity) | |
756 |
|
770 | |||
757 | if not dry_run: |
|
771 | if not dry_run: | |
758 | _markchanges(repo, unknown + forgotten, deleted, renames) |
|
772 | _markchanges(repo, unknown + forgotten, deleted, renames) | |
759 |
|
773 | |||
760 | for f in rejected: |
|
774 | for f in rejected: | |
761 | if f in m.files(): |
|
775 | if f in m.files(): | |
762 | return 1 |
|
776 | return 1 | |
763 | return ret |
|
777 | return ret | |
764 |
|
778 | |||
765 | def marktouched(repo, files, similarity=0.0): |
|
779 | def marktouched(repo, files, similarity=0.0): | |
766 | '''Assert that files have somehow been operated upon. files are relative to |
|
780 | '''Assert that files have somehow been operated upon. files are relative to | |
767 | the repo root.''' |
|
781 | the repo root.''' | |
768 | m = matchfiles(repo, files, badfn=lambda x, y: rejected.append(x)) |
|
782 | m = matchfiles(repo, files, badfn=lambda x, y: rejected.append(x)) | |
769 | rejected = [] |
|
783 | rejected = [] | |
770 |
|
784 | |||
771 | added, unknown, deleted, removed, forgotten = _interestingfiles(repo, m) |
|
785 | added, unknown, deleted, removed, forgotten = _interestingfiles(repo, m) | |
772 |
|
786 | |||
773 | if repo.ui.verbose: |
|
787 | if repo.ui.verbose: | |
774 | unknownset = set(unknown + forgotten) |
|
788 | unknownset = set(unknown + forgotten) | |
775 | toprint = unknownset.copy() |
|
789 | toprint = unknownset.copy() | |
776 | toprint.update(deleted) |
|
790 | toprint.update(deleted) | |
777 | for abs in sorted(toprint): |
|
791 | for abs in sorted(toprint): | |
778 | if abs in unknownset: |
|
792 | if abs in unknownset: | |
779 | status = _('adding %s\n') % abs |
|
793 | status = _('adding %s\n') % abs | |
780 | else: |
|
794 | else: | |
781 | status = _('removing %s\n') % abs |
|
795 | status = _('removing %s\n') % abs | |
782 | repo.ui.status(status) |
|
796 | repo.ui.status(status) | |
783 |
|
797 | |||
784 | renames = _findrenames(repo, m, added + unknown, removed + deleted, |
|
798 | renames = _findrenames(repo, m, added + unknown, removed + deleted, | |
785 | similarity) |
|
799 | similarity) | |
786 |
|
800 | |||
787 | _markchanges(repo, unknown + forgotten, deleted, renames) |
|
801 | _markchanges(repo, unknown + forgotten, deleted, renames) | |
788 |
|
802 | |||
789 | for f in rejected: |
|
803 | for f in rejected: | |
790 | if f in m.files(): |
|
804 | if f in m.files(): | |
791 | return 1 |
|
805 | return 1 | |
792 | return 0 |
|
806 | return 0 | |
793 |
|
807 | |||
794 | def _interestingfiles(repo, matcher): |
|
808 | def _interestingfiles(repo, matcher): | |
795 | '''Walk dirstate with matcher, looking for files that addremove would care |
|
809 | '''Walk dirstate with matcher, looking for files that addremove would care | |
796 | about. |
|
810 | about. | |
797 |
|
811 | |||
798 | This is different from dirstate.status because it doesn't care about |
|
812 | This is different from dirstate.status because it doesn't care about | |
799 | whether files are modified or clean.''' |
|
813 | whether files are modified or clean.''' | |
800 | added, unknown, deleted, removed, forgotten = [], [], [], [], [] |
|
814 | added, unknown, deleted, removed, forgotten = [], [], [], [], [] | |
801 | audit_path = pathutil.pathauditor(repo.root, cached=True) |
|
815 | audit_path = pathutil.pathauditor(repo.root, cached=True) | |
802 |
|
816 | |||
803 | ctx = repo[None] |
|
817 | ctx = repo[None] | |
804 | dirstate = repo.dirstate |
|
818 | dirstate = repo.dirstate | |
805 | walkresults = dirstate.walk(matcher, subrepos=sorted(ctx.substate), |
|
819 | walkresults = dirstate.walk(matcher, subrepos=sorted(ctx.substate), | |
806 | unknown=True, ignored=False, full=False) |
|
820 | unknown=True, ignored=False, full=False) | |
807 | for abs, st in walkresults.iteritems(): |
|
821 | for abs, st in walkresults.iteritems(): | |
808 | dstate = dirstate[abs] |
|
822 | dstate = dirstate[abs] | |
809 | if dstate == '?' and audit_path.check(abs): |
|
823 | if dstate == '?' and audit_path.check(abs): | |
810 | unknown.append(abs) |
|
824 | unknown.append(abs) | |
811 | elif dstate != 'r' and not st: |
|
825 | elif dstate != 'r' and not st: | |
812 | deleted.append(abs) |
|
826 | deleted.append(abs) | |
813 | elif dstate == 'r' and st: |
|
827 | elif dstate == 'r' and st: | |
814 | forgotten.append(abs) |
|
828 | forgotten.append(abs) | |
815 | # for finding renames |
|
829 | # for finding renames | |
816 | elif dstate == 'r' and not st: |
|
830 | elif dstate == 'r' and not st: | |
817 | removed.append(abs) |
|
831 | removed.append(abs) | |
818 | elif dstate == 'a': |
|
832 | elif dstate == 'a': | |
819 | added.append(abs) |
|
833 | added.append(abs) | |
820 |
|
834 | |||
821 | return added, unknown, deleted, removed, forgotten |
|
835 | return added, unknown, deleted, removed, forgotten | |
822 |
|
836 | |||
823 | def _findrenames(repo, matcher, added, removed, similarity): |
|
837 | def _findrenames(repo, matcher, added, removed, similarity): | |
824 | '''Find renames from removed files to added ones.''' |
|
838 | '''Find renames from removed files to added ones.''' | |
825 | renames = {} |
|
839 | renames = {} | |
826 | if similarity > 0: |
|
840 | if similarity > 0: | |
827 | for old, new, score in similar.findrenames(repo, added, removed, |
|
841 | for old, new, score in similar.findrenames(repo, added, removed, | |
828 | similarity): |
|
842 | similarity): | |
829 | if (repo.ui.verbose or not matcher.exact(old) |
|
843 | if (repo.ui.verbose or not matcher.exact(old) | |
830 | or not matcher.exact(new)): |
|
844 | or not matcher.exact(new)): | |
831 | repo.ui.status(_('recording removal of %s as rename to %s ' |
|
845 | repo.ui.status(_('recording removal of %s as rename to %s ' | |
832 | '(%d%% similar)\n') % |
|
846 | '(%d%% similar)\n') % | |
833 | (matcher.rel(old), matcher.rel(new), |
|
847 | (matcher.rel(old), matcher.rel(new), | |
834 | score * 100)) |
|
848 | score * 100)) | |
835 | renames[new] = old |
|
849 | renames[new] = old | |
836 | return renames |
|
850 | return renames | |
837 |
|
851 | |||
838 | def _markchanges(repo, unknown, deleted, renames): |
|
852 | def _markchanges(repo, unknown, deleted, renames): | |
839 | '''Marks the files in unknown as added, the files in deleted as removed, |
|
853 | '''Marks the files in unknown as added, the files in deleted as removed, | |
840 | and the files in renames as copied.''' |
|
854 | and the files in renames as copied.''' | |
841 | wctx = repo[None] |
|
855 | wctx = repo[None] | |
842 | with repo.wlock(): |
|
856 | with repo.wlock(): | |
843 | wctx.forget(deleted) |
|
857 | wctx.forget(deleted) | |
844 | wctx.add(unknown) |
|
858 | wctx.add(unknown) | |
845 | for new, old in renames.iteritems(): |
|
859 | for new, old in renames.iteritems(): | |
846 | wctx.copy(old, new) |
|
860 | wctx.copy(old, new) | |
847 |
|
861 | |||
848 | def dirstatecopy(ui, repo, wctx, src, dst, dryrun=False, cwd=None): |
|
862 | def dirstatecopy(ui, repo, wctx, src, dst, dryrun=False, cwd=None): | |
849 | """Update the dirstate to reflect the intent of copying src to dst. For |
|
863 | """Update the dirstate to reflect the intent of copying src to dst. For | |
850 | different reasons it might not end with dst being marked as copied from src. |
|
864 | different reasons it might not end with dst being marked as copied from src. | |
851 | """ |
|
865 | """ | |
852 | origsrc = repo.dirstate.copied(src) or src |
|
866 | origsrc = repo.dirstate.copied(src) or src | |
853 | if dst == origsrc: # copying back a copy? |
|
867 | if dst == origsrc: # copying back a copy? | |
854 | if repo.dirstate[dst] not in 'mn' and not dryrun: |
|
868 | if repo.dirstate[dst] not in 'mn' and not dryrun: | |
855 | repo.dirstate.normallookup(dst) |
|
869 | repo.dirstate.normallookup(dst) | |
856 | else: |
|
870 | else: | |
857 | if repo.dirstate[origsrc] == 'a' and origsrc == src: |
|
871 | if repo.dirstate[origsrc] == 'a' and origsrc == src: | |
858 | if not ui.quiet: |
|
872 | if not ui.quiet: | |
859 | ui.warn(_("%s has not been committed yet, so no copy " |
|
873 | ui.warn(_("%s has not been committed yet, so no copy " | |
860 | "data will be stored for %s.\n") |
|
874 | "data will be stored for %s.\n") | |
861 | % (repo.pathto(origsrc, cwd), repo.pathto(dst, cwd))) |
|
875 | % (repo.pathto(origsrc, cwd), repo.pathto(dst, cwd))) | |
862 | if repo.dirstate[dst] in '?r' and not dryrun: |
|
876 | if repo.dirstate[dst] in '?r' and not dryrun: | |
863 | wctx.add([dst]) |
|
877 | wctx.add([dst]) | |
864 | elif not dryrun: |
|
878 | elif not dryrun: | |
865 | wctx.copy(origsrc, dst) |
|
879 | wctx.copy(origsrc, dst) | |
866 |
|
880 | |||
867 | def readrequires(opener, supported): |
|
881 | def readrequires(opener, supported): | |
868 | '''Reads and parses .hg/requires and checks if all entries found |
|
882 | '''Reads and parses .hg/requires and checks if all entries found | |
869 | are in the list of supported features.''' |
|
883 | are in the list of supported features.''' | |
870 | requirements = set(opener.read("requires").splitlines()) |
|
884 | requirements = set(opener.read("requires").splitlines()) | |
871 | missings = [] |
|
885 | missings = [] | |
872 | for r in requirements: |
|
886 | for r in requirements: | |
873 | if r not in supported: |
|
887 | if r not in supported: | |
874 | if not r or not r[0].isalnum(): |
|
888 | if not r or not r[0].isalnum(): | |
875 | raise error.RequirementError(_(".hg/requires file is corrupt")) |
|
889 | raise error.RequirementError(_(".hg/requires file is corrupt")) | |
876 | missings.append(r) |
|
890 | missings.append(r) | |
877 | missings.sort() |
|
891 | missings.sort() | |
878 | if missings: |
|
892 | if missings: | |
879 | raise error.RequirementError( |
|
893 | raise error.RequirementError( | |
880 | _("repository requires features unknown to this Mercurial: %s") |
|
894 | _("repository requires features unknown to this Mercurial: %s") | |
881 | % " ".join(missings), |
|
895 | % " ".join(missings), | |
882 | hint=_("see https://mercurial-scm.org/wiki/MissingRequirement" |
|
896 | hint=_("see https://mercurial-scm.org/wiki/MissingRequirement" | |
883 | " for more information")) |
|
897 | " for more information")) | |
884 | return requirements |
|
898 | return requirements | |
885 |
|
899 | |||
886 | def writerequires(opener, requirements): |
|
900 | def writerequires(opener, requirements): | |
887 | with opener('requires', 'w') as fp: |
|
901 | with opener('requires', 'w') as fp: | |
888 | for r in sorted(requirements): |
|
902 | for r in sorted(requirements): | |
889 | fp.write("%s\n" % r) |
|
903 | fp.write("%s\n" % r) | |
890 |
|
904 | |||
891 | class filecachesubentry(object): |
|
905 | class filecachesubentry(object): | |
892 | def __init__(self, path, stat): |
|
906 | def __init__(self, path, stat): | |
893 | self.path = path |
|
907 | self.path = path | |
894 | self.cachestat = None |
|
908 | self.cachestat = None | |
895 | self._cacheable = None |
|
909 | self._cacheable = None | |
896 |
|
910 | |||
897 | if stat: |
|
911 | if stat: | |
898 | self.cachestat = filecachesubentry.stat(self.path) |
|
912 | self.cachestat = filecachesubentry.stat(self.path) | |
899 |
|
913 | |||
900 | if self.cachestat: |
|
914 | if self.cachestat: | |
901 | self._cacheable = self.cachestat.cacheable() |
|
915 | self._cacheable = self.cachestat.cacheable() | |
902 | else: |
|
916 | else: | |
903 | # None means we don't know yet |
|
917 | # None means we don't know yet | |
904 | self._cacheable = None |
|
918 | self._cacheable = None | |
905 |
|
919 | |||
906 | def refresh(self): |
|
920 | def refresh(self): | |
907 | if self.cacheable(): |
|
921 | if self.cacheable(): | |
908 | self.cachestat = filecachesubentry.stat(self.path) |
|
922 | self.cachestat = filecachesubentry.stat(self.path) | |
909 |
|
923 | |||
910 | def cacheable(self): |
|
924 | def cacheable(self): | |
911 | if self._cacheable is not None: |
|
925 | if self._cacheable is not None: | |
912 | return self._cacheable |
|
926 | return self._cacheable | |
913 |
|
927 | |||
914 | # we don't know yet, assume it is for now |
|
928 | # we don't know yet, assume it is for now | |
915 | return True |
|
929 | return True | |
916 |
|
930 | |||
917 | def changed(self): |
|
931 | def changed(self): | |
918 | # no point in going further if we can't cache it |
|
932 | # no point in going further if we can't cache it | |
919 | if not self.cacheable(): |
|
933 | if not self.cacheable(): | |
920 | return True |
|
934 | return True | |
921 |
|
935 | |||
922 | newstat = filecachesubentry.stat(self.path) |
|
936 | newstat = filecachesubentry.stat(self.path) | |
923 |
|
937 | |||
924 | # we may not know if it's cacheable yet, check again now |
|
938 | # we may not know if it's cacheable yet, check again now | |
925 | if newstat and self._cacheable is None: |
|
939 | if newstat and self._cacheable is None: | |
926 | self._cacheable = newstat.cacheable() |
|
940 | self._cacheable = newstat.cacheable() | |
927 |
|
941 | |||
928 | # check again |
|
942 | # check again | |
929 | if not self._cacheable: |
|
943 | if not self._cacheable: | |
930 | return True |
|
944 | return True | |
931 |
|
945 | |||
932 | if self.cachestat != newstat: |
|
946 | if self.cachestat != newstat: | |
933 | self.cachestat = newstat |
|
947 | self.cachestat = newstat | |
934 | return True |
|
948 | return True | |
935 | else: |
|
949 | else: | |
936 | return False |
|
950 | return False | |
937 |
|
951 | |||
938 | @staticmethod |
|
952 | @staticmethod | |
939 | def stat(path): |
|
953 | def stat(path): | |
940 | try: |
|
954 | try: | |
941 | return util.cachestat(path) |
|
955 | return util.cachestat(path) | |
942 | except OSError as e: |
|
956 | except OSError as e: | |
943 | if e.errno != errno.ENOENT: |
|
957 | if e.errno != errno.ENOENT: | |
944 | raise |
|
958 | raise | |
945 |
|
959 | |||
946 | class filecacheentry(object): |
|
960 | class filecacheentry(object): | |
947 | def __init__(self, paths, stat=True): |
|
961 | def __init__(self, paths, stat=True): | |
948 | self._entries = [] |
|
962 | self._entries = [] | |
949 | for path in paths: |
|
963 | for path in paths: | |
950 | self._entries.append(filecachesubentry(path, stat)) |
|
964 | self._entries.append(filecachesubentry(path, stat)) | |
951 |
|
965 | |||
952 | def changed(self): |
|
966 | def changed(self): | |
953 | '''true if any entry has changed''' |
|
967 | '''true if any entry has changed''' | |
954 | for entry in self._entries: |
|
968 | for entry in self._entries: | |
955 | if entry.changed(): |
|
969 | if entry.changed(): | |
956 | return True |
|
970 | return True | |
957 | return False |
|
971 | return False | |
958 |
|
972 | |||
959 | def refresh(self): |
|
973 | def refresh(self): | |
960 | for entry in self._entries: |
|
974 | for entry in self._entries: | |
961 | entry.refresh() |
|
975 | entry.refresh() | |
962 |
|
976 | |||
963 | class filecache(object): |
|
977 | class filecache(object): | |
964 | '''A property like decorator that tracks files under .hg/ for updates. |
|
978 | '''A property like decorator that tracks files under .hg/ for updates. | |
965 |
|
979 | |||
966 | Records stat info when called in _filecache. |
|
980 | Records stat info when called in _filecache. | |
967 |
|
981 | |||
968 | On subsequent calls, compares old stat info with new info, and recreates the |
|
982 | On subsequent calls, compares old stat info with new info, and recreates the | |
969 | object when any of the files changes, updating the new stat info in |
|
983 | object when any of the files changes, updating the new stat info in | |
970 | _filecache. |
|
984 | _filecache. | |
971 |
|
985 | |||
972 | Mercurial either atomic renames or appends for files under .hg, |
|
986 | Mercurial either atomic renames or appends for files under .hg, | |
973 | so to ensure the cache is reliable we need the filesystem to be able |
|
987 | so to ensure the cache is reliable we need the filesystem to be able | |
974 | to tell us if a file has been replaced. If it can't, we fallback to |
|
988 | to tell us if a file has been replaced. If it can't, we fallback to | |
975 | recreating the object on every call (essentially the same behavior as |
|
989 | recreating the object on every call (essentially the same behavior as | |
976 | propertycache). |
|
990 | propertycache). | |
977 |
|
991 | |||
978 | ''' |
|
992 | ''' | |
979 | def __init__(self, *paths): |
|
993 | def __init__(self, *paths): | |
980 | self.paths = paths |
|
994 | self.paths = paths | |
981 |
|
995 | |||
982 | def join(self, obj, fname): |
|
996 | def join(self, obj, fname): | |
983 | """Used to compute the runtime path of a cached file. |
|
997 | """Used to compute the runtime path of a cached file. | |
984 |
|
998 | |||
985 | Users should subclass filecache and provide their own version of this |
|
999 | Users should subclass filecache and provide their own version of this | |
986 | function to call the appropriate join function on 'obj' (an instance |
|
1000 | function to call the appropriate join function on 'obj' (an instance | |
987 | of the class that its member function was decorated). |
|
1001 | of the class that its member function was decorated). | |
988 | """ |
|
1002 | """ | |
989 | raise NotImplementedError |
|
1003 | raise NotImplementedError | |
990 |
|
1004 | |||
991 | def __call__(self, func): |
|
1005 | def __call__(self, func): | |
992 | self.func = func |
|
1006 | self.func = func | |
993 | self.name = func.__name__.encode('ascii') |
|
1007 | self.name = func.__name__.encode('ascii') | |
994 | return self |
|
1008 | return self | |
995 |
|
1009 | |||
996 | def __get__(self, obj, type=None): |
|
1010 | def __get__(self, obj, type=None): | |
997 | # if accessed on the class, return the descriptor itself. |
|
1011 | # if accessed on the class, return the descriptor itself. | |
998 | if obj is None: |
|
1012 | if obj is None: | |
999 | return self |
|
1013 | return self | |
1000 | # do we need to check if the file changed? |
|
1014 | # do we need to check if the file changed? | |
1001 | if self.name in obj.__dict__: |
|
1015 | if self.name in obj.__dict__: | |
1002 | assert self.name in obj._filecache, self.name |
|
1016 | assert self.name in obj._filecache, self.name | |
1003 | return obj.__dict__[self.name] |
|
1017 | return obj.__dict__[self.name] | |
1004 |
|
1018 | |||
1005 | entry = obj._filecache.get(self.name) |
|
1019 | entry = obj._filecache.get(self.name) | |
1006 |
|
1020 | |||
1007 | if entry: |
|
1021 | if entry: | |
1008 | if entry.changed(): |
|
1022 | if entry.changed(): | |
1009 | entry.obj = self.func(obj) |
|
1023 | entry.obj = self.func(obj) | |
1010 | else: |
|
1024 | else: | |
1011 | paths = [self.join(obj, path) for path in self.paths] |
|
1025 | paths = [self.join(obj, path) for path in self.paths] | |
1012 |
|
1026 | |||
1013 | # We stat -before- creating the object so our cache doesn't lie if |
|
1027 | # We stat -before- creating the object so our cache doesn't lie if | |
1014 | # a writer modified between the time we read and stat |
|
1028 | # a writer modified between the time we read and stat | |
1015 | entry = filecacheentry(paths, True) |
|
1029 | entry = filecacheentry(paths, True) | |
1016 | entry.obj = self.func(obj) |
|
1030 | entry.obj = self.func(obj) | |
1017 |
|
1031 | |||
1018 | obj._filecache[self.name] = entry |
|
1032 | obj._filecache[self.name] = entry | |
1019 |
|
1033 | |||
1020 | obj.__dict__[self.name] = entry.obj |
|
1034 | obj.__dict__[self.name] = entry.obj | |
1021 | return entry.obj |
|
1035 | return entry.obj | |
1022 |
|
1036 | |||
1023 | def __set__(self, obj, value): |
|
1037 | def __set__(self, obj, value): | |
1024 | if self.name not in obj._filecache: |
|
1038 | if self.name not in obj._filecache: | |
1025 | # we add an entry for the missing value because X in __dict__ |
|
1039 | # we add an entry for the missing value because X in __dict__ | |
1026 | # implies X in _filecache |
|
1040 | # implies X in _filecache | |
1027 | paths = [self.join(obj, path) for path in self.paths] |
|
1041 | paths = [self.join(obj, path) for path in self.paths] | |
1028 | ce = filecacheentry(paths, False) |
|
1042 | ce = filecacheentry(paths, False) | |
1029 | obj._filecache[self.name] = ce |
|
1043 | obj._filecache[self.name] = ce | |
1030 | else: |
|
1044 | else: | |
1031 | ce = obj._filecache[self.name] |
|
1045 | ce = obj._filecache[self.name] | |
1032 |
|
1046 | |||
1033 | ce.obj = value # update cached copy |
|
1047 | ce.obj = value # update cached copy | |
1034 | obj.__dict__[self.name] = value # update copy returned by obj.x |
|
1048 | obj.__dict__[self.name] = value # update copy returned by obj.x | |
1035 |
|
1049 | |||
1036 | def __delete__(self, obj): |
|
1050 | def __delete__(self, obj): | |
1037 | try: |
|
1051 | try: | |
1038 | del obj.__dict__[self.name] |
|
1052 | del obj.__dict__[self.name] | |
1039 | except KeyError: |
|
1053 | except KeyError: | |
1040 | raise AttributeError(self.name) |
|
1054 | raise AttributeError(self.name) | |
1041 |
|
1055 | |||
1042 | def extdatasource(repo, source): |
|
1056 | def extdatasource(repo, source): | |
1043 | """Gather a map of rev -> value dict from the specified source |
|
1057 | """Gather a map of rev -> value dict from the specified source | |
1044 |
|
1058 | |||
1045 | A source spec is treated as a URL, with a special case shell: type |
|
1059 | A source spec is treated as a URL, with a special case shell: type | |
1046 | for parsing the output from a shell command. |
|
1060 | for parsing the output from a shell command. | |
1047 |
|
1061 | |||
1048 | The data is parsed as a series of newline-separated records where |
|
1062 | The data is parsed as a series of newline-separated records where | |
1049 | each record is a revision specifier optionally followed by a space |
|
1063 | each record is a revision specifier optionally followed by a space | |
1050 | and a freeform string value. If the revision is known locally, it |
|
1064 | and a freeform string value. If the revision is known locally, it | |
1051 | is converted to a rev, otherwise the record is skipped. |
|
1065 | is converted to a rev, otherwise the record is skipped. | |
1052 |
|
1066 | |||
1053 | Note that both key and value are treated as UTF-8 and converted to |
|
1067 | Note that both key and value are treated as UTF-8 and converted to | |
1054 | the local encoding. This allows uniformity between local and |
|
1068 | the local encoding. This allows uniformity between local and | |
1055 | remote data sources. |
|
1069 | remote data sources. | |
1056 | """ |
|
1070 | """ | |
1057 |
|
1071 | |||
1058 | spec = repo.ui.config("extdata", source) |
|
1072 | spec = repo.ui.config("extdata", source) | |
1059 | if not spec: |
|
1073 | if not spec: | |
1060 | raise error.Abort(_("unknown extdata source '%s'") % source) |
|
1074 | raise error.Abort(_("unknown extdata source '%s'") % source) | |
1061 |
|
1075 | |||
1062 | data = {} |
|
1076 | data = {} | |
1063 | src = proc = None |
|
1077 | src = proc = None | |
1064 | try: |
|
1078 | try: | |
1065 | if spec.startswith("shell:"): |
|
1079 | if spec.startswith("shell:"): | |
1066 | # external commands should be run relative to the repo root |
|
1080 | # external commands should be run relative to the repo root | |
1067 | cmd = spec[6:] |
|
1081 | cmd = spec[6:] | |
1068 | proc = subprocess.Popen(cmd, shell=True, bufsize=-1, |
|
1082 | proc = subprocess.Popen(cmd, shell=True, bufsize=-1, | |
1069 | close_fds=util.closefds, |
|
1083 | close_fds=util.closefds, | |
1070 | stdout=subprocess.PIPE, cwd=repo.root) |
|
1084 | stdout=subprocess.PIPE, cwd=repo.root) | |
1071 | src = proc.stdout |
|
1085 | src = proc.stdout | |
1072 | else: |
|
1086 | else: | |
1073 | # treat as a URL or file |
|
1087 | # treat as a URL or file | |
1074 | src = url.open(repo.ui, spec) |
|
1088 | src = url.open(repo.ui, spec) | |
1075 | for l in src: |
|
1089 | for l in src: | |
1076 | if " " in l: |
|
1090 | if " " in l: | |
1077 | k, v = l.strip().split(" ", 1) |
|
1091 | k, v = l.strip().split(" ", 1) | |
1078 | else: |
|
1092 | else: | |
1079 | k, v = l.strip(), "" |
|
1093 | k, v = l.strip(), "" | |
1080 |
|
1094 | |||
1081 | k = encoding.tolocal(k) |
|
1095 | k = encoding.tolocal(k) | |
1082 | try: |
|
1096 | try: | |
1083 | data[repo[k].rev()] = encoding.tolocal(v) |
|
1097 | data[repo[k].rev()] = encoding.tolocal(v) | |
1084 | except (error.LookupError, error.RepoLookupError): |
|
1098 | except (error.LookupError, error.RepoLookupError): | |
1085 | pass # we ignore data for nodes that don't exist locally |
|
1099 | pass # we ignore data for nodes that don't exist locally | |
1086 | finally: |
|
1100 | finally: | |
1087 | if proc: |
|
1101 | if proc: | |
1088 | proc.communicate() |
|
1102 | proc.communicate() | |
1089 | if proc.returncode != 0: |
|
1103 | if proc.returncode != 0: | |
1090 | # not an error so 'cmd | grep' can be empty |
|
1104 | # not an error so 'cmd | grep' can be empty | |
1091 | repo.ui.debug("extdata command '%s' %s\n" |
|
1105 | repo.ui.debug("extdata command '%s' %s\n" | |
1092 | % (cmd, util.explainexit(proc.returncode)[0])) |
|
1106 | % (cmd, util.explainexit(proc.returncode)[0])) | |
1093 | if src: |
|
1107 | if src: | |
1094 | src.close() |
|
1108 | src.close() | |
1095 |
|
1109 | |||
1096 | return data |
|
1110 | return data | |
1097 |
|
1111 | |||
1098 | def _locksub(repo, lock, envvar, cmd, environ=None, *args, **kwargs): |
|
1112 | def _locksub(repo, lock, envvar, cmd, environ=None, *args, **kwargs): | |
1099 | if lock is None: |
|
1113 | if lock is None: | |
1100 | raise error.LockInheritanceContractViolation( |
|
1114 | raise error.LockInheritanceContractViolation( | |
1101 | 'lock can only be inherited while held') |
|
1115 | 'lock can only be inherited while held') | |
1102 | if environ is None: |
|
1116 | if environ is None: | |
1103 | environ = {} |
|
1117 | environ = {} | |
1104 | with lock.inherit() as locker: |
|
1118 | with lock.inherit() as locker: | |
1105 | environ[envvar] = locker |
|
1119 | environ[envvar] = locker | |
1106 | return repo.ui.system(cmd, environ=environ, *args, **kwargs) |
|
1120 | return repo.ui.system(cmd, environ=environ, *args, **kwargs) | |
1107 |
|
1121 | |||
1108 | def wlocksub(repo, cmd, *args, **kwargs): |
|
1122 | def wlocksub(repo, cmd, *args, **kwargs): | |
1109 | """run cmd as a subprocess that allows inheriting repo's wlock |
|
1123 | """run cmd as a subprocess that allows inheriting repo's wlock | |
1110 |
|
1124 | |||
1111 | This can only be called while the wlock is held. This takes all the |
|
1125 | This can only be called while the wlock is held. This takes all the | |
1112 | arguments that ui.system does, and returns the exit code of the |
|
1126 | arguments that ui.system does, and returns the exit code of the | |
1113 | subprocess.""" |
|
1127 | subprocess.""" | |
1114 | return _locksub(repo, repo.currentwlock(), 'HG_WLOCK_LOCKER', cmd, *args, |
|
1128 | return _locksub(repo, repo.currentwlock(), 'HG_WLOCK_LOCKER', cmd, *args, | |
1115 | **kwargs) |
|
1129 | **kwargs) | |
1116 |
|
1130 | |||
1117 | def gdinitconfig(ui): |
|
1131 | def gdinitconfig(ui): | |
1118 | """helper function to know if a repo should be created as general delta |
|
1132 | """helper function to know if a repo should be created as general delta | |
1119 | """ |
|
1133 | """ | |
1120 | # experimental config: format.generaldelta |
|
1134 | # experimental config: format.generaldelta | |
1121 | return (ui.configbool('format', 'generaldelta') |
|
1135 | return (ui.configbool('format', 'generaldelta') | |
1122 | or ui.configbool('format', 'usegeneraldelta')) |
|
1136 | or ui.configbool('format', 'usegeneraldelta')) | |
1123 |
|
1137 | |||
1124 | def gddeltaconfig(ui): |
|
1138 | def gddeltaconfig(ui): | |
1125 | """helper function to know if incoming delta should be optimised |
|
1139 | """helper function to know if incoming delta should be optimised | |
1126 | """ |
|
1140 | """ | |
1127 | # experimental config: format.generaldelta |
|
1141 | # experimental config: format.generaldelta | |
1128 | return ui.configbool('format', 'generaldelta') |
|
1142 | return ui.configbool('format', 'generaldelta') | |
1129 |
|
1143 | |||
1130 | class simplekeyvaluefile(object): |
|
1144 | class simplekeyvaluefile(object): | |
1131 | """A simple file with key=value lines |
|
1145 | """A simple file with key=value lines | |
1132 |
|
1146 | |||
1133 | Keys must be alphanumerics and start with a letter, values must not |
|
1147 | Keys must be alphanumerics and start with a letter, values must not | |
1134 | contain '\n' characters""" |
|
1148 | contain '\n' characters""" | |
1135 | firstlinekey = '__firstline' |
|
1149 | firstlinekey = '__firstline' | |
1136 |
|
1150 | |||
1137 | def __init__(self, vfs, path, keys=None): |
|
1151 | def __init__(self, vfs, path, keys=None): | |
1138 | self.vfs = vfs |
|
1152 | self.vfs = vfs | |
1139 | self.path = path |
|
1153 | self.path = path | |
1140 |
|
1154 | |||
1141 | def read(self, firstlinenonkeyval=False): |
|
1155 | def read(self, firstlinenonkeyval=False): | |
1142 | """Read the contents of a simple key-value file |
|
1156 | """Read the contents of a simple key-value file | |
1143 |
|
1157 | |||
1144 | 'firstlinenonkeyval' indicates whether the first line of file should |
|
1158 | 'firstlinenonkeyval' indicates whether the first line of file should | |
1145 | be treated as a key-value pair or reuturned fully under the |
|
1159 | be treated as a key-value pair or reuturned fully under the | |
1146 | __firstline key.""" |
|
1160 | __firstline key.""" | |
1147 | lines = self.vfs.readlines(self.path) |
|
1161 | lines = self.vfs.readlines(self.path) | |
1148 | d = {} |
|
1162 | d = {} | |
1149 | if firstlinenonkeyval: |
|
1163 | if firstlinenonkeyval: | |
1150 | if not lines: |
|
1164 | if not lines: | |
1151 | e = _("empty simplekeyvalue file") |
|
1165 | e = _("empty simplekeyvalue file") | |
1152 | raise error.CorruptedState(e) |
|
1166 | raise error.CorruptedState(e) | |
1153 | # we don't want to include '\n' in the __firstline |
|
1167 | # we don't want to include '\n' in the __firstline | |
1154 | d[self.firstlinekey] = lines[0][:-1] |
|
1168 | d[self.firstlinekey] = lines[0][:-1] | |
1155 | del lines[0] |
|
1169 | del lines[0] | |
1156 |
|
1170 | |||
1157 | try: |
|
1171 | try: | |
1158 | # the 'if line.strip()' part prevents us from failing on empty |
|
1172 | # the 'if line.strip()' part prevents us from failing on empty | |
1159 | # lines which only contain '\n' therefore are not skipped |
|
1173 | # lines which only contain '\n' therefore are not skipped | |
1160 | # by 'if line' |
|
1174 | # by 'if line' | |
1161 | updatedict = dict(line[:-1].split('=', 1) for line in lines |
|
1175 | updatedict = dict(line[:-1].split('=', 1) for line in lines | |
1162 | if line.strip()) |
|
1176 | if line.strip()) | |
1163 | if self.firstlinekey in updatedict: |
|
1177 | if self.firstlinekey in updatedict: | |
1164 | e = _("%r can't be used as a key") |
|
1178 | e = _("%r can't be used as a key") | |
1165 | raise error.CorruptedState(e % self.firstlinekey) |
|
1179 | raise error.CorruptedState(e % self.firstlinekey) | |
1166 | d.update(updatedict) |
|
1180 | d.update(updatedict) | |
1167 | except ValueError as e: |
|
1181 | except ValueError as e: | |
1168 | raise error.CorruptedState(str(e)) |
|
1182 | raise error.CorruptedState(str(e)) | |
1169 | return d |
|
1183 | return d | |
1170 |
|
1184 | |||
1171 | def write(self, data, firstline=None): |
|
1185 | def write(self, data, firstline=None): | |
1172 | """Write key=>value mapping to a file |
|
1186 | """Write key=>value mapping to a file | |
1173 | data is a dict. Keys must be alphanumerical and start with a letter. |
|
1187 | data is a dict. Keys must be alphanumerical and start with a letter. | |
1174 | Values must not contain newline characters. |
|
1188 | Values must not contain newline characters. | |
1175 |
|
1189 | |||
1176 | If 'firstline' is not None, it is written to file before |
|
1190 | If 'firstline' is not None, it is written to file before | |
1177 | everything else, as it is, not in a key=value form""" |
|
1191 | everything else, as it is, not in a key=value form""" | |
1178 | lines = [] |
|
1192 | lines = [] | |
1179 | if firstline is not None: |
|
1193 | if firstline is not None: | |
1180 | lines.append('%s\n' % firstline) |
|
1194 | lines.append('%s\n' % firstline) | |
1181 |
|
1195 | |||
1182 | for k, v in data.items(): |
|
1196 | for k, v in data.items(): | |
1183 | if k == self.firstlinekey: |
|
1197 | if k == self.firstlinekey: | |
1184 | e = "key name '%s' is reserved" % self.firstlinekey |
|
1198 | e = "key name '%s' is reserved" % self.firstlinekey | |
1185 | raise error.ProgrammingError(e) |
|
1199 | raise error.ProgrammingError(e) | |
1186 | if not k[0].isalpha(): |
|
1200 | if not k[0].isalpha(): | |
1187 | e = "keys must start with a letter in a key-value file" |
|
1201 | e = "keys must start with a letter in a key-value file" | |
1188 | raise error.ProgrammingError(e) |
|
1202 | raise error.ProgrammingError(e) | |
1189 | if not k.isalnum(): |
|
1203 | if not k.isalnum(): | |
1190 | e = "invalid key name in a simple key-value file" |
|
1204 | e = "invalid key name in a simple key-value file" | |
1191 | raise error.ProgrammingError(e) |
|
1205 | raise error.ProgrammingError(e) | |
1192 | if '\n' in v: |
|
1206 | if '\n' in v: | |
1193 | e = "invalid value in a simple key-value file" |
|
1207 | e = "invalid value in a simple key-value file" | |
1194 | raise error.ProgrammingError(e) |
|
1208 | raise error.ProgrammingError(e) | |
1195 | lines.append("%s=%s\n" % (k, v)) |
|
1209 | lines.append("%s=%s\n" % (k, v)) | |
1196 | with self.vfs(self.path, mode='wb', atomictemp=True) as fp: |
|
1210 | with self.vfs(self.path, mode='wb', atomictemp=True) as fp: | |
1197 | fp.write(''.join(lines)) |
|
1211 | fp.write(''.join(lines)) | |
1198 |
|
1212 | |||
1199 | _reportobsoletedsource = [ |
|
1213 | _reportobsoletedsource = [ | |
1200 | 'debugobsolete', |
|
1214 | 'debugobsolete', | |
1201 | 'pull', |
|
1215 | 'pull', | |
1202 | 'push', |
|
1216 | 'push', | |
1203 | 'serve', |
|
1217 | 'serve', | |
1204 | 'unbundle', |
|
1218 | 'unbundle', | |
1205 | ] |
|
1219 | ] | |
1206 |
|
1220 | |||
1207 | _reportnewcssource = [ |
|
1221 | _reportnewcssource = [ | |
1208 | 'pull', |
|
1222 | 'pull', | |
1209 | 'unbundle', |
|
1223 | 'unbundle', | |
1210 | ] |
|
1224 | ] | |
1211 |
|
1225 | |||
1212 | def registersummarycallback(repo, otr, txnname=''): |
|
1226 | def registersummarycallback(repo, otr, txnname=''): | |
1213 | """register a callback to issue a summary after the transaction is closed |
|
1227 | """register a callback to issue a summary after the transaction is closed | |
1214 | """ |
|
1228 | """ | |
1215 | def txmatch(sources): |
|
1229 | def txmatch(sources): | |
1216 | return any(txnname.startswith(source) for source in sources) |
|
1230 | return any(txnname.startswith(source) for source in sources) | |
1217 |
|
1231 | |||
1218 | categories = [] |
|
1232 | categories = [] | |
1219 |
|
1233 | |||
1220 | def reportsummary(func): |
|
1234 | def reportsummary(func): | |
1221 | """decorator for report callbacks.""" |
|
1235 | """decorator for report callbacks.""" | |
1222 | reporef = weakref.ref(repo) |
|
1236 | reporef = weakref.ref(repo) | |
1223 | def wrapped(tr): |
|
1237 | def wrapped(tr): | |
1224 | repo = reporef() |
|
1238 | repo = reporef() | |
1225 | func(repo, tr) |
|
1239 | func(repo, tr) | |
1226 | newcat = '%2i-txnreport' % len(categories) |
|
1240 | newcat = '%2i-txnreport' % len(categories) | |
1227 | otr.addpostclose(newcat, wrapped) |
|
1241 | otr.addpostclose(newcat, wrapped) | |
1228 | categories.append(newcat) |
|
1242 | categories.append(newcat) | |
1229 | return wrapped |
|
1243 | return wrapped | |
1230 |
|
1244 | |||
1231 | if txmatch(_reportobsoletedsource): |
|
1245 | if txmatch(_reportobsoletedsource): | |
1232 | @reportsummary |
|
1246 | @reportsummary | |
1233 | def reportobsoleted(repo, tr): |
|
1247 | def reportobsoleted(repo, tr): | |
1234 | obsoleted = obsutil.getobsoleted(repo, tr) |
|
1248 | obsoleted = obsutil.getobsoleted(repo, tr) | |
1235 | if obsoleted: |
|
1249 | if obsoleted: | |
1236 | repo.ui.status(_('obsoleted %i changesets\n') |
|
1250 | repo.ui.status(_('obsoleted %i changesets\n') | |
1237 | % len(obsoleted)) |
|
1251 | % len(obsoleted)) | |
1238 |
|
1252 | |||
1239 | if txmatch(_reportnewcssource): |
|
1253 | if txmatch(_reportnewcssource): | |
1240 | @reportsummary |
|
1254 | @reportsummary | |
1241 | def reportnewcs(repo, tr): |
|
1255 | def reportnewcs(repo, tr): | |
1242 | """Report the range of new revisions pulled/unbundled.""" |
|
1256 | """Report the range of new revisions pulled/unbundled.""" | |
1243 | newrevs = list(tr.changes.get('revs', set())) |
|
1257 | newrevs = list(tr.changes.get('revs', set())) | |
1244 | if not newrevs: |
|
1258 | if not newrevs: | |
1245 | return |
|
1259 | return | |
1246 |
|
1260 | |||
1247 | # Compute the bounds of new revisions' range, excluding obsoletes. |
|
1261 | # Compute the bounds of new revisions' range, excluding obsoletes. | |
1248 | unfi = repo.unfiltered() |
|
1262 | unfi = repo.unfiltered() | |
1249 | revs = unfi.revs('%ld and not obsolete()', newrevs) |
|
1263 | revs = unfi.revs('%ld and not obsolete()', newrevs) | |
1250 | if not revs: |
|
1264 | if not revs: | |
1251 | # Got only obsoletes. |
|
1265 | # Got only obsoletes. | |
1252 | return |
|
1266 | return | |
1253 | minrev, maxrev = repo[revs.min()], repo[revs.max()] |
|
1267 | minrev, maxrev = repo[revs.min()], repo[revs.max()] | |
1254 |
|
1268 | |||
1255 | if minrev == maxrev: |
|
1269 | if minrev == maxrev: | |
1256 | revrange = minrev |
|
1270 | revrange = minrev | |
1257 | else: |
|
1271 | else: | |
1258 | revrange = '%s:%s' % (minrev, maxrev) |
|
1272 | revrange = '%s:%s' % (minrev, maxrev) | |
1259 | repo.ui.status(_('new changesets %s\n') % revrange) |
|
1273 | repo.ui.status(_('new changesets %s\n') % revrange) |
General Comments 0
You need to be logged in to leave comments.
Login now