##// END OF EJS Templates
revset-filelog: handle hidden linkrev for file missing for head (issue4490)...
Pierre-Yves David -
r23729:07a6faf9 default
parent child Browse files
Show More
@@ -1,3074 +1,3075 b''
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 import re
8 import re
9 import parser, util, error, discovery, hbisect, phases
9 import parser, util, error, discovery, hbisect, phases
10 import node
10 import node
11 import heapq
11 import heapq
12 import match as matchmod
12 import match as matchmod
13 from i18n import _
13 from i18n import _
14 import encoding
14 import encoding
15 import obsolete as obsmod
15 import obsolete as obsmod
16 import pathutil
16 import pathutil
17 import repoview
17 import repoview
18
18
19 def _revancestors(repo, revs, followfirst):
19 def _revancestors(repo, revs, followfirst):
20 """Like revlog.ancestors(), but supports followfirst."""
20 """Like revlog.ancestors(), but supports followfirst."""
21 cut = followfirst and 1 or None
21 cut = followfirst and 1 or None
22 cl = repo.changelog
22 cl = repo.changelog
23
23
24 def iterate():
24 def iterate():
25 revqueue, revsnode = None, None
25 revqueue, revsnode = None, None
26 h = []
26 h = []
27
27
28 revs.sort(reverse=True)
28 revs.sort(reverse=True)
29 revqueue = util.deque(revs)
29 revqueue = util.deque(revs)
30 if revqueue:
30 if revqueue:
31 revsnode = revqueue.popleft()
31 revsnode = revqueue.popleft()
32 heapq.heappush(h, -revsnode)
32 heapq.heappush(h, -revsnode)
33
33
34 seen = set([node.nullrev])
34 seen = set([node.nullrev])
35 while h:
35 while h:
36 current = -heapq.heappop(h)
36 current = -heapq.heappop(h)
37 if current not in seen:
37 if current not in seen:
38 if revsnode and current == revsnode:
38 if revsnode and current == revsnode:
39 if revqueue:
39 if revqueue:
40 revsnode = revqueue.popleft()
40 revsnode = revqueue.popleft()
41 heapq.heappush(h, -revsnode)
41 heapq.heappush(h, -revsnode)
42 seen.add(current)
42 seen.add(current)
43 yield current
43 yield current
44 for parent in cl.parentrevs(current)[:cut]:
44 for parent in cl.parentrevs(current)[:cut]:
45 if parent != node.nullrev:
45 if parent != node.nullrev:
46 heapq.heappush(h, -parent)
46 heapq.heappush(h, -parent)
47
47
48 return generatorset(iterate(), iterasc=False)
48 return generatorset(iterate(), iterasc=False)
49
49
50 def _revdescendants(repo, revs, followfirst):
50 def _revdescendants(repo, revs, followfirst):
51 """Like revlog.descendants() but supports followfirst."""
51 """Like revlog.descendants() but supports followfirst."""
52 cut = followfirst and 1 or None
52 cut = followfirst and 1 or None
53
53
54 def iterate():
54 def iterate():
55 cl = repo.changelog
55 cl = repo.changelog
56 first = min(revs)
56 first = min(revs)
57 nullrev = node.nullrev
57 nullrev = node.nullrev
58 if first == nullrev:
58 if first == nullrev:
59 # Are there nodes with a null first parent and a non-null
59 # Are there nodes with a null first parent and a non-null
60 # second one? Maybe. Do we care? Probably not.
60 # second one? Maybe. Do we care? Probably not.
61 for i in cl:
61 for i in cl:
62 yield i
62 yield i
63 else:
63 else:
64 seen = set(revs)
64 seen = set(revs)
65 for i in cl.revs(first + 1):
65 for i in cl.revs(first + 1):
66 for x in cl.parentrevs(i)[:cut]:
66 for x in cl.parentrevs(i)[:cut]:
67 if x != nullrev and x in seen:
67 if x != nullrev and x in seen:
68 seen.add(i)
68 seen.add(i)
69 yield i
69 yield i
70 break
70 break
71
71
72 return generatorset(iterate(), iterasc=True)
72 return generatorset(iterate(), iterasc=True)
73
73
74 def _revsbetween(repo, roots, heads):
74 def _revsbetween(repo, roots, heads):
75 """Return all paths between roots and heads, inclusive of both endpoint
75 """Return all paths between roots and heads, inclusive of both endpoint
76 sets."""
76 sets."""
77 if not roots:
77 if not roots:
78 return baseset()
78 return baseset()
79 parentrevs = repo.changelog.parentrevs
79 parentrevs = repo.changelog.parentrevs
80 visit = list(heads)
80 visit = list(heads)
81 reachable = set()
81 reachable = set()
82 seen = {}
82 seen = {}
83 minroot = min(roots)
83 minroot = min(roots)
84 roots = set(roots)
84 roots = set(roots)
85 # open-code the post-order traversal due to the tiny size of
85 # open-code the post-order traversal due to the tiny size of
86 # sys.getrecursionlimit()
86 # sys.getrecursionlimit()
87 while visit:
87 while visit:
88 rev = visit.pop()
88 rev = visit.pop()
89 if rev in roots:
89 if rev in roots:
90 reachable.add(rev)
90 reachable.add(rev)
91 parents = parentrevs(rev)
91 parents = parentrevs(rev)
92 seen[rev] = parents
92 seen[rev] = parents
93 for parent in parents:
93 for parent in parents:
94 if parent >= minroot and parent not in seen:
94 if parent >= minroot and parent not in seen:
95 visit.append(parent)
95 visit.append(parent)
96 if not reachable:
96 if not reachable:
97 return baseset()
97 return baseset()
98 for rev in sorted(seen):
98 for rev in sorted(seen):
99 for parent in seen[rev]:
99 for parent in seen[rev]:
100 if parent in reachable:
100 if parent in reachable:
101 reachable.add(rev)
101 reachable.add(rev)
102 return baseset(sorted(reachable))
102 return baseset(sorted(reachable))
103
103
104 elements = {
104 elements = {
105 "(": (20, ("group", 1, ")"), ("func", 1, ")")),
105 "(": (20, ("group", 1, ")"), ("func", 1, ")")),
106 "~": (18, None, ("ancestor", 18)),
106 "~": (18, None, ("ancestor", 18)),
107 "^": (18, None, ("parent", 18), ("parentpost", 18)),
107 "^": (18, None, ("parent", 18), ("parentpost", 18)),
108 "-": (5, ("negate", 19), ("minus", 5)),
108 "-": (5, ("negate", 19), ("minus", 5)),
109 "::": (17, ("dagrangepre", 17), ("dagrange", 17),
109 "::": (17, ("dagrangepre", 17), ("dagrange", 17),
110 ("dagrangepost", 17)),
110 ("dagrangepost", 17)),
111 "..": (17, ("dagrangepre", 17), ("dagrange", 17),
111 "..": (17, ("dagrangepre", 17), ("dagrange", 17),
112 ("dagrangepost", 17)),
112 ("dagrangepost", 17)),
113 ":": (15, ("rangepre", 15), ("range", 15), ("rangepost", 15)),
113 ":": (15, ("rangepre", 15), ("range", 15), ("rangepost", 15)),
114 "not": (10, ("not", 10)),
114 "not": (10, ("not", 10)),
115 "!": (10, ("not", 10)),
115 "!": (10, ("not", 10)),
116 "and": (5, None, ("and", 5)),
116 "and": (5, None, ("and", 5)),
117 "&": (5, None, ("and", 5)),
117 "&": (5, None, ("and", 5)),
118 "or": (4, None, ("or", 4)),
118 "or": (4, None, ("or", 4)),
119 "|": (4, None, ("or", 4)),
119 "|": (4, None, ("or", 4)),
120 "+": (4, None, ("or", 4)),
120 "+": (4, None, ("or", 4)),
121 ",": (2, None, ("list", 2)),
121 ",": (2, None, ("list", 2)),
122 ")": (0, None, None),
122 ")": (0, None, None),
123 "symbol": (0, ("symbol",), None),
123 "symbol": (0, ("symbol",), None),
124 "string": (0, ("string",), None),
124 "string": (0, ("string",), None),
125 "end": (0, None, None),
125 "end": (0, None, None),
126 }
126 }
127
127
128 keywords = set(['and', 'or', 'not'])
128 keywords = set(['and', 'or', 'not'])
129
129
130 def tokenize(program, lookup=None):
130 def tokenize(program, lookup=None):
131 '''
131 '''
132 Parse a revset statement into a stream of tokens
132 Parse a revset statement into a stream of tokens
133
133
134 Check that @ is a valid unquoted token character (issue3686):
134 Check that @ is a valid unquoted token character (issue3686):
135 >>> list(tokenize("@::"))
135 >>> list(tokenize("@::"))
136 [('symbol', '@', 0), ('::', None, 1), ('end', None, 3)]
136 [('symbol', '@', 0), ('::', None, 1), ('end', None, 3)]
137
137
138 '''
138 '''
139
139
140 pos, l = 0, len(program)
140 pos, l = 0, len(program)
141 while pos < l:
141 while pos < l:
142 c = program[pos]
142 c = program[pos]
143 if c.isspace(): # skip inter-token whitespace
143 if c.isspace(): # skip inter-token whitespace
144 pass
144 pass
145 elif c == ':' and program[pos:pos + 2] == '::': # look ahead carefully
145 elif c == ':' and program[pos:pos + 2] == '::': # look ahead carefully
146 yield ('::', None, pos)
146 yield ('::', None, pos)
147 pos += 1 # skip ahead
147 pos += 1 # skip ahead
148 elif c == '.' and program[pos:pos + 2] == '..': # look ahead carefully
148 elif c == '.' and program[pos:pos + 2] == '..': # look ahead carefully
149 yield ('..', None, pos)
149 yield ('..', None, pos)
150 pos += 1 # skip ahead
150 pos += 1 # skip ahead
151 elif c in "():,-|&+!~^": # handle simple operators
151 elif c in "():,-|&+!~^": # handle simple operators
152 yield (c, None, pos)
152 yield (c, None, pos)
153 elif (c in '"\'' or c == 'r' and
153 elif (c in '"\'' or c == 'r' and
154 program[pos:pos + 2] in ("r'", 'r"')): # handle quoted strings
154 program[pos:pos + 2] in ("r'", 'r"')): # handle quoted strings
155 if c == 'r':
155 if c == 'r':
156 pos += 1
156 pos += 1
157 c = program[pos]
157 c = program[pos]
158 decode = lambda x: x
158 decode = lambda x: x
159 else:
159 else:
160 decode = lambda x: x.decode('string-escape')
160 decode = lambda x: x.decode('string-escape')
161 pos += 1
161 pos += 1
162 s = pos
162 s = pos
163 while pos < l: # find closing quote
163 while pos < l: # find closing quote
164 d = program[pos]
164 d = program[pos]
165 if d == '\\': # skip over escaped characters
165 if d == '\\': # skip over escaped characters
166 pos += 2
166 pos += 2
167 continue
167 continue
168 if d == c:
168 if d == c:
169 yield ('string', decode(program[s:pos]), s)
169 yield ('string', decode(program[s:pos]), s)
170 break
170 break
171 pos += 1
171 pos += 1
172 else:
172 else:
173 raise error.ParseError(_("unterminated string"), s)
173 raise error.ParseError(_("unterminated string"), s)
174 # gather up a symbol/keyword
174 # gather up a symbol/keyword
175 elif c.isalnum() or c in '._@' or ord(c) > 127:
175 elif c.isalnum() or c in '._@' or ord(c) > 127:
176 s = pos
176 s = pos
177 pos += 1
177 pos += 1
178 while pos < l: # find end of symbol
178 while pos < l: # find end of symbol
179 d = program[pos]
179 d = program[pos]
180 if not (d.isalnum() or d in "-._/@" or ord(d) > 127):
180 if not (d.isalnum() or d in "-._/@" or ord(d) > 127):
181 break
181 break
182 if d == '.' and program[pos - 1] == '.': # special case for ..
182 if d == '.' and program[pos - 1] == '.': # special case for ..
183 pos -= 1
183 pos -= 1
184 break
184 break
185 pos += 1
185 pos += 1
186 sym = program[s:pos]
186 sym = program[s:pos]
187 if sym in keywords: # operator keywords
187 if sym in keywords: # operator keywords
188 yield (sym, None, s)
188 yield (sym, None, s)
189 elif '-' in sym:
189 elif '-' in sym:
190 # some jerk gave us foo-bar-baz, try to check if it's a symbol
190 # some jerk gave us foo-bar-baz, try to check if it's a symbol
191 if lookup and lookup(sym):
191 if lookup and lookup(sym):
192 # looks like a real symbol
192 # looks like a real symbol
193 yield ('symbol', sym, s)
193 yield ('symbol', sym, s)
194 else:
194 else:
195 # looks like an expression
195 # looks like an expression
196 parts = sym.split('-')
196 parts = sym.split('-')
197 for p in parts[:-1]:
197 for p in parts[:-1]:
198 if p: # possible consecutive -
198 if p: # possible consecutive -
199 yield ('symbol', p, s)
199 yield ('symbol', p, s)
200 s += len(p)
200 s += len(p)
201 yield ('-', None, pos)
201 yield ('-', None, pos)
202 s += 1
202 s += 1
203 if parts[-1]: # possible trailing -
203 if parts[-1]: # possible trailing -
204 yield ('symbol', parts[-1], s)
204 yield ('symbol', parts[-1], s)
205 else:
205 else:
206 yield ('symbol', sym, s)
206 yield ('symbol', sym, s)
207 pos -= 1
207 pos -= 1
208 else:
208 else:
209 raise error.ParseError(_("syntax error"), pos)
209 raise error.ParseError(_("syntax error"), pos)
210 pos += 1
210 pos += 1
211 yield ('end', None, pos)
211 yield ('end', None, pos)
212
212
213 # helpers
213 # helpers
214
214
215 def getstring(x, err):
215 def getstring(x, err):
216 if x and (x[0] == 'string' or x[0] == 'symbol'):
216 if x and (x[0] == 'string' or x[0] == 'symbol'):
217 return x[1]
217 return x[1]
218 raise error.ParseError(err)
218 raise error.ParseError(err)
219
219
220 def getlist(x):
220 def getlist(x):
221 if not x:
221 if not x:
222 return []
222 return []
223 if x[0] == 'list':
223 if x[0] == 'list':
224 return getlist(x[1]) + [x[2]]
224 return getlist(x[1]) + [x[2]]
225 return [x]
225 return [x]
226
226
227 def getargs(x, min, max, err):
227 def getargs(x, min, max, err):
228 l = getlist(x)
228 l = getlist(x)
229 if len(l) < min or (max >= 0 and len(l) > max):
229 if len(l) < min or (max >= 0 and len(l) > max):
230 raise error.ParseError(err)
230 raise error.ParseError(err)
231 return l
231 return l
232
232
233 def getset(repo, subset, x):
233 def getset(repo, subset, x):
234 if not x:
234 if not x:
235 raise error.ParseError(_("missing argument"))
235 raise error.ParseError(_("missing argument"))
236 s = methods[x[0]](repo, subset, *x[1:])
236 s = methods[x[0]](repo, subset, *x[1:])
237 if util.safehasattr(s, 'isascending'):
237 if util.safehasattr(s, 'isascending'):
238 return s
238 return s
239 return baseset(s)
239 return baseset(s)
240
240
241 def _getrevsource(repo, r):
241 def _getrevsource(repo, r):
242 extra = repo[r].extra()
242 extra = repo[r].extra()
243 for label in ('source', 'transplant_source', 'rebase_source'):
243 for label in ('source', 'transplant_source', 'rebase_source'):
244 if label in extra:
244 if label in extra:
245 try:
245 try:
246 return repo[extra[label]].rev()
246 return repo[extra[label]].rev()
247 except error.RepoLookupError:
247 except error.RepoLookupError:
248 pass
248 pass
249 return None
249 return None
250
250
251 # operator methods
251 # operator methods
252
252
253 def stringset(repo, subset, x):
253 def stringset(repo, subset, x):
254 x = repo[x].rev()
254 x = repo[x].rev()
255 if x == -1 and len(subset) == len(repo):
255 if x == -1 and len(subset) == len(repo):
256 return baseset([-1])
256 return baseset([-1])
257 if x in subset:
257 if x in subset:
258 return baseset([x])
258 return baseset([x])
259 return baseset()
259 return baseset()
260
260
261 def symbolset(repo, subset, x):
261 def symbolset(repo, subset, x):
262 if x in symbols:
262 if x in symbols:
263 raise error.ParseError(_("can't use %s here") % x)
263 raise error.ParseError(_("can't use %s here") % x)
264 return stringset(repo, subset, x)
264 return stringset(repo, subset, x)
265
265
266 def rangeset(repo, subset, x, y):
266 def rangeset(repo, subset, x, y):
267 m = getset(repo, fullreposet(repo), x)
267 m = getset(repo, fullreposet(repo), x)
268 n = getset(repo, fullreposet(repo), y)
268 n = getset(repo, fullreposet(repo), y)
269
269
270 if not m or not n:
270 if not m or not n:
271 return baseset()
271 return baseset()
272 m, n = m.first(), n.last()
272 m, n = m.first(), n.last()
273
273
274 if m < n:
274 if m < n:
275 r = spanset(repo, m, n + 1)
275 r = spanset(repo, m, n + 1)
276 else:
276 else:
277 r = spanset(repo, m, n - 1)
277 r = spanset(repo, m, n - 1)
278 return r & subset
278 return r & subset
279
279
280 def dagrange(repo, subset, x, y):
280 def dagrange(repo, subset, x, y):
281 r = spanset(repo)
281 r = spanset(repo)
282 xs = _revsbetween(repo, getset(repo, r, x), getset(repo, r, y))
282 xs = _revsbetween(repo, getset(repo, r, x), getset(repo, r, y))
283 return xs & subset
283 return xs & subset
284
284
285 def andset(repo, subset, x, y):
285 def andset(repo, subset, x, y):
286 return getset(repo, getset(repo, subset, x), y)
286 return getset(repo, getset(repo, subset, x), y)
287
287
288 def orset(repo, subset, x, y):
288 def orset(repo, subset, x, y):
289 xl = getset(repo, subset, x)
289 xl = getset(repo, subset, x)
290 yl = getset(repo, subset - xl, y)
290 yl = getset(repo, subset - xl, y)
291 return xl + yl
291 return xl + yl
292
292
293 def notset(repo, subset, x):
293 def notset(repo, subset, x):
294 return subset - getset(repo, subset, x)
294 return subset - getset(repo, subset, x)
295
295
296 def listset(repo, subset, a, b):
296 def listset(repo, subset, a, b):
297 raise error.ParseError(_("can't use a list in this context"))
297 raise error.ParseError(_("can't use a list in this context"))
298
298
299 def func(repo, subset, a, b):
299 def func(repo, subset, a, b):
300 if a[0] == 'symbol' and a[1] in symbols:
300 if a[0] == 'symbol' and a[1] in symbols:
301 return symbols[a[1]](repo, subset, b)
301 return symbols[a[1]](repo, subset, b)
302 raise error.ParseError(_("not a function: %s") % a[1])
302 raise error.ParseError(_("not a function: %s") % a[1])
303
303
304 # functions
304 # functions
305
305
306 def adds(repo, subset, x):
306 def adds(repo, subset, x):
307 """``adds(pattern)``
307 """``adds(pattern)``
308 Changesets that add a file matching pattern.
308 Changesets that add a file matching pattern.
309
309
310 The pattern without explicit kind like ``glob:`` is expected to be
310 The pattern without explicit kind like ``glob:`` is expected to be
311 relative to the current directory and match against a file or a
311 relative to the current directory and match against a file or a
312 directory.
312 directory.
313 """
313 """
314 # i18n: "adds" is a keyword
314 # i18n: "adds" is a keyword
315 pat = getstring(x, _("adds requires a pattern"))
315 pat = getstring(x, _("adds requires a pattern"))
316 return checkstatus(repo, subset, pat, 1)
316 return checkstatus(repo, subset, pat, 1)
317
317
318 def ancestor(repo, subset, x):
318 def ancestor(repo, subset, x):
319 """``ancestor(*changeset)``
319 """``ancestor(*changeset)``
320 A greatest common ancestor of the changesets.
320 A greatest common ancestor of the changesets.
321
321
322 Accepts 0 or more changesets.
322 Accepts 0 or more changesets.
323 Will return empty list when passed no args.
323 Will return empty list when passed no args.
324 Greatest common ancestor of a single changeset is that changeset.
324 Greatest common ancestor of a single changeset is that changeset.
325 """
325 """
326 # i18n: "ancestor" is a keyword
326 # i18n: "ancestor" is a keyword
327 l = getlist(x)
327 l = getlist(x)
328 rl = spanset(repo)
328 rl = spanset(repo)
329 anc = None
329 anc = None
330
330
331 # (getset(repo, rl, i) for i in l) generates a list of lists
331 # (getset(repo, rl, i) for i in l) generates a list of lists
332 for revs in (getset(repo, rl, i) for i in l):
332 for revs in (getset(repo, rl, i) for i in l):
333 for r in revs:
333 for r in revs:
334 if anc is None:
334 if anc is None:
335 anc = repo[r]
335 anc = repo[r]
336 else:
336 else:
337 anc = anc.ancestor(repo[r])
337 anc = anc.ancestor(repo[r])
338
338
339 if anc is not None and anc.rev() in subset:
339 if anc is not None and anc.rev() in subset:
340 return baseset([anc.rev()])
340 return baseset([anc.rev()])
341 return baseset()
341 return baseset()
342
342
343 def _ancestors(repo, subset, x, followfirst=False):
343 def _ancestors(repo, subset, x, followfirst=False):
344 heads = getset(repo, spanset(repo), x)
344 heads = getset(repo, spanset(repo), x)
345 if not heads:
345 if not heads:
346 return baseset()
346 return baseset()
347 s = _revancestors(repo, heads, followfirst)
347 s = _revancestors(repo, heads, followfirst)
348 return subset & s
348 return subset & s
349
349
350 def ancestors(repo, subset, x):
350 def ancestors(repo, subset, x):
351 """``ancestors(set)``
351 """``ancestors(set)``
352 Changesets that are ancestors of a changeset in set.
352 Changesets that are ancestors of a changeset in set.
353 """
353 """
354 return _ancestors(repo, subset, x)
354 return _ancestors(repo, subset, x)
355
355
356 def _firstancestors(repo, subset, x):
356 def _firstancestors(repo, subset, x):
357 # ``_firstancestors(set)``
357 # ``_firstancestors(set)``
358 # Like ``ancestors(set)`` but follows only the first parents.
358 # Like ``ancestors(set)`` but follows only the first parents.
359 return _ancestors(repo, subset, x, followfirst=True)
359 return _ancestors(repo, subset, x, followfirst=True)
360
360
361 def ancestorspec(repo, subset, x, n):
361 def ancestorspec(repo, subset, x, n):
362 """``set~n``
362 """``set~n``
363 Changesets that are the Nth ancestor (first parents only) of a changeset
363 Changesets that are the Nth ancestor (first parents only) of a changeset
364 in set.
364 in set.
365 """
365 """
366 try:
366 try:
367 n = int(n[1])
367 n = int(n[1])
368 except (TypeError, ValueError):
368 except (TypeError, ValueError):
369 raise error.ParseError(_("~ expects a number"))
369 raise error.ParseError(_("~ expects a number"))
370 ps = set()
370 ps = set()
371 cl = repo.changelog
371 cl = repo.changelog
372 for r in getset(repo, fullreposet(repo), x):
372 for r in getset(repo, fullreposet(repo), x):
373 for i in range(n):
373 for i in range(n):
374 r = cl.parentrevs(r)[0]
374 r = cl.parentrevs(r)[0]
375 ps.add(r)
375 ps.add(r)
376 return subset & ps
376 return subset & ps
377
377
378 def author(repo, subset, x):
378 def author(repo, subset, x):
379 """``author(string)``
379 """``author(string)``
380 Alias for ``user(string)``.
380 Alias for ``user(string)``.
381 """
381 """
382 # i18n: "author" is a keyword
382 # i18n: "author" is a keyword
383 n = encoding.lower(getstring(x, _("author requires a string")))
383 n = encoding.lower(getstring(x, _("author requires a string")))
384 kind, pattern, matcher = _substringmatcher(n)
384 kind, pattern, matcher = _substringmatcher(n)
385 return subset.filter(lambda x: matcher(encoding.lower(repo[x].user())))
385 return subset.filter(lambda x: matcher(encoding.lower(repo[x].user())))
386
386
387 def bisect(repo, subset, x):
387 def bisect(repo, subset, x):
388 """``bisect(string)``
388 """``bisect(string)``
389 Changesets marked in the specified bisect status:
389 Changesets marked in the specified bisect status:
390
390
391 - ``good``, ``bad``, ``skip``: csets explicitly marked as good/bad/skip
391 - ``good``, ``bad``, ``skip``: csets explicitly marked as good/bad/skip
392 - ``goods``, ``bads`` : csets topologically good/bad
392 - ``goods``, ``bads`` : csets topologically good/bad
393 - ``range`` : csets taking part in the bisection
393 - ``range`` : csets taking part in the bisection
394 - ``pruned`` : csets that are goods, bads or skipped
394 - ``pruned`` : csets that are goods, bads or skipped
395 - ``untested`` : csets whose fate is yet unknown
395 - ``untested`` : csets whose fate is yet unknown
396 - ``ignored`` : csets ignored due to DAG topology
396 - ``ignored`` : csets ignored due to DAG topology
397 - ``current`` : the cset currently being bisected
397 - ``current`` : the cset currently being bisected
398 """
398 """
399 # i18n: "bisect" is a keyword
399 # i18n: "bisect" is a keyword
400 status = getstring(x, _("bisect requires a string")).lower()
400 status = getstring(x, _("bisect requires a string")).lower()
401 state = set(hbisect.get(repo, status))
401 state = set(hbisect.get(repo, status))
402 return subset & state
402 return subset & state
403
403
404 # Backward-compatibility
404 # Backward-compatibility
405 # - no help entry so that we do not advertise it any more
405 # - no help entry so that we do not advertise it any more
406 def bisected(repo, subset, x):
406 def bisected(repo, subset, x):
407 return bisect(repo, subset, x)
407 return bisect(repo, subset, x)
408
408
409 def bookmark(repo, subset, x):
409 def bookmark(repo, subset, x):
410 """``bookmark([name])``
410 """``bookmark([name])``
411 The named bookmark or all bookmarks.
411 The named bookmark or all bookmarks.
412
412
413 If `name` starts with `re:`, the remainder of the name is treated as
413 If `name` starts with `re:`, the remainder of the name is treated as
414 a regular expression. To match a bookmark that actually starts with `re:`,
414 a regular expression. To match a bookmark that actually starts with `re:`,
415 use the prefix `literal:`.
415 use the prefix `literal:`.
416 """
416 """
417 # i18n: "bookmark" is a keyword
417 # i18n: "bookmark" is a keyword
418 args = getargs(x, 0, 1, _('bookmark takes one or no arguments'))
418 args = getargs(x, 0, 1, _('bookmark takes one or no arguments'))
419 if args:
419 if args:
420 bm = getstring(args[0],
420 bm = getstring(args[0],
421 # i18n: "bookmark" is a keyword
421 # i18n: "bookmark" is a keyword
422 _('the argument to bookmark must be a string'))
422 _('the argument to bookmark must be a string'))
423 kind, pattern, matcher = _stringmatcher(bm)
423 kind, pattern, matcher = _stringmatcher(bm)
424 bms = set()
424 bms = set()
425 if kind == 'literal':
425 if kind == 'literal':
426 bmrev = repo._bookmarks.get(pattern, None)
426 bmrev = repo._bookmarks.get(pattern, None)
427 if not bmrev:
427 if not bmrev:
428 raise util.Abort(_("bookmark '%s' does not exist") % bm)
428 raise util.Abort(_("bookmark '%s' does not exist") % bm)
429 bms.add(repo[bmrev].rev())
429 bms.add(repo[bmrev].rev())
430 else:
430 else:
431 matchrevs = set()
431 matchrevs = set()
432 for name, bmrev in repo._bookmarks.iteritems():
432 for name, bmrev in repo._bookmarks.iteritems():
433 if matcher(name):
433 if matcher(name):
434 matchrevs.add(bmrev)
434 matchrevs.add(bmrev)
435 if not matchrevs:
435 if not matchrevs:
436 raise util.Abort(_("no bookmarks exist that match '%s'")
436 raise util.Abort(_("no bookmarks exist that match '%s'")
437 % pattern)
437 % pattern)
438 for bmrev in matchrevs:
438 for bmrev in matchrevs:
439 bms.add(repo[bmrev].rev())
439 bms.add(repo[bmrev].rev())
440 else:
440 else:
441 bms = set([repo[r].rev()
441 bms = set([repo[r].rev()
442 for r in repo._bookmarks.values()])
442 for r in repo._bookmarks.values()])
443 bms -= set([node.nullrev])
443 bms -= set([node.nullrev])
444 return subset & bms
444 return subset & bms
445
445
446 def branch(repo, subset, x):
446 def branch(repo, subset, x):
447 """``branch(string or set)``
447 """``branch(string or set)``
448 All changesets belonging to the given branch or the branches of the given
448 All changesets belonging to the given branch or the branches of the given
449 changesets.
449 changesets.
450
450
451 If `string` starts with `re:`, the remainder of the name is treated as
451 If `string` starts with `re:`, the remainder of the name is treated as
452 a regular expression. To match a branch that actually starts with `re:`,
452 a regular expression. To match a branch that actually starts with `re:`,
453 use the prefix `literal:`.
453 use the prefix `literal:`.
454 """
454 """
455 try:
455 try:
456 b = getstring(x, '')
456 b = getstring(x, '')
457 except error.ParseError:
457 except error.ParseError:
458 # not a string, but another revspec, e.g. tip()
458 # not a string, but another revspec, e.g. tip()
459 pass
459 pass
460 else:
460 else:
461 kind, pattern, matcher = _stringmatcher(b)
461 kind, pattern, matcher = _stringmatcher(b)
462 if kind == 'literal':
462 if kind == 'literal':
463 # note: falls through to the revspec case if no branch with
463 # note: falls through to the revspec case if no branch with
464 # this name exists
464 # this name exists
465 if pattern in repo.branchmap():
465 if pattern in repo.branchmap():
466 return subset.filter(lambda r: matcher(repo[r].branch()))
466 return subset.filter(lambda r: matcher(repo[r].branch()))
467 else:
467 else:
468 return subset.filter(lambda r: matcher(repo[r].branch()))
468 return subset.filter(lambda r: matcher(repo[r].branch()))
469
469
470 s = getset(repo, spanset(repo), x)
470 s = getset(repo, spanset(repo), x)
471 b = set()
471 b = set()
472 for r in s:
472 for r in s:
473 b.add(repo[r].branch())
473 b.add(repo[r].branch())
474 c = s.__contains__
474 c = s.__contains__
475 return subset.filter(lambda r: c(r) or repo[r].branch() in b)
475 return subset.filter(lambda r: c(r) or repo[r].branch() in b)
476
476
477 def bumped(repo, subset, x):
477 def bumped(repo, subset, x):
478 """``bumped()``
478 """``bumped()``
479 Mutable changesets marked as successors of public changesets.
479 Mutable changesets marked as successors of public changesets.
480
480
481 Only non-public and non-obsolete changesets can be `bumped`.
481 Only non-public and non-obsolete changesets can be `bumped`.
482 """
482 """
483 # i18n: "bumped" is a keyword
483 # i18n: "bumped" is a keyword
484 getargs(x, 0, 0, _("bumped takes no arguments"))
484 getargs(x, 0, 0, _("bumped takes no arguments"))
485 bumped = obsmod.getrevs(repo, 'bumped')
485 bumped = obsmod.getrevs(repo, 'bumped')
486 return subset & bumped
486 return subset & bumped
487
487
488 def bundle(repo, subset, x):
488 def bundle(repo, subset, x):
489 """``bundle()``
489 """``bundle()``
490 Changesets in the bundle.
490 Changesets in the bundle.
491
491
492 Bundle must be specified by the -R option."""
492 Bundle must be specified by the -R option."""
493
493
494 try:
494 try:
495 bundlerevs = repo.changelog.bundlerevs
495 bundlerevs = repo.changelog.bundlerevs
496 except AttributeError:
496 except AttributeError:
497 raise util.Abort(_("no bundle provided - specify with -R"))
497 raise util.Abort(_("no bundle provided - specify with -R"))
498 return subset & bundlerevs
498 return subset & bundlerevs
499
499
500 def checkstatus(repo, subset, pat, field):
500 def checkstatus(repo, subset, pat, field):
501 hasset = matchmod.patkind(pat) == 'set'
501 hasset = matchmod.patkind(pat) == 'set'
502
502
503 mcache = [None]
503 mcache = [None]
504 def matches(x):
504 def matches(x):
505 c = repo[x]
505 c = repo[x]
506 if not mcache[0] or hasset:
506 if not mcache[0] or hasset:
507 mcache[0] = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=c)
507 mcache[0] = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=c)
508 m = mcache[0]
508 m = mcache[0]
509 fname = None
509 fname = None
510 if not m.anypats() and len(m.files()) == 1:
510 if not m.anypats() and len(m.files()) == 1:
511 fname = m.files()[0]
511 fname = m.files()[0]
512 if fname is not None:
512 if fname is not None:
513 if fname not in c.files():
513 if fname not in c.files():
514 return False
514 return False
515 else:
515 else:
516 for f in c.files():
516 for f in c.files():
517 if m(f):
517 if m(f):
518 break
518 break
519 else:
519 else:
520 return False
520 return False
521 files = repo.status(c.p1().node(), c.node())[field]
521 files = repo.status(c.p1().node(), c.node())[field]
522 if fname is not None:
522 if fname is not None:
523 if fname in files:
523 if fname in files:
524 return True
524 return True
525 else:
525 else:
526 for f in files:
526 for f in files:
527 if m(f):
527 if m(f):
528 return True
528 return True
529
529
530 return subset.filter(matches)
530 return subset.filter(matches)
531
531
532 def _children(repo, narrow, parentset):
532 def _children(repo, narrow, parentset):
533 cs = set()
533 cs = set()
534 if not parentset:
534 if not parentset:
535 return baseset(cs)
535 return baseset(cs)
536 pr = repo.changelog.parentrevs
536 pr = repo.changelog.parentrevs
537 minrev = min(parentset)
537 minrev = min(parentset)
538 for r in narrow:
538 for r in narrow:
539 if r <= minrev:
539 if r <= minrev:
540 continue
540 continue
541 for p in pr(r):
541 for p in pr(r):
542 if p in parentset:
542 if p in parentset:
543 cs.add(r)
543 cs.add(r)
544 return baseset(cs)
544 return baseset(cs)
545
545
546 def children(repo, subset, x):
546 def children(repo, subset, x):
547 """``children(set)``
547 """``children(set)``
548 Child changesets of changesets in set.
548 Child changesets of changesets in set.
549 """
549 """
550 s = getset(repo, fullreposet(repo), x)
550 s = getset(repo, fullreposet(repo), x)
551 cs = _children(repo, subset, s)
551 cs = _children(repo, subset, s)
552 return subset & cs
552 return subset & cs
553
553
554 def closed(repo, subset, x):
554 def closed(repo, subset, x):
555 """``closed()``
555 """``closed()``
556 Changeset is closed.
556 Changeset is closed.
557 """
557 """
558 # i18n: "closed" is a keyword
558 # i18n: "closed" is a keyword
559 getargs(x, 0, 0, _("closed takes no arguments"))
559 getargs(x, 0, 0, _("closed takes no arguments"))
560 return subset.filter(lambda r: repo[r].closesbranch())
560 return subset.filter(lambda r: repo[r].closesbranch())
561
561
562 def contains(repo, subset, x):
562 def contains(repo, subset, x):
563 """``contains(pattern)``
563 """``contains(pattern)``
564 The revision's manifest contains a file matching pattern (but might not
564 The revision's manifest contains a file matching pattern (but might not
565 modify it). See :hg:`help patterns` for information about file patterns.
565 modify it). See :hg:`help patterns` for information about file patterns.
566
566
567 The pattern without explicit kind like ``glob:`` is expected to be
567 The pattern without explicit kind like ``glob:`` is expected to be
568 relative to the current directory and match against a file exactly
568 relative to the current directory and match against a file exactly
569 for efficiency.
569 for efficiency.
570 """
570 """
571 # i18n: "contains" is a keyword
571 # i18n: "contains" is a keyword
572 pat = getstring(x, _("contains requires a pattern"))
572 pat = getstring(x, _("contains requires a pattern"))
573
573
574 def matches(x):
574 def matches(x):
575 if not matchmod.patkind(pat):
575 if not matchmod.patkind(pat):
576 pats = pathutil.canonpath(repo.root, repo.getcwd(), pat)
576 pats = pathutil.canonpath(repo.root, repo.getcwd(), pat)
577 if pats in repo[x]:
577 if pats in repo[x]:
578 return True
578 return True
579 else:
579 else:
580 c = repo[x]
580 c = repo[x]
581 m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=c)
581 m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=c)
582 for f in c.manifest():
582 for f in c.manifest():
583 if m(f):
583 if m(f):
584 return True
584 return True
585 return False
585 return False
586
586
587 return subset.filter(matches)
587 return subset.filter(matches)
588
588
589 def converted(repo, subset, x):
589 def converted(repo, subset, x):
590 """``converted([id])``
590 """``converted([id])``
591 Changesets converted from the given identifier in the old repository if
591 Changesets converted from the given identifier in the old repository if
592 present, or all converted changesets if no identifier is specified.
592 present, or all converted changesets if no identifier is specified.
593 """
593 """
594
594
595 # There is exactly no chance of resolving the revision, so do a simple
595 # There is exactly no chance of resolving the revision, so do a simple
596 # string compare and hope for the best
596 # string compare and hope for the best
597
597
598 rev = None
598 rev = None
599 # i18n: "converted" is a keyword
599 # i18n: "converted" is a keyword
600 l = getargs(x, 0, 1, _('converted takes one or no arguments'))
600 l = getargs(x, 0, 1, _('converted takes one or no arguments'))
601 if l:
601 if l:
602 # i18n: "converted" is a keyword
602 # i18n: "converted" is a keyword
603 rev = getstring(l[0], _('converted requires a revision'))
603 rev = getstring(l[0], _('converted requires a revision'))
604
604
605 def _matchvalue(r):
605 def _matchvalue(r):
606 source = repo[r].extra().get('convert_revision', None)
606 source = repo[r].extra().get('convert_revision', None)
607 return source is not None and (rev is None or source.startswith(rev))
607 return source is not None and (rev is None or source.startswith(rev))
608
608
609 return subset.filter(lambda r: _matchvalue(r))
609 return subset.filter(lambda r: _matchvalue(r))
610
610
611 def date(repo, subset, x):
611 def date(repo, subset, x):
612 """``date(interval)``
612 """``date(interval)``
613 Changesets within the interval, see :hg:`help dates`.
613 Changesets within the interval, see :hg:`help dates`.
614 """
614 """
615 # i18n: "date" is a keyword
615 # i18n: "date" is a keyword
616 ds = getstring(x, _("date requires a string"))
616 ds = getstring(x, _("date requires a string"))
617 dm = util.matchdate(ds)
617 dm = util.matchdate(ds)
618 return subset.filter(lambda x: dm(repo[x].date()[0]))
618 return subset.filter(lambda x: dm(repo[x].date()[0]))
619
619
620 def desc(repo, subset, x):
620 def desc(repo, subset, x):
621 """``desc(string)``
621 """``desc(string)``
622 Search commit message for string. The match is case-insensitive.
622 Search commit message for string. The match is case-insensitive.
623 """
623 """
624 # i18n: "desc" is a keyword
624 # i18n: "desc" is a keyword
625 ds = encoding.lower(getstring(x, _("desc requires a string")))
625 ds = encoding.lower(getstring(x, _("desc requires a string")))
626
626
627 def matches(x):
627 def matches(x):
628 c = repo[x]
628 c = repo[x]
629 return ds in encoding.lower(c.description())
629 return ds in encoding.lower(c.description())
630
630
631 return subset.filter(matches)
631 return subset.filter(matches)
632
632
633 def _descendants(repo, subset, x, followfirst=False):
633 def _descendants(repo, subset, x, followfirst=False):
634 roots = getset(repo, spanset(repo), x)
634 roots = getset(repo, spanset(repo), x)
635 if not roots:
635 if not roots:
636 return baseset()
636 return baseset()
637 s = _revdescendants(repo, roots, followfirst)
637 s = _revdescendants(repo, roots, followfirst)
638
638
639 # Both sets need to be ascending in order to lazily return the union
639 # Both sets need to be ascending in order to lazily return the union
640 # in the correct order.
640 # in the correct order.
641 base = subset & roots
641 base = subset & roots
642 desc = subset & s
642 desc = subset & s
643 result = base + desc
643 result = base + desc
644 if subset.isascending():
644 if subset.isascending():
645 result.sort()
645 result.sort()
646 elif subset.isdescending():
646 elif subset.isdescending():
647 result.sort(reverse=True)
647 result.sort(reverse=True)
648 else:
648 else:
649 result = subset & result
649 result = subset & result
650 return result
650 return result
651
651
652 def descendants(repo, subset, x):
652 def descendants(repo, subset, x):
653 """``descendants(set)``
653 """``descendants(set)``
654 Changesets which are descendants of changesets in set.
654 Changesets which are descendants of changesets in set.
655 """
655 """
656 return _descendants(repo, subset, x)
656 return _descendants(repo, subset, x)
657
657
658 def _firstdescendants(repo, subset, x):
658 def _firstdescendants(repo, subset, x):
659 # ``_firstdescendants(set)``
659 # ``_firstdescendants(set)``
660 # Like ``descendants(set)`` but follows only the first parents.
660 # Like ``descendants(set)`` but follows only the first parents.
661 return _descendants(repo, subset, x, followfirst=True)
661 return _descendants(repo, subset, x, followfirst=True)
662
662
663 def destination(repo, subset, x):
663 def destination(repo, subset, x):
664 """``destination([set])``
664 """``destination([set])``
665 Changesets that were created by a graft, transplant or rebase operation,
665 Changesets that were created by a graft, transplant or rebase operation,
666 with the given revisions specified as the source. Omitting the optional set
666 with the given revisions specified as the source. Omitting the optional set
667 is the same as passing all().
667 is the same as passing all().
668 """
668 """
669 if x is not None:
669 if x is not None:
670 sources = getset(repo, spanset(repo), x)
670 sources = getset(repo, spanset(repo), x)
671 else:
671 else:
672 sources = getall(repo, spanset(repo), x)
672 sources = getall(repo, spanset(repo), x)
673
673
674 dests = set()
674 dests = set()
675
675
676 # subset contains all of the possible destinations that can be returned, so
676 # subset contains all of the possible destinations that can be returned, so
677 # iterate over them and see if their source(s) were provided in the arg set.
677 # iterate over them and see if their source(s) were provided in the arg set.
678 # Even if the immediate src of r is not in the arg set, src's source (or
678 # Even if the immediate src of r is not in the arg set, src's source (or
679 # further back) may be. Scanning back further than the immediate src allows
679 # further back) may be. Scanning back further than the immediate src allows
680 # transitive transplants and rebases to yield the same results as transitive
680 # transitive transplants and rebases to yield the same results as transitive
681 # grafts.
681 # grafts.
682 for r in subset:
682 for r in subset:
683 src = _getrevsource(repo, r)
683 src = _getrevsource(repo, r)
684 lineage = None
684 lineage = None
685
685
686 while src is not None:
686 while src is not None:
687 if lineage is None:
687 if lineage is None:
688 lineage = list()
688 lineage = list()
689
689
690 lineage.append(r)
690 lineage.append(r)
691
691
692 # The visited lineage is a match if the current source is in the arg
692 # The visited lineage is a match if the current source is in the arg
693 # set. Since every candidate dest is visited by way of iterating
693 # set. Since every candidate dest is visited by way of iterating
694 # subset, any dests further back in the lineage will be tested by a
694 # subset, any dests further back in the lineage will be tested by a
695 # different iteration over subset. Likewise, if the src was already
695 # different iteration over subset. Likewise, if the src was already
696 # selected, the current lineage can be selected without going back
696 # selected, the current lineage can be selected without going back
697 # further.
697 # further.
698 if src in sources or src in dests:
698 if src in sources or src in dests:
699 dests.update(lineage)
699 dests.update(lineage)
700 break
700 break
701
701
702 r = src
702 r = src
703 src = _getrevsource(repo, r)
703 src = _getrevsource(repo, r)
704
704
705 return subset.filter(dests.__contains__)
705 return subset.filter(dests.__contains__)
706
706
707 def divergent(repo, subset, x):
707 def divergent(repo, subset, x):
708 """``divergent()``
708 """``divergent()``
709 Final successors of changesets with an alternative set of final successors.
709 Final successors of changesets with an alternative set of final successors.
710 """
710 """
711 # i18n: "divergent" is a keyword
711 # i18n: "divergent" is a keyword
712 getargs(x, 0, 0, _("divergent takes no arguments"))
712 getargs(x, 0, 0, _("divergent takes no arguments"))
713 divergent = obsmod.getrevs(repo, 'divergent')
713 divergent = obsmod.getrevs(repo, 'divergent')
714 return subset & divergent
714 return subset & divergent
715
715
716 def draft(repo, subset, x):
716 def draft(repo, subset, x):
717 """``draft()``
717 """``draft()``
718 Changeset in draft phase."""
718 Changeset in draft phase."""
719 # i18n: "draft" is a keyword
719 # i18n: "draft" is a keyword
720 getargs(x, 0, 0, _("draft takes no arguments"))
720 getargs(x, 0, 0, _("draft takes no arguments"))
721 phase = repo._phasecache.phase
721 phase = repo._phasecache.phase
722 target = phases.draft
722 target = phases.draft
723 condition = lambda r: phase(repo, r) == target
723 condition = lambda r: phase(repo, r) == target
724 return subset.filter(condition, cache=False)
724 return subset.filter(condition, cache=False)
725
725
726 def extinct(repo, subset, x):
726 def extinct(repo, subset, x):
727 """``extinct()``
727 """``extinct()``
728 Obsolete changesets with obsolete descendants only.
728 Obsolete changesets with obsolete descendants only.
729 """
729 """
730 # i18n: "extinct" is a keyword
730 # i18n: "extinct" is a keyword
731 getargs(x, 0, 0, _("extinct takes no arguments"))
731 getargs(x, 0, 0, _("extinct takes no arguments"))
732 extincts = obsmod.getrevs(repo, 'extinct')
732 extincts = obsmod.getrevs(repo, 'extinct')
733 return subset & extincts
733 return subset & extincts
734
734
735 def extra(repo, subset, x):
735 def extra(repo, subset, x):
736 """``extra(label, [value])``
736 """``extra(label, [value])``
737 Changesets with the given label in the extra metadata, with the given
737 Changesets with the given label in the extra metadata, with the given
738 optional value.
738 optional value.
739
739
740 If `value` starts with `re:`, the remainder of the value is treated as
740 If `value` starts with `re:`, the remainder of the value is treated as
741 a regular expression. To match a value that actually starts with `re:`,
741 a regular expression. To match a value that actually starts with `re:`,
742 use the prefix `literal:`.
742 use the prefix `literal:`.
743 """
743 """
744
744
745 # i18n: "extra" is a keyword
745 # i18n: "extra" is a keyword
746 l = getargs(x, 1, 2, _('extra takes at least 1 and at most 2 arguments'))
746 l = getargs(x, 1, 2, _('extra takes at least 1 and at most 2 arguments'))
747 # i18n: "extra" is a keyword
747 # i18n: "extra" is a keyword
748 label = getstring(l[0], _('first argument to extra must be a string'))
748 label = getstring(l[0], _('first argument to extra must be a string'))
749 value = None
749 value = None
750
750
751 if len(l) > 1:
751 if len(l) > 1:
752 # i18n: "extra" is a keyword
752 # i18n: "extra" is a keyword
753 value = getstring(l[1], _('second argument to extra must be a string'))
753 value = getstring(l[1], _('second argument to extra must be a string'))
754 kind, value, matcher = _stringmatcher(value)
754 kind, value, matcher = _stringmatcher(value)
755
755
756 def _matchvalue(r):
756 def _matchvalue(r):
757 extra = repo[r].extra()
757 extra = repo[r].extra()
758 return label in extra and (value is None or matcher(extra[label]))
758 return label in extra and (value is None or matcher(extra[label]))
759
759
760 return subset.filter(lambda r: _matchvalue(r))
760 return subset.filter(lambda r: _matchvalue(r))
761
761
762 def filelog(repo, subset, x):
762 def filelog(repo, subset, x):
763 """``filelog(pattern)``
763 """``filelog(pattern)``
764 Changesets connected to the specified filelog.
764 Changesets connected to the specified filelog.
765
765
766 For performance reasons, visits only revisions mentioned in the file-level
766 For performance reasons, visits only revisions mentioned in the file-level
767 filelog, rather than filtering through all changesets (much faster, but
767 filelog, rather than filtering through all changesets (much faster, but
768 doesn't include deletes or duplicate changes). For a slower, more accurate
768 doesn't include deletes or duplicate changes). For a slower, more accurate
769 result, use ``file()``.
769 result, use ``file()``.
770
770
771 The pattern without explicit kind like ``glob:`` is expected to be
771 The pattern without explicit kind like ``glob:`` is expected to be
772 relative to the current directory and match against a file exactly
772 relative to the current directory and match against a file exactly
773 for efficiency.
773 for efficiency.
774
774
775 If some linkrev points to revisions filtered by the current repoview, we'll
775 If some linkrev points to revisions filtered by the current repoview, we'll
776 work around it to return a non-filtered value.
776 work around it to return a non-filtered value.
777 """
777 """
778
778
779 # i18n: "filelog" is a keyword
779 # i18n: "filelog" is a keyword
780 pat = getstring(x, _("filelog requires a pattern"))
780 pat = getstring(x, _("filelog requires a pattern"))
781 s = set()
781 s = set()
782 cl = repo.changelog
782 cl = repo.changelog
783
783
784 if not matchmod.patkind(pat):
784 if not matchmod.patkind(pat):
785 f = pathutil.canonpath(repo.root, repo.getcwd(), pat)
785 f = pathutil.canonpath(repo.root, repo.getcwd(), pat)
786 files = [f]
786 files = [f]
787 else:
787 else:
788 m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=repo[None])
788 m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=repo[None])
789 files = (f for f in repo[None] if m(f))
789 files = (f for f in repo[None] if m(f))
790
790
791 for f in files:
791 for f in files:
792 backrevref = {} # final value for: changerev -> filerev
792 backrevref = {} # final value for: changerev -> filerev
793 lowestchild = {} # lowest known filerev child of a filerev
793 lowestchild = {} # lowest known filerev child of a filerev
794 delayed = [] # filerev with filtered linkrev, for post-processing
794 delayed = [] # filerev with filtered linkrev, for post-processing
795 lowesthead = None # cache for manifest content of all head revisions
795 lowesthead = None # cache for manifest content of all head revisions
796 fl = repo.file(f)
796 fl = repo.file(f)
797 for fr in list(fl):
797 for fr in list(fl):
798 lkr = rev = fl.linkrev(fr)
798 lkr = rev = fl.linkrev(fr)
799 if rev not in cl:
799 if rev not in cl:
800 # changerev pointed in linkrev is filtered
800 # changerev pointed in linkrev is filtered
801 # record it for post processing.
801 # record it for post processing.
802 delayed.append((fr, rev))
802 delayed.append((fr, rev))
803 continue
803 continue
804 for p in fl.parentrevs(fr):
804 for p in fl.parentrevs(fr):
805 if 0 <= p and p not in lowestchild:
805 if 0 <= p and p not in lowestchild:
806 lowestchild[p] = fr
806 lowestchild[p] = fr
807 backrevref[fr] = rev
807 backrevref[fr] = rev
808 s.add(rev)
808 s.add(rev)
809
809
810 # Post-processing of all filerevs we skipped because they were
810 # Post-processing of all filerevs we skipped because they were
811 # filtered. If such filerevs have known and unfiltered children, this
811 # filtered. If such filerevs have known and unfiltered children, this
812 # means they have an unfiltered appearance out there. We'll use linkrev
812 # means they have an unfiltered appearance out there. We'll use linkrev
813 # adjustment to find one of these appearances. The lowest known child
813 # adjustment to find one of these appearances. The lowest known child
814 # will be used as a starting point because it is the best upper-bound we
814 # will be used as a starting point because it is the best upper-bound we
815 # have.
815 # have.
816 #
816 #
817 # This approach will fail when an unfiltered but linkrev-shadowed
817 # This approach will fail when an unfiltered but linkrev-shadowed
818 # appearance exists in a head changeset without unfiltered filerev
818 # appearance exists in a head changeset without unfiltered filerev
819 # children anywhere.
819 # children anywhere.
820 while delayed:
820 while delayed:
821 # must be a descending iteration. To slowly fill lowest child
821 # must be a descending iteration. To slowly fill lowest child
822 # information that is of potential use by the next item.
822 # information that is of potential use by the next item.
823 fr, rev = delayed.pop()
823 fr, rev = delayed.pop()
824 lkr = rev
824 lkr = rev
825
825
826 child = lowestchild.get(fr)
826 child = lowestchild.get(fr)
827
827
828 if child is None:
828 if child is None:
829 # search for existence of this file revision in a head revision.
829 # search for existence of this file revision in a head revision.
830 # There are three possibilities:
830 # There are three possibilities:
831 # - the revision exists in a head and we can find an
831 # - the revision exists in a head and we can find an
832 # introduction from there,
832 # introduction from there,
833 # - the revision does not exist in a head because it has been
833 # - the revision does not exist in a head because it has been
834 # changed since its introduction: we would have found a child
834 # changed since its introduction: we would have found a child
835 # and be in the other 'else' clause,
835 # and be in the other 'else' clause,
836 # - all versions of the revision are hidden.
836 # - all versions of the revision are hidden.
837 if lowesthead is None:
837 if lowesthead is None:
838 lowesthead = {}
838 lowesthead = {}
839 for h in repo.heads():
839 for h in repo.heads():
840 fnode = repo[h].manifest()[f]
840 fnode = repo[h].manifest().get(f)
841 lowesthead[fl.rev(fnode)] = h
841 if fnode is not None:
842 lowesthead[fl.rev(fnode)] = h
842 headrev = lowesthead.get(fr)
843 headrev = lowesthead.get(fr)
843 if headrev is None:
844 if headrev is None:
844 # content is nowhere unfiltered
845 # content is nowhere unfiltered
845 continue
846 continue
846 rev = repo[headrev][f].introrev()
847 rev = repo[headrev][f].introrev()
847 else:
848 else:
848 # the lowest known child is a good upper bound
849 # the lowest known child is a good upper bound
849 childcrev = backrevref[child]
850 childcrev = backrevref[child]
850 # XXX this does not guarantee returning the lowest
851 # XXX this does not guarantee returning the lowest
851 # introduction of this revision, but this gives a
852 # introduction of this revision, but this gives a
852 # result which is a good start and will fit in most
853 # result which is a good start and will fit in most
853 # cases. We probably need to fix the multiple
854 # cases. We probably need to fix the multiple
854 # introductions case properly (report each
855 # introductions case properly (report each
855 # introduction, even for identical file revisions)
856 # introduction, even for identical file revisions)
856 # once and for all at some point anyway.
857 # once and for all at some point anyway.
857 for p in repo[childcrev][f].parents():
858 for p in repo[childcrev][f].parents():
858 if p.filerev() == fr:
859 if p.filerev() == fr:
859 rev = p.rev()
860 rev = p.rev()
860 break
861 break
861 if rev == lkr: # no shadowed entry found
862 if rev == lkr: # no shadowed entry found
862 # XXX This should never happen unless some manifest points
863 # XXX This should never happen unless some manifest points
863 # to biggish file revisions (like a revision that uses a
864 # to biggish file revisions (like a revision that uses a
864 # parent that never appears in the manifest ancestors)
865 # parent that never appears in the manifest ancestors)
865 continue
866 continue
866
867
867 # Fill the data for the next iteration.
868 # Fill the data for the next iteration.
868 for p in fl.parentrevs(fr):
869 for p in fl.parentrevs(fr):
869 if 0 <= p and p not in lowestchild:
870 if 0 <= p and p not in lowestchild:
870 lowestchild[p] = fr
871 lowestchild[p] = fr
871 backrevref[fr] = rev
872 backrevref[fr] = rev
872 s.add(rev)
873 s.add(rev)
873
874
874 return subset & s
875 return subset & s
875
876
876 def first(repo, subset, x):
877 def first(repo, subset, x):
877 """``first(set, [n])``
878 """``first(set, [n])``
878 An alias for limit().
879 An alias for limit().
879 """
880 """
880 return limit(repo, subset, x)
881 return limit(repo, subset, x)
881
882
882 def _follow(repo, subset, x, name, followfirst=False):
883 def _follow(repo, subset, x, name, followfirst=False):
883 l = getargs(x, 0, 1, _("%s takes no arguments or a filename") % name)
884 l = getargs(x, 0, 1, _("%s takes no arguments or a filename") % name)
884 c = repo['.']
885 c = repo['.']
885 if l:
886 if l:
886 x = getstring(l[0], _("%s expected a filename") % name)
887 x = getstring(l[0], _("%s expected a filename") % name)
887 if x in c:
888 if x in c:
888 cx = c[x]
889 cx = c[x]
889 s = set(ctx.rev() for ctx in cx.ancestors(followfirst=followfirst))
890 s = set(ctx.rev() for ctx in cx.ancestors(followfirst=followfirst))
890 # include the revision responsible for the most recent version
891 # include the revision responsible for the most recent version
891 s.add(cx.introrev())
892 s.add(cx.introrev())
892 else:
893 else:
893 return baseset()
894 return baseset()
894 else:
895 else:
895 s = _revancestors(repo, baseset([c.rev()]), followfirst)
896 s = _revancestors(repo, baseset([c.rev()]), followfirst)
896
897
897 return subset & s
898 return subset & s
898
899
899 def follow(repo, subset, x):
900 def follow(repo, subset, x):
900 """``follow([file])``
901 """``follow([file])``
901 An alias for ``::.`` (ancestors of the working copy's first parent).
902 An alias for ``::.`` (ancestors of the working copy's first parent).
902 If a filename is specified, the history of the given file is followed,
903 If a filename is specified, the history of the given file is followed,
903 including copies.
904 including copies.
904 """
905 """
905 return _follow(repo, subset, x, 'follow')
906 return _follow(repo, subset, x, 'follow')
906
907
907 def _followfirst(repo, subset, x):
908 def _followfirst(repo, subset, x):
908 # ``followfirst([file])``
909 # ``followfirst([file])``
909 # Like ``follow([file])`` but follows only the first parent of
910 # Like ``follow([file])`` but follows only the first parent of
910 # every revision or file revision.
911 # every revision or file revision.
911 return _follow(repo, subset, x, '_followfirst', followfirst=True)
912 return _follow(repo, subset, x, '_followfirst', followfirst=True)
912
913
913 def getall(repo, subset, x):
914 def getall(repo, subset, x):
914 """``all()``
915 """``all()``
915 All changesets, the same as ``0:tip``.
916 All changesets, the same as ``0:tip``.
916 """
917 """
917 # i18n: "all" is a keyword
918 # i18n: "all" is a keyword
918 getargs(x, 0, 0, _("all takes no arguments"))
919 getargs(x, 0, 0, _("all takes no arguments"))
919 return subset
920 return subset
920
921
921 def grep(repo, subset, x):
922 def grep(repo, subset, x):
922 """``grep(regex)``
923 """``grep(regex)``
923 Like ``keyword(string)`` but accepts a regex. Use ``grep(r'...')``
924 Like ``keyword(string)`` but accepts a regex. Use ``grep(r'...')``
924 to ensure special escape characters are handled correctly. Unlike
925 to ensure special escape characters are handled correctly. Unlike
925 ``keyword(string)``, the match is case-sensitive.
926 ``keyword(string)``, the match is case-sensitive.
926 """
927 """
927 try:
928 try:
928 # i18n: "grep" is a keyword
929 # i18n: "grep" is a keyword
929 gr = re.compile(getstring(x, _("grep requires a string")))
930 gr = re.compile(getstring(x, _("grep requires a string")))
930 except re.error, e:
931 except re.error, e:
931 raise error.ParseError(_('invalid match pattern: %s') % e)
932 raise error.ParseError(_('invalid match pattern: %s') % e)
932
933
933 def matches(x):
934 def matches(x):
934 c = repo[x]
935 c = repo[x]
935 for e in c.files() + [c.user(), c.description()]:
936 for e in c.files() + [c.user(), c.description()]:
936 if gr.search(e):
937 if gr.search(e):
937 return True
938 return True
938 return False
939 return False
939
940
940 return subset.filter(matches)
941 return subset.filter(matches)
941
942
942 def _matchfiles(repo, subset, x):
943 def _matchfiles(repo, subset, x):
943 # _matchfiles takes a revset list of prefixed arguments:
944 # _matchfiles takes a revset list of prefixed arguments:
944 #
945 #
945 # [p:foo, i:bar, x:baz]
946 # [p:foo, i:bar, x:baz]
946 #
947 #
947 # builds a match object from them and filters subset. Allowed
948 # builds a match object from them and filters subset. Allowed
948 # prefixes are 'p:' for regular patterns, 'i:' for include
949 # prefixes are 'p:' for regular patterns, 'i:' for include
949 # patterns and 'x:' for exclude patterns. Use 'r:' prefix to pass
950 # patterns and 'x:' for exclude patterns. Use 'r:' prefix to pass
950 # a revision identifier, or the empty string to reference the
951 # a revision identifier, or the empty string to reference the
951 # working directory, from which the match object is
952 # working directory, from which the match object is
952 # initialized. Use 'd:' to set the default matching mode, default
953 # initialized. Use 'd:' to set the default matching mode, default
953 # to 'glob'. At most one 'r:' and 'd:' argument can be passed.
954 # to 'glob'. At most one 'r:' and 'd:' argument can be passed.
954
955
955 # i18n: "_matchfiles" is a keyword
956 # i18n: "_matchfiles" is a keyword
956 l = getargs(x, 1, -1, _("_matchfiles requires at least one argument"))
957 l = getargs(x, 1, -1, _("_matchfiles requires at least one argument"))
957 pats, inc, exc = [], [], []
958 pats, inc, exc = [], [], []
958 rev, default = None, None
959 rev, default = None, None
959 for arg in l:
960 for arg in l:
960 # i18n: "_matchfiles" is a keyword
961 # i18n: "_matchfiles" is a keyword
961 s = getstring(arg, _("_matchfiles requires string arguments"))
962 s = getstring(arg, _("_matchfiles requires string arguments"))
962 prefix, value = s[:2], s[2:]
963 prefix, value = s[:2], s[2:]
963 if prefix == 'p:':
964 if prefix == 'p:':
964 pats.append(value)
965 pats.append(value)
965 elif prefix == 'i:':
966 elif prefix == 'i:':
966 inc.append(value)
967 inc.append(value)
967 elif prefix == 'x:':
968 elif prefix == 'x:':
968 exc.append(value)
969 exc.append(value)
969 elif prefix == 'r:':
970 elif prefix == 'r:':
970 if rev is not None:
971 if rev is not None:
971 # i18n: "_matchfiles" is a keyword
972 # i18n: "_matchfiles" is a keyword
972 raise error.ParseError(_('_matchfiles expected at most one '
973 raise error.ParseError(_('_matchfiles expected at most one '
973 'revision'))
974 'revision'))
974 rev = value
975 rev = value
975 elif prefix == 'd:':
976 elif prefix == 'd:':
976 if default is not None:
977 if default is not None:
977 # i18n: "_matchfiles" is a keyword
978 # i18n: "_matchfiles" is a keyword
978 raise error.ParseError(_('_matchfiles expected at most one '
979 raise error.ParseError(_('_matchfiles expected at most one '
979 'default mode'))
980 'default mode'))
980 default = value
981 default = value
981 else:
982 else:
982 # i18n: "_matchfiles" is a keyword
983 # i18n: "_matchfiles" is a keyword
983 raise error.ParseError(_('invalid _matchfiles prefix: %s') % prefix)
984 raise error.ParseError(_('invalid _matchfiles prefix: %s') % prefix)
984 if not default:
985 if not default:
985 default = 'glob'
986 default = 'glob'
986
987
987 m = matchmod.match(repo.root, repo.getcwd(), pats, include=inc,
988 m = matchmod.match(repo.root, repo.getcwd(), pats, include=inc,
988 exclude=exc, ctx=repo[rev], default=default)
989 exclude=exc, ctx=repo[rev], default=default)
989
990
990 def matches(x):
991 def matches(x):
991 for f in repo[x].files():
992 for f in repo[x].files():
992 if m(f):
993 if m(f):
993 return True
994 return True
994 return False
995 return False
995
996
996 return subset.filter(matches)
997 return subset.filter(matches)
997
998
998 def hasfile(repo, subset, x):
999 def hasfile(repo, subset, x):
999 """``file(pattern)``
1000 """``file(pattern)``
1000 Changesets affecting files matched by pattern.
1001 Changesets affecting files matched by pattern.
1001
1002
1002 For a faster but less accurate result, consider using ``filelog()``
1003 For a faster but less accurate result, consider using ``filelog()``
1003 instead.
1004 instead.
1004
1005
1005 This predicate uses ``glob:`` as the default kind of pattern.
1006 This predicate uses ``glob:`` as the default kind of pattern.
1006 """
1007 """
1007 # i18n: "file" is a keyword
1008 # i18n: "file" is a keyword
1008 pat = getstring(x, _("file requires a pattern"))
1009 pat = getstring(x, _("file requires a pattern"))
1009 return _matchfiles(repo, subset, ('string', 'p:' + pat))
1010 return _matchfiles(repo, subset, ('string', 'p:' + pat))
1010
1011
1011 def head(repo, subset, x):
1012 def head(repo, subset, x):
1012 """``head()``
1013 """``head()``
1013 Changeset is a named branch head.
1014 Changeset is a named branch head.
1014 """
1015 """
1015 # i18n: "head" is a keyword
1016 # i18n: "head" is a keyword
1016 getargs(x, 0, 0, _("head takes no arguments"))
1017 getargs(x, 0, 0, _("head takes no arguments"))
1017 hs = set()
1018 hs = set()
1018 for b, ls in repo.branchmap().iteritems():
1019 for b, ls in repo.branchmap().iteritems():
1019 hs.update(repo[h].rev() for h in ls)
1020 hs.update(repo[h].rev() for h in ls)
1020 return baseset(hs).filter(subset.__contains__)
1021 return baseset(hs).filter(subset.__contains__)
1021
1022
1022 def heads(repo, subset, x):
1023 def heads(repo, subset, x):
1023 """``heads(set)``
1024 """``heads(set)``
1024 Members of set with no children in set.
1025 Members of set with no children in set.
1025 """
1026 """
1026 s = getset(repo, subset, x)
1027 s = getset(repo, subset, x)
1027 ps = parents(repo, subset, x)
1028 ps = parents(repo, subset, x)
1028 return s - ps
1029 return s - ps
1029
1030
1030 def hidden(repo, subset, x):
1031 def hidden(repo, subset, x):
1031 """``hidden()``
1032 """``hidden()``
1032 Hidden changesets.
1033 Hidden changesets.
1033 """
1034 """
1034 # i18n: "hidden" is a keyword
1035 # i18n: "hidden" is a keyword
1035 getargs(x, 0, 0, _("hidden takes no arguments"))
1036 getargs(x, 0, 0, _("hidden takes no arguments"))
1036 hiddenrevs = repoview.filterrevs(repo, 'visible')
1037 hiddenrevs = repoview.filterrevs(repo, 'visible')
1037 return subset & hiddenrevs
1038 return subset & hiddenrevs
1038
1039
1039 def keyword(repo, subset, x):
1040 def keyword(repo, subset, x):
1040 """``keyword(string)``
1041 """``keyword(string)``
1041 Search commit message, user name, and names of changed files for
1042 Search commit message, user name, and names of changed files for
1042 string. The match is case-insensitive.
1043 string. The match is case-insensitive.
1043 """
1044 """
1044 # i18n: "keyword" is a keyword
1045 # i18n: "keyword" is a keyword
1045 kw = encoding.lower(getstring(x, _("keyword requires a string")))
1046 kw = encoding.lower(getstring(x, _("keyword requires a string")))
1046
1047
1047 def matches(r):
1048 def matches(r):
1048 c = repo[r]
1049 c = repo[r]
1049 return util.any(kw in encoding.lower(t) for t in c.files() + [c.user(),
1050 return util.any(kw in encoding.lower(t) for t in c.files() + [c.user(),
1050 c.description()])
1051 c.description()])
1051
1052
1052 return subset.filter(matches)
1053 return subset.filter(matches)
1053
1054
1054 def limit(repo, subset, x):
1055 def limit(repo, subset, x):
1055 """``limit(set, [n])``
1056 """``limit(set, [n])``
1056 First n members of set, defaulting to 1.
1057 First n members of set, defaulting to 1.
1057 """
1058 """
1058 # i18n: "limit" is a keyword
1059 # i18n: "limit" is a keyword
1059 l = getargs(x, 1, 2, _("limit requires one or two arguments"))
1060 l = getargs(x, 1, 2, _("limit requires one or two arguments"))
1060 try:
1061 try:
1061 lim = 1
1062 lim = 1
1062 if len(l) == 2:
1063 if len(l) == 2:
1063 # i18n: "limit" is a keyword
1064 # i18n: "limit" is a keyword
1064 lim = int(getstring(l[1], _("limit requires a number")))
1065 lim = int(getstring(l[1], _("limit requires a number")))
1065 except (TypeError, ValueError):
1066 except (TypeError, ValueError):
1066 # i18n: "limit" is a keyword
1067 # i18n: "limit" is a keyword
1067 raise error.ParseError(_("limit expects a number"))
1068 raise error.ParseError(_("limit expects a number"))
1068 ss = subset
1069 ss = subset
1069 os = getset(repo, spanset(repo), l[0])
1070 os = getset(repo, spanset(repo), l[0])
1070 result = []
1071 result = []
1071 it = iter(os)
1072 it = iter(os)
1072 for x in xrange(lim):
1073 for x in xrange(lim):
1073 try:
1074 try:
1074 y = it.next()
1075 y = it.next()
1075 if y in ss:
1076 if y in ss:
1076 result.append(y)
1077 result.append(y)
1077 except (StopIteration):
1078 except (StopIteration):
1078 break
1079 break
1079 return baseset(result)
1080 return baseset(result)
1080
1081
1081 def last(repo, subset, x):
1082 def last(repo, subset, x):
1082 """``last(set, [n])``
1083 """``last(set, [n])``
1083 Last n members of set, defaulting to 1.
1084 Last n members of set, defaulting to 1.
1084 """
1085 """
1085 # i18n: "last" is a keyword
1086 # i18n: "last" is a keyword
1086 l = getargs(x, 1, 2, _("last requires one or two arguments"))
1087 l = getargs(x, 1, 2, _("last requires one or two arguments"))
1087 try:
1088 try:
1088 lim = 1
1089 lim = 1
1089 if len(l) == 2:
1090 if len(l) == 2:
1090 # i18n: "last" is a keyword
1091 # i18n: "last" is a keyword
1091 lim = int(getstring(l[1], _("last requires a number")))
1092 lim = int(getstring(l[1], _("last requires a number")))
1092 except (TypeError, ValueError):
1093 except (TypeError, ValueError):
1093 # i18n: "last" is a keyword
1094 # i18n: "last" is a keyword
1094 raise error.ParseError(_("last expects a number"))
1095 raise error.ParseError(_("last expects a number"))
1095 ss = subset
1096 ss = subset
1096 os = getset(repo, spanset(repo), l[0])
1097 os = getset(repo, spanset(repo), l[0])
1097 os.reverse()
1098 os.reverse()
1098 result = []
1099 result = []
1099 it = iter(os)
1100 it = iter(os)
1100 for x in xrange(lim):
1101 for x in xrange(lim):
1101 try:
1102 try:
1102 y = it.next()
1103 y = it.next()
1103 if y in ss:
1104 if y in ss:
1104 result.append(y)
1105 result.append(y)
1105 except (StopIteration):
1106 except (StopIteration):
1106 break
1107 break
1107 return baseset(result)
1108 return baseset(result)
1108
1109
1109 def maxrev(repo, subset, x):
1110 def maxrev(repo, subset, x):
1110 """``max(set)``
1111 """``max(set)``
1111 Changeset with highest revision number in set.
1112 Changeset with highest revision number in set.
1112 """
1113 """
1113 os = getset(repo, spanset(repo), x)
1114 os = getset(repo, spanset(repo), x)
1114 if os:
1115 if os:
1115 m = os.max()
1116 m = os.max()
1116 if m in subset:
1117 if m in subset:
1117 return baseset([m])
1118 return baseset([m])
1118 return baseset()
1119 return baseset()
1119
1120
1120 def merge(repo, subset, x):
1121 def merge(repo, subset, x):
1121 """``merge()``
1122 """``merge()``
1122 Changeset is a merge changeset.
1123 Changeset is a merge changeset.
1123 """
1124 """
1124 # i18n: "merge" is a keyword
1125 # i18n: "merge" is a keyword
1125 getargs(x, 0, 0, _("merge takes no arguments"))
1126 getargs(x, 0, 0, _("merge takes no arguments"))
1126 cl = repo.changelog
1127 cl = repo.changelog
1127 return subset.filter(lambda r: cl.parentrevs(r)[1] != -1)
1128 return subset.filter(lambda r: cl.parentrevs(r)[1] != -1)
1128
1129
1129 def branchpoint(repo, subset, x):
1130 def branchpoint(repo, subset, x):
1130 """``branchpoint()``
1131 """``branchpoint()``
1131 Changesets with more than one child.
1132 Changesets with more than one child.
1132 """
1133 """
1133 # i18n: "branchpoint" is a keyword
1134 # i18n: "branchpoint" is a keyword
1134 getargs(x, 0, 0, _("branchpoint takes no arguments"))
1135 getargs(x, 0, 0, _("branchpoint takes no arguments"))
1135 cl = repo.changelog
1136 cl = repo.changelog
1136 if not subset:
1137 if not subset:
1137 return baseset()
1138 return baseset()
1138 baserev = min(subset)
1139 baserev = min(subset)
1139 parentscount = [0]*(len(repo) - baserev)
1140 parentscount = [0]*(len(repo) - baserev)
1140 for r in cl.revs(start=baserev + 1):
1141 for r in cl.revs(start=baserev + 1):
1141 for p in cl.parentrevs(r):
1142 for p in cl.parentrevs(r):
1142 if p >= baserev:
1143 if p >= baserev:
1143 parentscount[p - baserev] += 1
1144 parentscount[p - baserev] += 1
1144 return subset.filter(lambda r: parentscount[r - baserev] > 1)
1145 return subset.filter(lambda r: parentscount[r - baserev] > 1)
1145
1146
1146 def minrev(repo, subset, x):
1147 def minrev(repo, subset, x):
1147 """``min(set)``
1148 """``min(set)``
1148 Changeset with lowest revision number in set.
1149 Changeset with lowest revision number in set.
1149 """
1150 """
1150 os = getset(repo, spanset(repo), x)
1151 os = getset(repo, spanset(repo), x)
1151 if os:
1152 if os:
1152 m = os.min()
1153 m = os.min()
1153 if m in subset:
1154 if m in subset:
1154 return baseset([m])
1155 return baseset([m])
1155 return baseset()
1156 return baseset()
1156
1157
1157 def modifies(repo, subset, x):
1158 def modifies(repo, subset, x):
1158 """``modifies(pattern)``
1159 """``modifies(pattern)``
1159 Changesets modifying files matched by pattern.
1160 Changesets modifying files matched by pattern.
1160
1161
1161 The pattern without explicit kind like ``glob:`` is expected to be
1162 The pattern without explicit kind like ``glob:`` is expected to be
1162 relative to the current directory and match against a file or a
1163 relative to the current directory and match against a file or a
1163 directory.
1164 directory.
1164 """
1165 """
1165 # i18n: "modifies" is a keyword
1166 # i18n: "modifies" is a keyword
1166 pat = getstring(x, _("modifies requires a pattern"))
1167 pat = getstring(x, _("modifies requires a pattern"))
1167 return checkstatus(repo, subset, pat, 0)
1168 return checkstatus(repo, subset, pat, 0)
1168
1169
1169 def node_(repo, subset, x):
1170 def node_(repo, subset, x):
1170 """``id(string)``
1171 """``id(string)``
1171 Revision non-ambiguously specified by the given hex string prefix.
1172 Revision non-ambiguously specified by the given hex string prefix.
1172 """
1173 """
1173 # i18n: "id" is a keyword
1174 # i18n: "id" is a keyword
1174 l = getargs(x, 1, 1, _("id requires one argument"))
1175 l = getargs(x, 1, 1, _("id requires one argument"))
1175 # i18n: "id" is a keyword
1176 # i18n: "id" is a keyword
1176 n = getstring(l[0], _("id requires a string"))
1177 n = getstring(l[0], _("id requires a string"))
1177 if len(n) == 40:
1178 if len(n) == 40:
1178 rn = repo[n].rev()
1179 rn = repo[n].rev()
1179 else:
1180 else:
1180 rn = None
1181 rn = None
1181 pm = repo.changelog._partialmatch(n)
1182 pm = repo.changelog._partialmatch(n)
1182 if pm is not None:
1183 if pm is not None:
1183 rn = repo.changelog.rev(pm)
1184 rn = repo.changelog.rev(pm)
1184
1185
1185 if rn is None:
1186 if rn is None:
1186 return baseset()
1187 return baseset()
1187 result = baseset([rn])
1188 result = baseset([rn])
1188 return result & subset
1189 return result & subset
1189
1190
1190 def obsolete(repo, subset, x):
1191 def obsolete(repo, subset, x):
1191 """``obsolete()``
1192 """``obsolete()``
1192 Mutable changeset with a newer version."""
1193 Mutable changeset with a newer version."""
1193 # i18n: "obsolete" is a keyword
1194 # i18n: "obsolete" is a keyword
1194 getargs(x, 0, 0, _("obsolete takes no arguments"))
1195 getargs(x, 0, 0, _("obsolete takes no arguments"))
1195 obsoletes = obsmod.getrevs(repo, 'obsolete')
1196 obsoletes = obsmod.getrevs(repo, 'obsolete')
1196 return subset & obsoletes
1197 return subset & obsoletes
1197
1198
1198 def only(repo, subset, x):
1199 def only(repo, subset, x):
1199 """``only(set, [set])``
1200 """``only(set, [set])``
1200 Changesets that are ancestors of the first set that are not ancestors
1201 Changesets that are ancestors of the first set that are not ancestors
1201 of any other head in the repo. If a second set is specified, the result
1202 of any other head in the repo. If a second set is specified, the result
1202 is ancestors of the first set that are not ancestors of the second set
1203 is ancestors of the first set that are not ancestors of the second set
1203 (i.e. ::<set1> - ::<set2>).
1204 (i.e. ::<set1> - ::<set2>).
1204 """
1205 """
1205 cl = repo.changelog
1206 cl = repo.changelog
1206 # i18n: "only" is a keyword
1207 # i18n: "only" is a keyword
1207 args = getargs(x, 1, 2, _('only takes one or two arguments'))
1208 args = getargs(x, 1, 2, _('only takes one or two arguments'))
1208 include = getset(repo, spanset(repo), args[0])
1209 include = getset(repo, spanset(repo), args[0])
1209 if len(args) == 1:
1210 if len(args) == 1:
1210 if not include:
1211 if not include:
1211 return baseset()
1212 return baseset()
1212
1213
1213 descendants = set(_revdescendants(repo, include, False))
1214 descendants = set(_revdescendants(repo, include, False))
1214 exclude = [rev for rev in cl.headrevs()
1215 exclude = [rev for rev in cl.headrevs()
1215 if not rev in descendants and not rev in include]
1216 if not rev in descendants and not rev in include]
1216 else:
1217 else:
1217 exclude = getset(repo, spanset(repo), args[1])
1218 exclude = getset(repo, spanset(repo), args[1])
1218
1219
1219 results = set(cl.findmissingrevs(common=exclude, heads=include))
1220 results = set(cl.findmissingrevs(common=exclude, heads=include))
1220 return subset & results
1221 return subset & results
1221
1222
1222 def origin(repo, subset, x):
1223 def origin(repo, subset, x):
1223 """``origin([set])``
1224 """``origin([set])``
1224 Changesets that were specified as a source for the grafts, transplants or
1225 Changesets that were specified as a source for the grafts, transplants or
1225 rebases that created the given revisions. Omitting the optional set is the
1226 rebases that created the given revisions. Omitting the optional set is the
1226 same as passing all(). If a changeset created by these operations is itself
1227 same as passing all(). If a changeset created by these operations is itself
1227 specified as a source for one of these operations, only the source changeset
1228 specified as a source for one of these operations, only the source changeset
1228 for the first operation is selected.
1229 for the first operation is selected.
1229 """
1230 """
1230 if x is not None:
1231 if x is not None:
1231 dests = getset(repo, spanset(repo), x)
1232 dests = getset(repo, spanset(repo), x)
1232 else:
1233 else:
1233 dests = getall(repo, spanset(repo), x)
1234 dests = getall(repo, spanset(repo), x)
1234
1235
1235 def _firstsrc(rev):
1236 def _firstsrc(rev):
1236 src = _getrevsource(repo, rev)
1237 src = _getrevsource(repo, rev)
1237 if src is None:
1238 if src is None:
1238 return None
1239 return None
1239
1240
1240 while True:
1241 while True:
1241 prev = _getrevsource(repo, src)
1242 prev = _getrevsource(repo, src)
1242
1243
1243 if prev is None:
1244 if prev is None:
1244 return src
1245 return src
1245 src = prev
1246 src = prev
1246
1247
1247 o = set([_firstsrc(r) for r in dests])
1248 o = set([_firstsrc(r) for r in dests])
1248 o -= set([None])
1249 o -= set([None])
1249 return subset & o
1250 return subset & o
1250
1251
1251 def outgoing(repo, subset, x):
1252 def outgoing(repo, subset, x):
1252 """``outgoing([path])``
1253 """``outgoing([path])``
1253 Changesets not found in the specified destination repository, or the
1254 Changesets not found in the specified destination repository, or the
1254 default push location.
1255 default push location.
1255 """
1256 """
1256 import hg # avoid start-up nasties
1257 import hg # avoid start-up nasties
1257 # i18n: "outgoing" is a keyword
1258 # i18n: "outgoing" is a keyword
1258 l = getargs(x, 0, 1, _("outgoing takes one or no arguments"))
1259 l = getargs(x, 0, 1, _("outgoing takes one or no arguments"))
1259 # i18n: "outgoing" is a keyword
1260 # i18n: "outgoing" is a keyword
1260 dest = l and getstring(l[0], _("outgoing requires a repository path")) or ''
1261 dest = l and getstring(l[0], _("outgoing requires a repository path")) or ''
1261 dest = repo.ui.expandpath(dest or 'default-push', dest or 'default')
1262 dest = repo.ui.expandpath(dest or 'default-push', dest or 'default')
1262 dest, branches = hg.parseurl(dest)
1263 dest, branches = hg.parseurl(dest)
1263 revs, checkout = hg.addbranchrevs(repo, repo, branches, [])
1264 revs, checkout = hg.addbranchrevs(repo, repo, branches, [])
1264 if revs:
1265 if revs:
1265 revs = [repo.lookup(rev) for rev in revs]
1266 revs = [repo.lookup(rev) for rev in revs]
1266 other = hg.peer(repo, {}, dest)
1267 other = hg.peer(repo, {}, dest)
1267 repo.ui.pushbuffer()
1268 repo.ui.pushbuffer()
1268 outgoing = discovery.findcommonoutgoing(repo, other, onlyheads=revs)
1269 outgoing = discovery.findcommonoutgoing(repo, other, onlyheads=revs)
1269 repo.ui.popbuffer()
1270 repo.ui.popbuffer()
1270 cl = repo.changelog
1271 cl = repo.changelog
1271 o = set([cl.rev(r) for r in outgoing.missing])
1272 o = set([cl.rev(r) for r in outgoing.missing])
1272 return subset & o
1273 return subset & o
1273
1274
1274 def p1(repo, subset, x):
1275 def p1(repo, subset, x):
1275 """``p1([set])``
1276 """``p1([set])``
1276 First parent of changesets in set, or the working directory.
1277 First parent of changesets in set, or the working directory.
1277 """
1278 """
1278 if x is None:
1279 if x is None:
1279 p = repo[x].p1().rev()
1280 p = repo[x].p1().rev()
1280 if p >= 0:
1281 if p >= 0:
1281 return subset & baseset([p])
1282 return subset & baseset([p])
1282 return baseset()
1283 return baseset()
1283
1284
1284 ps = set()
1285 ps = set()
1285 cl = repo.changelog
1286 cl = repo.changelog
1286 for r in getset(repo, spanset(repo), x):
1287 for r in getset(repo, spanset(repo), x):
1287 ps.add(cl.parentrevs(r)[0])
1288 ps.add(cl.parentrevs(r)[0])
1288 ps -= set([node.nullrev])
1289 ps -= set([node.nullrev])
1289 return subset & ps
1290 return subset & ps
1290
1291
1291 def p2(repo, subset, x):
1292 def p2(repo, subset, x):
1292 """``p2([set])``
1293 """``p2([set])``
1293 Second parent of changesets in set, or the working directory.
1294 Second parent of changesets in set, or the working directory.
1294 """
1295 """
1295 if x is None:
1296 if x is None:
1296 ps = repo[x].parents()
1297 ps = repo[x].parents()
1297 try:
1298 try:
1298 p = ps[1].rev()
1299 p = ps[1].rev()
1299 if p >= 0:
1300 if p >= 0:
1300 return subset & baseset([p])
1301 return subset & baseset([p])
1301 return baseset()
1302 return baseset()
1302 except IndexError:
1303 except IndexError:
1303 return baseset()
1304 return baseset()
1304
1305
1305 ps = set()
1306 ps = set()
1306 cl = repo.changelog
1307 cl = repo.changelog
1307 for r in getset(repo, spanset(repo), x):
1308 for r in getset(repo, spanset(repo), x):
1308 ps.add(cl.parentrevs(r)[1])
1309 ps.add(cl.parentrevs(r)[1])
1309 ps -= set([node.nullrev])
1310 ps -= set([node.nullrev])
1310 return subset & ps
1311 return subset & ps
1311
1312
1312 def parents(repo, subset, x):
1313 def parents(repo, subset, x):
1313 """``parents([set])``
1314 """``parents([set])``
1314 The set of all parents for all changesets in set, or the working directory.
1315 The set of all parents for all changesets in set, or the working directory.
1315 """
1316 """
1316 if x is None:
1317 if x is None:
1317 ps = set(p.rev() for p in repo[x].parents())
1318 ps = set(p.rev() for p in repo[x].parents())
1318 else:
1319 else:
1319 ps = set()
1320 ps = set()
1320 cl = repo.changelog
1321 cl = repo.changelog
1321 for r in getset(repo, spanset(repo), x):
1322 for r in getset(repo, spanset(repo), x):
1322 ps.update(cl.parentrevs(r))
1323 ps.update(cl.parentrevs(r))
1323 ps -= set([node.nullrev])
1324 ps -= set([node.nullrev])
1324 return subset & ps
1325 return subset & ps
1325
1326
1326 def parentspec(repo, subset, x, n):
1327 def parentspec(repo, subset, x, n):
1327 """``set^0``
1328 """``set^0``
1328 The set.
1329 The set.
1329 ``set^1`` (or ``set^``), ``set^2``
1330 ``set^1`` (or ``set^``), ``set^2``
1330 First or second parent, respectively, of all changesets in set.
1331 First or second parent, respectively, of all changesets in set.
1331 """
1332 """
1332 try:
1333 try:
1333 n = int(n[1])
1334 n = int(n[1])
1334 if n not in (0, 1, 2):
1335 if n not in (0, 1, 2):
1335 raise ValueError
1336 raise ValueError
1336 except (TypeError, ValueError):
1337 except (TypeError, ValueError):
1337 raise error.ParseError(_("^ expects a number 0, 1, or 2"))
1338 raise error.ParseError(_("^ expects a number 0, 1, or 2"))
1338 ps = set()
1339 ps = set()
1339 cl = repo.changelog
1340 cl = repo.changelog
1340 for r in getset(repo, fullreposet(repo), x):
1341 for r in getset(repo, fullreposet(repo), x):
1341 if n == 0:
1342 if n == 0:
1342 ps.add(r)
1343 ps.add(r)
1343 elif n == 1:
1344 elif n == 1:
1344 ps.add(cl.parentrevs(r)[0])
1345 ps.add(cl.parentrevs(r)[0])
1345 elif n == 2:
1346 elif n == 2:
1346 parents = cl.parentrevs(r)
1347 parents = cl.parentrevs(r)
1347 if len(parents) > 1:
1348 if len(parents) > 1:
1348 ps.add(parents[1])
1349 ps.add(parents[1])
1349 return subset & ps
1350 return subset & ps
1350
1351
1351 def present(repo, subset, x):
1352 def present(repo, subset, x):
1352 """``present(set)``
1353 """``present(set)``
1353 An empty set, if any revision in set isn't found; otherwise,
1354 An empty set, if any revision in set isn't found; otherwise,
1354 all revisions in set.
1355 all revisions in set.
1355
1356
1356 If any of specified revisions is not present in the local repository,
1357 If any of specified revisions is not present in the local repository,
1357 the query is normally aborted. But this predicate allows the query
1358 the query is normally aborted. But this predicate allows the query
1358 to continue even in such cases.
1359 to continue even in such cases.
1359 """
1360 """
1360 try:
1361 try:
1361 return getset(repo, subset, x)
1362 return getset(repo, subset, x)
1362 except error.RepoLookupError:
1363 except error.RepoLookupError:
1363 return baseset()
1364 return baseset()
1364
1365
1365 def public(repo, subset, x):
1366 def public(repo, subset, x):
1366 """``public()``
1367 """``public()``
1367 Changeset in public phase."""
1368 Changeset in public phase."""
1368 # i18n: "public" is a keyword
1369 # i18n: "public" is a keyword
1369 getargs(x, 0, 0, _("public takes no arguments"))
1370 getargs(x, 0, 0, _("public takes no arguments"))
1370 phase = repo._phasecache.phase
1371 phase = repo._phasecache.phase
1371 target = phases.public
1372 target = phases.public
1372 condition = lambda r: phase(repo, r) == target
1373 condition = lambda r: phase(repo, r) == target
1373 return subset.filter(condition, cache=False)
1374 return subset.filter(condition, cache=False)
1374
1375
1375 def remote(repo, subset, x):
1376 def remote(repo, subset, x):
1376 """``remote([id [,path]])``
1377 """``remote([id [,path]])``
1377 Local revision that corresponds to the given identifier in a
1378 Local revision that corresponds to the given identifier in a
1378 remote repository, if present. Here, the '.' identifier is a
1379 remote repository, if present. Here, the '.' identifier is a
1379 synonym for the current local branch.
1380 synonym for the current local branch.
1380 """
1381 """
1381
1382
1382 import hg # avoid start-up nasties
1383 import hg # avoid start-up nasties
1383 # i18n: "remote" is a keyword
1384 # i18n: "remote" is a keyword
1384 l = getargs(x, 0, 2, _("remote takes one, two or no arguments"))
1385 l = getargs(x, 0, 2, _("remote takes one, two or no arguments"))
1385
1386
1386 q = '.'
1387 q = '.'
1387 if len(l) > 0:
1388 if len(l) > 0:
1388 # i18n: "remote" is a keyword
1389 # i18n: "remote" is a keyword
1389 q = getstring(l[0], _("remote requires a string id"))
1390 q = getstring(l[0], _("remote requires a string id"))
1390 if q == '.':
1391 if q == '.':
1391 q = repo['.'].branch()
1392 q = repo['.'].branch()
1392
1393
1393 dest = ''
1394 dest = ''
1394 if len(l) > 1:
1395 if len(l) > 1:
1395 # i18n: "remote" is a keyword
1396 # i18n: "remote" is a keyword
1396 dest = getstring(l[1], _("remote requires a repository path"))
1397 dest = getstring(l[1], _("remote requires a repository path"))
1397 dest = repo.ui.expandpath(dest or 'default')
1398 dest = repo.ui.expandpath(dest or 'default')
1398 dest, branches = hg.parseurl(dest)
1399 dest, branches = hg.parseurl(dest)
1399 revs, checkout = hg.addbranchrevs(repo, repo, branches, [])
1400 revs, checkout = hg.addbranchrevs(repo, repo, branches, [])
1400 if revs:
1401 if revs:
1401 revs = [repo.lookup(rev) for rev in revs]
1402 revs = [repo.lookup(rev) for rev in revs]
1402 other = hg.peer(repo, {}, dest)
1403 other = hg.peer(repo, {}, dest)
1403 n = other.lookup(q)
1404 n = other.lookup(q)
1404 if n in repo:
1405 if n in repo:
1405 r = repo[n].rev()
1406 r = repo[n].rev()
1406 if r in subset:
1407 if r in subset:
1407 return baseset([r])
1408 return baseset([r])
1408 return baseset()
1409 return baseset()
1409
1410
1410 def removes(repo, subset, x):
1411 def removes(repo, subset, x):
1411 """``removes(pattern)``
1412 """``removes(pattern)``
1412 Changesets which remove files matching pattern.
1413 Changesets which remove files matching pattern.
1413
1414
1414 The pattern without explicit kind like ``glob:`` is expected to be
1415 The pattern without explicit kind like ``glob:`` is expected to be
1415 relative to the current directory and match against a file or a
1416 relative to the current directory and match against a file or a
1416 directory.
1417 directory.
1417 """
1418 """
1418 # i18n: "removes" is a keyword
1419 # i18n: "removes" is a keyword
1419 pat = getstring(x, _("removes requires a pattern"))
1420 pat = getstring(x, _("removes requires a pattern"))
1420 return checkstatus(repo, subset, pat, 2)
1421 return checkstatus(repo, subset, pat, 2)
1421
1422
1422 def rev(repo, subset, x):
1423 def rev(repo, subset, x):
1423 """``rev(number)``
1424 """``rev(number)``
1424 Revision with the given numeric identifier.
1425 Revision with the given numeric identifier.
1425 """
1426 """
1426 # i18n: "rev" is a keyword
1427 # i18n: "rev" is a keyword
1427 l = getargs(x, 1, 1, _("rev requires one argument"))
1428 l = getargs(x, 1, 1, _("rev requires one argument"))
1428 try:
1429 try:
1429 # i18n: "rev" is a keyword
1430 # i18n: "rev" is a keyword
1430 l = int(getstring(l[0], _("rev requires a number")))
1431 l = int(getstring(l[0], _("rev requires a number")))
1431 except (TypeError, ValueError):
1432 except (TypeError, ValueError):
1432 # i18n: "rev" is a keyword
1433 # i18n: "rev" is a keyword
1433 raise error.ParseError(_("rev expects a number"))
1434 raise error.ParseError(_("rev expects a number"))
1434 if l not in fullreposet(repo):
1435 if l not in fullreposet(repo):
1435 return baseset()
1436 return baseset()
1436 return subset & baseset([l])
1437 return subset & baseset([l])
1437
1438
1438 def matching(repo, subset, x):
1439 def matching(repo, subset, x):
1439 """``matching(revision [, field])``
1440 """``matching(revision [, field])``
1440 Changesets in which a given set of fields match the set of fields in the
1441 Changesets in which a given set of fields match the set of fields in the
1441 selected revision or set.
1442 selected revision or set.
1442
1443
1443 To match more than one field pass the list of fields to match separated
1444 To match more than one field pass the list of fields to match separated
1444 by spaces (e.g. ``author description``).
1445 by spaces (e.g. ``author description``).
1445
1446
1446 Valid fields are most regular revision fields and some special fields.
1447 Valid fields are most regular revision fields and some special fields.
1447
1448
1448 Regular revision fields are ``description``, ``author``, ``branch``,
1449 Regular revision fields are ``description``, ``author``, ``branch``,
1449 ``date``, ``files``, ``phase``, ``parents``, ``substate``, ``user``
1450 ``date``, ``files``, ``phase``, ``parents``, ``substate``, ``user``
1450 and ``diff``.
1451 and ``diff``.
1451 Note that ``author`` and ``user`` are synonyms. ``diff`` refers to the
1452 Note that ``author`` and ``user`` are synonyms. ``diff`` refers to the
1452 contents of the revision. Two revisions matching their ``diff`` will
1453 contents of the revision. Two revisions matching their ``diff`` will
1453 also match their ``files``.
1454 also match their ``files``.
1454
1455
1455 Special fields are ``summary`` and ``metadata``:
1456 Special fields are ``summary`` and ``metadata``:
1456 ``summary`` matches the first line of the description.
1457 ``summary`` matches the first line of the description.
1457 ``metadata`` is equivalent to matching ``description user date``
1458 ``metadata`` is equivalent to matching ``description user date``
1458 (i.e. it matches the main metadata fields).
1459 (i.e. it matches the main metadata fields).
1459
1460
1460 ``metadata`` is the default field which is used when no fields are
1461 ``metadata`` is the default field which is used when no fields are
1461 specified. You can match more than one field at a time.
1462 specified. You can match more than one field at a time.
1462 """
1463 """
1463 # i18n: "matching" is a keyword
1464 # i18n: "matching" is a keyword
1464 l = getargs(x, 1, 2, _("matching takes 1 or 2 arguments"))
1465 l = getargs(x, 1, 2, _("matching takes 1 or 2 arguments"))
1465
1466
1466 revs = getset(repo, fullreposet(repo), l[0])
1467 revs = getset(repo, fullreposet(repo), l[0])
1467
1468
1468 fieldlist = ['metadata']
1469 fieldlist = ['metadata']
1469 if len(l) > 1:
1470 if len(l) > 1:
1470 fieldlist = getstring(l[1],
1471 fieldlist = getstring(l[1],
1471 # i18n: "matching" is a keyword
1472 # i18n: "matching" is a keyword
1472 _("matching requires a string "
1473 _("matching requires a string "
1473 "as its second argument")).split()
1474 "as its second argument")).split()
1474
1475
1475 # Make sure that there are no repeated fields,
1476 # Make sure that there are no repeated fields,
1476 # expand the 'special' 'metadata' field type
1477 # expand the 'special' 'metadata' field type
1477 # and check the 'files' whenever we check the 'diff'
1478 # and check the 'files' whenever we check the 'diff'
1478 fields = []
1479 fields = []
1479 for field in fieldlist:
1480 for field in fieldlist:
1480 if field == 'metadata':
1481 if field == 'metadata':
1481 fields += ['user', 'description', 'date']
1482 fields += ['user', 'description', 'date']
1482 elif field == 'diff':
1483 elif field == 'diff':
1483 # a revision matching the diff must also match the files
1484 # a revision matching the diff must also match the files
1484 # since matching the diff is very costly, make sure to
1485 # since matching the diff is very costly, make sure to
1485 # also match the files first
1486 # also match the files first
1486 fields += ['files', 'diff']
1487 fields += ['files', 'diff']
1487 else:
1488 else:
1488 if field == 'author':
1489 if field == 'author':
1489 field = 'user'
1490 field = 'user'
1490 fields.append(field)
1491 fields.append(field)
1491 fields = set(fields)
1492 fields = set(fields)
1492 if 'summary' in fields and 'description' in fields:
1493 if 'summary' in fields and 'description' in fields:
1493 # If a revision matches its description it also matches its summary
1494 # If a revision matches its description it also matches its summary
1494 fields.discard('summary')
1495 fields.discard('summary')
1495
1496
1496 # We may want to match more than one field
1497 # We may want to match more than one field
1497 # Not all fields take the same amount of time to be matched
1498 # Not all fields take the same amount of time to be matched
1498 # Sort the selected fields in order of increasing matching cost
1499 # Sort the selected fields in order of increasing matching cost
1499 fieldorder = ['phase', 'parents', 'user', 'date', 'branch', 'summary',
1500 fieldorder = ['phase', 'parents', 'user', 'date', 'branch', 'summary',
1500 'files', 'description', 'substate', 'diff']
1501 'files', 'description', 'substate', 'diff']
1501 def fieldkeyfunc(f):
1502 def fieldkeyfunc(f):
1502 try:
1503 try:
1503 return fieldorder.index(f)
1504 return fieldorder.index(f)
1504 except ValueError:
1505 except ValueError:
1505 # assume an unknown field is very costly
1506 # assume an unknown field is very costly
1506 return len(fieldorder)
1507 return len(fieldorder)
1507 fields = list(fields)
1508 fields = list(fields)
1508 fields.sort(key=fieldkeyfunc)
1509 fields.sort(key=fieldkeyfunc)
1509
1510
1510 # Each field will be matched with its own "getfield" function
1511 # Each field will be matched with its own "getfield" function
1511 # which will be added to the getfieldfuncs array of functions
1512 # which will be added to the getfieldfuncs array of functions
1512 getfieldfuncs = []
1513 getfieldfuncs = []
1513 _funcs = {
1514 _funcs = {
1514 'user': lambda r: repo[r].user(),
1515 'user': lambda r: repo[r].user(),
1515 'branch': lambda r: repo[r].branch(),
1516 'branch': lambda r: repo[r].branch(),
1516 'date': lambda r: repo[r].date(),
1517 'date': lambda r: repo[r].date(),
1517 'description': lambda r: repo[r].description(),
1518 'description': lambda r: repo[r].description(),
1518 'files': lambda r: repo[r].files(),
1519 'files': lambda r: repo[r].files(),
1519 'parents': lambda r: repo[r].parents(),
1520 'parents': lambda r: repo[r].parents(),
1520 'phase': lambda r: repo[r].phase(),
1521 'phase': lambda r: repo[r].phase(),
1521 'substate': lambda r: repo[r].substate,
1522 'substate': lambda r: repo[r].substate,
1522 'summary': lambda r: repo[r].description().splitlines()[0],
1523 'summary': lambda r: repo[r].description().splitlines()[0],
1523 'diff': lambda r: list(repo[r].diff(git=True),)
1524 'diff': lambda r: list(repo[r].diff(git=True),)
1524 }
1525 }
1525 for info in fields:
1526 for info in fields:
1526 getfield = _funcs.get(info, None)
1527 getfield = _funcs.get(info, None)
1527 if getfield is None:
1528 if getfield is None:
1528 raise error.ParseError(
1529 raise error.ParseError(
1529 # i18n: "matching" is a keyword
1530 # i18n: "matching" is a keyword
1530 _("unexpected field name passed to matching: %s") % info)
1531 _("unexpected field name passed to matching: %s") % info)
1531 getfieldfuncs.append(getfield)
1532 getfieldfuncs.append(getfield)
1532 # convert the getfield array of functions into a "getinfo" function
1533 # convert the getfield array of functions into a "getinfo" function
1533 # which returns an array of field values (or a single value if there
1534 # which returns an array of field values (or a single value if there
1534 # is only one field to match)
1535 # is only one field to match)
1535 getinfo = lambda r: [f(r) for f in getfieldfuncs]
1536 getinfo = lambda r: [f(r) for f in getfieldfuncs]
1536
1537
1537 def matches(x):
1538 def matches(x):
1538 for rev in revs:
1539 for rev in revs:
1539 target = getinfo(rev)
1540 target = getinfo(rev)
1540 match = True
1541 match = True
1541 for n, f in enumerate(getfieldfuncs):
1542 for n, f in enumerate(getfieldfuncs):
1542 if target[n] != f(x):
1543 if target[n] != f(x):
1543 match = False
1544 match = False
1544 if match:
1545 if match:
1545 return True
1546 return True
1546 return False
1547 return False
1547
1548
1548 return subset.filter(matches)
1549 return subset.filter(matches)
1549
1550
1550 def reverse(repo, subset, x):
1551 def reverse(repo, subset, x):
1551 """``reverse(set)``
1552 """``reverse(set)``
1552 Reverse order of set.
1553 Reverse order of set.
1553 """
1554 """
1554 l = getset(repo, subset, x)
1555 l = getset(repo, subset, x)
1555 l.reverse()
1556 l.reverse()
1556 return l
1557 return l
1557
1558
1558 def roots(repo, subset, x):
1559 def roots(repo, subset, x):
1559 """``roots(set)``
1560 """``roots(set)``
1560 Changesets in set with no parent changeset in set.
1561 Changesets in set with no parent changeset in set.
1561 """
1562 """
1562 s = getset(repo, spanset(repo), x)
1563 s = getset(repo, spanset(repo), x)
1563 subset = baseset([r for r in s if r in subset])
1564 subset = baseset([r for r in s if r in subset])
1564 cs = _children(repo, subset, s)
1565 cs = _children(repo, subset, s)
1565 return subset - cs
1566 return subset - cs
1566
1567
1567 def secret(repo, subset, x):
1568 def secret(repo, subset, x):
1568 """``secret()``
1569 """``secret()``
1569 Changeset in secret phase."""
1570 Changeset in secret phase."""
1570 # i18n: "secret" is a keyword
1571 # i18n: "secret" is a keyword
1571 getargs(x, 0, 0, _("secret takes no arguments"))
1572 getargs(x, 0, 0, _("secret takes no arguments"))
1572 phase = repo._phasecache.phase
1573 phase = repo._phasecache.phase
1573 target = phases.secret
1574 target = phases.secret
1574 condition = lambda r: phase(repo, r) == target
1575 condition = lambda r: phase(repo, r) == target
1575 return subset.filter(condition, cache=False)
1576 return subset.filter(condition, cache=False)
1576
1577
1577 def sort(repo, subset, x):
1578 def sort(repo, subset, x):
1578 """``sort(set[, [-]key...])``
1579 """``sort(set[, [-]key...])``
1579 Sort set by keys. The default sort order is ascending, specify a key
1580 Sort set by keys. The default sort order is ascending, specify a key
1580 as ``-key`` to sort in descending order.
1581 as ``-key`` to sort in descending order.
1581
1582
1582 The keys can be:
1583 The keys can be:
1583
1584
1584 - ``rev`` for the revision number,
1585 - ``rev`` for the revision number,
1585 - ``branch`` for the branch name,
1586 - ``branch`` for the branch name,
1586 - ``desc`` for the commit message (description),
1587 - ``desc`` for the commit message (description),
1587 - ``user`` for user name (``author`` can be used as an alias),
1588 - ``user`` for user name (``author`` can be used as an alias),
1588 - ``date`` for the commit date
1589 - ``date`` for the commit date
1589 """
1590 """
1590 # i18n: "sort" is a keyword
1591 # i18n: "sort" is a keyword
1591 l = getargs(x, 1, 2, _("sort requires one or two arguments"))
1592 l = getargs(x, 1, 2, _("sort requires one or two arguments"))
1592 keys = "rev"
1593 keys = "rev"
1593 if len(l) == 2:
1594 if len(l) == 2:
1594 # i18n: "sort" is a keyword
1595 # i18n: "sort" is a keyword
1595 keys = getstring(l[1], _("sort spec must be a string"))
1596 keys = getstring(l[1], _("sort spec must be a string"))
1596
1597
1597 s = l[0]
1598 s = l[0]
1598 keys = keys.split()
1599 keys = keys.split()
1599 l = []
1600 l = []
1600 def invert(s):
1601 def invert(s):
1601 return "".join(chr(255 - ord(c)) for c in s)
1602 return "".join(chr(255 - ord(c)) for c in s)
1602 revs = getset(repo, subset, s)
1603 revs = getset(repo, subset, s)
1603 if keys == ["rev"]:
1604 if keys == ["rev"]:
1604 revs.sort()
1605 revs.sort()
1605 return revs
1606 return revs
1606 elif keys == ["-rev"]:
1607 elif keys == ["-rev"]:
1607 revs.sort(reverse=True)
1608 revs.sort(reverse=True)
1608 return revs
1609 return revs
1609 for r in revs:
1610 for r in revs:
1610 c = repo[r]
1611 c = repo[r]
1611 e = []
1612 e = []
1612 for k in keys:
1613 for k in keys:
1613 if k == 'rev':
1614 if k == 'rev':
1614 e.append(r)
1615 e.append(r)
1615 elif k == '-rev':
1616 elif k == '-rev':
1616 e.append(-r)
1617 e.append(-r)
1617 elif k == 'branch':
1618 elif k == 'branch':
1618 e.append(c.branch())
1619 e.append(c.branch())
1619 elif k == '-branch':
1620 elif k == '-branch':
1620 e.append(invert(c.branch()))
1621 e.append(invert(c.branch()))
1621 elif k == 'desc':
1622 elif k == 'desc':
1622 e.append(c.description())
1623 e.append(c.description())
1623 elif k == '-desc':
1624 elif k == '-desc':
1624 e.append(invert(c.description()))
1625 e.append(invert(c.description()))
1625 elif k in 'user author':
1626 elif k in 'user author':
1626 e.append(c.user())
1627 e.append(c.user())
1627 elif k in '-user -author':
1628 elif k in '-user -author':
1628 e.append(invert(c.user()))
1629 e.append(invert(c.user()))
1629 elif k == 'date':
1630 elif k == 'date':
1630 e.append(c.date()[0])
1631 e.append(c.date()[0])
1631 elif k == '-date':
1632 elif k == '-date':
1632 e.append(-c.date()[0])
1633 e.append(-c.date()[0])
1633 else:
1634 else:
1634 raise error.ParseError(_("unknown sort key %r") % k)
1635 raise error.ParseError(_("unknown sort key %r") % k)
1635 e.append(r)
1636 e.append(r)
1636 l.append(e)
1637 l.append(e)
1637 l.sort()
1638 l.sort()
1638 return baseset([e[-1] for e in l])
1639 return baseset([e[-1] for e in l])
1639
1640
1640 def _stringmatcher(pattern):
1641 def _stringmatcher(pattern):
1641 """
1642 """
1642 accepts a string, possibly starting with 're:' or 'literal:' prefix.
1643 accepts a string, possibly starting with 're:' or 'literal:' prefix.
1643 returns the matcher name, pattern, and matcher function.
1644 returns the matcher name, pattern, and matcher function.
1644 missing or unknown prefixes are treated as literal matches.
1645 missing or unknown prefixes are treated as literal matches.
1645
1646
1646 helper for tests:
1647 helper for tests:
1647 >>> def test(pattern, *tests):
1648 >>> def test(pattern, *tests):
1648 ... kind, pattern, matcher = _stringmatcher(pattern)
1649 ... kind, pattern, matcher = _stringmatcher(pattern)
1649 ... return (kind, pattern, [bool(matcher(t)) for t in tests])
1650 ... return (kind, pattern, [bool(matcher(t)) for t in tests])
1650
1651
1651 exact matching (no prefix):
1652 exact matching (no prefix):
1652 >>> test('abcdefg', 'abc', 'def', 'abcdefg')
1653 >>> test('abcdefg', 'abc', 'def', 'abcdefg')
1653 ('literal', 'abcdefg', [False, False, True])
1654 ('literal', 'abcdefg', [False, False, True])
1654
1655
1655 regex matching ('re:' prefix)
1656 regex matching ('re:' prefix)
1656 >>> test('re:a.+b', 'nomatch', 'fooadef', 'fooadefbar')
1657 >>> test('re:a.+b', 'nomatch', 'fooadef', 'fooadefbar')
1657 ('re', 'a.+b', [False, False, True])
1658 ('re', 'a.+b', [False, False, True])
1658
1659
1659 force exact matches ('literal:' prefix)
1660 force exact matches ('literal:' prefix)
1660 >>> test('literal:re:foobar', 'foobar', 're:foobar')
1661 >>> test('literal:re:foobar', 'foobar', 're:foobar')
1661 ('literal', 're:foobar', [False, True])
1662 ('literal', 're:foobar', [False, True])
1662
1663
1663 unknown prefixes are ignored and treated as literals
1664 unknown prefixes are ignored and treated as literals
1664 >>> test('foo:bar', 'foo', 'bar', 'foo:bar')
1665 >>> test('foo:bar', 'foo', 'bar', 'foo:bar')
1665 ('literal', 'foo:bar', [False, False, True])
1666 ('literal', 'foo:bar', [False, False, True])
1666 """
1667 """
1667 if pattern.startswith('re:'):
1668 if pattern.startswith('re:'):
1668 pattern = pattern[3:]
1669 pattern = pattern[3:]
1669 try:
1670 try:
1670 regex = re.compile(pattern)
1671 regex = re.compile(pattern)
1671 except re.error, e:
1672 except re.error, e:
1672 raise error.ParseError(_('invalid regular expression: %s')
1673 raise error.ParseError(_('invalid regular expression: %s')
1673 % e)
1674 % e)
1674 return 're', pattern, regex.search
1675 return 're', pattern, regex.search
1675 elif pattern.startswith('literal:'):
1676 elif pattern.startswith('literal:'):
1676 pattern = pattern[8:]
1677 pattern = pattern[8:]
1677 return 'literal', pattern, pattern.__eq__
1678 return 'literal', pattern, pattern.__eq__
1678
1679
1679 def _substringmatcher(pattern):
1680 def _substringmatcher(pattern):
1680 kind, pattern, matcher = _stringmatcher(pattern)
1681 kind, pattern, matcher = _stringmatcher(pattern)
1681 if kind == 'literal':
1682 if kind == 'literal':
1682 matcher = lambda s: pattern in s
1683 matcher = lambda s: pattern in s
1683 return kind, pattern, matcher
1684 return kind, pattern, matcher
1684
1685
1685 def tag(repo, subset, x):
1686 def tag(repo, subset, x):
1686 """``tag([name])``
1687 """``tag([name])``
1687 The specified tag by name, or all tagged revisions if no name is given.
1688 The specified tag by name, or all tagged revisions if no name is given.
1688
1689
1689 If `name` starts with `re:`, the remainder of the name is treated as
1690 If `name` starts with `re:`, the remainder of the name is treated as
1690 a regular expression. To match a tag that actually starts with `re:`,
1691 a regular expression. To match a tag that actually starts with `re:`,
1691 use the prefix `literal:`.
1692 use the prefix `literal:`.
1692 """
1693 """
1693 # i18n: "tag" is a keyword
1694 # i18n: "tag" is a keyword
1694 args = getargs(x, 0, 1, _("tag takes one or no arguments"))
1695 args = getargs(x, 0, 1, _("tag takes one or no arguments"))
1695 cl = repo.changelog
1696 cl = repo.changelog
1696 if args:
1697 if args:
1697 pattern = getstring(args[0],
1698 pattern = getstring(args[0],
1698 # i18n: "tag" is a keyword
1699 # i18n: "tag" is a keyword
1699 _('the argument to tag must be a string'))
1700 _('the argument to tag must be a string'))
1700 kind, pattern, matcher = _stringmatcher(pattern)
1701 kind, pattern, matcher = _stringmatcher(pattern)
1701 if kind == 'literal':
1702 if kind == 'literal':
1702 # avoid resolving all tags
1703 # avoid resolving all tags
1703 tn = repo._tagscache.tags.get(pattern, None)
1704 tn = repo._tagscache.tags.get(pattern, None)
1704 if tn is None:
1705 if tn is None:
1705 raise util.Abort(_("tag '%s' does not exist") % pattern)
1706 raise util.Abort(_("tag '%s' does not exist") % pattern)
1706 s = set([repo[tn].rev()])
1707 s = set([repo[tn].rev()])
1707 else:
1708 else:
1708 s = set([cl.rev(n) for t, n in repo.tagslist() if matcher(t)])
1709 s = set([cl.rev(n) for t, n in repo.tagslist() if matcher(t)])
1709 else:
1710 else:
1710 s = set([cl.rev(n) for t, n in repo.tagslist() if t != 'tip'])
1711 s = set([cl.rev(n) for t, n in repo.tagslist() if t != 'tip'])
1711 return subset & s
1712 return subset & s
1712
1713
1713 def tagged(repo, subset, x):
1714 def tagged(repo, subset, x):
1714 return tag(repo, subset, x)
1715 return tag(repo, subset, x)
1715
1716
1716 def unstable(repo, subset, x):
1717 def unstable(repo, subset, x):
1717 """``unstable()``
1718 """``unstable()``
1718 Non-obsolete changesets with obsolete ancestors.
1719 Non-obsolete changesets with obsolete ancestors.
1719 """
1720 """
1720 # i18n: "unstable" is a keyword
1721 # i18n: "unstable" is a keyword
1721 getargs(x, 0, 0, _("unstable takes no arguments"))
1722 getargs(x, 0, 0, _("unstable takes no arguments"))
1722 unstables = obsmod.getrevs(repo, 'unstable')
1723 unstables = obsmod.getrevs(repo, 'unstable')
1723 return subset & unstables
1724 return subset & unstables
1724
1725
1725
1726
1726 def user(repo, subset, x):
1727 def user(repo, subset, x):
1727 """``user(string)``
1728 """``user(string)``
1728 User name contains string. The match is case-insensitive.
1729 User name contains string. The match is case-insensitive.
1729
1730
1730 If `string` starts with `re:`, the remainder of the string is treated as
1731 If `string` starts with `re:`, the remainder of the string is treated as
1731 a regular expression. To match a user that actually contains `re:`, use
1732 a regular expression. To match a user that actually contains `re:`, use
1732 the prefix `literal:`.
1733 the prefix `literal:`.
1733 """
1734 """
1734 return author(repo, subset, x)
1735 return author(repo, subset, x)
1735
1736
1736 # for internal use
1737 # for internal use
1737 def _list(repo, subset, x):
1738 def _list(repo, subset, x):
1738 s = getstring(x, "internal error")
1739 s = getstring(x, "internal error")
1739 if not s:
1740 if not s:
1740 return baseset()
1741 return baseset()
1741 ls = [repo[r].rev() for r in s.split('\0')]
1742 ls = [repo[r].rev() for r in s.split('\0')]
1742 s = subset
1743 s = subset
1743 return baseset([r for r in ls if r in s])
1744 return baseset([r for r in ls if r in s])
1744
1745
1745 # for internal use
1746 # for internal use
1746 def _intlist(repo, subset, x):
1747 def _intlist(repo, subset, x):
1747 s = getstring(x, "internal error")
1748 s = getstring(x, "internal error")
1748 if not s:
1749 if not s:
1749 return baseset()
1750 return baseset()
1750 ls = [int(r) for r in s.split('\0')]
1751 ls = [int(r) for r in s.split('\0')]
1751 s = subset
1752 s = subset
1752 return baseset([r for r in ls if r in s])
1753 return baseset([r for r in ls if r in s])
1753
1754
1754 # for internal use
1755 # for internal use
1755 def _hexlist(repo, subset, x):
1756 def _hexlist(repo, subset, x):
1756 s = getstring(x, "internal error")
1757 s = getstring(x, "internal error")
1757 if not s:
1758 if not s:
1758 return baseset()
1759 return baseset()
1759 cl = repo.changelog
1760 cl = repo.changelog
1760 ls = [cl.rev(node.bin(r)) for r in s.split('\0')]
1761 ls = [cl.rev(node.bin(r)) for r in s.split('\0')]
1761 s = subset
1762 s = subset
1762 return baseset([r for r in ls if r in s])
1763 return baseset([r for r in ls if r in s])
1763
1764
1764 symbols = {
1765 symbols = {
1765 "adds": adds,
1766 "adds": adds,
1766 "all": getall,
1767 "all": getall,
1767 "ancestor": ancestor,
1768 "ancestor": ancestor,
1768 "ancestors": ancestors,
1769 "ancestors": ancestors,
1769 "_firstancestors": _firstancestors,
1770 "_firstancestors": _firstancestors,
1770 "author": author,
1771 "author": author,
1771 "bisect": bisect,
1772 "bisect": bisect,
1772 "bisected": bisected,
1773 "bisected": bisected,
1773 "bookmark": bookmark,
1774 "bookmark": bookmark,
1774 "branch": branch,
1775 "branch": branch,
1775 "branchpoint": branchpoint,
1776 "branchpoint": branchpoint,
1776 "bumped": bumped,
1777 "bumped": bumped,
1777 "bundle": bundle,
1778 "bundle": bundle,
1778 "children": children,
1779 "children": children,
1779 "closed": closed,
1780 "closed": closed,
1780 "contains": contains,
1781 "contains": contains,
1781 "converted": converted,
1782 "converted": converted,
1782 "date": date,
1783 "date": date,
1783 "desc": desc,
1784 "desc": desc,
1784 "descendants": descendants,
1785 "descendants": descendants,
1785 "_firstdescendants": _firstdescendants,
1786 "_firstdescendants": _firstdescendants,
1786 "destination": destination,
1787 "destination": destination,
1787 "divergent": divergent,
1788 "divergent": divergent,
1788 "draft": draft,
1789 "draft": draft,
1789 "extinct": extinct,
1790 "extinct": extinct,
1790 "extra": extra,
1791 "extra": extra,
1791 "file": hasfile,
1792 "file": hasfile,
1792 "filelog": filelog,
1793 "filelog": filelog,
1793 "first": first,
1794 "first": first,
1794 "follow": follow,
1795 "follow": follow,
1795 "_followfirst": _followfirst,
1796 "_followfirst": _followfirst,
1796 "grep": grep,
1797 "grep": grep,
1797 "head": head,
1798 "head": head,
1798 "heads": heads,
1799 "heads": heads,
1799 "hidden": hidden,
1800 "hidden": hidden,
1800 "id": node_,
1801 "id": node_,
1801 "keyword": keyword,
1802 "keyword": keyword,
1802 "last": last,
1803 "last": last,
1803 "limit": limit,
1804 "limit": limit,
1804 "_matchfiles": _matchfiles,
1805 "_matchfiles": _matchfiles,
1805 "max": maxrev,
1806 "max": maxrev,
1806 "merge": merge,
1807 "merge": merge,
1807 "min": minrev,
1808 "min": minrev,
1808 "modifies": modifies,
1809 "modifies": modifies,
1809 "obsolete": obsolete,
1810 "obsolete": obsolete,
1810 "only": only,
1811 "only": only,
1811 "origin": origin,
1812 "origin": origin,
1812 "outgoing": outgoing,
1813 "outgoing": outgoing,
1813 "p1": p1,
1814 "p1": p1,
1814 "p2": p2,
1815 "p2": p2,
1815 "parents": parents,
1816 "parents": parents,
1816 "present": present,
1817 "present": present,
1817 "public": public,
1818 "public": public,
1818 "remote": remote,
1819 "remote": remote,
1819 "removes": removes,
1820 "removes": removes,
1820 "rev": rev,
1821 "rev": rev,
1821 "reverse": reverse,
1822 "reverse": reverse,
1822 "roots": roots,
1823 "roots": roots,
1823 "sort": sort,
1824 "sort": sort,
1824 "secret": secret,
1825 "secret": secret,
1825 "matching": matching,
1826 "matching": matching,
1826 "tag": tag,
1827 "tag": tag,
1827 "tagged": tagged,
1828 "tagged": tagged,
1828 "user": user,
1829 "user": user,
1829 "unstable": unstable,
1830 "unstable": unstable,
1830 "_list": _list,
1831 "_list": _list,
1831 "_intlist": _intlist,
1832 "_intlist": _intlist,
1832 "_hexlist": _hexlist,
1833 "_hexlist": _hexlist,
1833 }
1834 }
1834
1835
1835 # symbols which can't be used for a DoS attack for any given input
1836 # symbols which can't be used for a DoS attack for any given input
1836 # (e.g. those which accept regexes as plain strings shouldn't be included)
1837 # (e.g. those which accept regexes as plain strings shouldn't be included)
1837 # functions that just return a lot of changesets (like all) don't count here
1838 # functions that just return a lot of changesets (like all) don't count here
1838 safesymbols = set([
1839 safesymbols = set([
1839 "adds",
1840 "adds",
1840 "all",
1841 "all",
1841 "ancestor",
1842 "ancestor",
1842 "ancestors",
1843 "ancestors",
1843 "_firstancestors",
1844 "_firstancestors",
1844 "author",
1845 "author",
1845 "bisect",
1846 "bisect",
1846 "bisected",
1847 "bisected",
1847 "bookmark",
1848 "bookmark",
1848 "branch",
1849 "branch",
1849 "branchpoint",
1850 "branchpoint",
1850 "bumped",
1851 "bumped",
1851 "bundle",
1852 "bundle",
1852 "children",
1853 "children",
1853 "closed",
1854 "closed",
1854 "converted",
1855 "converted",
1855 "date",
1856 "date",
1856 "desc",
1857 "desc",
1857 "descendants",
1858 "descendants",
1858 "_firstdescendants",
1859 "_firstdescendants",
1859 "destination",
1860 "destination",
1860 "divergent",
1861 "divergent",
1861 "draft",
1862 "draft",
1862 "extinct",
1863 "extinct",
1863 "extra",
1864 "extra",
1864 "file",
1865 "file",
1865 "filelog",
1866 "filelog",
1866 "first",
1867 "first",
1867 "follow",
1868 "follow",
1868 "_followfirst",
1869 "_followfirst",
1869 "head",
1870 "head",
1870 "heads",
1871 "heads",
1871 "hidden",
1872 "hidden",
1872 "id",
1873 "id",
1873 "keyword",
1874 "keyword",
1874 "last",
1875 "last",
1875 "limit",
1876 "limit",
1876 "_matchfiles",
1877 "_matchfiles",
1877 "max",
1878 "max",
1878 "merge",
1879 "merge",
1879 "min",
1880 "min",
1880 "modifies",
1881 "modifies",
1881 "obsolete",
1882 "obsolete",
1882 "only",
1883 "only",
1883 "origin",
1884 "origin",
1884 "outgoing",
1885 "outgoing",
1885 "p1",
1886 "p1",
1886 "p2",
1887 "p2",
1887 "parents",
1888 "parents",
1888 "present",
1889 "present",
1889 "public",
1890 "public",
1890 "remote",
1891 "remote",
1891 "removes",
1892 "removes",
1892 "rev",
1893 "rev",
1893 "reverse",
1894 "reverse",
1894 "roots",
1895 "roots",
1895 "sort",
1896 "sort",
1896 "secret",
1897 "secret",
1897 "matching",
1898 "matching",
1898 "tag",
1899 "tag",
1899 "tagged",
1900 "tagged",
1900 "user",
1901 "user",
1901 "unstable",
1902 "unstable",
1902 "_list",
1903 "_list",
1903 "_intlist",
1904 "_intlist",
1904 "_hexlist",
1905 "_hexlist",
1905 ])
1906 ])
1906
1907
1907 methods = {
1908 methods = {
1908 "range": rangeset,
1909 "range": rangeset,
1909 "dagrange": dagrange,
1910 "dagrange": dagrange,
1910 "string": stringset,
1911 "string": stringset,
1911 "symbol": symbolset,
1912 "symbol": symbolset,
1912 "and": andset,
1913 "and": andset,
1913 "or": orset,
1914 "or": orset,
1914 "not": notset,
1915 "not": notset,
1915 "list": listset,
1916 "list": listset,
1916 "func": func,
1917 "func": func,
1917 "ancestor": ancestorspec,
1918 "ancestor": ancestorspec,
1918 "parent": parentspec,
1919 "parent": parentspec,
1919 "parentpost": p1,
1920 "parentpost": p1,
1920 }
1921 }
1921
1922
1922 def optimize(x, small):
1923 def optimize(x, small):
1923 if x is None:
1924 if x is None:
1924 return 0, x
1925 return 0, x
1925
1926
1926 smallbonus = 1
1927 smallbonus = 1
1927 if small:
1928 if small:
1928 smallbonus = .5
1929 smallbonus = .5
1929
1930
1930 op = x[0]
1931 op = x[0]
1931 if op == 'minus':
1932 if op == 'minus':
1932 return optimize(('and', x[1], ('not', x[2])), small)
1933 return optimize(('and', x[1], ('not', x[2])), small)
1933 elif op == 'dagrangepre':
1934 elif op == 'dagrangepre':
1934 return optimize(('func', ('symbol', 'ancestors'), x[1]), small)
1935 return optimize(('func', ('symbol', 'ancestors'), x[1]), small)
1935 elif op == 'dagrangepost':
1936 elif op == 'dagrangepost':
1936 return optimize(('func', ('symbol', 'descendants'), x[1]), small)
1937 return optimize(('func', ('symbol', 'descendants'), x[1]), small)
1937 elif op == 'rangepre':
1938 elif op == 'rangepre':
1938 return optimize(('range', ('string', '0'), x[1]), small)
1939 return optimize(('range', ('string', '0'), x[1]), small)
1939 elif op == 'rangepost':
1940 elif op == 'rangepost':
1940 return optimize(('range', x[1], ('string', 'tip')), small)
1941 return optimize(('range', x[1], ('string', 'tip')), small)
1941 elif op == 'negate':
1942 elif op == 'negate':
1942 return optimize(('string',
1943 return optimize(('string',
1943 '-' + getstring(x[1], _("can't negate that"))), small)
1944 '-' + getstring(x[1], _("can't negate that"))), small)
1944 elif op in 'string symbol negate':
1945 elif op in 'string symbol negate':
1945 return smallbonus, x # single revisions are small
1946 return smallbonus, x # single revisions are small
1946 elif op == 'and':
1947 elif op == 'and':
1947 wa, ta = optimize(x[1], True)
1948 wa, ta = optimize(x[1], True)
1948 wb, tb = optimize(x[2], True)
1949 wb, tb = optimize(x[2], True)
1949
1950
1950 # (::x and not ::y)/(not ::y and ::x) have a fast path
1951 # (::x and not ::y)/(not ::y and ::x) have a fast path
1951 def isonly(revs, bases):
1952 def isonly(revs, bases):
1952 return (
1953 return (
1953 revs[0] == 'func'
1954 revs[0] == 'func'
1954 and getstring(revs[1], _('not a symbol')) == 'ancestors'
1955 and getstring(revs[1], _('not a symbol')) == 'ancestors'
1955 and bases[0] == 'not'
1956 and bases[0] == 'not'
1956 and bases[1][0] == 'func'
1957 and bases[1][0] == 'func'
1957 and getstring(bases[1][1], _('not a symbol')) == 'ancestors')
1958 and getstring(bases[1][1], _('not a symbol')) == 'ancestors')
1958
1959
1959 w = min(wa, wb)
1960 w = min(wa, wb)
1960 if isonly(ta, tb):
1961 if isonly(ta, tb):
1961 return w, ('func', ('symbol', 'only'), ('list', ta[2], tb[1][2]))
1962 return w, ('func', ('symbol', 'only'), ('list', ta[2], tb[1][2]))
1962 if isonly(tb, ta):
1963 if isonly(tb, ta):
1963 return w, ('func', ('symbol', 'only'), ('list', tb[2], ta[1][2]))
1964 return w, ('func', ('symbol', 'only'), ('list', tb[2], ta[1][2]))
1964
1965
1965 if wa > wb:
1966 if wa > wb:
1966 return w, (op, tb, ta)
1967 return w, (op, tb, ta)
1967 return w, (op, ta, tb)
1968 return w, (op, ta, tb)
1968 elif op == 'or':
1969 elif op == 'or':
1969 wa, ta = optimize(x[1], False)
1970 wa, ta = optimize(x[1], False)
1970 wb, tb = optimize(x[2], False)
1971 wb, tb = optimize(x[2], False)
1971 if wb < wa:
1972 if wb < wa:
1972 wb, wa = wa, wb
1973 wb, wa = wa, wb
1973 return max(wa, wb), (op, ta, tb)
1974 return max(wa, wb), (op, ta, tb)
1974 elif op == 'not':
1975 elif op == 'not':
1975 o = optimize(x[1], not small)
1976 o = optimize(x[1], not small)
1976 return o[0], (op, o[1])
1977 return o[0], (op, o[1])
1977 elif op == 'parentpost':
1978 elif op == 'parentpost':
1978 o = optimize(x[1], small)
1979 o = optimize(x[1], small)
1979 return o[0], (op, o[1])
1980 return o[0], (op, o[1])
1980 elif op == 'group':
1981 elif op == 'group':
1981 return optimize(x[1], small)
1982 return optimize(x[1], small)
1982 elif op in 'dagrange range list parent ancestorspec':
1983 elif op in 'dagrange range list parent ancestorspec':
1983 if op == 'parent':
1984 if op == 'parent':
1984 # x^:y means (x^) : y, not x ^ (:y)
1985 # x^:y means (x^) : y, not x ^ (:y)
1985 post = ('parentpost', x[1])
1986 post = ('parentpost', x[1])
1986 if x[2][0] == 'dagrangepre':
1987 if x[2][0] == 'dagrangepre':
1987 return optimize(('dagrange', post, x[2][1]), small)
1988 return optimize(('dagrange', post, x[2][1]), small)
1988 elif x[2][0] == 'rangepre':
1989 elif x[2][0] == 'rangepre':
1989 return optimize(('range', post, x[2][1]), small)
1990 return optimize(('range', post, x[2][1]), small)
1990
1991
1991 wa, ta = optimize(x[1], small)
1992 wa, ta = optimize(x[1], small)
1992 wb, tb = optimize(x[2], small)
1993 wb, tb = optimize(x[2], small)
1993 return wa + wb, (op, ta, tb)
1994 return wa + wb, (op, ta, tb)
1994 elif op == 'func':
1995 elif op == 'func':
1995 f = getstring(x[1], _("not a symbol"))
1996 f = getstring(x[1], _("not a symbol"))
1996 wa, ta = optimize(x[2], small)
1997 wa, ta = optimize(x[2], small)
1997 if f in ("author branch closed date desc file grep keyword "
1998 if f in ("author branch closed date desc file grep keyword "
1998 "outgoing user"):
1999 "outgoing user"):
1999 w = 10 # slow
2000 w = 10 # slow
2000 elif f in "modifies adds removes":
2001 elif f in "modifies adds removes":
2001 w = 30 # slower
2002 w = 30 # slower
2002 elif f == "contains":
2003 elif f == "contains":
2003 w = 100 # very slow
2004 w = 100 # very slow
2004 elif f == "ancestor":
2005 elif f == "ancestor":
2005 w = 1 * smallbonus
2006 w = 1 * smallbonus
2006 elif f in "reverse limit first _intlist":
2007 elif f in "reverse limit first _intlist":
2007 w = 0
2008 w = 0
2008 elif f in "sort":
2009 elif f in "sort":
2009 w = 10 # assume most sorts look at changelog
2010 w = 10 # assume most sorts look at changelog
2010 else:
2011 else:
2011 w = 1
2012 w = 1
2012 return w + wa, (op, x[1], ta)
2013 return w + wa, (op, x[1], ta)
2013 return 1, x
2014 return 1, x
2014
2015
2015 _aliasarg = ('func', ('symbol', '_aliasarg'))
2016 _aliasarg = ('func', ('symbol', '_aliasarg'))
2016 def _getaliasarg(tree):
2017 def _getaliasarg(tree):
2017 """If tree matches ('func', ('symbol', '_aliasarg'), ('string', X))
2018 """If tree matches ('func', ('symbol', '_aliasarg'), ('string', X))
2018 return X, None otherwise.
2019 return X, None otherwise.
2019 """
2020 """
2020 if (len(tree) == 3 and tree[:2] == _aliasarg
2021 if (len(tree) == 3 and tree[:2] == _aliasarg
2021 and tree[2][0] == 'string'):
2022 and tree[2][0] == 'string'):
2022 return tree[2][1]
2023 return tree[2][1]
2023 return None
2024 return None
2024
2025
2025 def _checkaliasarg(tree, known=None):
2026 def _checkaliasarg(tree, known=None):
2026 """Check tree contains no _aliasarg construct or only ones which
2027 """Check tree contains no _aliasarg construct or only ones which
2027 value is in known. Used to avoid alias placeholders injection.
2028 value is in known. Used to avoid alias placeholders injection.
2028 """
2029 """
2029 if isinstance(tree, tuple):
2030 if isinstance(tree, tuple):
2030 arg = _getaliasarg(tree)
2031 arg = _getaliasarg(tree)
2031 if arg is not None and (not known or arg not in known):
2032 if arg is not None and (not known or arg not in known):
2032 raise error.ParseError(_("not a function: %s") % '_aliasarg')
2033 raise error.ParseError(_("not a function: %s") % '_aliasarg')
2033 for t in tree:
2034 for t in tree:
2034 _checkaliasarg(t, known)
2035 _checkaliasarg(t, known)
2035
2036
2036 class revsetalias(object):
2037 class revsetalias(object):
2037 funcre = re.compile('^([^(]+)\(([^)]+)\)$')
2038 funcre = re.compile('^([^(]+)\(([^)]+)\)$')
2038 args = None
2039 args = None
2039
2040
2040 # error message at parsing, or None
2041 # error message at parsing, or None
2041 error = None
2042 error = None
2042 # whether own `error` information is already shown or not.
2043 # whether own `error` information is already shown or not.
2043 # this avoids showing same warning multiple times at each `findaliases`.
2044 # this avoids showing same warning multiple times at each `findaliases`.
2044 warned = False
2045 warned = False
2045
2046
2046 def __init__(self, name, value):
2047 def __init__(self, name, value):
2047 '''Aliases like:
2048 '''Aliases like:
2048
2049
2049 h = heads(default)
2050 h = heads(default)
2050 b($1) = ancestors($1) - ancestors(default)
2051 b($1) = ancestors($1) - ancestors(default)
2051 '''
2052 '''
2052 m = self.funcre.search(name)
2053 m = self.funcre.search(name)
2053 if m:
2054 if m:
2054 self.name = m.group(1)
2055 self.name = m.group(1)
2055 self.tree = ('func', ('symbol', m.group(1)))
2056 self.tree = ('func', ('symbol', m.group(1)))
2056 self.args = [x.strip() for x in m.group(2).split(',')]
2057 self.args = [x.strip() for x in m.group(2).split(',')]
2057 for arg in self.args:
2058 for arg in self.args:
2058 # _aliasarg() is an unknown symbol only used separate
2059 # _aliasarg() is an unknown symbol only used separate
2059 # alias argument placeholders from regular strings.
2060 # alias argument placeholders from regular strings.
2060 value = value.replace(arg, '_aliasarg(%r)' % (arg,))
2061 value = value.replace(arg, '_aliasarg(%r)' % (arg,))
2061 else:
2062 else:
2062 self.name = name
2063 self.name = name
2063 self.tree = ('symbol', name)
2064 self.tree = ('symbol', name)
2064
2065
2065 try:
2066 try:
2066 self.replacement, pos = parse(value)
2067 self.replacement, pos = parse(value)
2067 if pos != len(value):
2068 if pos != len(value):
2068 raise error.ParseError(_('invalid token'), pos)
2069 raise error.ParseError(_('invalid token'), pos)
2069 # Check for placeholder injection
2070 # Check for placeholder injection
2070 _checkaliasarg(self.replacement, self.args)
2071 _checkaliasarg(self.replacement, self.args)
2071 except error.ParseError, inst:
2072 except error.ParseError, inst:
2072 if len(inst.args) > 1:
2073 if len(inst.args) > 1:
2073 self.error = _('at %s: %s') % (inst.args[1], inst.args[0])
2074 self.error = _('at %s: %s') % (inst.args[1], inst.args[0])
2074 else:
2075 else:
2075 self.error = inst.args[0]
2076 self.error = inst.args[0]
2076
2077
2077 def _getalias(aliases, tree):
2078 def _getalias(aliases, tree):
2078 """If tree looks like an unexpanded alias, return it. Return None
2079 """If tree looks like an unexpanded alias, return it. Return None
2079 otherwise.
2080 otherwise.
2080 """
2081 """
2081 if isinstance(tree, tuple) and tree:
2082 if isinstance(tree, tuple) and tree:
2082 if tree[0] == 'symbol' and len(tree) == 2:
2083 if tree[0] == 'symbol' and len(tree) == 2:
2083 name = tree[1]
2084 name = tree[1]
2084 alias = aliases.get(name)
2085 alias = aliases.get(name)
2085 if alias and alias.args is None and alias.tree == tree:
2086 if alias and alias.args is None and alias.tree == tree:
2086 return alias
2087 return alias
2087 if tree[0] == 'func' and len(tree) > 1:
2088 if tree[0] == 'func' and len(tree) > 1:
2088 if tree[1][0] == 'symbol' and len(tree[1]) == 2:
2089 if tree[1][0] == 'symbol' and len(tree[1]) == 2:
2089 name = tree[1][1]
2090 name = tree[1][1]
2090 alias = aliases.get(name)
2091 alias = aliases.get(name)
2091 if alias and alias.args is not None and alias.tree == tree[:2]:
2092 if alias and alias.args is not None and alias.tree == tree[:2]:
2092 return alias
2093 return alias
2093 return None
2094 return None
2094
2095
2095 def _expandargs(tree, args):
2096 def _expandargs(tree, args):
2096 """Replace _aliasarg instances with the substitution value of the
2097 """Replace _aliasarg instances with the substitution value of the
2097 same name in args, recursively.
2098 same name in args, recursively.
2098 """
2099 """
2099 if not tree or not isinstance(tree, tuple):
2100 if not tree or not isinstance(tree, tuple):
2100 return tree
2101 return tree
2101 arg = _getaliasarg(tree)
2102 arg = _getaliasarg(tree)
2102 if arg is not None:
2103 if arg is not None:
2103 return args[arg]
2104 return args[arg]
2104 return tuple(_expandargs(t, args) for t in tree)
2105 return tuple(_expandargs(t, args) for t in tree)
2105
2106
2106 def _expandaliases(aliases, tree, expanding, cache):
2107 def _expandaliases(aliases, tree, expanding, cache):
2107 """Expand aliases in tree, recursively.
2108 """Expand aliases in tree, recursively.
2108
2109
2109 'aliases' is a dictionary mapping user defined aliases to
2110 'aliases' is a dictionary mapping user defined aliases to
2110 revsetalias objects.
2111 revsetalias objects.
2111 """
2112 """
2112 if not isinstance(tree, tuple):
2113 if not isinstance(tree, tuple):
2113 # Do not expand raw strings
2114 # Do not expand raw strings
2114 return tree
2115 return tree
2115 alias = _getalias(aliases, tree)
2116 alias = _getalias(aliases, tree)
2116 if alias is not None:
2117 if alias is not None:
2117 if alias.error:
2118 if alias.error:
2118 raise util.Abort(_('failed to parse revset alias "%s": %s') %
2119 raise util.Abort(_('failed to parse revset alias "%s": %s') %
2119 (alias.name, alias.error))
2120 (alias.name, alias.error))
2120 if alias in expanding:
2121 if alias in expanding:
2121 raise error.ParseError(_('infinite expansion of revset alias "%s" '
2122 raise error.ParseError(_('infinite expansion of revset alias "%s" '
2122 'detected') % alias.name)
2123 'detected') % alias.name)
2123 expanding.append(alias)
2124 expanding.append(alias)
2124 if alias.name not in cache:
2125 if alias.name not in cache:
2125 cache[alias.name] = _expandaliases(aliases, alias.replacement,
2126 cache[alias.name] = _expandaliases(aliases, alias.replacement,
2126 expanding, cache)
2127 expanding, cache)
2127 result = cache[alias.name]
2128 result = cache[alias.name]
2128 expanding.pop()
2129 expanding.pop()
2129 if alias.args is not None:
2130 if alias.args is not None:
2130 l = getlist(tree[2])
2131 l = getlist(tree[2])
2131 if len(l) != len(alias.args):
2132 if len(l) != len(alias.args):
2132 raise error.ParseError(
2133 raise error.ParseError(
2133 _('invalid number of arguments: %s') % len(l))
2134 _('invalid number of arguments: %s') % len(l))
2134 l = [_expandaliases(aliases, a, [], cache) for a in l]
2135 l = [_expandaliases(aliases, a, [], cache) for a in l]
2135 result = _expandargs(result, dict(zip(alias.args, l)))
2136 result = _expandargs(result, dict(zip(alias.args, l)))
2136 else:
2137 else:
2137 result = tuple(_expandaliases(aliases, t, expanding, cache)
2138 result = tuple(_expandaliases(aliases, t, expanding, cache)
2138 for t in tree)
2139 for t in tree)
2139 return result
2140 return result
2140
2141
2141 def findaliases(ui, tree, showwarning=None):
2142 def findaliases(ui, tree, showwarning=None):
2142 _checkaliasarg(tree)
2143 _checkaliasarg(tree)
2143 aliases = {}
2144 aliases = {}
2144 for k, v in ui.configitems('revsetalias'):
2145 for k, v in ui.configitems('revsetalias'):
2145 alias = revsetalias(k, v)
2146 alias = revsetalias(k, v)
2146 aliases[alias.name] = alias
2147 aliases[alias.name] = alias
2147 tree = _expandaliases(aliases, tree, [], {})
2148 tree = _expandaliases(aliases, tree, [], {})
2148 if showwarning:
2149 if showwarning:
2149 # warn about problematic (but not referred) aliases
2150 # warn about problematic (but not referred) aliases
2150 for name, alias in sorted(aliases.iteritems()):
2151 for name, alias in sorted(aliases.iteritems()):
2151 if alias.error and not alias.warned:
2152 if alias.error and not alias.warned:
2152 msg = _('failed to parse revset alias "%s": %s'
2153 msg = _('failed to parse revset alias "%s": %s'
2153 ) % (name, alias.error)
2154 ) % (name, alias.error)
2154 showwarning(_('warning: %s\n') % (msg))
2155 showwarning(_('warning: %s\n') % (msg))
2155 alias.warned = True
2156 alias.warned = True
2156 return tree
2157 return tree
2157
2158
2158 def parse(spec, lookup=None):
2159 def parse(spec, lookup=None):
2159 p = parser.parser(tokenize, elements)
2160 p = parser.parser(tokenize, elements)
2160 return p.parse(spec, lookup=lookup)
2161 return p.parse(spec, lookup=lookup)
2161
2162
2162 def match(ui, spec, repo=None):
2163 def match(ui, spec, repo=None):
2163 if not spec:
2164 if not spec:
2164 raise error.ParseError(_("empty query"))
2165 raise error.ParseError(_("empty query"))
2165 lookup = None
2166 lookup = None
2166 if repo:
2167 if repo:
2167 lookup = repo.__contains__
2168 lookup = repo.__contains__
2168 tree, pos = parse(spec, lookup)
2169 tree, pos = parse(spec, lookup)
2169 if (pos != len(spec)):
2170 if (pos != len(spec)):
2170 raise error.ParseError(_("invalid token"), pos)
2171 raise error.ParseError(_("invalid token"), pos)
2171 if ui:
2172 if ui:
2172 tree = findaliases(ui, tree, showwarning=ui.warn)
2173 tree = findaliases(ui, tree, showwarning=ui.warn)
2173 weight, tree = optimize(tree, True)
2174 weight, tree = optimize(tree, True)
2174 def mfunc(repo, subset):
2175 def mfunc(repo, subset):
2175 if util.safehasattr(subset, 'isascending'):
2176 if util.safehasattr(subset, 'isascending'):
2176 result = getset(repo, subset, tree)
2177 result = getset(repo, subset, tree)
2177 else:
2178 else:
2178 result = getset(repo, baseset(subset), tree)
2179 result = getset(repo, baseset(subset), tree)
2179 return result
2180 return result
2180 return mfunc
2181 return mfunc
2181
2182
2182 def formatspec(expr, *args):
2183 def formatspec(expr, *args):
2183 '''
2184 '''
2184 This is a convenience function for using revsets internally, and
2185 This is a convenience function for using revsets internally, and
2185 escapes arguments appropriately. Aliases are intentionally ignored
2186 escapes arguments appropriately. Aliases are intentionally ignored
2186 so that intended expression behavior isn't accidentally subverted.
2187 so that intended expression behavior isn't accidentally subverted.
2187
2188
2188 Supported arguments:
2189 Supported arguments:
2189
2190
2190 %r = revset expression, parenthesized
2191 %r = revset expression, parenthesized
2191 %d = int(arg), no quoting
2192 %d = int(arg), no quoting
2192 %s = string(arg), escaped and single-quoted
2193 %s = string(arg), escaped and single-quoted
2193 %b = arg.branch(), escaped and single-quoted
2194 %b = arg.branch(), escaped and single-quoted
2194 %n = hex(arg), single-quoted
2195 %n = hex(arg), single-quoted
2195 %% = a literal '%'
2196 %% = a literal '%'
2196
2197
2197 Prefixing the type with 'l' specifies a parenthesized list of that type.
2198 Prefixing the type with 'l' specifies a parenthesized list of that type.
2198
2199
2199 >>> formatspec('%r:: and %lr', '10 or 11', ("this()", "that()"))
2200 >>> formatspec('%r:: and %lr', '10 or 11', ("this()", "that()"))
2200 '(10 or 11):: and ((this()) or (that()))'
2201 '(10 or 11):: and ((this()) or (that()))'
2201 >>> formatspec('%d:: and not %d::', 10, 20)
2202 >>> formatspec('%d:: and not %d::', 10, 20)
2202 '10:: and not 20::'
2203 '10:: and not 20::'
2203 >>> formatspec('%ld or %ld', [], [1])
2204 >>> formatspec('%ld or %ld', [], [1])
2204 "_list('') or 1"
2205 "_list('') or 1"
2205 >>> formatspec('keyword(%s)', 'foo\\xe9')
2206 >>> formatspec('keyword(%s)', 'foo\\xe9')
2206 "keyword('foo\\\\xe9')"
2207 "keyword('foo\\\\xe9')"
2207 >>> b = lambda: 'default'
2208 >>> b = lambda: 'default'
2208 >>> b.branch = b
2209 >>> b.branch = b
2209 >>> formatspec('branch(%b)', b)
2210 >>> formatspec('branch(%b)', b)
2210 "branch('default')"
2211 "branch('default')"
2211 >>> formatspec('root(%ls)', ['a', 'b', 'c', 'd'])
2212 >>> formatspec('root(%ls)', ['a', 'b', 'c', 'd'])
2212 "root(_list('a\\x00b\\x00c\\x00d'))"
2213 "root(_list('a\\x00b\\x00c\\x00d'))"
2213 '''
2214 '''
2214
2215
2215 def quote(s):
2216 def quote(s):
2216 return repr(str(s))
2217 return repr(str(s))
2217
2218
2218 def argtype(c, arg):
2219 def argtype(c, arg):
2219 if c == 'd':
2220 if c == 'd':
2220 return str(int(arg))
2221 return str(int(arg))
2221 elif c == 's':
2222 elif c == 's':
2222 return quote(arg)
2223 return quote(arg)
2223 elif c == 'r':
2224 elif c == 'r':
2224 parse(arg) # make sure syntax errors are confined
2225 parse(arg) # make sure syntax errors are confined
2225 return '(%s)' % arg
2226 return '(%s)' % arg
2226 elif c == 'n':
2227 elif c == 'n':
2227 return quote(node.hex(arg))
2228 return quote(node.hex(arg))
2228 elif c == 'b':
2229 elif c == 'b':
2229 return quote(arg.branch())
2230 return quote(arg.branch())
2230
2231
2231 def listexp(s, t):
2232 def listexp(s, t):
2232 l = len(s)
2233 l = len(s)
2233 if l == 0:
2234 if l == 0:
2234 return "_list('')"
2235 return "_list('')"
2235 elif l == 1:
2236 elif l == 1:
2236 return argtype(t, s[0])
2237 return argtype(t, s[0])
2237 elif t == 'd':
2238 elif t == 'd':
2238 return "_intlist('%s')" % "\0".join(str(int(a)) for a in s)
2239 return "_intlist('%s')" % "\0".join(str(int(a)) for a in s)
2239 elif t == 's':
2240 elif t == 's':
2240 return "_list('%s')" % "\0".join(s)
2241 return "_list('%s')" % "\0".join(s)
2241 elif t == 'n':
2242 elif t == 'n':
2242 return "_hexlist('%s')" % "\0".join(node.hex(a) for a in s)
2243 return "_hexlist('%s')" % "\0".join(node.hex(a) for a in s)
2243 elif t == 'b':
2244 elif t == 'b':
2244 return "_list('%s')" % "\0".join(a.branch() for a in s)
2245 return "_list('%s')" % "\0".join(a.branch() for a in s)
2245
2246
2246 m = l // 2
2247 m = l // 2
2247 return '(%s or %s)' % (listexp(s[:m], t), listexp(s[m:], t))
2248 return '(%s or %s)' % (listexp(s[:m], t), listexp(s[m:], t))
2248
2249
2249 ret = ''
2250 ret = ''
2250 pos = 0
2251 pos = 0
2251 arg = 0
2252 arg = 0
2252 while pos < len(expr):
2253 while pos < len(expr):
2253 c = expr[pos]
2254 c = expr[pos]
2254 if c == '%':
2255 if c == '%':
2255 pos += 1
2256 pos += 1
2256 d = expr[pos]
2257 d = expr[pos]
2257 if d == '%':
2258 if d == '%':
2258 ret += d
2259 ret += d
2259 elif d in 'dsnbr':
2260 elif d in 'dsnbr':
2260 ret += argtype(d, args[arg])
2261 ret += argtype(d, args[arg])
2261 arg += 1
2262 arg += 1
2262 elif d == 'l':
2263 elif d == 'l':
2263 # a list of some type
2264 # a list of some type
2264 pos += 1
2265 pos += 1
2265 d = expr[pos]
2266 d = expr[pos]
2266 ret += listexp(list(args[arg]), d)
2267 ret += listexp(list(args[arg]), d)
2267 arg += 1
2268 arg += 1
2268 else:
2269 else:
2269 raise util.Abort('unexpected revspec format character %s' % d)
2270 raise util.Abort('unexpected revspec format character %s' % d)
2270 else:
2271 else:
2271 ret += c
2272 ret += c
2272 pos += 1
2273 pos += 1
2273
2274
2274 return ret
2275 return ret
2275
2276
2276 def prettyformat(tree):
2277 def prettyformat(tree):
2277 def _prettyformat(tree, level, lines):
2278 def _prettyformat(tree, level, lines):
2278 if not isinstance(tree, tuple) or tree[0] in ('string', 'symbol'):
2279 if not isinstance(tree, tuple) or tree[0] in ('string', 'symbol'):
2279 lines.append((level, str(tree)))
2280 lines.append((level, str(tree)))
2280 else:
2281 else:
2281 lines.append((level, '(%s' % tree[0]))
2282 lines.append((level, '(%s' % tree[0]))
2282 for s in tree[1:]:
2283 for s in tree[1:]:
2283 _prettyformat(s, level + 1, lines)
2284 _prettyformat(s, level + 1, lines)
2284 lines[-1:] = [(lines[-1][0], lines[-1][1] + ')')]
2285 lines[-1:] = [(lines[-1][0], lines[-1][1] + ')')]
2285
2286
2286 lines = []
2287 lines = []
2287 _prettyformat(tree, 0, lines)
2288 _prettyformat(tree, 0, lines)
2288 output = '\n'.join((' '*l + s) for l, s in lines)
2289 output = '\n'.join((' '*l + s) for l, s in lines)
2289 return output
2290 return output
2290
2291
2291 def depth(tree):
2292 def depth(tree):
2292 if isinstance(tree, tuple):
2293 if isinstance(tree, tuple):
2293 return max(map(depth, tree)) + 1
2294 return max(map(depth, tree)) + 1
2294 else:
2295 else:
2295 return 0
2296 return 0
2296
2297
2297 def funcsused(tree):
2298 def funcsused(tree):
2298 if not isinstance(tree, tuple) or tree[0] in ('string', 'symbol'):
2299 if not isinstance(tree, tuple) or tree[0] in ('string', 'symbol'):
2299 return set()
2300 return set()
2300 else:
2301 else:
2301 funcs = set()
2302 funcs = set()
2302 for s in tree[1:]:
2303 for s in tree[1:]:
2303 funcs |= funcsused(s)
2304 funcs |= funcsused(s)
2304 if tree[0] == 'func':
2305 if tree[0] == 'func':
2305 funcs.add(tree[1][1])
2306 funcs.add(tree[1][1])
2306 return funcs
2307 return funcs
2307
2308
2308 class abstractsmartset(object):
2309 class abstractsmartset(object):
2309
2310
2310 def __nonzero__(self):
2311 def __nonzero__(self):
2311 """True if the smartset is not empty"""
2312 """True if the smartset is not empty"""
2312 raise NotImplementedError()
2313 raise NotImplementedError()
2313
2314
2314 def __contains__(self, rev):
2315 def __contains__(self, rev):
2315 """provide fast membership testing"""
2316 """provide fast membership testing"""
2316 raise NotImplementedError()
2317 raise NotImplementedError()
2317
2318
2318 def __iter__(self):
2319 def __iter__(self):
2319 """iterate the set in the order it is supposed to be iterated"""
2320 """iterate the set in the order it is supposed to be iterated"""
2320 raise NotImplementedError()
2321 raise NotImplementedError()
2321
2322
2322 # Attributes containing a function to perform a fast iteration in a given
2323 # Attributes containing a function to perform a fast iteration in a given
2323 # direction. A smartset can have none, one, or both defined.
2324 # direction. A smartset can have none, one, or both defined.
2324 #
2325 #
2325 # Default value is None instead of a function returning None to avoid
2326 # Default value is None instead of a function returning None to avoid
2326 # initializing an iterator just for testing if a fast method exists.
2327 # initializing an iterator just for testing if a fast method exists.
2327 fastasc = None
2328 fastasc = None
2328 fastdesc = None
2329 fastdesc = None
2329
2330
2330 def isascending(self):
2331 def isascending(self):
2331 """True if the set will iterate in ascending order"""
2332 """True if the set will iterate in ascending order"""
2332 raise NotImplementedError()
2333 raise NotImplementedError()
2333
2334
2334 def isdescending(self):
2335 def isdescending(self):
2335 """True if the set will iterate in descending order"""
2336 """True if the set will iterate in descending order"""
2336 raise NotImplementedError()
2337 raise NotImplementedError()
2337
2338
2338 def min(self):
2339 def min(self):
2339 """return the minimum element in the set"""
2340 """return the minimum element in the set"""
2340 if self.fastasc is not None:
2341 if self.fastasc is not None:
2341 for r in self.fastasc():
2342 for r in self.fastasc():
2342 return r
2343 return r
2343 raise ValueError('arg is an empty sequence')
2344 raise ValueError('arg is an empty sequence')
2344 return min(self)
2345 return min(self)
2345
2346
2346 def max(self):
2347 def max(self):
2347 """return the maximum element in the set"""
2348 """return the maximum element in the set"""
2348 if self.fastdesc is not None:
2349 if self.fastdesc is not None:
2349 for r in self.fastdesc():
2350 for r in self.fastdesc():
2350 return r
2351 return r
2351 raise ValueError('arg is an empty sequence')
2352 raise ValueError('arg is an empty sequence')
2352 return max(self)
2353 return max(self)
2353
2354
2354 def first(self):
2355 def first(self):
2355 """return the first element in the set (user iteration perspective)
2356 """return the first element in the set (user iteration perspective)
2356
2357
2357 Return None if the set is empty"""
2358 Return None if the set is empty"""
2358 raise NotImplementedError()
2359 raise NotImplementedError()
2359
2360
2360 def last(self):
2361 def last(self):
2361 """return the last element in the set (user iteration perspective)
2362 """return the last element in the set (user iteration perspective)
2362
2363
2363 Return None if the set is empty"""
2364 Return None if the set is empty"""
2364 raise NotImplementedError()
2365 raise NotImplementedError()
2365
2366
2366 def __len__(self):
2367 def __len__(self):
2367 """return the length of the smartsets
2368 """return the length of the smartsets
2368
2369
2369 This can be expensive on smartset that could be lazy otherwise."""
2370 This can be expensive on smartset that could be lazy otherwise."""
2370 raise NotImplementedError()
2371 raise NotImplementedError()
2371
2372
2372 def reverse(self):
2373 def reverse(self):
2373 """reverse the expected iteration order"""
2374 """reverse the expected iteration order"""
2374 raise NotImplementedError()
2375 raise NotImplementedError()
2375
2376
2376 def sort(self, reverse=True):
2377 def sort(self, reverse=True):
2377 """get the set to iterate in an ascending or descending order"""
2378 """get the set to iterate in an ascending or descending order"""
2378 raise NotImplementedError()
2379 raise NotImplementedError()
2379
2380
2380 def __and__(self, other):
2381 def __and__(self, other):
2381 """Returns a new object with the intersection of the two collections.
2382 """Returns a new object with the intersection of the two collections.
2382
2383
2383 This is part of the mandatory API for smartset."""
2384 This is part of the mandatory API for smartset."""
2384 return self.filter(other.__contains__, cache=False)
2385 return self.filter(other.__contains__, cache=False)
2385
2386
2386 def __add__(self, other):
2387 def __add__(self, other):
2387 """Returns a new object with the union of the two collections.
2388 """Returns a new object with the union of the two collections.
2388
2389
2389 This is part of the mandatory API for smartset."""
2390 This is part of the mandatory API for smartset."""
2390 return addset(self, other)
2391 return addset(self, other)
2391
2392
2392 def __sub__(self, other):
2393 def __sub__(self, other):
2393 """Returns a new object with the substraction of the two collections.
2394 """Returns a new object with the substraction of the two collections.
2394
2395
2395 This is part of the mandatory API for smartset."""
2396 This is part of the mandatory API for smartset."""
2396 c = other.__contains__
2397 c = other.__contains__
2397 return self.filter(lambda r: not c(r), cache=False)
2398 return self.filter(lambda r: not c(r), cache=False)
2398
2399
2399 def filter(self, condition, cache=True):
2400 def filter(self, condition, cache=True):
2400 """Returns this smartset filtered by condition as a new smartset.
2401 """Returns this smartset filtered by condition as a new smartset.
2401
2402
2402 `condition` is a callable which takes a revision number and returns a
2403 `condition` is a callable which takes a revision number and returns a
2403 boolean.
2404 boolean.
2404
2405
2405 This is part of the mandatory API for smartset."""
2406 This is part of the mandatory API for smartset."""
2406 # builtin cannot be cached. but do not needs to
2407 # builtin cannot be cached. but do not needs to
2407 if cache and util.safehasattr(condition, 'func_code'):
2408 if cache and util.safehasattr(condition, 'func_code'):
2408 condition = util.cachefunc(condition)
2409 condition = util.cachefunc(condition)
2409 return filteredset(self, condition)
2410 return filteredset(self, condition)
2410
2411
2411 class baseset(abstractsmartset):
2412 class baseset(abstractsmartset):
2412 """Basic data structure that represents a revset and contains the basic
2413 """Basic data structure that represents a revset and contains the basic
2413 operation that it should be able to perform.
2414 operation that it should be able to perform.
2414
2415
2415 Every method in this class should be implemented by any smartset class.
2416 Every method in this class should be implemented by any smartset class.
2416 """
2417 """
2417 def __init__(self, data=()):
2418 def __init__(self, data=()):
2418 if not isinstance(data, list):
2419 if not isinstance(data, list):
2419 data = list(data)
2420 data = list(data)
2420 self._list = data
2421 self._list = data
2421 self._ascending = None
2422 self._ascending = None
2422
2423
2423 @util.propertycache
2424 @util.propertycache
2424 def _set(self):
2425 def _set(self):
2425 return set(self._list)
2426 return set(self._list)
2426
2427
2427 @util.propertycache
2428 @util.propertycache
2428 def _asclist(self):
2429 def _asclist(self):
2429 asclist = self._list[:]
2430 asclist = self._list[:]
2430 asclist.sort()
2431 asclist.sort()
2431 return asclist
2432 return asclist
2432
2433
2433 def __iter__(self):
2434 def __iter__(self):
2434 if self._ascending is None:
2435 if self._ascending is None:
2435 return iter(self._list)
2436 return iter(self._list)
2436 elif self._ascending:
2437 elif self._ascending:
2437 return iter(self._asclist)
2438 return iter(self._asclist)
2438 else:
2439 else:
2439 return reversed(self._asclist)
2440 return reversed(self._asclist)
2440
2441
2441 def fastasc(self):
2442 def fastasc(self):
2442 return iter(self._asclist)
2443 return iter(self._asclist)
2443
2444
2444 def fastdesc(self):
2445 def fastdesc(self):
2445 return reversed(self._asclist)
2446 return reversed(self._asclist)
2446
2447
2447 @util.propertycache
2448 @util.propertycache
2448 def __contains__(self):
2449 def __contains__(self):
2449 return self._set.__contains__
2450 return self._set.__contains__
2450
2451
2451 def __nonzero__(self):
2452 def __nonzero__(self):
2452 return bool(self._list)
2453 return bool(self._list)
2453
2454
2454 def sort(self, reverse=False):
2455 def sort(self, reverse=False):
2455 self._ascending = not bool(reverse)
2456 self._ascending = not bool(reverse)
2456
2457
2457 def reverse(self):
2458 def reverse(self):
2458 if self._ascending is None:
2459 if self._ascending is None:
2459 self._list.reverse()
2460 self._list.reverse()
2460 else:
2461 else:
2461 self._ascending = not self._ascending
2462 self._ascending = not self._ascending
2462
2463
2463 def __len__(self):
2464 def __len__(self):
2464 return len(self._list)
2465 return len(self._list)
2465
2466
2466 def isascending(self):
2467 def isascending(self):
2467 """Returns True if the collection is ascending order, False if not.
2468 """Returns True if the collection is ascending order, False if not.
2468
2469
2469 This is part of the mandatory API for smartset."""
2470 This is part of the mandatory API for smartset."""
2470 if len(self) <= 1:
2471 if len(self) <= 1:
2471 return True
2472 return True
2472 return self._ascending is not None and self._ascending
2473 return self._ascending is not None and self._ascending
2473
2474
2474 def isdescending(self):
2475 def isdescending(self):
2475 """Returns True if the collection is descending order, False if not.
2476 """Returns True if the collection is descending order, False if not.
2476
2477
2477 This is part of the mandatory API for smartset."""
2478 This is part of the mandatory API for smartset."""
2478 if len(self) <= 1:
2479 if len(self) <= 1:
2479 return True
2480 return True
2480 return self._ascending is not None and not self._ascending
2481 return self._ascending is not None and not self._ascending
2481
2482
2482 def first(self):
2483 def first(self):
2483 if self:
2484 if self:
2484 if self._ascending is None:
2485 if self._ascending is None:
2485 return self._list[0]
2486 return self._list[0]
2486 elif self._ascending:
2487 elif self._ascending:
2487 return self._asclist[0]
2488 return self._asclist[0]
2488 else:
2489 else:
2489 return self._asclist[-1]
2490 return self._asclist[-1]
2490 return None
2491 return None
2491
2492
2492 def last(self):
2493 def last(self):
2493 if self:
2494 if self:
2494 if self._ascending is None:
2495 if self._ascending is None:
2495 return self._list[-1]
2496 return self._list[-1]
2496 elif self._ascending:
2497 elif self._ascending:
2497 return self._asclist[-1]
2498 return self._asclist[-1]
2498 else:
2499 else:
2499 return self._asclist[0]
2500 return self._asclist[0]
2500 return None
2501 return None
2501
2502
2502 class filteredset(abstractsmartset):
2503 class filteredset(abstractsmartset):
2503 """Duck type for baseset class which iterates lazily over the revisions in
2504 """Duck type for baseset class which iterates lazily over the revisions in
2504 the subset and contains a function which tests for membership in the
2505 the subset and contains a function which tests for membership in the
2505 revset
2506 revset
2506 """
2507 """
2507 def __init__(self, subset, condition=lambda x: True):
2508 def __init__(self, subset, condition=lambda x: True):
2508 """
2509 """
2509 condition: a function that decide whether a revision in the subset
2510 condition: a function that decide whether a revision in the subset
2510 belongs to the revset or not.
2511 belongs to the revset or not.
2511 """
2512 """
2512 self._subset = subset
2513 self._subset = subset
2513 self._condition = condition
2514 self._condition = condition
2514 self._cache = {}
2515 self._cache = {}
2515
2516
2516 def __contains__(self, x):
2517 def __contains__(self, x):
2517 c = self._cache
2518 c = self._cache
2518 if x not in c:
2519 if x not in c:
2519 v = c[x] = x in self._subset and self._condition(x)
2520 v = c[x] = x in self._subset and self._condition(x)
2520 return v
2521 return v
2521 return c[x]
2522 return c[x]
2522
2523
2523 def __iter__(self):
2524 def __iter__(self):
2524 return self._iterfilter(self._subset)
2525 return self._iterfilter(self._subset)
2525
2526
2526 def _iterfilter(self, it):
2527 def _iterfilter(self, it):
2527 cond = self._condition
2528 cond = self._condition
2528 for x in it:
2529 for x in it:
2529 if cond(x):
2530 if cond(x):
2530 yield x
2531 yield x
2531
2532
2532 @property
2533 @property
2533 def fastasc(self):
2534 def fastasc(self):
2534 it = self._subset.fastasc
2535 it = self._subset.fastasc
2535 if it is None:
2536 if it is None:
2536 return None
2537 return None
2537 return lambda: self._iterfilter(it())
2538 return lambda: self._iterfilter(it())
2538
2539
2539 @property
2540 @property
2540 def fastdesc(self):
2541 def fastdesc(self):
2541 it = self._subset.fastdesc
2542 it = self._subset.fastdesc
2542 if it is None:
2543 if it is None:
2543 return None
2544 return None
2544 return lambda: self._iterfilter(it())
2545 return lambda: self._iterfilter(it())
2545
2546
2546 def __nonzero__(self):
2547 def __nonzero__(self):
2547 for r in self:
2548 for r in self:
2548 return True
2549 return True
2549 return False
2550 return False
2550
2551
2551 def __len__(self):
2552 def __len__(self):
2552 # Basic implementation to be changed in future patches.
2553 # Basic implementation to be changed in future patches.
2553 l = baseset([r for r in self])
2554 l = baseset([r for r in self])
2554 return len(l)
2555 return len(l)
2555
2556
2556 def sort(self, reverse=False):
2557 def sort(self, reverse=False):
2557 self._subset.sort(reverse=reverse)
2558 self._subset.sort(reverse=reverse)
2558
2559
2559 def reverse(self):
2560 def reverse(self):
2560 self._subset.reverse()
2561 self._subset.reverse()
2561
2562
2562 def isascending(self):
2563 def isascending(self):
2563 return self._subset.isascending()
2564 return self._subset.isascending()
2564
2565
2565 def isdescending(self):
2566 def isdescending(self):
2566 return self._subset.isdescending()
2567 return self._subset.isdescending()
2567
2568
2568 def first(self):
2569 def first(self):
2569 for x in self:
2570 for x in self:
2570 return x
2571 return x
2571 return None
2572 return None
2572
2573
2573 def last(self):
2574 def last(self):
2574 it = None
2575 it = None
2575 if self._subset.isascending:
2576 if self._subset.isascending:
2576 it = self.fastdesc
2577 it = self.fastdesc
2577 elif self._subset.isdescending:
2578 elif self._subset.isdescending:
2578 it = self.fastdesc
2579 it = self.fastdesc
2579 if it is None:
2580 if it is None:
2580 # slowly consume everything. This needs improvement
2581 # slowly consume everything. This needs improvement
2581 it = lambda: reversed(list(self))
2582 it = lambda: reversed(list(self))
2582 for x in it():
2583 for x in it():
2583 return x
2584 return x
2584 return None
2585 return None
2585
2586
2586 class addset(abstractsmartset):
2587 class addset(abstractsmartset):
2587 """Represent the addition of two sets
2588 """Represent the addition of two sets
2588
2589
2589 Wrapper structure for lazily adding two structures without losing much
2590 Wrapper structure for lazily adding two structures without losing much
2590 performance on the __contains__ method
2591 performance on the __contains__ method
2591
2592
2592 If the ascending attribute is set, that means the two structures are
2593 If the ascending attribute is set, that means the two structures are
2593 ordered in either an ascending or descending way. Therefore, we can add
2594 ordered in either an ascending or descending way. Therefore, we can add
2594 them maintaining the order by iterating over both at the same time
2595 them maintaining the order by iterating over both at the same time
2595 """
2596 """
2596 def __init__(self, revs1, revs2, ascending=None):
2597 def __init__(self, revs1, revs2, ascending=None):
2597 self._r1 = revs1
2598 self._r1 = revs1
2598 self._r2 = revs2
2599 self._r2 = revs2
2599 self._iter = None
2600 self._iter = None
2600 self._ascending = ascending
2601 self._ascending = ascending
2601 self._genlist = None
2602 self._genlist = None
2602 self._asclist = None
2603 self._asclist = None
2603
2604
2604 def __len__(self):
2605 def __len__(self):
2605 return len(self._list)
2606 return len(self._list)
2606
2607
2607 def __nonzero__(self):
2608 def __nonzero__(self):
2608 return bool(self._r1) or bool(self._r2)
2609 return bool(self._r1) or bool(self._r2)
2609
2610
2610 @util.propertycache
2611 @util.propertycache
2611 def _list(self):
2612 def _list(self):
2612 if not self._genlist:
2613 if not self._genlist:
2613 self._genlist = baseset(self._iterator())
2614 self._genlist = baseset(self._iterator())
2614 return self._genlist
2615 return self._genlist
2615
2616
2616 def _iterator(self):
2617 def _iterator(self):
2617 """Iterate over both collections without repeating elements
2618 """Iterate over both collections without repeating elements
2618
2619
2619 If the ascending attribute is not set, iterate over the first one and
2620 If the ascending attribute is not set, iterate over the first one and
2620 then over the second one checking for membership on the first one so we
2621 then over the second one checking for membership on the first one so we
2621 dont yield any duplicates.
2622 dont yield any duplicates.
2622
2623
2623 If the ascending attribute is set, iterate over both collections at the
2624 If the ascending attribute is set, iterate over both collections at the
2624 same time, yielding only one value at a time in the given order.
2625 same time, yielding only one value at a time in the given order.
2625 """
2626 """
2626 if self._ascending is None:
2627 if self._ascending is None:
2627 def gen():
2628 def gen():
2628 for r in self._r1:
2629 for r in self._r1:
2629 yield r
2630 yield r
2630 inr1 = self._r1.__contains__
2631 inr1 = self._r1.__contains__
2631 for r in self._r2:
2632 for r in self._r2:
2632 if not inr1(r):
2633 if not inr1(r):
2633 yield r
2634 yield r
2634 gen = gen()
2635 gen = gen()
2635 else:
2636 else:
2636 iter1 = iter(self._r1)
2637 iter1 = iter(self._r1)
2637 iter2 = iter(self._r2)
2638 iter2 = iter(self._r2)
2638 gen = self._iterordered(self._ascending, iter1, iter2)
2639 gen = self._iterordered(self._ascending, iter1, iter2)
2639 return gen
2640 return gen
2640
2641
2641 def __iter__(self):
2642 def __iter__(self):
2642 if self._ascending is None:
2643 if self._ascending is None:
2643 if self._genlist:
2644 if self._genlist:
2644 return iter(self._genlist)
2645 return iter(self._genlist)
2645 return iter(self._iterator())
2646 return iter(self._iterator())
2646 self._trysetasclist()
2647 self._trysetasclist()
2647 if self._ascending:
2648 if self._ascending:
2648 it = self.fastasc
2649 it = self.fastasc
2649 else:
2650 else:
2650 it = self.fastdesc
2651 it = self.fastdesc
2651 if it is None:
2652 if it is None:
2652 # consume the gen and try again
2653 # consume the gen and try again
2653 self._list
2654 self._list
2654 return iter(self)
2655 return iter(self)
2655 return it()
2656 return it()
2656
2657
2657 def _trysetasclist(self):
2658 def _trysetasclist(self):
2658 """populate the _asclist attribute if possible and necessary"""
2659 """populate the _asclist attribute if possible and necessary"""
2659 if self._genlist is not None and self._asclist is None:
2660 if self._genlist is not None and self._asclist is None:
2660 self._asclist = sorted(self._genlist)
2661 self._asclist = sorted(self._genlist)
2661
2662
2662 @property
2663 @property
2663 def fastasc(self):
2664 def fastasc(self):
2664 self._trysetasclist()
2665 self._trysetasclist()
2665 if self._asclist is not None:
2666 if self._asclist is not None:
2666 return self._asclist.__iter__
2667 return self._asclist.__iter__
2667 iter1 = self._r1.fastasc
2668 iter1 = self._r1.fastasc
2668 iter2 = self._r2.fastasc
2669 iter2 = self._r2.fastasc
2669 if None in (iter1, iter2):
2670 if None in (iter1, iter2):
2670 return None
2671 return None
2671 return lambda: self._iterordered(True, iter1(), iter2())
2672 return lambda: self._iterordered(True, iter1(), iter2())
2672
2673
2673 @property
2674 @property
2674 def fastdesc(self):
2675 def fastdesc(self):
2675 self._trysetasclist()
2676 self._trysetasclist()
2676 if self._asclist is not None:
2677 if self._asclist is not None:
2677 return self._asclist.__reversed__
2678 return self._asclist.__reversed__
2678 iter1 = self._r1.fastdesc
2679 iter1 = self._r1.fastdesc
2679 iter2 = self._r2.fastdesc
2680 iter2 = self._r2.fastdesc
2680 if None in (iter1, iter2):
2681 if None in (iter1, iter2):
2681 return None
2682 return None
2682 return lambda: self._iterordered(False, iter1(), iter2())
2683 return lambda: self._iterordered(False, iter1(), iter2())
2683
2684
2684 def _iterordered(self, ascending, iter1, iter2):
2685 def _iterordered(self, ascending, iter1, iter2):
2685 """produce an ordered iteration from two iterators with the same order
2686 """produce an ordered iteration from two iterators with the same order
2686
2687
2687 The ascending is used to indicated the iteration direction.
2688 The ascending is used to indicated the iteration direction.
2688 """
2689 """
2689 choice = max
2690 choice = max
2690 if ascending:
2691 if ascending:
2691 choice = min
2692 choice = min
2692
2693
2693 val1 = None
2694 val1 = None
2694 val2 = None
2695 val2 = None
2695
2696
2696 choice = max
2697 choice = max
2697 if ascending:
2698 if ascending:
2698 choice = min
2699 choice = min
2699 try:
2700 try:
2700 # Consume both iterators in an ordered way until one is
2701 # Consume both iterators in an ordered way until one is
2701 # empty
2702 # empty
2702 while True:
2703 while True:
2703 if val1 is None:
2704 if val1 is None:
2704 val1 = iter1.next()
2705 val1 = iter1.next()
2705 if val2 is None:
2706 if val2 is None:
2706 val2 = iter2.next()
2707 val2 = iter2.next()
2707 next = choice(val1, val2)
2708 next = choice(val1, val2)
2708 yield next
2709 yield next
2709 if val1 == next:
2710 if val1 == next:
2710 val1 = None
2711 val1 = None
2711 if val2 == next:
2712 if val2 == next:
2712 val2 = None
2713 val2 = None
2713 except StopIteration:
2714 except StopIteration:
2714 # Flush any remaining values and consume the other one
2715 # Flush any remaining values and consume the other one
2715 it = iter2
2716 it = iter2
2716 if val1 is not None:
2717 if val1 is not None:
2717 yield val1
2718 yield val1
2718 it = iter1
2719 it = iter1
2719 elif val2 is not None:
2720 elif val2 is not None:
2720 # might have been equality and both are empty
2721 # might have been equality and both are empty
2721 yield val2
2722 yield val2
2722 for val in it:
2723 for val in it:
2723 yield val
2724 yield val
2724
2725
2725 def __contains__(self, x):
2726 def __contains__(self, x):
2726 return x in self._r1 or x in self._r2
2727 return x in self._r1 or x in self._r2
2727
2728
2728 def sort(self, reverse=False):
2729 def sort(self, reverse=False):
2729 """Sort the added set
2730 """Sort the added set
2730
2731
2731 For this we use the cached list with all the generated values and if we
2732 For this we use the cached list with all the generated values and if we
2732 know they are ascending or descending we can sort them in a smart way.
2733 know they are ascending or descending we can sort them in a smart way.
2733 """
2734 """
2734 self._ascending = not reverse
2735 self._ascending = not reverse
2735
2736
2736 def isascending(self):
2737 def isascending(self):
2737 return self._ascending is not None and self._ascending
2738 return self._ascending is not None and self._ascending
2738
2739
2739 def isdescending(self):
2740 def isdescending(self):
2740 return self._ascending is not None and not self._ascending
2741 return self._ascending is not None and not self._ascending
2741
2742
2742 def reverse(self):
2743 def reverse(self):
2743 if self._ascending is None:
2744 if self._ascending is None:
2744 self._list.reverse()
2745 self._list.reverse()
2745 else:
2746 else:
2746 self._ascending = not self._ascending
2747 self._ascending = not self._ascending
2747
2748
2748 def first(self):
2749 def first(self):
2749 for x in self:
2750 for x in self:
2750 return x
2751 return x
2751 return None
2752 return None
2752
2753
2753 def last(self):
2754 def last(self):
2754 self.reverse()
2755 self.reverse()
2755 val = self.first()
2756 val = self.first()
2756 self.reverse()
2757 self.reverse()
2757 return val
2758 return val
2758
2759
2759 class generatorset(abstractsmartset):
2760 class generatorset(abstractsmartset):
2760 """Wrap a generator for lazy iteration
2761 """Wrap a generator for lazy iteration
2761
2762
2762 Wrapper structure for generators that provides lazy membership and can
2763 Wrapper structure for generators that provides lazy membership and can
2763 be iterated more than once.
2764 be iterated more than once.
2764 When asked for membership it generates values until either it finds the
2765 When asked for membership it generates values until either it finds the
2765 requested one or has gone through all the elements in the generator
2766 requested one or has gone through all the elements in the generator
2766 """
2767 """
2767 def __init__(self, gen, iterasc=None):
2768 def __init__(self, gen, iterasc=None):
2768 """
2769 """
2769 gen: a generator producing the values for the generatorset.
2770 gen: a generator producing the values for the generatorset.
2770 """
2771 """
2771 self._gen = gen
2772 self._gen = gen
2772 self._asclist = None
2773 self._asclist = None
2773 self._cache = {}
2774 self._cache = {}
2774 self._genlist = []
2775 self._genlist = []
2775 self._finished = False
2776 self._finished = False
2776 self._ascending = True
2777 self._ascending = True
2777 if iterasc is not None:
2778 if iterasc is not None:
2778 if iterasc:
2779 if iterasc:
2779 self.fastasc = self._iterator
2780 self.fastasc = self._iterator
2780 self.__contains__ = self._asccontains
2781 self.__contains__ = self._asccontains
2781 else:
2782 else:
2782 self.fastdesc = self._iterator
2783 self.fastdesc = self._iterator
2783 self.__contains__ = self._desccontains
2784 self.__contains__ = self._desccontains
2784
2785
2785 def __nonzero__(self):
2786 def __nonzero__(self):
2786 for r in self:
2787 for r in self:
2787 return True
2788 return True
2788 return False
2789 return False
2789
2790
2790 def __contains__(self, x):
2791 def __contains__(self, x):
2791 if x in self._cache:
2792 if x in self._cache:
2792 return self._cache[x]
2793 return self._cache[x]
2793
2794
2794 # Use new values only, as existing values would be cached.
2795 # Use new values only, as existing values would be cached.
2795 for l in self._consumegen():
2796 for l in self._consumegen():
2796 if l == x:
2797 if l == x:
2797 return True
2798 return True
2798
2799
2799 self._cache[x] = False
2800 self._cache[x] = False
2800 return False
2801 return False
2801
2802
2802 def _asccontains(self, x):
2803 def _asccontains(self, x):
2803 """version of contains optimised for ascending generator"""
2804 """version of contains optimised for ascending generator"""
2804 if x in self._cache:
2805 if x in self._cache:
2805 return self._cache[x]
2806 return self._cache[x]
2806
2807
2807 # Use new values only, as existing values would be cached.
2808 # Use new values only, as existing values would be cached.
2808 for l in self._consumegen():
2809 for l in self._consumegen():
2809 if l == x:
2810 if l == x:
2810 return True
2811 return True
2811 if l > x:
2812 if l > x:
2812 break
2813 break
2813
2814
2814 self._cache[x] = False
2815 self._cache[x] = False
2815 return False
2816 return False
2816
2817
2817 def _desccontains(self, x):
2818 def _desccontains(self, x):
2818 """version of contains optimised for descending generator"""
2819 """version of contains optimised for descending generator"""
2819 if x in self._cache:
2820 if x in self._cache:
2820 return self._cache[x]
2821 return self._cache[x]
2821
2822
2822 # Use new values only, as existing values would be cached.
2823 # Use new values only, as existing values would be cached.
2823 for l in self._consumegen():
2824 for l in self._consumegen():
2824 if l == x:
2825 if l == x:
2825 return True
2826 return True
2826 if l < x:
2827 if l < x:
2827 break
2828 break
2828
2829
2829 self._cache[x] = False
2830 self._cache[x] = False
2830 return False
2831 return False
2831
2832
2832 def __iter__(self):
2833 def __iter__(self):
2833 if self._ascending:
2834 if self._ascending:
2834 it = self.fastasc
2835 it = self.fastasc
2835 else:
2836 else:
2836 it = self.fastdesc
2837 it = self.fastdesc
2837 if it is not None:
2838 if it is not None:
2838 return it()
2839 return it()
2839 # we need to consume the iterator
2840 # we need to consume the iterator
2840 for x in self._consumegen():
2841 for x in self._consumegen():
2841 pass
2842 pass
2842 # recall the same code
2843 # recall the same code
2843 return iter(self)
2844 return iter(self)
2844
2845
2845 def _iterator(self):
2846 def _iterator(self):
2846 if self._finished:
2847 if self._finished:
2847 return iter(self._genlist)
2848 return iter(self._genlist)
2848
2849
2849 # We have to use this complex iteration strategy to allow multiple
2850 # We have to use this complex iteration strategy to allow multiple
2850 # iterations at the same time. We need to be able to catch revision
2851 # iterations at the same time. We need to be able to catch revision
2851 # removed from _consumegen and added to genlist in another instance.
2852 # removed from _consumegen and added to genlist in another instance.
2852 #
2853 #
2853 # Getting rid of it would provide an about 15% speed up on this
2854 # Getting rid of it would provide an about 15% speed up on this
2854 # iteration.
2855 # iteration.
2855 genlist = self._genlist
2856 genlist = self._genlist
2856 nextrev = self._consumegen().next
2857 nextrev = self._consumegen().next
2857 _len = len # cache global lookup
2858 _len = len # cache global lookup
2858 def gen():
2859 def gen():
2859 i = 0
2860 i = 0
2860 while True:
2861 while True:
2861 if i < _len(genlist):
2862 if i < _len(genlist):
2862 yield genlist[i]
2863 yield genlist[i]
2863 else:
2864 else:
2864 yield nextrev()
2865 yield nextrev()
2865 i += 1
2866 i += 1
2866 return gen()
2867 return gen()
2867
2868
2868 def _consumegen(self):
2869 def _consumegen(self):
2869 cache = self._cache
2870 cache = self._cache
2870 genlist = self._genlist.append
2871 genlist = self._genlist.append
2871 for item in self._gen:
2872 for item in self._gen:
2872 cache[item] = True
2873 cache[item] = True
2873 genlist(item)
2874 genlist(item)
2874 yield item
2875 yield item
2875 if not self._finished:
2876 if not self._finished:
2876 self._finished = True
2877 self._finished = True
2877 asc = self._genlist[:]
2878 asc = self._genlist[:]
2878 asc.sort()
2879 asc.sort()
2879 self._asclist = asc
2880 self._asclist = asc
2880 self.fastasc = asc.__iter__
2881 self.fastasc = asc.__iter__
2881 self.fastdesc = asc.__reversed__
2882 self.fastdesc = asc.__reversed__
2882
2883
2883 def __len__(self):
2884 def __len__(self):
2884 for x in self._consumegen():
2885 for x in self._consumegen():
2885 pass
2886 pass
2886 return len(self._genlist)
2887 return len(self._genlist)
2887
2888
2888 def sort(self, reverse=False):
2889 def sort(self, reverse=False):
2889 self._ascending = not reverse
2890 self._ascending = not reverse
2890
2891
2891 def reverse(self):
2892 def reverse(self):
2892 self._ascending = not self._ascending
2893 self._ascending = not self._ascending
2893
2894
2894 def isascending(self):
2895 def isascending(self):
2895 return self._ascending
2896 return self._ascending
2896
2897
2897 def isdescending(self):
2898 def isdescending(self):
2898 return not self._ascending
2899 return not self._ascending
2899
2900
2900 def first(self):
2901 def first(self):
2901 if self._ascending:
2902 if self._ascending:
2902 it = self.fastasc
2903 it = self.fastasc
2903 else:
2904 else:
2904 it = self.fastdesc
2905 it = self.fastdesc
2905 if it is None:
2906 if it is None:
2906 # we need to consume all and try again
2907 # we need to consume all and try again
2907 for x in self._consumegen():
2908 for x in self._consumegen():
2908 pass
2909 pass
2909 return self.first()
2910 return self.first()
2910 if self:
2911 if self:
2911 return it().next()
2912 return it().next()
2912 return None
2913 return None
2913
2914
2914 def last(self):
2915 def last(self):
2915 if self._ascending:
2916 if self._ascending:
2916 it = self.fastdesc
2917 it = self.fastdesc
2917 else:
2918 else:
2918 it = self.fastasc
2919 it = self.fastasc
2919 if it is None:
2920 if it is None:
2920 # we need to consume all and try again
2921 # we need to consume all and try again
2921 for x in self._consumegen():
2922 for x in self._consumegen():
2922 pass
2923 pass
2923 return self.first()
2924 return self.first()
2924 if self:
2925 if self:
2925 return it().next()
2926 return it().next()
2926 return None
2927 return None
2927
2928
2928 def spanset(repo, start=None, end=None):
2929 def spanset(repo, start=None, end=None):
2929 """factory function to dispatch between fullreposet and actual spanset
2930 """factory function to dispatch between fullreposet and actual spanset
2930
2931
2931 Feel free to update all spanset call sites and kill this function at some
2932 Feel free to update all spanset call sites and kill this function at some
2932 point.
2933 point.
2933 """
2934 """
2934 if start is None and end is None:
2935 if start is None and end is None:
2935 return fullreposet(repo)
2936 return fullreposet(repo)
2936 return _spanset(repo, start, end)
2937 return _spanset(repo, start, end)
2937
2938
2938
2939
2939 class _spanset(abstractsmartset):
2940 class _spanset(abstractsmartset):
2940 """Duck type for baseset class which represents a range of revisions and
2941 """Duck type for baseset class which represents a range of revisions and
2941 can work lazily and without having all the range in memory
2942 can work lazily and without having all the range in memory
2942
2943
2943 Note that spanset(x, y) behave almost like xrange(x, y) except for two
2944 Note that spanset(x, y) behave almost like xrange(x, y) except for two
2944 notable points:
2945 notable points:
2945 - when x < y it will be automatically descending,
2946 - when x < y it will be automatically descending,
2946 - revision filtered with this repoview will be skipped.
2947 - revision filtered with this repoview will be skipped.
2947
2948
2948 """
2949 """
2949 def __init__(self, repo, start=0, end=None):
2950 def __init__(self, repo, start=0, end=None):
2950 """
2951 """
2951 start: first revision included the set
2952 start: first revision included the set
2952 (default to 0)
2953 (default to 0)
2953 end: first revision excluded (last+1)
2954 end: first revision excluded (last+1)
2954 (default to len(repo)
2955 (default to len(repo)
2955
2956
2956 Spanset will be descending if `end` < `start`.
2957 Spanset will be descending if `end` < `start`.
2957 """
2958 """
2958 if end is None:
2959 if end is None:
2959 end = len(repo)
2960 end = len(repo)
2960 self._ascending = start <= end
2961 self._ascending = start <= end
2961 if not self._ascending:
2962 if not self._ascending:
2962 start, end = end + 1, start +1
2963 start, end = end + 1, start +1
2963 self._start = start
2964 self._start = start
2964 self._end = end
2965 self._end = end
2965 self._hiddenrevs = repo.changelog.filteredrevs
2966 self._hiddenrevs = repo.changelog.filteredrevs
2966
2967
2967 def sort(self, reverse=False):
2968 def sort(self, reverse=False):
2968 self._ascending = not reverse
2969 self._ascending = not reverse
2969
2970
2970 def reverse(self):
2971 def reverse(self):
2971 self._ascending = not self._ascending
2972 self._ascending = not self._ascending
2972
2973
2973 def _iterfilter(self, iterrange):
2974 def _iterfilter(self, iterrange):
2974 s = self._hiddenrevs
2975 s = self._hiddenrevs
2975 for r in iterrange:
2976 for r in iterrange:
2976 if r not in s:
2977 if r not in s:
2977 yield r
2978 yield r
2978
2979
2979 def __iter__(self):
2980 def __iter__(self):
2980 if self._ascending:
2981 if self._ascending:
2981 return self.fastasc()
2982 return self.fastasc()
2982 else:
2983 else:
2983 return self.fastdesc()
2984 return self.fastdesc()
2984
2985
2985 def fastasc(self):
2986 def fastasc(self):
2986 iterrange = xrange(self._start, self._end)
2987 iterrange = xrange(self._start, self._end)
2987 if self._hiddenrevs:
2988 if self._hiddenrevs:
2988 return self._iterfilter(iterrange)
2989 return self._iterfilter(iterrange)
2989 return iter(iterrange)
2990 return iter(iterrange)
2990
2991
2991 def fastdesc(self):
2992 def fastdesc(self):
2992 iterrange = xrange(self._end - 1, self._start - 1, -1)
2993 iterrange = xrange(self._end - 1, self._start - 1, -1)
2993 if self._hiddenrevs:
2994 if self._hiddenrevs:
2994 return self._iterfilter(iterrange)
2995 return self._iterfilter(iterrange)
2995 return iter(iterrange)
2996 return iter(iterrange)
2996
2997
2997 def __contains__(self, rev):
2998 def __contains__(self, rev):
2998 hidden = self._hiddenrevs
2999 hidden = self._hiddenrevs
2999 return ((self._start <= rev < self._end)
3000 return ((self._start <= rev < self._end)
3000 and not (hidden and rev in hidden))
3001 and not (hidden and rev in hidden))
3001
3002
3002 def __nonzero__(self):
3003 def __nonzero__(self):
3003 for r in self:
3004 for r in self:
3004 return True
3005 return True
3005 return False
3006 return False
3006
3007
3007 def __len__(self):
3008 def __len__(self):
3008 if not self._hiddenrevs:
3009 if not self._hiddenrevs:
3009 return abs(self._end - self._start)
3010 return abs(self._end - self._start)
3010 else:
3011 else:
3011 count = 0
3012 count = 0
3012 start = self._start
3013 start = self._start
3013 end = self._end
3014 end = self._end
3014 for rev in self._hiddenrevs:
3015 for rev in self._hiddenrevs:
3015 if (end < rev <= start) or (start <= rev < end):
3016 if (end < rev <= start) or (start <= rev < end):
3016 count += 1
3017 count += 1
3017 return abs(self._end - self._start) - count
3018 return abs(self._end - self._start) - count
3018
3019
3019 def isascending(self):
3020 def isascending(self):
3020 return self._start <= self._end
3021 return self._start <= self._end
3021
3022
3022 def isdescending(self):
3023 def isdescending(self):
3023 return self._start >= self._end
3024 return self._start >= self._end
3024
3025
3025 def first(self):
3026 def first(self):
3026 if self._ascending:
3027 if self._ascending:
3027 it = self.fastasc
3028 it = self.fastasc
3028 else:
3029 else:
3029 it = self.fastdesc
3030 it = self.fastdesc
3030 for x in it():
3031 for x in it():
3031 return x
3032 return x
3032 return None
3033 return None
3033
3034
3034 def last(self):
3035 def last(self):
3035 if self._ascending:
3036 if self._ascending:
3036 it = self.fastdesc
3037 it = self.fastdesc
3037 else:
3038 else:
3038 it = self.fastasc
3039 it = self.fastasc
3039 for x in it():
3040 for x in it():
3040 return x
3041 return x
3041 return None
3042 return None
3042
3043
3043 class fullreposet(_spanset):
3044 class fullreposet(_spanset):
3044 """a set containing all revisions in the repo
3045 """a set containing all revisions in the repo
3045
3046
3046 This class exists to host special optimization.
3047 This class exists to host special optimization.
3047 """
3048 """
3048
3049
3049 def __init__(self, repo):
3050 def __init__(self, repo):
3050 super(fullreposet, self).__init__(repo)
3051 super(fullreposet, self).__init__(repo)
3051
3052
3052 def __and__(self, other):
3053 def __and__(self, other):
3053 """As self contains the whole repo, all of the other set should also be
3054 """As self contains the whole repo, all of the other set should also be
3054 in self. Therefore `self & other = other`.
3055 in self. Therefore `self & other = other`.
3055
3056
3056 This boldly assumes the other contains valid revs only.
3057 This boldly assumes the other contains valid revs only.
3057 """
3058 """
3058 # other not a smartset, make is so
3059 # other not a smartset, make is so
3059 if not util.safehasattr(other, 'isascending'):
3060 if not util.safehasattr(other, 'isascending'):
3060 # filter out hidden revision
3061 # filter out hidden revision
3061 # (this boldly assumes all smartset are pure)
3062 # (this boldly assumes all smartset are pure)
3062 #
3063 #
3063 # `other` was used with "&", let's assume this is a set like
3064 # `other` was used with "&", let's assume this is a set like
3064 # object.
3065 # object.
3065 other = baseset(other - self._hiddenrevs)
3066 other = baseset(other - self._hiddenrevs)
3066
3067
3067 if self.isascending():
3068 if self.isascending():
3068 other.sort()
3069 other.sort()
3069 else:
3070 else:
3070 other.sort(reverse)
3071 other.sort(reverse)
3071 return other
3072 return other
3072
3073
3073 # tell hggettext to extract docstrings from these functions:
3074 # tell hggettext to extract docstrings from these functions:
3074 i18nfunctions = symbols.values()
3075 i18nfunctions = symbols.values()
@@ -1,1746 +1,1802 b''
1 Log on empty repository: checking consistency
1 Log on empty repository: checking consistency
2
2
3 $ hg init empty
3 $ hg init empty
4 $ cd empty
4 $ cd empty
5 $ hg log
5 $ hg log
6 $ hg log -r 1
6 $ hg log -r 1
7 abort: unknown revision '1'!
7 abort: unknown revision '1'!
8 [255]
8 [255]
9 $ hg log -r -1:0
9 $ hg log -r -1:0
10 abort: unknown revision '-1'!
10 abort: unknown revision '-1'!
11 [255]
11 [255]
12 $ hg log -r 'branch(name)'
12 $ hg log -r 'branch(name)'
13 abort: unknown revision 'name'!
13 abort: unknown revision 'name'!
14 [255]
14 [255]
15 $ hg log -r null -q
15 $ hg log -r null -q
16 -1:000000000000
16 -1:000000000000
17
17
18 The g is crafted to have 2 filelog topological heads in a linear
18 The g is crafted to have 2 filelog topological heads in a linear
19 changeset graph
19 changeset graph
20
20
21 $ hg init a
21 $ hg init a
22 $ cd a
22 $ cd a
23 $ echo a > a
23 $ echo a > a
24 $ echo f > f
24 $ echo f > f
25 $ hg ci -Ama -d '1 0'
25 $ hg ci -Ama -d '1 0'
26 adding a
26 adding a
27 adding f
27 adding f
28
28
29 $ hg cp a b
29 $ hg cp a b
30 $ hg cp f g
30 $ hg cp f g
31 $ hg ci -mb -d '2 0'
31 $ hg ci -mb -d '2 0'
32
32
33 $ mkdir dir
33 $ mkdir dir
34 $ hg mv b dir
34 $ hg mv b dir
35 $ echo g >> g
35 $ echo g >> g
36 $ echo f >> f
36 $ echo f >> f
37 $ hg ci -mc -d '3 0'
37 $ hg ci -mc -d '3 0'
38
38
39 $ hg mv a b
39 $ hg mv a b
40 $ hg cp -f f g
40 $ hg cp -f f g
41 $ echo a > d
41 $ echo a > d
42 $ hg add d
42 $ hg add d
43 $ hg ci -md -d '4 0'
43 $ hg ci -md -d '4 0'
44
44
45 $ hg mv dir/b e
45 $ hg mv dir/b e
46 $ hg ci -me -d '5 0'
46 $ hg ci -me -d '5 0'
47
47
48 $ hg log a
48 $ hg log a
49 changeset: 0:9161b9aeaf16
49 changeset: 0:9161b9aeaf16
50 user: test
50 user: test
51 date: Thu Jan 01 00:00:01 1970 +0000
51 date: Thu Jan 01 00:00:01 1970 +0000
52 summary: a
52 summary: a
53
53
54 log on directory
54 log on directory
55
55
56 $ hg log dir
56 $ hg log dir
57 changeset: 4:7e4639b4691b
57 changeset: 4:7e4639b4691b
58 tag: tip
58 tag: tip
59 user: test
59 user: test
60 date: Thu Jan 01 00:00:05 1970 +0000
60 date: Thu Jan 01 00:00:05 1970 +0000
61 summary: e
61 summary: e
62
62
63 changeset: 2:f8954cd4dc1f
63 changeset: 2:f8954cd4dc1f
64 user: test
64 user: test
65 date: Thu Jan 01 00:00:03 1970 +0000
65 date: Thu Jan 01 00:00:03 1970 +0000
66 summary: c
66 summary: c
67
67
68 $ hg log somethingthatdoesntexist dir
68 $ hg log somethingthatdoesntexist dir
69 changeset: 4:7e4639b4691b
69 changeset: 4:7e4639b4691b
70 tag: tip
70 tag: tip
71 user: test
71 user: test
72 date: Thu Jan 01 00:00:05 1970 +0000
72 date: Thu Jan 01 00:00:05 1970 +0000
73 summary: e
73 summary: e
74
74
75 changeset: 2:f8954cd4dc1f
75 changeset: 2:f8954cd4dc1f
76 user: test
76 user: test
77 date: Thu Jan 01 00:00:03 1970 +0000
77 date: Thu Jan 01 00:00:03 1970 +0000
78 summary: c
78 summary: c
79
79
80
80
81 -f, non-existent directory
81 -f, non-existent directory
82
82
83 $ hg log -f dir
83 $ hg log -f dir
84 abort: cannot follow file not in parent revision: "dir"
84 abort: cannot follow file not in parent revision: "dir"
85 [255]
85 [255]
86
86
87 -f, directory
87 -f, directory
88
88
89 $ hg up -q 3
89 $ hg up -q 3
90 $ hg log -f dir
90 $ hg log -f dir
91 changeset: 2:f8954cd4dc1f
91 changeset: 2:f8954cd4dc1f
92 user: test
92 user: test
93 date: Thu Jan 01 00:00:03 1970 +0000
93 date: Thu Jan 01 00:00:03 1970 +0000
94 summary: c
94 summary: c
95
95
96 -f, directory with --patch
96 -f, directory with --patch
97
97
98 $ hg log -f dir -p
98 $ hg log -f dir -p
99 changeset: 2:f8954cd4dc1f
99 changeset: 2:f8954cd4dc1f
100 user: test
100 user: test
101 date: Thu Jan 01 00:00:03 1970 +0000
101 date: Thu Jan 01 00:00:03 1970 +0000
102 summary: c
102 summary: c
103
103
104 diff -r d89b0a12d229 -r f8954cd4dc1f dir/b
104 diff -r d89b0a12d229 -r f8954cd4dc1f dir/b
105 --- /dev/null* (glob)
105 --- /dev/null* (glob)
106 +++ b/dir/b* (glob)
106 +++ b/dir/b* (glob)
107 @@ -0,0 +1,1 @@
107 @@ -0,0 +1,1 @@
108 +a
108 +a
109
109
110
110
111 -f, pattern
111 -f, pattern
112
112
113 $ hg log -f -I 'dir**' -p
113 $ hg log -f -I 'dir**' -p
114 changeset: 2:f8954cd4dc1f
114 changeset: 2:f8954cd4dc1f
115 user: test
115 user: test
116 date: Thu Jan 01 00:00:03 1970 +0000
116 date: Thu Jan 01 00:00:03 1970 +0000
117 summary: c
117 summary: c
118
118
119 diff -r d89b0a12d229 -r f8954cd4dc1f dir/b
119 diff -r d89b0a12d229 -r f8954cd4dc1f dir/b
120 --- /dev/null* (glob)
120 --- /dev/null* (glob)
121 +++ b/dir/b* (glob)
121 +++ b/dir/b* (glob)
122 @@ -0,0 +1,1 @@
122 @@ -0,0 +1,1 @@
123 +a
123 +a
124
124
125 $ hg up -q 4
125 $ hg up -q 4
126
126
127 -f, a wrong style
127 -f, a wrong style
128
128
129 $ hg log -f -l1 --style something
129 $ hg log -f -l1 --style something
130 abort: style 'something' not found
130 abort: style 'something' not found
131 (available styles: bisect, changelog, compact, default, phases, xml)
131 (available styles: bisect, changelog, compact, default, phases, xml)
132 [255]
132 [255]
133
133
134 -f, phases style
134 -f, phases style
135
135
136
136
137 $ hg log -f -l1 --style phases
137 $ hg log -f -l1 --style phases
138 changeset: 4:7e4639b4691b
138 changeset: 4:7e4639b4691b
139 tag: tip
139 tag: tip
140 phase: draft
140 phase: draft
141 user: test
141 user: test
142 date: Thu Jan 01 00:00:05 1970 +0000
142 date: Thu Jan 01 00:00:05 1970 +0000
143 summary: e
143 summary: e
144
144
145
145
146 -f, but no args
146 -f, but no args
147
147
148 $ hg log -f
148 $ hg log -f
149 changeset: 4:7e4639b4691b
149 changeset: 4:7e4639b4691b
150 tag: tip
150 tag: tip
151 user: test
151 user: test
152 date: Thu Jan 01 00:00:05 1970 +0000
152 date: Thu Jan 01 00:00:05 1970 +0000
153 summary: e
153 summary: e
154
154
155 changeset: 3:2ca5ba701980
155 changeset: 3:2ca5ba701980
156 user: test
156 user: test
157 date: Thu Jan 01 00:00:04 1970 +0000
157 date: Thu Jan 01 00:00:04 1970 +0000
158 summary: d
158 summary: d
159
159
160 changeset: 2:f8954cd4dc1f
160 changeset: 2:f8954cd4dc1f
161 user: test
161 user: test
162 date: Thu Jan 01 00:00:03 1970 +0000
162 date: Thu Jan 01 00:00:03 1970 +0000
163 summary: c
163 summary: c
164
164
165 changeset: 1:d89b0a12d229
165 changeset: 1:d89b0a12d229
166 user: test
166 user: test
167 date: Thu Jan 01 00:00:02 1970 +0000
167 date: Thu Jan 01 00:00:02 1970 +0000
168 summary: b
168 summary: b
169
169
170 changeset: 0:9161b9aeaf16
170 changeset: 0:9161b9aeaf16
171 user: test
171 user: test
172 date: Thu Jan 01 00:00:01 1970 +0000
172 date: Thu Jan 01 00:00:01 1970 +0000
173 summary: a
173 summary: a
174
174
175
175
176 one rename
176 one rename
177
177
178 $ hg up -q 2
178 $ hg up -q 2
179 $ hg log -vf a
179 $ hg log -vf a
180 changeset: 0:9161b9aeaf16
180 changeset: 0:9161b9aeaf16
181 user: test
181 user: test
182 date: Thu Jan 01 00:00:01 1970 +0000
182 date: Thu Jan 01 00:00:01 1970 +0000
183 files: a f
183 files: a f
184 description:
184 description:
185 a
185 a
186
186
187
187
188
188
189 many renames
189 many renames
190
190
191 $ hg up -q tip
191 $ hg up -q tip
192 $ hg log -vf e
192 $ hg log -vf e
193 changeset: 4:7e4639b4691b
193 changeset: 4:7e4639b4691b
194 tag: tip
194 tag: tip
195 user: test
195 user: test
196 date: Thu Jan 01 00:00:05 1970 +0000
196 date: Thu Jan 01 00:00:05 1970 +0000
197 files: dir/b e
197 files: dir/b e
198 description:
198 description:
199 e
199 e
200
200
201
201
202 changeset: 2:f8954cd4dc1f
202 changeset: 2:f8954cd4dc1f
203 user: test
203 user: test
204 date: Thu Jan 01 00:00:03 1970 +0000
204 date: Thu Jan 01 00:00:03 1970 +0000
205 files: b dir/b f g
205 files: b dir/b f g
206 description:
206 description:
207 c
207 c
208
208
209
209
210 changeset: 1:d89b0a12d229
210 changeset: 1:d89b0a12d229
211 user: test
211 user: test
212 date: Thu Jan 01 00:00:02 1970 +0000
212 date: Thu Jan 01 00:00:02 1970 +0000
213 files: b g
213 files: b g
214 description:
214 description:
215 b
215 b
216
216
217
217
218 changeset: 0:9161b9aeaf16
218 changeset: 0:9161b9aeaf16
219 user: test
219 user: test
220 date: Thu Jan 01 00:00:01 1970 +0000
220 date: Thu Jan 01 00:00:01 1970 +0000
221 files: a f
221 files: a f
222 description:
222 description:
223 a
223 a
224
224
225
225
226
226
227
227
228 log -pf dir/b
228 log -pf dir/b
229
229
230 $ hg up -q 3
230 $ hg up -q 3
231 $ hg log -pf dir/b
231 $ hg log -pf dir/b
232 changeset: 2:f8954cd4dc1f
232 changeset: 2:f8954cd4dc1f
233 user: test
233 user: test
234 date: Thu Jan 01 00:00:03 1970 +0000
234 date: Thu Jan 01 00:00:03 1970 +0000
235 summary: c
235 summary: c
236
236
237 diff -r d89b0a12d229 -r f8954cd4dc1f dir/b
237 diff -r d89b0a12d229 -r f8954cd4dc1f dir/b
238 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
238 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
239 +++ b/dir/b Thu Jan 01 00:00:03 1970 +0000
239 +++ b/dir/b Thu Jan 01 00:00:03 1970 +0000
240 @@ -0,0 +1,1 @@
240 @@ -0,0 +1,1 @@
241 +a
241 +a
242
242
243 changeset: 1:d89b0a12d229
243 changeset: 1:d89b0a12d229
244 user: test
244 user: test
245 date: Thu Jan 01 00:00:02 1970 +0000
245 date: Thu Jan 01 00:00:02 1970 +0000
246 summary: b
246 summary: b
247
247
248 diff -r 9161b9aeaf16 -r d89b0a12d229 b
248 diff -r 9161b9aeaf16 -r d89b0a12d229 b
249 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
249 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
250 +++ b/b Thu Jan 01 00:00:02 1970 +0000
250 +++ b/b Thu Jan 01 00:00:02 1970 +0000
251 @@ -0,0 +1,1 @@
251 @@ -0,0 +1,1 @@
252 +a
252 +a
253
253
254 changeset: 0:9161b9aeaf16
254 changeset: 0:9161b9aeaf16
255 user: test
255 user: test
256 date: Thu Jan 01 00:00:01 1970 +0000
256 date: Thu Jan 01 00:00:01 1970 +0000
257 summary: a
257 summary: a
258
258
259 diff -r 000000000000 -r 9161b9aeaf16 a
259 diff -r 000000000000 -r 9161b9aeaf16 a
260 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
260 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
261 +++ b/a Thu Jan 01 00:00:01 1970 +0000
261 +++ b/a Thu Jan 01 00:00:01 1970 +0000
262 @@ -0,0 +1,1 @@
262 @@ -0,0 +1,1 @@
263 +a
263 +a
264
264
265
265
266 log -pf b inside dir
266 log -pf b inside dir
267
267
268 $ hg --cwd=dir log -pf b
268 $ hg --cwd=dir log -pf b
269 changeset: 2:f8954cd4dc1f
269 changeset: 2:f8954cd4dc1f
270 user: test
270 user: test
271 date: Thu Jan 01 00:00:03 1970 +0000
271 date: Thu Jan 01 00:00:03 1970 +0000
272 summary: c
272 summary: c
273
273
274 diff -r d89b0a12d229 -r f8954cd4dc1f dir/b
274 diff -r d89b0a12d229 -r f8954cd4dc1f dir/b
275 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
275 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
276 +++ b/dir/b Thu Jan 01 00:00:03 1970 +0000
276 +++ b/dir/b Thu Jan 01 00:00:03 1970 +0000
277 @@ -0,0 +1,1 @@
277 @@ -0,0 +1,1 @@
278 +a
278 +a
279
279
280 changeset: 1:d89b0a12d229
280 changeset: 1:d89b0a12d229
281 user: test
281 user: test
282 date: Thu Jan 01 00:00:02 1970 +0000
282 date: Thu Jan 01 00:00:02 1970 +0000
283 summary: b
283 summary: b
284
284
285 diff -r 9161b9aeaf16 -r d89b0a12d229 b
285 diff -r 9161b9aeaf16 -r d89b0a12d229 b
286 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
286 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
287 +++ b/b Thu Jan 01 00:00:02 1970 +0000
287 +++ b/b Thu Jan 01 00:00:02 1970 +0000
288 @@ -0,0 +1,1 @@
288 @@ -0,0 +1,1 @@
289 +a
289 +a
290
290
291 changeset: 0:9161b9aeaf16
291 changeset: 0:9161b9aeaf16
292 user: test
292 user: test
293 date: Thu Jan 01 00:00:01 1970 +0000
293 date: Thu Jan 01 00:00:01 1970 +0000
294 summary: a
294 summary: a
295
295
296 diff -r 000000000000 -r 9161b9aeaf16 a
296 diff -r 000000000000 -r 9161b9aeaf16 a
297 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
297 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
298 +++ b/a Thu Jan 01 00:00:01 1970 +0000
298 +++ b/a Thu Jan 01 00:00:01 1970 +0000
299 @@ -0,0 +1,1 @@
299 @@ -0,0 +1,1 @@
300 +a
300 +a
301
301
302
302
303 log -pf, but no args
303 log -pf, but no args
304
304
305 $ hg log -pf
305 $ hg log -pf
306 changeset: 3:2ca5ba701980
306 changeset: 3:2ca5ba701980
307 user: test
307 user: test
308 date: Thu Jan 01 00:00:04 1970 +0000
308 date: Thu Jan 01 00:00:04 1970 +0000
309 summary: d
309 summary: d
310
310
311 diff -r f8954cd4dc1f -r 2ca5ba701980 a
311 diff -r f8954cd4dc1f -r 2ca5ba701980 a
312 --- a/a Thu Jan 01 00:00:03 1970 +0000
312 --- a/a Thu Jan 01 00:00:03 1970 +0000
313 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
313 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
314 @@ -1,1 +0,0 @@
314 @@ -1,1 +0,0 @@
315 -a
315 -a
316 diff -r f8954cd4dc1f -r 2ca5ba701980 b
316 diff -r f8954cd4dc1f -r 2ca5ba701980 b
317 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
317 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
318 +++ b/b Thu Jan 01 00:00:04 1970 +0000
318 +++ b/b Thu Jan 01 00:00:04 1970 +0000
319 @@ -0,0 +1,1 @@
319 @@ -0,0 +1,1 @@
320 +a
320 +a
321 diff -r f8954cd4dc1f -r 2ca5ba701980 d
321 diff -r f8954cd4dc1f -r 2ca5ba701980 d
322 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
322 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
323 +++ b/d Thu Jan 01 00:00:04 1970 +0000
323 +++ b/d Thu Jan 01 00:00:04 1970 +0000
324 @@ -0,0 +1,1 @@
324 @@ -0,0 +1,1 @@
325 +a
325 +a
326 diff -r f8954cd4dc1f -r 2ca5ba701980 g
326 diff -r f8954cd4dc1f -r 2ca5ba701980 g
327 --- a/g Thu Jan 01 00:00:03 1970 +0000
327 --- a/g Thu Jan 01 00:00:03 1970 +0000
328 +++ b/g Thu Jan 01 00:00:04 1970 +0000
328 +++ b/g Thu Jan 01 00:00:04 1970 +0000
329 @@ -1,2 +1,2 @@
329 @@ -1,2 +1,2 @@
330 f
330 f
331 -g
331 -g
332 +f
332 +f
333
333
334 changeset: 2:f8954cd4dc1f
334 changeset: 2:f8954cd4dc1f
335 user: test
335 user: test
336 date: Thu Jan 01 00:00:03 1970 +0000
336 date: Thu Jan 01 00:00:03 1970 +0000
337 summary: c
337 summary: c
338
338
339 diff -r d89b0a12d229 -r f8954cd4dc1f b
339 diff -r d89b0a12d229 -r f8954cd4dc1f b
340 --- a/b Thu Jan 01 00:00:02 1970 +0000
340 --- a/b Thu Jan 01 00:00:02 1970 +0000
341 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
341 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
342 @@ -1,1 +0,0 @@
342 @@ -1,1 +0,0 @@
343 -a
343 -a
344 diff -r d89b0a12d229 -r f8954cd4dc1f dir/b
344 diff -r d89b0a12d229 -r f8954cd4dc1f dir/b
345 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
345 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
346 +++ b/dir/b Thu Jan 01 00:00:03 1970 +0000
346 +++ b/dir/b Thu Jan 01 00:00:03 1970 +0000
347 @@ -0,0 +1,1 @@
347 @@ -0,0 +1,1 @@
348 +a
348 +a
349 diff -r d89b0a12d229 -r f8954cd4dc1f f
349 diff -r d89b0a12d229 -r f8954cd4dc1f f
350 --- a/f Thu Jan 01 00:00:02 1970 +0000
350 --- a/f Thu Jan 01 00:00:02 1970 +0000
351 +++ b/f Thu Jan 01 00:00:03 1970 +0000
351 +++ b/f Thu Jan 01 00:00:03 1970 +0000
352 @@ -1,1 +1,2 @@
352 @@ -1,1 +1,2 @@
353 f
353 f
354 +f
354 +f
355 diff -r d89b0a12d229 -r f8954cd4dc1f g
355 diff -r d89b0a12d229 -r f8954cd4dc1f g
356 --- a/g Thu Jan 01 00:00:02 1970 +0000
356 --- a/g Thu Jan 01 00:00:02 1970 +0000
357 +++ b/g Thu Jan 01 00:00:03 1970 +0000
357 +++ b/g Thu Jan 01 00:00:03 1970 +0000
358 @@ -1,1 +1,2 @@
358 @@ -1,1 +1,2 @@
359 f
359 f
360 +g
360 +g
361
361
362 changeset: 1:d89b0a12d229
362 changeset: 1:d89b0a12d229
363 user: test
363 user: test
364 date: Thu Jan 01 00:00:02 1970 +0000
364 date: Thu Jan 01 00:00:02 1970 +0000
365 summary: b
365 summary: b
366
366
367 diff -r 9161b9aeaf16 -r d89b0a12d229 b
367 diff -r 9161b9aeaf16 -r d89b0a12d229 b
368 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
368 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
369 +++ b/b Thu Jan 01 00:00:02 1970 +0000
369 +++ b/b Thu Jan 01 00:00:02 1970 +0000
370 @@ -0,0 +1,1 @@
370 @@ -0,0 +1,1 @@
371 +a
371 +a
372 diff -r 9161b9aeaf16 -r d89b0a12d229 g
372 diff -r 9161b9aeaf16 -r d89b0a12d229 g
373 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
373 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
374 +++ b/g Thu Jan 01 00:00:02 1970 +0000
374 +++ b/g Thu Jan 01 00:00:02 1970 +0000
375 @@ -0,0 +1,1 @@
375 @@ -0,0 +1,1 @@
376 +f
376 +f
377
377
378 changeset: 0:9161b9aeaf16
378 changeset: 0:9161b9aeaf16
379 user: test
379 user: test
380 date: Thu Jan 01 00:00:01 1970 +0000
380 date: Thu Jan 01 00:00:01 1970 +0000
381 summary: a
381 summary: a
382
382
383 diff -r 000000000000 -r 9161b9aeaf16 a
383 diff -r 000000000000 -r 9161b9aeaf16 a
384 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
384 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
385 +++ b/a Thu Jan 01 00:00:01 1970 +0000
385 +++ b/a Thu Jan 01 00:00:01 1970 +0000
386 @@ -0,0 +1,1 @@
386 @@ -0,0 +1,1 @@
387 +a
387 +a
388 diff -r 000000000000 -r 9161b9aeaf16 f
388 diff -r 000000000000 -r 9161b9aeaf16 f
389 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
389 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
390 +++ b/f Thu Jan 01 00:00:01 1970 +0000
390 +++ b/f Thu Jan 01 00:00:01 1970 +0000
391 @@ -0,0 +1,1 @@
391 @@ -0,0 +1,1 @@
392 +f
392 +f
393
393
394
394
395 log -vf dir/b
395 log -vf dir/b
396
396
397 $ hg log -vf dir/b
397 $ hg log -vf dir/b
398 changeset: 2:f8954cd4dc1f
398 changeset: 2:f8954cd4dc1f
399 user: test
399 user: test
400 date: Thu Jan 01 00:00:03 1970 +0000
400 date: Thu Jan 01 00:00:03 1970 +0000
401 files: b dir/b f g
401 files: b dir/b f g
402 description:
402 description:
403 c
403 c
404
404
405
405
406 changeset: 1:d89b0a12d229
406 changeset: 1:d89b0a12d229
407 user: test
407 user: test
408 date: Thu Jan 01 00:00:02 1970 +0000
408 date: Thu Jan 01 00:00:02 1970 +0000
409 files: b g
409 files: b g
410 description:
410 description:
411 b
411 b
412
412
413
413
414 changeset: 0:9161b9aeaf16
414 changeset: 0:9161b9aeaf16
415 user: test
415 user: test
416 date: Thu Jan 01 00:00:01 1970 +0000
416 date: Thu Jan 01 00:00:01 1970 +0000
417 files: a f
417 files: a f
418 description:
418 description:
419 a
419 a
420
420
421
421
422
422
423
423
424 -f and multiple filelog heads
424 -f and multiple filelog heads
425
425
426 $ hg up -q 2
426 $ hg up -q 2
427 $ hg log -f g --template '{rev}\n'
427 $ hg log -f g --template '{rev}\n'
428 2
428 2
429 1
429 1
430 0
430 0
431 $ hg up -q tip
431 $ hg up -q tip
432 $ hg log -f g --template '{rev}\n'
432 $ hg log -f g --template '{rev}\n'
433 3
433 3
434 2
434 2
435 0
435 0
436
436
437
437
438 log copies with --copies
438 log copies with --copies
439
439
440 $ hg log -vC --template '{rev} {file_copies}\n'
440 $ hg log -vC --template '{rev} {file_copies}\n'
441 4 e (dir/b)
441 4 e (dir/b)
442 3 b (a)g (f)
442 3 b (a)g (f)
443 2 dir/b (b)
443 2 dir/b (b)
444 1 b (a)g (f)
444 1 b (a)g (f)
445 0
445 0
446
446
447 log copies switch without --copies, with old filecopy template
447 log copies switch without --copies, with old filecopy template
448
448
449 $ hg log -v --template '{rev} {file_copies_switch%filecopy}\n'
449 $ hg log -v --template '{rev} {file_copies_switch%filecopy}\n'
450 4
450 4
451 3
451 3
452 2
452 2
453 1
453 1
454 0
454 0
455
455
456 log copies switch with --copies
456 log copies switch with --copies
457
457
458 $ hg log -vC --template '{rev} {file_copies_switch}\n'
458 $ hg log -vC --template '{rev} {file_copies_switch}\n'
459 4 e (dir/b)
459 4 e (dir/b)
460 3 b (a)g (f)
460 3 b (a)g (f)
461 2 dir/b (b)
461 2 dir/b (b)
462 1 b (a)g (f)
462 1 b (a)g (f)
463 0
463 0
464
464
465
465
466 log copies with hardcoded style and with --style=default
466 log copies with hardcoded style and with --style=default
467
467
468 $ hg log -vC -r4
468 $ hg log -vC -r4
469 changeset: 4:7e4639b4691b
469 changeset: 4:7e4639b4691b
470 tag: tip
470 tag: tip
471 user: test
471 user: test
472 date: Thu Jan 01 00:00:05 1970 +0000
472 date: Thu Jan 01 00:00:05 1970 +0000
473 files: dir/b e
473 files: dir/b e
474 copies: e (dir/b)
474 copies: e (dir/b)
475 description:
475 description:
476 e
476 e
477
477
478
478
479 $ hg log -vC -r4 --style=default
479 $ hg log -vC -r4 --style=default
480 changeset: 4:7e4639b4691b
480 changeset: 4:7e4639b4691b
481 tag: tip
481 tag: tip
482 user: test
482 user: test
483 date: Thu Jan 01 00:00:05 1970 +0000
483 date: Thu Jan 01 00:00:05 1970 +0000
484 files: dir/b e
484 files: dir/b e
485 copies: e (dir/b)
485 copies: e (dir/b)
486 description:
486 description:
487 e
487 e
488
488
489
489
490
490
491
491
492 log copies, non-linear manifest
492 log copies, non-linear manifest
493
493
494 $ hg up -C 3
494 $ hg up -C 3
495 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
495 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
496 $ hg mv dir/b e
496 $ hg mv dir/b e
497 $ echo foo > foo
497 $ echo foo > foo
498 $ hg ci -Ame2 -d '6 0'
498 $ hg ci -Ame2 -d '6 0'
499 adding foo
499 adding foo
500 created new head
500 created new head
501 $ hg log -v --template '{rev} {file_copies}\n' -r 5
501 $ hg log -v --template '{rev} {file_copies}\n' -r 5
502 5 e (dir/b)
502 5 e (dir/b)
503
503
504
504
505 log copies, execute bit set
505 log copies, execute bit set
506
506
507 #if execbit
507 #if execbit
508 $ chmod +x e
508 $ chmod +x e
509 $ hg ci -me3 -d '7 0'
509 $ hg ci -me3 -d '7 0'
510 $ hg log -v --template '{rev} {file_copies}\n' -r 6
510 $ hg log -v --template '{rev} {file_copies}\n' -r 6
511 6
511 6
512 #endif
512 #endif
513
513
514
514
515 log -p d
515 log -p d
516
516
517 $ hg log -pv d
517 $ hg log -pv d
518 changeset: 3:2ca5ba701980
518 changeset: 3:2ca5ba701980
519 user: test
519 user: test
520 date: Thu Jan 01 00:00:04 1970 +0000
520 date: Thu Jan 01 00:00:04 1970 +0000
521 files: a b d g
521 files: a b d g
522 description:
522 description:
523 d
523 d
524
524
525
525
526 diff -r f8954cd4dc1f -r 2ca5ba701980 d
526 diff -r f8954cd4dc1f -r 2ca5ba701980 d
527 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
527 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
528 +++ b/d Thu Jan 01 00:00:04 1970 +0000
528 +++ b/d Thu Jan 01 00:00:04 1970 +0000
529 @@ -0,0 +1,1 @@
529 @@ -0,0 +1,1 @@
530 +a
530 +a
531
531
532
532
533
533
534 log --removed file
534 log --removed file
535
535
536 $ hg log --removed -v a
536 $ hg log --removed -v a
537 changeset: 3:2ca5ba701980
537 changeset: 3:2ca5ba701980
538 user: test
538 user: test
539 date: Thu Jan 01 00:00:04 1970 +0000
539 date: Thu Jan 01 00:00:04 1970 +0000
540 files: a b d g
540 files: a b d g
541 description:
541 description:
542 d
542 d
543
543
544
544
545 changeset: 0:9161b9aeaf16
545 changeset: 0:9161b9aeaf16
546 user: test
546 user: test
547 date: Thu Jan 01 00:00:01 1970 +0000
547 date: Thu Jan 01 00:00:01 1970 +0000
548 files: a f
548 files: a f
549 description:
549 description:
550 a
550 a
551
551
552
552
553
553
554 log --removed revrange file
554 log --removed revrange file
555
555
556 $ hg log --removed -v -r0:2 a
556 $ hg log --removed -v -r0:2 a
557 changeset: 0:9161b9aeaf16
557 changeset: 0:9161b9aeaf16
558 user: test
558 user: test
559 date: Thu Jan 01 00:00:01 1970 +0000
559 date: Thu Jan 01 00:00:01 1970 +0000
560 files: a f
560 files: a f
561 description:
561 description:
562 a
562 a
563
563
564
564
565 $ cd ..
565 $ cd ..
566
566
567 log --follow tests
567 log --follow tests
568
568
569 $ hg init follow
569 $ hg init follow
570 $ cd follow
570 $ cd follow
571
571
572 $ echo base > base
572 $ echo base > base
573 $ hg ci -Ambase -d '1 0'
573 $ hg ci -Ambase -d '1 0'
574 adding base
574 adding base
575
575
576 $ echo r1 >> base
576 $ echo r1 >> base
577 $ hg ci -Amr1 -d '1 0'
577 $ hg ci -Amr1 -d '1 0'
578 $ echo r2 >> base
578 $ echo r2 >> base
579 $ hg ci -Amr2 -d '1 0'
579 $ hg ci -Amr2 -d '1 0'
580
580
581 $ hg up -C 1
581 $ hg up -C 1
582 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
582 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
583 $ echo b1 > b1
583 $ echo b1 > b1
584 $ hg ci -Amb1 -d '1 0'
584 $ hg ci -Amb1 -d '1 0'
585 adding b1
585 adding b1
586 created new head
586 created new head
587
587
588
588
589 log -f
589 log -f
590
590
591 $ hg log -f
591 $ hg log -f
592 changeset: 3:e62f78d544b4
592 changeset: 3:e62f78d544b4
593 tag: tip
593 tag: tip
594 parent: 1:3d5bf5654eda
594 parent: 1:3d5bf5654eda
595 user: test
595 user: test
596 date: Thu Jan 01 00:00:01 1970 +0000
596 date: Thu Jan 01 00:00:01 1970 +0000
597 summary: b1
597 summary: b1
598
598
599 changeset: 1:3d5bf5654eda
599 changeset: 1:3d5bf5654eda
600 user: test
600 user: test
601 date: Thu Jan 01 00:00:01 1970 +0000
601 date: Thu Jan 01 00:00:01 1970 +0000
602 summary: r1
602 summary: r1
603
603
604 changeset: 0:67e992f2c4f3
604 changeset: 0:67e992f2c4f3
605 user: test
605 user: test
606 date: Thu Jan 01 00:00:01 1970 +0000
606 date: Thu Jan 01 00:00:01 1970 +0000
607 summary: base
607 summary: base
608
608
609
609
610
610
611 log -f -r 1:tip
611 log -f -r 1:tip
612
612
613 $ hg up -C 0
613 $ hg up -C 0
614 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
614 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
615 $ echo b2 > b2
615 $ echo b2 > b2
616 $ hg ci -Amb2 -d '1 0'
616 $ hg ci -Amb2 -d '1 0'
617 adding b2
617 adding b2
618 created new head
618 created new head
619 $ hg log -f -r 1:tip
619 $ hg log -f -r 1:tip
620 changeset: 1:3d5bf5654eda
620 changeset: 1:3d5bf5654eda
621 user: test
621 user: test
622 date: Thu Jan 01 00:00:01 1970 +0000
622 date: Thu Jan 01 00:00:01 1970 +0000
623 summary: r1
623 summary: r1
624
624
625 changeset: 2:60c670bf5b30
625 changeset: 2:60c670bf5b30
626 user: test
626 user: test
627 date: Thu Jan 01 00:00:01 1970 +0000
627 date: Thu Jan 01 00:00:01 1970 +0000
628 summary: r2
628 summary: r2
629
629
630 changeset: 3:e62f78d544b4
630 changeset: 3:e62f78d544b4
631 parent: 1:3d5bf5654eda
631 parent: 1:3d5bf5654eda
632 user: test
632 user: test
633 date: Thu Jan 01 00:00:01 1970 +0000
633 date: Thu Jan 01 00:00:01 1970 +0000
634 summary: b1
634 summary: b1
635
635
636
636
637
637
638 log -r . with two parents
638 log -r . with two parents
639
639
640 $ hg up -C 3
640 $ hg up -C 3
641 2 files updated, 0 files merged, 1 files removed, 0 files unresolved
641 2 files updated, 0 files merged, 1 files removed, 0 files unresolved
642 $ hg merge tip
642 $ hg merge tip
643 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
643 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
644 (branch merge, don't forget to commit)
644 (branch merge, don't forget to commit)
645 $ hg log -r .
645 $ hg log -r .
646 changeset: 3:e62f78d544b4
646 changeset: 3:e62f78d544b4
647 parent: 1:3d5bf5654eda
647 parent: 1:3d5bf5654eda
648 user: test
648 user: test
649 date: Thu Jan 01 00:00:01 1970 +0000
649 date: Thu Jan 01 00:00:01 1970 +0000
650 summary: b1
650 summary: b1
651
651
652
652
653
653
654 log -r . with one parent
654 log -r . with one parent
655
655
656 $ hg ci -mm12 -d '1 0'
656 $ hg ci -mm12 -d '1 0'
657 $ hg log -r .
657 $ hg log -r .
658 changeset: 5:302e9dd6890d
658 changeset: 5:302e9dd6890d
659 tag: tip
659 tag: tip
660 parent: 3:e62f78d544b4
660 parent: 3:e62f78d544b4
661 parent: 4:ddb82e70d1a1
661 parent: 4:ddb82e70d1a1
662 user: test
662 user: test
663 date: Thu Jan 01 00:00:01 1970 +0000
663 date: Thu Jan 01 00:00:01 1970 +0000
664 summary: m12
664 summary: m12
665
665
666
666
667 $ echo postm >> b1
667 $ echo postm >> b1
668 $ hg ci -Amb1.1 -d'1 0'
668 $ hg ci -Amb1.1 -d'1 0'
669
669
670
670
671 log --follow-first
671 log --follow-first
672
672
673 $ hg log --follow-first
673 $ hg log --follow-first
674 changeset: 6:2404bbcab562
674 changeset: 6:2404bbcab562
675 tag: tip
675 tag: tip
676 user: test
676 user: test
677 date: Thu Jan 01 00:00:01 1970 +0000
677 date: Thu Jan 01 00:00:01 1970 +0000
678 summary: b1.1
678 summary: b1.1
679
679
680 changeset: 5:302e9dd6890d
680 changeset: 5:302e9dd6890d
681 parent: 3:e62f78d544b4
681 parent: 3:e62f78d544b4
682 parent: 4:ddb82e70d1a1
682 parent: 4:ddb82e70d1a1
683 user: test
683 user: test
684 date: Thu Jan 01 00:00:01 1970 +0000
684 date: Thu Jan 01 00:00:01 1970 +0000
685 summary: m12
685 summary: m12
686
686
687 changeset: 3:e62f78d544b4
687 changeset: 3:e62f78d544b4
688 parent: 1:3d5bf5654eda
688 parent: 1:3d5bf5654eda
689 user: test
689 user: test
690 date: Thu Jan 01 00:00:01 1970 +0000
690 date: Thu Jan 01 00:00:01 1970 +0000
691 summary: b1
691 summary: b1
692
692
693 changeset: 1:3d5bf5654eda
693 changeset: 1:3d5bf5654eda
694 user: test
694 user: test
695 date: Thu Jan 01 00:00:01 1970 +0000
695 date: Thu Jan 01 00:00:01 1970 +0000
696 summary: r1
696 summary: r1
697
697
698 changeset: 0:67e992f2c4f3
698 changeset: 0:67e992f2c4f3
699 user: test
699 user: test
700 date: Thu Jan 01 00:00:01 1970 +0000
700 date: Thu Jan 01 00:00:01 1970 +0000
701 summary: base
701 summary: base
702
702
703
703
704
704
705 log -P 2
705 log -P 2
706
706
707 $ hg log -P 2
707 $ hg log -P 2
708 changeset: 6:2404bbcab562
708 changeset: 6:2404bbcab562
709 tag: tip
709 tag: tip
710 user: test
710 user: test
711 date: Thu Jan 01 00:00:01 1970 +0000
711 date: Thu Jan 01 00:00:01 1970 +0000
712 summary: b1.1
712 summary: b1.1
713
713
714 changeset: 5:302e9dd6890d
714 changeset: 5:302e9dd6890d
715 parent: 3:e62f78d544b4
715 parent: 3:e62f78d544b4
716 parent: 4:ddb82e70d1a1
716 parent: 4:ddb82e70d1a1
717 user: test
717 user: test
718 date: Thu Jan 01 00:00:01 1970 +0000
718 date: Thu Jan 01 00:00:01 1970 +0000
719 summary: m12
719 summary: m12
720
720
721 changeset: 4:ddb82e70d1a1
721 changeset: 4:ddb82e70d1a1
722 parent: 0:67e992f2c4f3
722 parent: 0:67e992f2c4f3
723 user: test
723 user: test
724 date: Thu Jan 01 00:00:01 1970 +0000
724 date: Thu Jan 01 00:00:01 1970 +0000
725 summary: b2
725 summary: b2
726
726
727 changeset: 3:e62f78d544b4
727 changeset: 3:e62f78d544b4
728 parent: 1:3d5bf5654eda
728 parent: 1:3d5bf5654eda
729 user: test
729 user: test
730 date: Thu Jan 01 00:00:01 1970 +0000
730 date: Thu Jan 01 00:00:01 1970 +0000
731 summary: b1
731 summary: b1
732
732
733
733
734
734
735 log -r tip -p --git
735 log -r tip -p --git
736
736
737 $ hg log -r tip -p --git
737 $ hg log -r tip -p --git
738 changeset: 6:2404bbcab562
738 changeset: 6:2404bbcab562
739 tag: tip
739 tag: tip
740 user: test
740 user: test
741 date: Thu Jan 01 00:00:01 1970 +0000
741 date: Thu Jan 01 00:00:01 1970 +0000
742 summary: b1.1
742 summary: b1.1
743
743
744 diff --git a/b1 b/b1
744 diff --git a/b1 b/b1
745 --- a/b1
745 --- a/b1
746 +++ b/b1
746 +++ b/b1
747 @@ -1,1 +1,2 @@
747 @@ -1,1 +1,2 @@
748 b1
748 b1
749 +postm
749 +postm
750
750
751
751
752
752
753 log -r ""
753 log -r ""
754
754
755 $ hg log -r ''
755 $ hg log -r ''
756 hg: parse error: empty query
756 hg: parse error: empty query
757 [255]
757 [255]
758
758
759 log -r <some unknown node id>
759 log -r <some unknown node id>
760
760
761 $ hg log -r 1000000000000000000000000000000000000000
761 $ hg log -r 1000000000000000000000000000000000000000
762 abort: unknown revision '1000000000000000000000000000000000000000'!
762 abort: unknown revision '1000000000000000000000000000000000000000'!
763 [255]
763 [255]
764
764
765 log -k r1
765 log -k r1
766
766
767 $ hg log -k r1
767 $ hg log -k r1
768 changeset: 1:3d5bf5654eda
768 changeset: 1:3d5bf5654eda
769 user: test
769 user: test
770 date: Thu Jan 01 00:00:01 1970 +0000
770 date: Thu Jan 01 00:00:01 1970 +0000
771 summary: r1
771 summary: r1
772
772
773 log -p -l2 --color=always
773 log -p -l2 --color=always
774
774
775 $ hg --config extensions.color= --config color.mode=ansi \
775 $ hg --config extensions.color= --config color.mode=ansi \
776 > log -p -l2 --color=always
776 > log -p -l2 --color=always
777 \x1b[0;33mchangeset: 6:2404bbcab562\x1b[0m (esc)
777 \x1b[0;33mchangeset: 6:2404bbcab562\x1b[0m (esc)
778 tag: tip
778 tag: tip
779 user: test
779 user: test
780 date: Thu Jan 01 00:00:01 1970 +0000
780 date: Thu Jan 01 00:00:01 1970 +0000
781 summary: b1.1
781 summary: b1.1
782
782
783 \x1b[0;1mdiff -r 302e9dd6890d -r 2404bbcab562 b1\x1b[0m (esc)
783 \x1b[0;1mdiff -r 302e9dd6890d -r 2404bbcab562 b1\x1b[0m (esc)
784 \x1b[0;31;1m--- a/b1 Thu Jan 01 00:00:01 1970 +0000\x1b[0m (esc)
784 \x1b[0;31;1m--- a/b1 Thu Jan 01 00:00:01 1970 +0000\x1b[0m (esc)
785 \x1b[0;32;1m+++ b/b1 Thu Jan 01 00:00:01 1970 +0000\x1b[0m (esc)
785 \x1b[0;32;1m+++ b/b1 Thu Jan 01 00:00:01 1970 +0000\x1b[0m (esc)
786 \x1b[0;35m@@ -1,1 +1,2 @@\x1b[0m (esc)
786 \x1b[0;35m@@ -1,1 +1,2 @@\x1b[0m (esc)
787 b1
787 b1
788 \x1b[0;32m+postm\x1b[0m (esc)
788 \x1b[0;32m+postm\x1b[0m (esc)
789
789
790 \x1b[0;33mchangeset: 5:302e9dd6890d\x1b[0m (esc)
790 \x1b[0;33mchangeset: 5:302e9dd6890d\x1b[0m (esc)
791 parent: 3:e62f78d544b4
791 parent: 3:e62f78d544b4
792 parent: 4:ddb82e70d1a1
792 parent: 4:ddb82e70d1a1
793 user: test
793 user: test
794 date: Thu Jan 01 00:00:01 1970 +0000
794 date: Thu Jan 01 00:00:01 1970 +0000
795 summary: m12
795 summary: m12
796
796
797 \x1b[0;1mdiff -r e62f78d544b4 -r 302e9dd6890d b2\x1b[0m (esc)
797 \x1b[0;1mdiff -r e62f78d544b4 -r 302e9dd6890d b2\x1b[0m (esc)
798 \x1b[0;31;1m--- /dev/null Thu Jan 01 00:00:00 1970 +0000\x1b[0m (esc)
798 \x1b[0;31;1m--- /dev/null Thu Jan 01 00:00:00 1970 +0000\x1b[0m (esc)
799 \x1b[0;32;1m+++ b/b2 Thu Jan 01 00:00:01 1970 +0000\x1b[0m (esc)
799 \x1b[0;32;1m+++ b/b2 Thu Jan 01 00:00:01 1970 +0000\x1b[0m (esc)
800 \x1b[0;35m@@ -0,0 +1,1 @@\x1b[0m (esc)
800 \x1b[0;35m@@ -0,0 +1,1 @@\x1b[0m (esc)
801 \x1b[0;32m+b2\x1b[0m (esc)
801 \x1b[0;32m+b2\x1b[0m (esc)
802
802
803
803
804
804
805 log -r tip --stat
805 log -r tip --stat
806
806
807 $ hg log -r tip --stat
807 $ hg log -r tip --stat
808 changeset: 6:2404bbcab562
808 changeset: 6:2404bbcab562
809 tag: tip
809 tag: tip
810 user: test
810 user: test
811 date: Thu Jan 01 00:00:01 1970 +0000
811 date: Thu Jan 01 00:00:01 1970 +0000
812 summary: b1.1
812 summary: b1.1
813
813
814 b1 | 1 +
814 b1 | 1 +
815 1 files changed, 1 insertions(+), 0 deletions(-)
815 1 files changed, 1 insertions(+), 0 deletions(-)
816
816
817
817
818 $ cd ..
818 $ cd ..
819
819
820
820
821 User
821 User
822
822
823 $ hg init usertest
823 $ hg init usertest
824 $ cd usertest
824 $ cd usertest
825
825
826 $ echo a > a
826 $ echo a > a
827 $ hg ci -A -m "a" -u "User One <user1@example.org>"
827 $ hg ci -A -m "a" -u "User One <user1@example.org>"
828 adding a
828 adding a
829 $ echo b > b
829 $ echo b > b
830 $ hg ci -A -m "b" -u "User Two <user2@example.org>"
830 $ hg ci -A -m "b" -u "User Two <user2@example.org>"
831 adding b
831 adding b
832
832
833 $ hg log -u "User One <user1@example.org>"
833 $ hg log -u "User One <user1@example.org>"
834 changeset: 0:29a4c94f1924
834 changeset: 0:29a4c94f1924
835 user: User One <user1@example.org>
835 user: User One <user1@example.org>
836 date: Thu Jan 01 00:00:00 1970 +0000
836 date: Thu Jan 01 00:00:00 1970 +0000
837 summary: a
837 summary: a
838
838
839 $ hg log -u "user1" -u "user2"
839 $ hg log -u "user1" -u "user2"
840 changeset: 1:e834b5e69c0e
840 changeset: 1:e834b5e69c0e
841 tag: tip
841 tag: tip
842 user: User Two <user2@example.org>
842 user: User Two <user2@example.org>
843 date: Thu Jan 01 00:00:00 1970 +0000
843 date: Thu Jan 01 00:00:00 1970 +0000
844 summary: b
844 summary: b
845
845
846 changeset: 0:29a4c94f1924
846 changeset: 0:29a4c94f1924
847 user: User One <user1@example.org>
847 user: User One <user1@example.org>
848 date: Thu Jan 01 00:00:00 1970 +0000
848 date: Thu Jan 01 00:00:00 1970 +0000
849 summary: a
849 summary: a
850
850
851 $ hg log -u "user3"
851 $ hg log -u "user3"
852
852
853 $ cd ..
853 $ cd ..
854
854
855 $ hg init branches
855 $ hg init branches
856 $ cd branches
856 $ cd branches
857
857
858 $ echo a > a
858 $ echo a > a
859 $ hg ci -A -m "commit on default"
859 $ hg ci -A -m "commit on default"
860 adding a
860 adding a
861 $ hg branch test
861 $ hg branch test
862 marked working directory as branch test
862 marked working directory as branch test
863 (branches are permanent and global, did you want a bookmark?)
863 (branches are permanent and global, did you want a bookmark?)
864 $ echo b > b
864 $ echo b > b
865 $ hg ci -A -m "commit on test"
865 $ hg ci -A -m "commit on test"
866 adding b
866 adding b
867
867
868 $ hg up default
868 $ hg up default
869 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
869 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
870 $ echo c > c
870 $ echo c > c
871 $ hg ci -A -m "commit on default"
871 $ hg ci -A -m "commit on default"
872 adding c
872 adding c
873 $ hg up test
873 $ hg up test
874 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
874 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
875 $ echo c > c
875 $ echo c > c
876 $ hg ci -A -m "commit on test"
876 $ hg ci -A -m "commit on test"
877 adding c
877 adding c
878
878
879
879
880 log -b default
880 log -b default
881
881
882 $ hg log -b default
882 $ hg log -b default
883 changeset: 2:c3a4f03cc9a7
883 changeset: 2:c3a4f03cc9a7
884 parent: 0:24427303d56f
884 parent: 0:24427303d56f
885 user: test
885 user: test
886 date: Thu Jan 01 00:00:00 1970 +0000
886 date: Thu Jan 01 00:00:00 1970 +0000
887 summary: commit on default
887 summary: commit on default
888
888
889 changeset: 0:24427303d56f
889 changeset: 0:24427303d56f
890 user: test
890 user: test
891 date: Thu Jan 01 00:00:00 1970 +0000
891 date: Thu Jan 01 00:00:00 1970 +0000
892 summary: commit on default
892 summary: commit on default
893
893
894
894
895
895
896 log -b test
896 log -b test
897
897
898 $ hg log -b test
898 $ hg log -b test
899 changeset: 3:f5d8de11c2e2
899 changeset: 3:f5d8de11c2e2
900 branch: test
900 branch: test
901 tag: tip
901 tag: tip
902 parent: 1:d32277701ccb
902 parent: 1:d32277701ccb
903 user: test
903 user: test
904 date: Thu Jan 01 00:00:00 1970 +0000
904 date: Thu Jan 01 00:00:00 1970 +0000
905 summary: commit on test
905 summary: commit on test
906
906
907 changeset: 1:d32277701ccb
907 changeset: 1:d32277701ccb
908 branch: test
908 branch: test
909 user: test
909 user: test
910 date: Thu Jan 01 00:00:00 1970 +0000
910 date: Thu Jan 01 00:00:00 1970 +0000
911 summary: commit on test
911 summary: commit on test
912
912
913
913
914
914
915 log -b dummy
915 log -b dummy
916
916
917 $ hg log -b dummy
917 $ hg log -b dummy
918 abort: unknown revision 'dummy'!
918 abort: unknown revision 'dummy'!
919 [255]
919 [255]
920
920
921
921
922 log -b .
922 log -b .
923
923
924 $ hg log -b .
924 $ hg log -b .
925 changeset: 3:f5d8de11c2e2
925 changeset: 3:f5d8de11c2e2
926 branch: test
926 branch: test
927 tag: tip
927 tag: tip
928 parent: 1:d32277701ccb
928 parent: 1:d32277701ccb
929 user: test
929 user: test
930 date: Thu Jan 01 00:00:00 1970 +0000
930 date: Thu Jan 01 00:00:00 1970 +0000
931 summary: commit on test
931 summary: commit on test
932
932
933 changeset: 1:d32277701ccb
933 changeset: 1:d32277701ccb
934 branch: test
934 branch: test
935 user: test
935 user: test
936 date: Thu Jan 01 00:00:00 1970 +0000
936 date: Thu Jan 01 00:00:00 1970 +0000
937 summary: commit on test
937 summary: commit on test
938
938
939
939
940
940
941 log -b default -b test
941 log -b default -b test
942
942
943 $ hg log -b default -b test
943 $ hg log -b default -b test
944 changeset: 3:f5d8de11c2e2
944 changeset: 3:f5d8de11c2e2
945 branch: test
945 branch: test
946 tag: tip
946 tag: tip
947 parent: 1:d32277701ccb
947 parent: 1:d32277701ccb
948 user: test
948 user: test
949 date: Thu Jan 01 00:00:00 1970 +0000
949 date: Thu Jan 01 00:00:00 1970 +0000
950 summary: commit on test
950 summary: commit on test
951
951
952 changeset: 2:c3a4f03cc9a7
952 changeset: 2:c3a4f03cc9a7
953 parent: 0:24427303d56f
953 parent: 0:24427303d56f
954 user: test
954 user: test
955 date: Thu Jan 01 00:00:00 1970 +0000
955 date: Thu Jan 01 00:00:00 1970 +0000
956 summary: commit on default
956 summary: commit on default
957
957
958 changeset: 1:d32277701ccb
958 changeset: 1:d32277701ccb
959 branch: test
959 branch: test
960 user: test
960 user: test
961 date: Thu Jan 01 00:00:00 1970 +0000
961 date: Thu Jan 01 00:00:00 1970 +0000
962 summary: commit on test
962 summary: commit on test
963
963
964 changeset: 0:24427303d56f
964 changeset: 0:24427303d56f
965 user: test
965 user: test
966 date: Thu Jan 01 00:00:00 1970 +0000
966 date: Thu Jan 01 00:00:00 1970 +0000
967 summary: commit on default
967 summary: commit on default
968
968
969
969
970
970
971 log -b default -b .
971 log -b default -b .
972
972
973 $ hg log -b default -b .
973 $ hg log -b default -b .
974 changeset: 3:f5d8de11c2e2
974 changeset: 3:f5d8de11c2e2
975 branch: test
975 branch: test
976 tag: tip
976 tag: tip
977 parent: 1:d32277701ccb
977 parent: 1:d32277701ccb
978 user: test
978 user: test
979 date: Thu Jan 01 00:00:00 1970 +0000
979 date: Thu Jan 01 00:00:00 1970 +0000
980 summary: commit on test
980 summary: commit on test
981
981
982 changeset: 2:c3a4f03cc9a7
982 changeset: 2:c3a4f03cc9a7
983 parent: 0:24427303d56f
983 parent: 0:24427303d56f
984 user: test
984 user: test
985 date: Thu Jan 01 00:00:00 1970 +0000
985 date: Thu Jan 01 00:00:00 1970 +0000
986 summary: commit on default
986 summary: commit on default
987
987
988 changeset: 1:d32277701ccb
988 changeset: 1:d32277701ccb
989 branch: test
989 branch: test
990 user: test
990 user: test
991 date: Thu Jan 01 00:00:00 1970 +0000
991 date: Thu Jan 01 00:00:00 1970 +0000
992 summary: commit on test
992 summary: commit on test
993
993
994 changeset: 0:24427303d56f
994 changeset: 0:24427303d56f
995 user: test
995 user: test
996 date: Thu Jan 01 00:00:00 1970 +0000
996 date: Thu Jan 01 00:00:00 1970 +0000
997 summary: commit on default
997 summary: commit on default
998
998
999
999
1000
1000
1001 log -b . -b test
1001 log -b . -b test
1002
1002
1003 $ hg log -b . -b test
1003 $ hg log -b . -b test
1004 changeset: 3:f5d8de11c2e2
1004 changeset: 3:f5d8de11c2e2
1005 branch: test
1005 branch: test
1006 tag: tip
1006 tag: tip
1007 parent: 1:d32277701ccb
1007 parent: 1:d32277701ccb
1008 user: test
1008 user: test
1009 date: Thu Jan 01 00:00:00 1970 +0000
1009 date: Thu Jan 01 00:00:00 1970 +0000
1010 summary: commit on test
1010 summary: commit on test
1011
1011
1012 changeset: 1:d32277701ccb
1012 changeset: 1:d32277701ccb
1013 branch: test
1013 branch: test
1014 user: test
1014 user: test
1015 date: Thu Jan 01 00:00:00 1970 +0000
1015 date: Thu Jan 01 00:00:00 1970 +0000
1016 summary: commit on test
1016 summary: commit on test
1017
1017
1018
1018
1019
1019
1020 log -b 2
1020 log -b 2
1021
1021
1022 $ hg log -b 2
1022 $ hg log -b 2
1023 changeset: 2:c3a4f03cc9a7
1023 changeset: 2:c3a4f03cc9a7
1024 parent: 0:24427303d56f
1024 parent: 0:24427303d56f
1025 user: test
1025 user: test
1026 date: Thu Jan 01 00:00:00 1970 +0000
1026 date: Thu Jan 01 00:00:00 1970 +0000
1027 summary: commit on default
1027 summary: commit on default
1028
1028
1029 changeset: 0:24427303d56f
1029 changeset: 0:24427303d56f
1030 user: test
1030 user: test
1031 date: Thu Jan 01 00:00:00 1970 +0000
1031 date: Thu Jan 01 00:00:00 1970 +0000
1032 summary: commit on default
1032 summary: commit on default
1033
1033
1034
1034
1035
1035
1036 log -p --cwd dir (in subdir)
1036 log -p --cwd dir (in subdir)
1037
1037
1038 $ mkdir dir
1038 $ mkdir dir
1039 $ hg log -p --cwd dir
1039 $ hg log -p --cwd dir
1040 changeset: 3:f5d8de11c2e2
1040 changeset: 3:f5d8de11c2e2
1041 branch: test
1041 branch: test
1042 tag: tip
1042 tag: tip
1043 parent: 1:d32277701ccb
1043 parent: 1:d32277701ccb
1044 user: test
1044 user: test
1045 date: Thu Jan 01 00:00:00 1970 +0000
1045 date: Thu Jan 01 00:00:00 1970 +0000
1046 summary: commit on test
1046 summary: commit on test
1047
1047
1048 diff -r d32277701ccb -r f5d8de11c2e2 c
1048 diff -r d32277701ccb -r f5d8de11c2e2 c
1049 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1049 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1050 +++ b/c Thu Jan 01 00:00:00 1970 +0000
1050 +++ b/c Thu Jan 01 00:00:00 1970 +0000
1051 @@ -0,0 +1,1 @@
1051 @@ -0,0 +1,1 @@
1052 +c
1052 +c
1053
1053
1054 changeset: 2:c3a4f03cc9a7
1054 changeset: 2:c3a4f03cc9a7
1055 parent: 0:24427303d56f
1055 parent: 0:24427303d56f
1056 user: test
1056 user: test
1057 date: Thu Jan 01 00:00:00 1970 +0000
1057 date: Thu Jan 01 00:00:00 1970 +0000
1058 summary: commit on default
1058 summary: commit on default
1059
1059
1060 diff -r 24427303d56f -r c3a4f03cc9a7 c
1060 diff -r 24427303d56f -r c3a4f03cc9a7 c
1061 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1061 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1062 +++ b/c Thu Jan 01 00:00:00 1970 +0000
1062 +++ b/c Thu Jan 01 00:00:00 1970 +0000
1063 @@ -0,0 +1,1 @@
1063 @@ -0,0 +1,1 @@
1064 +c
1064 +c
1065
1065
1066 changeset: 1:d32277701ccb
1066 changeset: 1:d32277701ccb
1067 branch: test
1067 branch: test
1068 user: test
1068 user: test
1069 date: Thu Jan 01 00:00:00 1970 +0000
1069 date: Thu Jan 01 00:00:00 1970 +0000
1070 summary: commit on test
1070 summary: commit on test
1071
1071
1072 diff -r 24427303d56f -r d32277701ccb b
1072 diff -r 24427303d56f -r d32277701ccb b
1073 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1073 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1074 +++ b/b Thu Jan 01 00:00:00 1970 +0000
1074 +++ b/b Thu Jan 01 00:00:00 1970 +0000
1075 @@ -0,0 +1,1 @@
1075 @@ -0,0 +1,1 @@
1076 +b
1076 +b
1077
1077
1078 changeset: 0:24427303d56f
1078 changeset: 0:24427303d56f
1079 user: test
1079 user: test
1080 date: Thu Jan 01 00:00:00 1970 +0000
1080 date: Thu Jan 01 00:00:00 1970 +0000
1081 summary: commit on default
1081 summary: commit on default
1082
1082
1083 diff -r 000000000000 -r 24427303d56f a
1083 diff -r 000000000000 -r 24427303d56f a
1084 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1084 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1085 +++ b/a Thu Jan 01 00:00:00 1970 +0000
1085 +++ b/a Thu Jan 01 00:00:00 1970 +0000
1086 @@ -0,0 +1,1 @@
1086 @@ -0,0 +1,1 @@
1087 +a
1087 +a
1088
1088
1089
1089
1090
1090
1091 log -p -R repo
1091 log -p -R repo
1092
1092
1093 $ cd dir
1093 $ cd dir
1094 $ hg log -p -R .. ../a
1094 $ hg log -p -R .. ../a
1095 changeset: 0:24427303d56f
1095 changeset: 0:24427303d56f
1096 user: test
1096 user: test
1097 date: Thu Jan 01 00:00:00 1970 +0000
1097 date: Thu Jan 01 00:00:00 1970 +0000
1098 summary: commit on default
1098 summary: commit on default
1099
1099
1100 diff -r 000000000000 -r 24427303d56f a
1100 diff -r 000000000000 -r 24427303d56f a
1101 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1101 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1102 +++ b/a Thu Jan 01 00:00:00 1970 +0000
1102 +++ b/a Thu Jan 01 00:00:00 1970 +0000
1103 @@ -0,0 +1,1 @@
1103 @@ -0,0 +1,1 @@
1104 +a
1104 +a
1105
1105
1106
1106
1107 $ cd ../..
1107 $ cd ../..
1108
1108
1109 $ hg init follow2
1109 $ hg init follow2
1110 $ cd follow2
1110 $ cd follow2
1111
1111
1112 # Build the following history:
1112 # Build the following history:
1113 # tip - o - x - o - x - x
1113 # tip - o - x - o - x - x
1114 # \ /
1114 # \ /
1115 # o - o - o - x
1115 # o - o - o - x
1116 # \ /
1116 # \ /
1117 # o
1117 # o
1118 #
1118 #
1119 # Where "o" is a revision containing "foo" and
1119 # Where "o" is a revision containing "foo" and
1120 # "x" is a revision without "foo"
1120 # "x" is a revision without "foo"
1121
1121
1122 $ touch init
1122 $ touch init
1123 $ hg ci -A -m "init, unrelated"
1123 $ hg ci -A -m "init, unrelated"
1124 adding init
1124 adding init
1125 $ echo 'foo' > init
1125 $ echo 'foo' > init
1126 $ hg ci -m "change, unrelated"
1126 $ hg ci -m "change, unrelated"
1127 $ echo 'foo' > foo
1127 $ echo 'foo' > foo
1128 $ hg ci -A -m "add unrelated old foo"
1128 $ hg ci -A -m "add unrelated old foo"
1129 adding foo
1129 adding foo
1130 $ hg rm foo
1130 $ hg rm foo
1131 $ hg ci -m "delete foo, unrelated"
1131 $ hg ci -m "delete foo, unrelated"
1132 $ echo 'related' > foo
1132 $ echo 'related' > foo
1133 $ hg ci -A -m "add foo, related"
1133 $ hg ci -A -m "add foo, related"
1134 adding foo
1134 adding foo
1135
1135
1136 $ hg up 0
1136 $ hg up 0
1137 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
1137 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
1138 $ touch branch
1138 $ touch branch
1139 $ hg ci -A -m "first branch, unrelated"
1139 $ hg ci -A -m "first branch, unrelated"
1140 adding branch
1140 adding branch
1141 created new head
1141 created new head
1142 $ touch foo
1142 $ touch foo
1143 $ hg ci -A -m "create foo, related"
1143 $ hg ci -A -m "create foo, related"
1144 adding foo
1144 adding foo
1145 $ echo 'change' > foo
1145 $ echo 'change' > foo
1146 $ hg ci -m "change foo, related"
1146 $ hg ci -m "change foo, related"
1147
1147
1148 $ hg up 6
1148 $ hg up 6
1149 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
1149 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
1150 $ echo 'change foo in branch' > foo
1150 $ echo 'change foo in branch' > foo
1151 $ hg ci -m "change foo in branch, related"
1151 $ hg ci -m "change foo in branch, related"
1152 created new head
1152 created new head
1153 $ hg merge 7
1153 $ hg merge 7
1154 merging foo
1154 merging foo
1155 warning: conflicts during merge.
1155 warning: conflicts during merge.
1156 merging foo incomplete! (edit conflicts, then use 'hg resolve --mark')
1156 merging foo incomplete! (edit conflicts, then use 'hg resolve --mark')
1157 0 files updated, 0 files merged, 0 files removed, 1 files unresolved
1157 0 files updated, 0 files merged, 0 files removed, 1 files unresolved
1158 use 'hg resolve' to retry unresolved file merges or 'hg update -C .' to abandon
1158 use 'hg resolve' to retry unresolved file merges or 'hg update -C .' to abandon
1159 [1]
1159 [1]
1160 $ echo 'merge 1' > foo
1160 $ echo 'merge 1' > foo
1161 $ hg resolve -m foo
1161 $ hg resolve -m foo
1162 (no more unresolved files)
1162 (no more unresolved files)
1163 $ hg ci -m "First merge, related"
1163 $ hg ci -m "First merge, related"
1164
1164
1165 $ hg merge 4
1165 $ hg merge 4
1166 merging foo
1166 merging foo
1167 warning: conflicts during merge.
1167 warning: conflicts during merge.
1168 merging foo incomplete! (edit conflicts, then use 'hg resolve --mark')
1168 merging foo incomplete! (edit conflicts, then use 'hg resolve --mark')
1169 1 files updated, 0 files merged, 0 files removed, 1 files unresolved
1169 1 files updated, 0 files merged, 0 files removed, 1 files unresolved
1170 use 'hg resolve' to retry unresolved file merges or 'hg update -C .' to abandon
1170 use 'hg resolve' to retry unresolved file merges or 'hg update -C .' to abandon
1171 [1]
1171 [1]
1172 $ echo 'merge 2' > foo
1172 $ echo 'merge 2' > foo
1173 $ hg resolve -m foo
1173 $ hg resolve -m foo
1174 (no more unresolved files)
1174 (no more unresolved files)
1175 $ hg ci -m "Last merge, related"
1175 $ hg ci -m "Last merge, related"
1176
1176
1177 $ hg log --graph
1177 $ hg log --graph
1178 @ changeset: 10:4dae8563d2c5
1178 @ changeset: 10:4dae8563d2c5
1179 |\ tag: tip
1179 |\ tag: tip
1180 | | parent: 9:7b35701b003e
1180 | | parent: 9:7b35701b003e
1181 | | parent: 4:88176d361b69
1181 | | parent: 4:88176d361b69
1182 | | user: test
1182 | | user: test
1183 | | date: Thu Jan 01 00:00:00 1970 +0000
1183 | | date: Thu Jan 01 00:00:00 1970 +0000
1184 | | summary: Last merge, related
1184 | | summary: Last merge, related
1185 | |
1185 | |
1186 | o changeset: 9:7b35701b003e
1186 | o changeset: 9:7b35701b003e
1187 | |\ parent: 8:e5416ad8a855
1187 | |\ parent: 8:e5416ad8a855
1188 | | | parent: 7:87fe3144dcfa
1188 | | | parent: 7:87fe3144dcfa
1189 | | | user: test
1189 | | | user: test
1190 | | | date: Thu Jan 01 00:00:00 1970 +0000
1190 | | | date: Thu Jan 01 00:00:00 1970 +0000
1191 | | | summary: First merge, related
1191 | | | summary: First merge, related
1192 | | |
1192 | | |
1193 | | o changeset: 8:e5416ad8a855
1193 | | o changeset: 8:e5416ad8a855
1194 | | | parent: 6:dc6c325fe5ee
1194 | | | parent: 6:dc6c325fe5ee
1195 | | | user: test
1195 | | | user: test
1196 | | | date: Thu Jan 01 00:00:00 1970 +0000
1196 | | | date: Thu Jan 01 00:00:00 1970 +0000
1197 | | | summary: change foo in branch, related
1197 | | | summary: change foo in branch, related
1198 | | |
1198 | | |
1199 | o | changeset: 7:87fe3144dcfa
1199 | o | changeset: 7:87fe3144dcfa
1200 | |/ user: test
1200 | |/ user: test
1201 | | date: Thu Jan 01 00:00:00 1970 +0000
1201 | | date: Thu Jan 01 00:00:00 1970 +0000
1202 | | summary: change foo, related
1202 | | summary: change foo, related
1203 | |
1203 | |
1204 | o changeset: 6:dc6c325fe5ee
1204 | o changeset: 6:dc6c325fe5ee
1205 | | user: test
1205 | | user: test
1206 | | date: Thu Jan 01 00:00:00 1970 +0000
1206 | | date: Thu Jan 01 00:00:00 1970 +0000
1207 | | summary: create foo, related
1207 | | summary: create foo, related
1208 | |
1208 | |
1209 | o changeset: 5:73db34516eb9
1209 | o changeset: 5:73db34516eb9
1210 | | parent: 0:e87515fd044a
1210 | | parent: 0:e87515fd044a
1211 | | user: test
1211 | | user: test
1212 | | date: Thu Jan 01 00:00:00 1970 +0000
1212 | | date: Thu Jan 01 00:00:00 1970 +0000
1213 | | summary: first branch, unrelated
1213 | | summary: first branch, unrelated
1214 | |
1214 | |
1215 o | changeset: 4:88176d361b69
1215 o | changeset: 4:88176d361b69
1216 | | user: test
1216 | | user: test
1217 | | date: Thu Jan 01 00:00:00 1970 +0000
1217 | | date: Thu Jan 01 00:00:00 1970 +0000
1218 | | summary: add foo, related
1218 | | summary: add foo, related
1219 | |
1219 | |
1220 o | changeset: 3:dd78ae4afb56
1220 o | changeset: 3:dd78ae4afb56
1221 | | user: test
1221 | | user: test
1222 | | date: Thu Jan 01 00:00:00 1970 +0000
1222 | | date: Thu Jan 01 00:00:00 1970 +0000
1223 | | summary: delete foo, unrelated
1223 | | summary: delete foo, unrelated
1224 | |
1224 | |
1225 o | changeset: 2:c4c64aedf0f7
1225 o | changeset: 2:c4c64aedf0f7
1226 | | user: test
1226 | | user: test
1227 | | date: Thu Jan 01 00:00:00 1970 +0000
1227 | | date: Thu Jan 01 00:00:00 1970 +0000
1228 | | summary: add unrelated old foo
1228 | | summary: add unrelated old foo
1229 | |
1229 | |
1230 o | changeset: 1:e5faa7440653
1230 o | changeset: 1:e5faa7440653
1231 |/ user: test
1231 |/ user: test
1232 | date: Thu Jan 01 00:00:00 1970 +0000
1232 | date: Thu Jan 01 00:00:00 1970 +0000
1233 | summary: change, unrelated
1233 | summary: change, unrelated
1234 |
1234 |
1235 o changeset: 0:e87515fd044a
1235 o changeset: 0:e87515fd044a
1236 user: test
1236 user: test
1237 date: Thu Jan 01 00:00:00 1970 +0000
1237 date: Thu Jan 01 00:00:00 1970 +0000
1238 summary: init, unrelated
1238 summary: init, unrelated
1239
1239
1240
1240
1241 $ hg --traceback log -f foo
1241 $ hg --traceback log -f foo
1242 changeset: 10:4dae8563d2c5
1242 changeset: 10:4dae8563d2c5
1243 tag: tip
1243 tag: tip
1244 parent: 9:7b35701b003e
1244 parent: 9:7b35701b003e
1245 parent: 4:88176d361b69
1245 parent: 4:88176d361b69
1246 user: test
1246 user: test
1247 date: Thu Jan 01 00:00:00 1970 +0000
1247 date: Thu Jan 01 00:00:00 1970 +0000
1248 summary: Last merge, related
1248 summary: Last merge, related
1249
1249
1250 changeset: 9:7b35701b003e
1250 changeset: 9:7b35701b003e
1251 parent: 8:e5416ad8a855
1251 parent: 8:e5416ad8a855
1252 parent: 7:87fe3144dcfa
1252 parent: 7:87fe3144dcfa
1253 user: test
1253 user: test
1254 date: Thu Jan 01 00:00:00 1970 +0000
1254 date: Thu Jan 01 00:00:00 1970 +0000
1255 summary: First merge, related
1255 summary: First merge, related
1256
1256
1257 changeset: 8:e5416ad8a855
1257 changeset: 8:e5416ad8a855
1258 parent: 6:dc6c325fe5ee
1258 parent: 6:dc6c325fe5ee
1259 user: test
1259 user: test
1260 date: Thu Jan 01 00:00:00 1970 +0000
1260 date: Thu Jan 01 00:00:00 1970 +0000
1261 summary: change foo in branch, related
1261 summary: change foo in branch, related
1262
1262
1263 changeset: 7:87fe3144dcfa
1263 changeset: 7:87fe3144dcfa
1264 user: test
1264 user: test
1265 date: Thu Jan 01 00:00:00 1970 +0000
1265 date: Thu Jan 01 00:00:00 1970 +0000
1266 summary: change foo, related
1266 summary: change foo, related
1267
1267
1268 changeset: 6:dc6c325fe5ee
1268 changeset: 6:dc6c325fe5ee
1269 user: test
1269 user: test
1270 date: Thu Jan 01 00:00:00 1970 +0000
1270 date: Thu Jan 01 00:00:00 1970 +0000
1271 summary: create foo, related
1271 summary: create foo, related
1272
1272
1273 changeset: 4:88176d361b69
1273 changeset: 4:88176d361b69
1274 user: test
1274 user: test
1275 date: Thu Jan 01 00:00:00 1970 +0000
1275 date: Thu Jan 01 00:00:00 1970 +0000
1276 summary: add foo, related
1276 summary: add foo, related
1277
1277
1278
1278
1279 Also check when maxrev < lastrevfilelog
1279 Also check when maxrev < lastrevfilelog
1280
1280
1281 $ hg --traceback log -f -r4 foo
1281 $ hg --traceback log -f -r4 foo
1282 changeset: 4:88176d361b69
1282 changeset: 4:88176d361b69
1283 user: test
1283 user: test
1284 date: Thu Jan 01 00:00:00 1970 +0000
1284 date: Thu Jan 01 00:00:00 1970 +0000
1285 summary: add foo, related
1285 summary: add foo, related
1286
1286
1287 $ cd ..
1287 $ cd ..
1288
1288
1289 Issue2383: hg log showing _less_ differences than hg diff
1289 Issue2383: hg log showing _less_ differences than hg diff
1290
1290
1291 $ hg init issue2383
1291 $ hg init issue2383
1292 $ cd issue2383
1292 $ cd issue2383
1293
1293
1294 Create a test repo:
1294 Create a test repo:
1295
1295
1296 $ echo a > a
1296 $ echo a > a
1297 $ hg ci -Am0
1297 $ hg ci -Am0
1298 adding a
1298 adding a
1299 $ echo b > b
1299 $ echo b > b
1300 $ hg ci -Am1
1300 $ hg ci -Am1
1301 adding b
1301 adding b
1302 $ hg co 0
1302 $ hg co 0
1303 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
1303 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
1304 $ echo b > a
1304 $ echo b > a
1305 $ hg ci -m2
1305 $ hg ci -m2
1306 created new head
1306 created new head
1307
1307
1308 Merge:
1308 Merge:
1309
1309
1310 $ hg merge
1310 $ hg merge
1311 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
1311 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
1312 (branch merge, don't forget to commit)
1312 (branch merge, don't forget to commit)
1313
1313
1314 Make sure there's a file listed in the merge to trigger the bug:
1314 Make sure there's a file listed in the merge to trigger the bug:
1315
1315
1316 $ echo c > a
1316 $ echo c > a
1317 $ hg ci -m3
1317 $ hg ci -m3
1318
1318
1319 Two files shown here in diff:
1319 Two files shown here in diff:
1320
1320
1321 $ hg diff --rev 2:3
1321 $ hg diff --rev 2:3
1322 diff -r b09be438c43a -r 8e07aafe1edc a
1322 diff -r b09be438c43a -r 8e07aafe1edc a
1323 --- a/a Thu Jan 01 00:00:00 1970 +0000
1323 --- a/a Thu Jan 01 00:00:00 1970 +0000
1324 +++ b/a Thu Jan 01 00:00:00 1970 +0000
1324 +++ b/a Thu Jan 01 00:00:00 1970 +0000
1325 @@ -1,1 +1,1 @@
1325 @@ -1,1 +1,1 @@
1326 -b
1326 -b
1327 +c
1327 +c
1328 diff -r b09be438c43a -r 8e07aafe1edc b
1328 diff -r b09be438c43a -r 8e07aafe1edc b
1329 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1329 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1330 +++ b/b Thu Jan 01 00:00:00 1970 +0000
1330 +++ b/b Thu Jan 01 00:00:00 1970 +0000
1331 @@ -0,0 +1,1 @@
1331 @@ -0,0 +1,1 @@
1332 +b
1332 +b
1333
1333
1334 Diff here should be the same:
1334 Diff here should be the same:
1335
1335
1336 $ hg log -vpr 3
1336 $ hg log -vpr 3
1337 changeset: 3:8e07aafe1edc
1337 changeset: 3:8e07aafe1edc
1338 tag: tip
1338 tag: tip
1339 parent: 2:b09be438c43a
1339 parent: 2:b09be438c43a
1340 parent: 1:925d80f479bb
1340 parent: 1:925d80f479bb
1341 user: test
1341 user: test
1342 date: Thu Jan 01 00:00:00 1970 +0000
1342 date: Thu Jan 01 00:00:00 1970 +0000
1343 files: a
1343 files: a
1344 description:
1344 description:
1345 3
1345 3
1346
1346
1347
1347
1348 diff -r b09be438c43a -r 8e07aafe1edc a
1348 diff -r b09be438c43a -r 8e07aafe1edc a
1349 --- a/a Thu Jan 01 00:00:00 1970 +0000
1349 --- a/a Thu Jan 01 00:00:00 1970 +0000
1350 +++ b/a Thu Jan 01 00:00:00 1970 +0000
1350 +++ b/a Thu Jan 01 00:00:00 1970 +0000
1351 @@ -1,1 +1,1 @@
1351 @@ -1,1 +1,1 @@
1352 -b
1352 -b
1353 +c
1353 +c
1354 diff -r b09be438c43a -r 8e07aafe1edc b
1354 diff -r b09be438c43a -r 8e07aafe1edc b
1355 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1355 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1356 +++ b/b Thu Jan 01 00:00:00 1970 +0000
1356 +++ b/b Thu Jan 01 00:00:00 1970 +0000
1357 @@ -0,0 +1,1 @@
1357 @@ -0,0 +1,1 @@
1358 +b
1358 +b
1359
1359
1360 $ cd ..
1360 $ cd ..
1361
1361
1362 'hg log -r rev fn' when last(filelog(fn)) != rev
1362 'hg log -r rev fn' when last(filelog(fn)) != rev
1363
1363
1364 $ hg init simplelog
1364 $ hg init simplelog
1365 $ cd simplelog
1365 $ cd simplelog
1366 $ echo f > a
1366 $ echo f > a
1367 $ hg ci -Am'a' -d '0 0'
1367 $ hg ci -Am'a' -d '0 0'
1368 adding a
1368 adding a
1369 $ echo f >> a
1369 $ echo f >> a
1370 $ hg ci -Am'a bis' -d '1 0'
1370 $ hg ci -Am'a bis' -d '1 0'
1371
1371
1372 $ hg log -r0 a
1372 $ hg log -r0 a
1373 changeset: 0:9f758d63dcde
1373 changeset: 0:9f758d63dcde
1374 user: test
1374 user: test
1375 date: Thu Jan 01 00:00:00 1970 +0000
1375 date: Thu Jan 01 00:00:00 1970 +0000
1376 summary: a
1376 summary: a
1377
1377
1378 enable obsolete to test hidden feature
1378 enable obsolete to test hidden feature
1379
1379
1380 $ cat >> $HGRCPATH << EOF
1380 $ cat >> $HGRCPATH << EOF
1381 > [experimental]
1381 > [experimental]
1382 > evolution=createmarkers
1382 > evolution=createmarkers
1383 > EOF
1383 > EOF
1384
1384
1385 $ hg log --template='{rev}:{node}\n'
1385 $ hg log --template='{rev}:{node}\n'
1386 1:a765632148dc55d38c35c4f247c618701886cb2f
1386 1:a765632148dc55d38c35c4f247c618701886cb2f
1387 0:9f758d63dcde62d547ebfb08e1e7ee96535f2b05
1387 0:9f758d63dcde62d547ebfb08e1e7ee96535f2b05
1388 $ hg debugobsolete a765632148dc55d38c35c4f247c618701886cb2f
1388 $ hg debugobsolete a765632148dc55d38c35c4f247c618701886cb2f
1389 $ hg up null -q
1389 $ hg up null -q
1390 $ hg log --template='{rev}:{node}\n'
1390 $ hg log --template='{rev}:{node}\n'
1391 0:9f758d63dcde62d547ebfb08e1e7ee96535f2b05
1391 0:9f758d63dcde62d547ebfb08e1e7ee96535f2b05
1392 $ hg log --template='{rev}:{node}\n' --hidden
1392 $ hg log --template='{rev}:{node}\n' --hidden
1393 1:a765632148dc55d38c35c4f247c618701886cb2f
1393 1:a765632148dc55d38c35c4f247c618701886cb2f
1394 0:9f758d63dcde62d547ebfb08e1e7ee96535f2b05
1394 0:9f758d63dcde62d547ebfb08e1e7ee96535f2b05
1395 $ hg log -r a
1395 $ hg log -r a
1396 abort: hidden revision 'a'!
1396 abort: hidden revision 'a'!
1397 (use --hidden to access hidden revisions)
1397 (use --hidden to access hidden revisions)
1398 [255]
1398 [255]
1399
1399
1400 test that parent prevent a changeset to be hidden
1400 test that parent prevent a changeset to be hidden
1401
1401
1402 $ hg up 1 -q --hidden
1402 $ hg up 1 -q --hidden
1403 $ hg log --template='{rev}:{node}\n'
1403 $ hg log --template='{rev}:{node}\n'
1404 1:a765632148dc55d38c35c4f247c618701886cb2f
1404 1:a765632148dc55d38c35c4f247c618701886cb2f
1405 0:9f758d63dcde62d547ebfb08e1e7ee96535f2b05
1405 0:9f758d63dcde62d547ebfb08e1e7ee96535f2b05
1406
1406
1407 test that second parent prevent a changeset to be hidden too
1407 test that second parent prevent a changeset to be hidden too
1408
1408
1409 $ hg debugsetparents 0 1 # nothing suitable to merge here
1409 $ hg debugsetparents 0 1 # nothing suitable to merge here
1410 $ hg log --template='{rev}:{node}\n'
1410 $ hg log --template='{rev}:{node}\n'
1411 1:a765632148dc55d38c35c4f247c618701886cb2f
1411 1:a765632148dc55d38c35c4f247c618701886cb2f
1412 0:9f758d63dcde62d547ebfb08e1e7ee96535f2b05
1412 0:9f758d63dcde62d547ebfb08e1e7ee96535f2b05
1413 $ hg debugsetparents 1
1413 $ hg debugsetparents 1
1414 $ hg up -q null
1414 $ hg up -q null
1415
1415
1416 bookmarks prevent a changeset being hidden
1416 bookmarks prevent a changeset being hidden
1417
1417
1418 $ hg bookmark --hidden -r 1 X
1418 $ hg bookmark --hidden -r 1 X
1419 $ hg log --template '{rev}:{node}\n'
1419 $ hg log --template '{rev}:{node}\n'
1420 1:a765632148dc55d38c35c4f247c618701886cb2f
1420 1:a765632148dc55d38c35c4f247c618701886cb2f
1421 0:9f758d63dcde62d547ebfb08e1e7ee96535f2b05
1421 0:9f758d63dcde62d547ebfb08e1e7ee96535f2b05
1422 $ hg bookmark -d X
1422 $ hg bookmark -d X
1423
1423
1424 divergent bookmarks are not hidden
1424 divergent bookmarks are not hidden
1425
1425
1426 $ hg bookmark --hidden -r 1 X@foo
1426 $ hg bookmark --hidden -r 1 X@foo
1427 $ hg log --template '{rev}:{node}\n'
1427 $ hg log --template '{rev}:{node}\n'
1428 1:a765632148dc55d38c35c4f247c618701886cb2f
1428 1:a765632148dc55d38c35c4f247c618701886cb2f
1429 0:9f758d63dcde62d547ebfb08e1e7ee96535f2b05
1429 0:9f758d63dcde62d547ebfb08e1e7ee96535f2b05
1430
1430
1431 clear extensions configuration
1431 clear extensions configuration
1432 $ echo '[extensions]' >> $HGRCPATH
1432 $ echo '[extensions]' >> $HGRCPATH
1433 $ echo "obs=!" >> $HGRCPATH
1433 $ echo "obs=!" >> $HGRCPATH
1434 $ cd ..
1434 $ cd ..
1435
1435
1436 test -u/-k for problematic encoding
1436 test -u/-k for problematic encoding
1437 # unicode: cp932:
1437 # unicode: cp932:
1438 # u30A2 0x83 0x41(= 'A')
1438 # u30A2 0x83 0x41(= 'A')
1439 # u30C2 0x83 0x61(= 'a')
1439 # u30C2 0x83 0x61(= 'a')
1440
1440
1441 $ hg init problematicencoding
1441 $ hg init problematicencoding
1442 $ cd problematicencoding
1442 $ cd problematicencoding
1443
1443
1444 $ python > setup.sh <<EOF
1444 $ python > setup.sh <<EOF
1445 > print u'''
1445 > print u'''
1446 > echo a > text
1446 > echo a > text
1447 > hg add text
1447 > hg add text
1448 > hg --encoding utf-8 commit -u '\u30A2' -m none
1448 > hg --encoding utf-8 commit -u '\u30A2' -m none
1449 > echo b > text
1449 > echo b > text
1450 > hg --encoding utf-8 commit -u '\u30C2' -m none
1450 > hg --encoding utf-8 commit -u '\u30C2' -m none
1451 > echo c > text
1451 > echo c > text
1452 > hg --encoding utf-8 commit -u none -m '\u30A2'
1452 > hg --encoding utf-8 commit -u none -m '\u30A2'
1453 > echo d > text
1453 > echo d > text
1454 > hg --encoding utf-8 commit -u none -m '\u30C2'
1454 > hg --encoding utf-8 commit -u none -m '\u30C2'
1455 > '''.encode('utf-8')
1455 > '''.encode('utf-8')
1456 > EOF
1456 > EOF
1457 $ sh < setup.sh
1457 $ sh < setup.sh
1458
1458
1459 test in problematic encoding
1459 test in problematic encoding
1460 $ python > test.sh <<EOF
1460 $ python > test.sh <<EOF
1461 > print u'''
1461 > print u'''
1462 > hg --encoding cp932 log --template '{rev}\\n' -u '\u30A2'
1462 > hg --encoding cp932 log --template '{rev}\\n' -u '\u30A2'
1463 > echo ====
1463 > echo ====
1464 > hg --encoding cp932 log --template '{rev}\\n' -u '\u30C2'
1464 > hg --encoding cp932 log --template '{rev}\\n' -u '\u30C2'
1465 > echo ====
1465 > echo ====
1466 > hg --encoding cp932 log --template '{rev}\\n' -k '\u30A2'
1466 > hg --encoding cp932 log --template '{rev}\\n' -k '\u30A2'
1467 > echo ====
1467 > echo ====
1468 > hg --encoding cp932 log --template '{rev}\\n' -k '\u30C2'
1468 > hg --encoding cp932 log --template '{rev}\\n' -k '\u30C2'
1469 > '''.encode('cp932')
1469 > '''.encode('cp932')
1470 > EOF
1470 > EOF
1471 $ sh < test.sh
1471 $ sh < test.sh
1472 0
1472 0
1473 ====
1473 ====
1474 1
1474 1
1475 ====
1475 ====
1476 2
1476 2
1477 0
1477 0
1478 ====
1478 ====
1479 3
1479 3
1480 1
1480 1
1481
1481
1482 $ cd ..
1482 $ cd ..
1483
1483
1484 test hg log on non-existent files and on directories
1484 test hg log on non-existent files and on directories
1485 $ hg init issue1340
1485 $ hg init issue1340
1486 $ cd issue1340
1486 $ cd issue1340
1487 $ mkdir d1; mkdir D2; mkdir D3.i; mkdir d4.hg; mkdir d5.d; mkdir .d6
1487 $ mkdir d1; mkdir D2; mkdir D3.i; mkdir d4.hg; mkdir d5.d; mkdir .d6
1488 $ echo 1 > d1/f1
1488 $ echo 1 > d1/f1
1489 $ echo 1 > D2/f1
1489 $ echo 1 > D2/f1
1490 $ echo 1 > D3.i/f1
1490 $ echo 1 > D3.i/f1
1491 $ echo 1 > d4.hg/f1
1491 $ echo 1 > d4.hg/f1
1492 $ echo 1 > d5.d/f1
1492 $ echo 1 > d5.d/f1
1493 $ echo 1 > .d6/f1
1493 $ echo 1 > .d6/f1
1494 $ hg -q add .
1494 $ hg -q add .
1495 $ hg commit -m "a bunch of weird directories"
1495 $ hg commit -m "a bunch of weird directories"
1496 $ hg log -l1 d1/f1 | grep changeset
1496 $ hg log -l1 d1/f1 | grep changeset
1497 changeset: 0:65624cd9070a
1497 changeset: 0:65624cd9070a
1498 $ hg log -l1 f1
1498 $ hg log -l1 f1
1499 $ hg log -l1 . | grep changeset
1499 $ hg log -l1 . | grep changeset
1500 changeset: 0:65624cd9070a
1500 changeset: 0:65624cd9070a
1501 $ hg log -l1 ./ | grep changeset
1501 $ hg log -l1 ./ | grep changeset
1502 changeset: 0:65624cd9070a
1502 changeset: 0:65624cd9070a
1503 $ hg log -l1 d1 | grep changeset
1503 $ hg log -l1 d1 | grep changeset
1504 changeset: 0:65624cd9070a
1504 changeset: 0:65624cd9070a
1505 $ hg log -l1 D2 | grep changeset
1505 $ hg log -l1 D2 | grep changeset
1506 changeset: 0:65624cd9070a
1506 changeset: 0:65624cd9070a
1507 $ hg log -l1 D2/f1 | grep changeset
1507 $ hg log -l1 D2/f1 | grep changeset
1508 changeset: 0:65624cd9070a
1508 changeset: 0:65624cd9070a
1509 $ hg log -l1 D3.i | grep changeset
1509 $ hg log -l1 D3.i | grep changeset
1510 changeset: 0:65624cd9070a
1510 changeset: 0:65624cd9070a
1511 $ hg log -l1 D3.i/f1 | grep changeset
1511 $ hg log -l1 D3.i/f1 | grep changeset
1512 changeset: 0:65624cd9070a
1512 changeset: 0:65624cd9070a
1513 $ hg log -l1 d4.hg | grep changeset
1513 $ hg log -l1 d4.hg | grep changeset
1514 changeset: 0:65624cd9070a
1514 changeset: 0:65624cd9070a
1515 $ hg log -l1 d4.hg/f1 | grep changeset
1515 $ hg log -l1 d4.hg/f1 | grep changeset
1516 changeset: 0:65624cd9070a
1516 changeset: 0:65624cd9070a
1517 $ hg log -l1 d5.d | grep changeset
1517 $ hg log -l1 d5.d | grep changeset
1518 changeset: 0:65624cd9070a
1518 changeset: 0:65624cd9070a
1519 $ hg log -l1 d5.d/f1 | grep changeset
1519 $ hg log -l1 d5.d/f1 | grep changeset
1520 changeset: 0:65624cd9070a
1520 changeset: 0:65624cd9070a
1521 $ hg log -l1 .d6 | grep changeset
1521 $ hg log -l1 .d6 | grep changeset
1522 changeset: 0:65624cd9070a
1522 changeset: 0:65624cd9070a
1523 $ hg log -l1 .d6/f1 | grep changeset
1523 $ hg log -l1 .d6/f1 | grep changeset
1524 changeset: 0:65624cd9070a
1524 changeset: 0:65624cd9070a
1525
1525
1526 issue3772: hg log -r :null showing revision 0 as well
1526 issue3772: hg log -r :null showing revision 0 as well
1527
1527
1528 $ hg log -r :null
1528 $ hg log -r :null
1529 changeset: 0:65624cd9070a
1529 changeset: 0:65624cd9070a
1530 tag: tip
1530 tag: tip
1531 user: test
1531 user: test
1532 date: Thu Jan 01 00:00:00 1970 +0000
1532 date: Thu Jan 01 00:00:00 1970 +0000
1533 summary: a bunch of weird directories
1533 summary: a bunch of weird directories
1534
1534
1535 changeset: -1:000000000000
1535 changeset: -1:000000000000
1536 user:
1536 user:
1537 date: Thu Jan 01 00:00:00 1970 +0000
1537 date: Thu Jan 01 00:00:00 1970 +0000
1538
1538
1539 $ hg log -r null:null
1539 $ hg log -r null:null
1540 changeset: -1:000000000000
1540 changeset: -1:000000000000
1541 user:
1541 user:
1542 date: Thu Jan 01 00:00:00 1970 +0000
1542 date: Thu Jan 01 00:00:00 1970 +0000
1543
1543
1544
1544
1545 $ cd ..
1545 $ cd ..
1546
1546
1547 hg log -f dir across branches
1547 hg log -f dir across branches
1548
1548
1549 $ hg init acrossbranches
1549 $ hg init acrossbranches
1550 $ cd acrossbranches
1550 $ cd acrossbranches
1551 $ mkdir d
1551 $ mkdir d
1552 $ echo a > d/a && hg ci -Aqm a
1552 $ echo a > d/a && hg ci -Aqm a
1553 $ echo b > d/a && hg ci -Aqm b
1553 $ echo b > d/a && hg ci -Aqm b
1554 $ hg up -q 0
1554 $ hg up -q 0
1555 $ echo b > d/a && hg ci -Aqm c
1555 $ echo b > d/a && hg ci -Aqm c
1556 $ hg log -f d -T '{desc}' -G
1556 $ hg log -f d -T '{desc}' -G
1557 @ c
1557 @ c
1558 |
1558 |
1559 o a
1559 o a
1560
1560
1561 $ hg log -f d/a -T '{desc}' -G
1561 $ hg log -f d/a -T '{desc}' -G
1562 @ c
1562 @ c
1563 |
1563 |
1564 o a
1564 o a
1565
1565
1566 $ cd ..
1566 $ cd ..
1567
1567
1568 hg log -f with linkrev pointing to another branch
1568 hg log -f with linkrev pointing to another branch
1569 -------------------------------------------------
1569 -------------------------------------------------
1570
1570
1571 create history with a filerev whose linkrev points to another branch
1571 create history with a filerev whose linkrev points to another branch
1572
1572
1573 $ hg init branchedlinkrev
1573 $ hg init branchedlinkrev
1574 $ cd branchedlinkrev
1574 $ cd branchedlinkrev
1575 $ echo 1 > a
1575 $ echo 1 > a
1576 $ hg commit -Am 'content1'
1576 $ hg commit -Am 'content1'
1577 adding a
1577 adding a
1578 $ echo 2 > a
1578 $ echo 2 > a
1579 $ hg commit -m 'content2'
1579 $ hg commit -m 'content2'
1580 $ hg up --rev 'desc(content1)'
1580 $ hg up --rev 'desc(content1)'
1581 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
1581 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
1582 $ echo unrelated > unrelated
1582 $ echo unrelated > unrelated
1583 $ hg commit -Am 'unrelated'
1583 $ hg commit -Am 'unrelated'
1584 adding unrelated
1584 adding unrelated
1585 created new head
1585 created new head
1586 $ hg graft -r 'desc(content2)'
1586 $ hg graft -r 'desc(content2)'
1587 grafting 1:2294ae80ad84 "content2"
1587 grafting 1:2294ae80ad84 "content2"
1588 $ echo 3 > a
1588 $ echo 3 > a
1589 $ hg commit -m 'content3'
1589 $ hg commit -m 'content3'
1590 $ hg log -G
1590 $ hg log -G
1591 @ changeset: 4:50b9b36e9c5d
1591 @ changeset: 4:50b9b36e9c5d
1592 | tag: tip
1592 | tag: tip
1593 | user: test
1593 | user: test
1594 | date: Thu Jan 01 00:00:00 1970 +0000
1594 | date: Thu Jan 01 00:00:00 1970 +0000
1595 | summary: content3
1595 | summary: content3
1596 |
1596 |
1597 o changeset: 3:15b2327059e5
1597 o changeset: 3:15b2327059e5
1598 | user: test
1598 | user: test
1599 | date: Thu Jan 01 00:00:00 1970 +0000
1599 | date: Thu Jan 01 00:00:00 1970 +0000
1600 | summary: content2
1600 | summary: content2
1601 |
1601 |
1602 o changeset: 2:2029acd1168c
1602 o changeset: 2:2029acd1168c
1603 | parent: 0:ae0a3c9f9e95
1603 | parent: 0:ae0a3c9f9e95
1604 | user: test
1604 | user: test
1605 | date: Thu Jan 01 00:00:00 1970 +0000
1605 | date: Thu Jan 01 00:00:00 1970 +0000
1606 | summary: unrelated
1606 | summary: unrelated
1607 |
1607 |
1608 | o changeset: 1:2294ae80ad84
1608 | o changeset: 1:2294ae80ad84
1609 |/ user: test
1609 |/ user: test
1610 | date: Thu Jan 01 00:00:00 1970 +0000
1610 | date: Thu Jan 01 00:00:00 1970 +0000
1611 | summary: content2
1611 | summary: content2
1612 |
1612 |
1613 o changeset: 0:ae0a3c9f9e95
1613 o changeset: 0:ae0a3c9f9e95
1614 user: test
1614 user: test
1615 date: Thu Jan 01 00:00:00 1970 +0000
1615 date: Thu Jan 01 00:00:00 1970 +0000
1616 summary: content1
1616 summary: content1
1617
1617
1618
1618
1619 log -f on the file should list the graft result.
1619 log -f on the file should list the graft result.
1620
1620
1621 $ hg log -Gf a
1621 $ hg log -Gf a
1622 @ changeset: 4:50b9b36e9c5d
1622 @ changeset: 4:50b9b36e9c5d
1623 | tag: tip
1623 | tag: tip
1624 | user: test
1624 | user: test
1625 | date: Thu Jan 01 00:00:00 1970 +0000
1625 | date: Thu Jan 01 00:00:00 1970 +0000
1626 | summary: content3
1626 | summary: content3
1627 |
1627 |
1628 o changeset: 3:15b2327059e5
1628 o changeset: 3:15b2327059e5
1629 | user: test
1629 | user: test
1630 | date: Thu Jan 01 00:00:00 1970 +0000
1630 | date: Thu Jan 01 00:00:00 1970 +0000
1631 | summary: content2
1631 | summary: content2
1632 |
1632 |
1633 o changeset: 0:ae0a3c9f9e95
1633 o changeset: 0:ae0a3c9f9e95
1634 user: test
1634 user: test
1635 date: Thu Jan 01 00:00:00 1970 +0000
1635 date: Thu Jan 01 00:00:00 1970 +0000
1636 summary: content1
1636 summary: content1
1637
1637
1638
1638
1639 plain log lists the original version
1639 plain log lists the original version
1640 (XXX we should probably list both)
1640 (XXX we should probably list both)
1641
1641
1642 $ hg log -G a
1642 $ hg log -G a
1643 @ changeset: 4:50b9b36e9c5d
1643 @ changeset: 4:50b9b36e9c5d
1644 | tag: tip
1644 | tag: tip
1645 | user: test
1645 | user: test
1646 | date: Thu Jan 01 00:00:00 1970 +0000
1646 | date: Thu Jan 01 00:00:00 1970 +0000
1647 | summary: content3
1647 | summary: content3
1648 |
1648 |
1649 | o changeset: 1:2294ae80ad84
1649 | o changeset: 1:2294ae80ad84
1650 |/ user: test
1650 |/ user: test
1651 | date: Thu Jan 01 00:00:00 1970 +0000
1651 | date: Thu Jan 01 00:00:00 1970 +0000
1652 | summary: content2
1652 | summary: content2
1653 |
1653 |
1654 o changeset: 0:ae0a3c9f9e95
1654 o changeset: 0:ae0a3c9f9e95
1655 user: test
1655 user: test
1656 date: Thu Jan 01 00:00:00 1970 +0000
1656 date: Thu Jan 01 00:00:00 1970 +0000
1657 summary: content1
1657 summary: content1
1658
1658
1659
1659
1660 hg log -f from the grafted changeset
1660 hg log -f from the grafted changeset
1661 (The bootstrap should properly take the topology in account)
1661 (The bootstrap should properly take the topology in account)
1662
1662
1663 $ hg up 'desc(content3)^'
1663 $ hg up 'desc(content3)^'
1664 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
1664 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
1665 $ hg log -Gf a
1665 $ hg log -Gf a
1666 @ changeset: 3:15b2327059e5
1666 @ changeset: 3:15b2327059e5
1667 | user: test
1667 | user: test
1668 | date: Thu Jan 01 00:00:00 1970 +0000
1668 | date: Thu Jan 01 00:00:00 1970 +0000
1669 | summary: content2
1669 | summary: content2
1670 |
1670 |
1671 o changeset: 0:ae0a3c9f9e95
1671 o changeset: 0:ae0a3c9f9e95
1672 user: test
1672 user: test
1673 date: Thu Jan 01 00:00:00 1970 +0000
1673 date: Thu Jan 01 00:00:00 1970 +0000
1674 summary: content1
1674 summary: content1
1675
1675
1676
1676
1677 Test that we use the first non-hidden changeset in that case.
1677 Test that we use the first non-hidden changeset in that case.
1678
1678
1679 (hide the changeset)
1679 (hide the changeset)
1680
1680
1681 $ hg log -T '{node}\n' -r 1
1681 $ hg log -T '{node}\n' -r 1
1682 2294ae80ad8447bc78383182eeac50cb049df623
1682 2294ae80ad8447bc78383182eeac50cb049df623
1683 $ hg debugobsolete 2294ae80ad8447bc78383182eeac50cb049df623
1683 $ hg debugobsolete 2294ae80ad8447bc78383182eeac50cb049df623
1684 $ hg log -G
1684 $ hg log -G
1685 o changeset: 4:50b9b36e9c5d
1685 o changeset: 4:50b9b36e9c5d
1686 | tag: tip
1686 | tag: tip
1687 | user: test
1687 | user: test
1688 | date: Thu Jan 01 00:00:00 1970 +0000
1688 | date: Thu Jan 01 00:00:00 1970 +0000
1689 | summary: content3
1689 | summary: content3
1690 |
1690 |
1691 @ changeset: 3:15b2327059e5
1691 @ changeset: 3:15b2327059e5
1692 | user: test
1692 | user: test
1693 | date: Thu Jan 01 00:00:00 1970 +0000
1693 | date: Thu Jan 01 00:00:00 1970 +0000
1694 | summary: content2
1694 | summary: content2
1695 |
1695 |
1696 o changeset: 2:2029acd1168c
1696 o changeset: 2:2029acd1168c
1697 | parent: 0:ae0a3c9f9e95
1697 | parent: 0:ae0a3c9f9e95
1698 | user: test
1698 | user: test
1699 | date: Thu Jan 01 00:00:00 1970 +0000
1699 | date: Thu Jan 01 00:00:00 1970 +0000
1700 | summary: unrelated
1700 | summary: unrelated
1701 |
1701 |
1702 o changeset: 0:ae0a3c9f9e95
1702 o changeset: 0:ae0a3c9f9e95
1703 user: test
1703 user: test
1704 date: Thu Jan 01 00:00:00 1970 +0000
1704 date: Thu Jan 01 00:00:00 1970 +0000
1705 summary: content1
1705 summary: content1
1706
1706
1707
1707
1708 Check that log on the file does not drop the file revision.
1708 Check that log on the file does not drop the file revision.
1709
1709
1710 $ hg log -G a
1710 $ hg log -G a
1711 o changeset: 4:50b9b36e9c5d
1711 o changeset: 4:50b9b36e9c5d
1712 | tag: tip
1712 | tag: tip
1713 | user: test
1713 | user: test
1714 | date: Thu Jan 01 00:00:00 1970 +0000
1714 | date: Thu Jan 01 00:00:00 1970 +0000
1715 | summary: content3
1715 | summary: content3
1716 |
1716 |
1717 @ changeset: 3:15b2327059e5
1717 @ changeset: 3:15b2327059e5
1718 | user: test
1718 | user: test
1719 | date: Thu Jan 01 00:00:00 1970 +0000
1719 | date: Thu Jan 01 00:00:00 1970 +0000
1720 | summary: content2
1720 | summary: content2
1721 |
1721 |
1722 o changeset: 0:ae0a3c9f9e95
1722 o changeset: 0:ae0a3c9f9e95
1723 user: test
1723 user: test
1724 date: Thu Jan 01 00:00:00 1970 +0000
1724 date: Thu Jan 01 00:00:00 1970 +0000
1725 summary: content1
1725 summary: content1
1726
1726
1727
1727
1728 Even when a head revision is linkrev-shadowed.
1728 Even when a head revision is linkrev-shadowed.
1729
1729
1730 $ hg log -T '{node}\n' -r 4
1730 $ hg log -T '{node}\n' -r 4
1731 50b9b36e9c5df2c6fc6dcefa8ad0da929e84aed2
1731 50b9b36e9c5df2c6fc6dcefa8ad0da929e84aed2
1732 $ hg debugobsolete 50b9b36e9c5df2c6fc6dcefa8ad0da929e84aed2
1732 $ hg debugobsolete 50b9b36e9c5df2c6fc6dcefa8ad0da929e84aed2
1733 $ hg log -G a
1733 $ hg log -G a
1734 @ changeset: 3:15b2327059e5
1734 @ changeset: 3:15b2327059e5
1735 | tag: tip
1735 | tag: tip
1736 | user: test
1736 | user: test
1737 | date: Thu Jan 01 00:00:00 1970 +0000
1737 | date: Thu Jan 01 00:00:00 1970 +0000
1738 | summary: content2
1738 | summary: content2
1739 |
1739 |
1740 o changeset: 0:ae0a3c9f9e95
1740 o changeset: 0:ae0a3c9f9e95
1741 user: test
1741 user: test
1742 date: Thu Jan 01 00:00:00 1970 +0000
1742 date: Thu Jan 01 00:00:00 1970 +0000
1743 summary: content1
1743 summary: content1
1744
1744
1745
1745
1746 $ cd ..
1746 $ cd ..
1747
1748 Even when the file revision is missing from some head:
1749
1750 $ hg init issue4490
1751 $ cd issue4490
1752 $ echo '[experimental]' >> .hg/hgrc
1753 $ echo 'evolution=createmarkers' >> .hg/hgrc
1754 $ echo a > a
1755 $ hg ci -Am0
1756 adding a
1757 $ echo b > b
1758 $ hg ci -Am1
1759 adding b
1760 $ echo B > b
1761 $ hg ci --amend -m 1
1762 $ hg up 0
1763 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
1764 $ echo c > c
1765 $ hg ci -Am2
1766 adding c
1767 created new head
1768 $ hg up 'head() and not .'
1769 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
1770 $ hg log -G
1771 o changeset: 4:db815d6d32e6
1772 | tag: tip
1773 | parent: 0:f7b1eb17ad24
1774 | user: test
1775 | date: Thu Jan 01 00:00:00 1970 +0000
1776 | summary: 2
1777 |
1778 | @ changeset: 3:9bc8ce7f9356
1779 |/ parent: 0:f7b1eb17ad24
1780 | user: test
1781 | date: Thu Jan 01 00:00:00 1970 +0000
1782 | summary: 1
1783 |
1784 o changeset: 0:f7b1eb17ad24
1785 user: test
1786 date: Thu Jan 01 00:00:00 1970 +0000
1787 summary: 0
1788
1789 $ hg log -f -G b
1790 @ changeset: 3:9bc8ce7f9356
1791 | parent: 0:f7b1eb17ad24
1792 | user: test
1793 | date: Thu Jan 01 00:00:00 1970 +0000
1794 | summary: 1
1795 |
1796 $ hg log -G b
1797 @ changeset: 3:9bc8ce7f9356
1798 | parent: 0:f7b1eb17ad24
1799 | user: test
1800 | date: Thu Jan 01 00:00:00 1970 +0000
1801 | summary: 1
1802 |
General Comments 0
You need to be logged in to leave comments. Login now