##// END OF EJS Templates
revset: do not transform range* operators in parsed tree...
Yuya Nishihara -
r30803:d389f19f default
parent child Browse files
Show More
@@ -1,3889 +1,3901 b''
1 1 # revset.py - revision set queries for mercurial
2 2 #
3 3 # Copyright 2010 Matt Mackall <mpm@selenic.com>
4 4 #
5 5 # This software may be used and distributed according to the terms of the
6 6 # GNU General Public License version 2 or any later version.
7 7
8 8 from __future__ import absolute_import
9 9
10 10 import heapq
11 11 import re
12 12 import string
13 13
14 14 from .i18n import _
15 15 from . import (
16 16 destutil,
17 17 encoding,
18 18 error,
19 19 hbisect,
20 20 match as matchmod,
21 21 node,
22 22 obsolete as obsmod,
23 23 parser,
24 24 pathutil,
25 25 phases,
26 26 pycompat,
27 27 registrar,
28 28 repoview,
29 29 util,
30 30 )
31 31
32 32 def _revancestors(repo, revs, followfirst):
33 33 """Like revlog.ancestors(), but supports followfirst."""
34 34 if followfirst:
35 35 cut = 1
36 36 else:
37 37 cut = None
38 38 cl = repo.changelog
39 39
40 40 def iterate():
41 41 revs.sort(reverse=True)
42 42 irevs = iter(revs)
43 43 h = []
44 44
45 45 inputrev = next(irevs, None)
46 46 if inputrev is not None:
47 47 heapq.heappush(h, -inputrev)
48 48
49 49 seen = set()
50 50 while h:
51 51 current = -heapq.heappop(h)
52 52 if current == inputrev:
53 53 inputrev = next(irevs, None)
54 54 if inputrev is not None:
55 55 heapq.heappush(h, -inputrev)
56 56 if current not in seen:
57 57 seen.add(current)
58 58 yield current
59 59 for parent in cl.parentrevs(current)[:cut]:
60 60 if parent != node.nullrev:
61 61 heapq.heappush(h, -parent)
62 62
63 63 return generatorset(iterate(), iterasc=False)
64 64
65 65 def _revdescendants(repo, revs, followfirst):
66 66 """Like revlog.descendants() but supports followfirst."""
67 67 if followfirst:
68 68 cut = 1
69 69 else:
70 70 cut = None
71 71
72 72 def iterate():
73 73 cl = repo.changelog
74 74 # XXX this should be 'parentset.min()' assuming 'parentset' is a
75 75 # smartset (and if it is not, it should.)
76 76 first = min(revs)
77 77 nullrev = node.nullrev
78 78 if first == nullrev:
79 79 # Are there nodes with a null first parent and a non-null
80 80 # second one? Maybe. Do we care? Probably not.
81 81 for i in cl:
82 82 yield i
83 83 else:
84 84 seen = set(revs)
85 85 for i in cl.revs(first + 1):
86 86 for x in cl.parentrevs(i)[:cut]:
87 87 if x != nullrev and x in seen:
88 88 seen.add(i)
89 89 yield i
90 90 break
91 91
92 92 return generatorset(iterate(), iterasc=True)
93 93
94 94 def _reachablerootspure(repo, minroot, roots, heads, includepath):
95 95 """return (heads(::<roots> and ::<heads>))
96 96
97 97 If includepath is True, return (<roots>::<heads>)."""
98 98 if not roots:
99 99 return []
100 100 parentrevs = repo.changelog.parentrevs
101 101 roots = set(roots)
102 102 visit = list(heads)
103 103 reachable = set()
104 104 seen = {}
105 105 # prefetch all the things! (because python is slow)
106 106 reached = reachable.add
107 107 dovisit = visit.append
108 108 nextvisit = visit.pop
109 109 # open-code the post-order traversal due to the tiny size of
110 110 # sys.getrecursionlimit()
111 111 while visit:
112 112 rev = nextvisit()
113 113 if rev in roots:
114 114 reached(rev)
115 115 if not includepath:
116 116 continue
117 117 parents = parentrevs(rev)
118 118 seen[rev] = parents
119 119 for parent in parents:
120 120 if parent >= minroot and parent not in seen:
121 121 dovisit(parent)
122 122 if not reachable:
123 123 return baseset()
124 124 if not includepath:
125 125 return reachable
126 126 for rev in sorted(seen):
127 127 for parent in seen[rev]:
128 128 if parent in reachable:
129 129 reached(rev)
130 130 return reachable
131 131
132 132 def reachableroots(repo, roots, heads, includepath=False):
133 133 """return (heads(::<roots> and ::<heads>))
134 134
135 135 If includepath is True, return (<roots>::<heads>)."""
136 136 if not roots:
137 137 return baseset()
138 138 minroot = roots.min()
139 139 roots = list(roots)
140 140 heads = list(heads)
141 141 try:
142 142 revs = repo.changelog.reachableroots(minroot, heads, roots, includepath)
143 143 except AttributeError:
144 144 revs = _reachablerootspure(repo, minroot, roots, heads, includepath)
145 145 revs = baseset(revs)
146 146 revs.sort()
147 147 return revs
148 148
149 149 elements = {
150 150 # token-type: binding-strength, primary, prefix, infix, suffix
151 151 "(": (21, None, ("group", 1, ")"), ("func", 1, ")"), None),
152 152 "##": (20, None, None, ("_concat", 20), None),
153 153 "~": (18, None, None, ("ancestor", 18), None),
154 154 "^": (18, None, None, ("parent", 18), "parentpost"),
155 155 "-": (5, None, ("negate", 19), ("minus", 5), None),
156 156 "::": (17, None, ("dagrangepre", 17), ("dagrange", 17), "dagrangepost"),
157 157 "..": (17, None, ("dagrangepre", 17), ("dagrange", 17), "dagrangepost"),
158 158 ":": (15, "rangeall", ("rangepre", 15), ("range", 15), "rangepost"),
159 159 "not": (10, None, ("not", 10), None, None),
160 160 "!": (10, None, ("not", 10), None, None),
161 161 "and": (5, None, None, ("and", 5), None),
162 162 "&": (5, None, None, ("and", 5), None),
163 163 "%": (5, None, None, ("only", 5), "onlypost"),
164 164 "or": (4, None, None, ("or", 4), None),
165 165 "|": (4, None, None, ("or", 4), None),
166 166 "+": (4, None, None, ("or", 4), None),
167 167 "=": (3, None, None, ("keyvalue", 3), None),
168 168 ",": (2, None, None, ("list", 2), None),
169 169 ")": (0, None, None, None, None),
170 170 "symbol": (0, "symbol", None, None, None),
171 171 "string": (0, "string", None, None, None),
172 172 "end": (0, None, None, None, None),
173 173 }
174 174
175 175 keywords = set(['and', 'or', 'not'])
176 176
177 177 # default set of valid characters for the initial letter of symbols
178 178 _syminitletters = set(
179 179 string.ascii_letters +
180 180 string.digits + pycompat.sysstr('._@')) | set(map(chr, xrange(128, 256)))
181 181
182 182 # default set of valid characters for non-initial letters of symbols
183 183 _symletters = _syminitletters | set(pycompat.sysstr('-/'))
184 184
185 185 def tokenize(program, lookup=None, syminitletters=None, symletters=None):
186 186 '''
187 187 Parse a revset statement into a stream of tokens
188 188
189 189 ``syminitletters`` is the set of valid characters for the initial
190 190 letter of symbols.
191 191
192 192 By default, character ``c`` is recognized as valid for initial
193 193 letter of symbols, if ``c.isalnum() or c in '._@' or ord(c) > 127``.
194 194
195 195 ``symletters`` is the set of valid characters for non-initial
196 196 letters of symbols.
197 197
198 198 By default, character ``c`` is recognized as valid for non-initial
199 199 letters of symbols, if ``c.isalnum() or c in '-._/@' or ord(c) > 127``.
200 200
201 201 Check that @ is a valid unquoted token character (issue3686):
202 202 >>> list(tokenize("@::"))
203 203 [('symbol', '@', 0), ('::', None, 1), ('end', None, 3)]
204 204
205 205 '''
206 206 if syminitletters is None:
207 207 syminitletters = _syminitletters
208 208 if symletters is None:
209 209 symletters = _symletters
210 210
211 211 if program and lookup:
212 212 # attempt to parse old-style ranges first to deal with
213 213 # things like old-tag which contain query metacharacters
214 214 parts = program.split(':', 1)
215 215 if all(lookup(sym) for sym in parts if sym):
216 216 if parts[0]:
217 217 yield ('symbol', parts[0], 0)
218 218 if len(parts) > 1:
219 219 s = len(parts[0])
220 220 yield (':', None, s)
221 221 if parts[1]:
222 222 yield ('symbol', parts[1], s + 1)
223 223 yield ('end', None, len(program))
224 224 return
225 225
226 226 pos, l = 0, len(program)
227 227 while pos < l:
228 228 c = program[pos]
229 229 if c.isspace(): # skip inter-token whitespace
230 230 pass
231 231 elif c == ':' and program[pos:pos + 2] == '::': # look ahead carefully
232 232 yield ('::', None, pos)
233 233 pos += 1 # skip ahead
234 234 elif c == '.' and program[pos:pos + 2] == '..': # look ahead carefully
235 235 yield ('..', None, pos)
236 236 pos += 1 # skip ahead
237 237 elif c == '#' and program[pos:pos + 2] == '##': # look ahead carefully
238 238 yield ('##', None, pos)
239 239 pos += 1 # skip ahead
240 240 elif c in "():=,-|&+!~^%": # handle simple operators
241 241 yield (c, None, pos)
242 242 elif (c in '"\'' or c == 'r' and
243 243 program[pos:pos + 2] in ("r'", 'r"')): # handle quoted strings
244 244 if c == 'r':
245 245 pos += 1
246 246 c = program[pos]
247 247 decode = lambda x: x
248 248 else:
249 249 decode = parser.unescapestr
250 250 pos += 1
251 251 s = pos
252 252 while pos < l: # find closing quote
253 253 d = program[pos]
254 254 if d == '\\': # skip over escaped characters
255 255 pos += 2
256 256 continue
257 257 if d == c:
258 258 yield ('string', decode(program[s:pos]), s)
259 259 break
260 260 pos += 1
261 261 else:
262 262 raise error.ParseError(_("unterminated string"), s)
263 263 # gather up a symbol/keyword
264 264 elif c in syminitletters:
265 265 s = pos
266 266 pos += 1
267 267 while pos < l: # find end of symbol
268 268 d = program[pos]
269 269 if d not in symletters:
270 270 break
271 271 if d == '.' and program[pos - 1] == '.': # special case for ..
272 272 pos -= 1
273 273 break
274 274 pos += 1
275 275 sym = program[s:pos]
276 276 if sym in keywords: # operator keywords
277 277 yield (sym, None, s)
278 278 elif '-' in sym:
279 279 # some jerk gave us foo-bar-baz, try to check if it's a symbol
280 280 if lookup and lookup(sym):
281 281 # looks like a real symbol
282 282 yield ('symbol', sym, s)
283 283 else:
284 284 # looks like an expression
285 285 parts = sym.split('-')
286 286 for p in parts[:-1]:
287 287 if p: # possible consecutive -
288 288 yield ('symbol', p, s)
289 289 s += len(p)
290 290 yield ('-', None, pos)
291 291 s += 1
292 292 if parts[-1]: # possible trailing -
293 293 yield ('symbol', parts[-1], s)
294 294 else:
295 295 yield ('symbol', sym, s)
296 296 pos -= 1
297 297 else:
298 298 raise error.ParseError(_("syntax error in revset '%s'") %
299 299 program, pos)
300 300 pos += 1
301 301 yield ('end', None, pos)
302 302
303 303 # helpers
304 304
305 305 _notset = object()
306 306
307 307 def getsymbol(x):
308 308 if x and x[0] == 'symbol':
309 309 return x[1]
310 310 raise error.ParseError(_('not a symbol'))
311 311
312 312 def getstring(x, err):
313 313 if x and (x[0] == 'string' or x[0] == 'symbol'):
314 314 return x[1]
315 315 raise error.ParseError(err)
316 316
317 317 def getinteger(x, err, default=_notset):
318 318 if not x and default is not _notset:
319 319 return default
320 320 try:
321 321 return int(getstring(x, err))
322 322 except ValueError:
323 323 raise error.ParseError(err)
324 324
325 325 def getlist(x):
326 326 if not x:
327 327 return []
328 328 if x[0] == 'list':
329 329 return list(x[1:])
330 330 return [x]
331 331
332 332 def getargs(x, min, max, err):
333 333 l = getlist(x)
334 334 if len(l) < min or (max >= 0 and len(l) > max):
335 335 raise error.ParseError(err)
336 336 return l
337 337
338 338 def getargsdict(x, funcname, keys):
339 339 return parser.buildargsdict(getlist(x), funcname, parser.splitargspec(keys),
340 340 keyvaluenode='keyvalue', keynode='symbol')
341 341
342 342 def getset(repo, subset, x):
343 343 if not x:
344 344 raise error.ParseError(_("missing argument"))
345 345 s = methods[x[0]](repo, subset, *x[1:])
346 346 if util.safehasattr(s, 'isascending'):
347 347 return s
348 348 # else case should not happen, because all non-func are internal,
349 349 # ignoring for now.
350 350 if x[0] == 'func' and x[1][0] == 'symbol' and x[1][1] in symbols:
351 351 repo.ui.deprecwarn('revset "%s" uses list instead of smartset'
352 352 % x[1][1],
353 353 '3.9')
354 354 return baseset(s)
355 355
356 356 def _getrevsource(repo, r):
357 357 extra = repo[r].extra()
358 358 for label in ('source', 'transplant_source', 'rebase_source'):
359 359 if label in extra:
360 360 try:
361 361 return repo[extra[label]].rev()
362 362 except error.RepoLookupError:
363 363 pass
364 364 return None
365 365
366 366 # operator methods
367 367
368 368 def stringset(repo, subset, x):
369 369 x = repo[x].rev()
370 370 if (x in subset
371 371 or x == node.nullrev and isinstance(subset, fullreposet)):
372 372 return baseset([x])
373 373 return baseset()
374 374
375 375 def rangeset(repo, subset, x, y, order):
376 376 m = getset(repo, fullreposet(repo), x)
377 377 n = getset(repo, fullreposet(repo), y)
378 378
379 379 if not m or not n:
380 380 return baseset()
381 381 return _makerangeset(repo, subset, m.first(), n.last(), order)
382 382
383 def rangeall(repo, subset, x, order):
384 assert x is None
385 return _makerangeset(repo, subset, 0, len(repo) - 1, order)
386
383 387 def rangepre(repo, subset, y, order):
384 388 # ':y' can't be rewritten to '0:y' since '0' may be hidden
385 389 n = getset(repo, fullreposet(repo), y)
386 390 if not n:
387 391 return baseset()
388 392 return _makerangeset(repo, subset, 0, n.last(), order)
389 393
394 def rangepost(repo, subset, x, order):
395 m = getset(repo, fullreposet(repo), x)
396 if not m:
397 return baseset()
398 return _makerangeset(repo, subset, m.first(), len(repo) - 1, order)
399
390 400 def _makerangeset(repo, subset, m, n, order):
391 401 if m == n:
392 402 r = baseset([m])
393 403 elif n == node.wdirrev:
394 404 r = spanset(repo, m, len(repo)) + baseset([n])
395 405 elif m == node.wdirrev:
396 406 r = baseset([m]) + spanset(repo, len(repo) - 1, n - 1)
397 407 elif m < n:
398 408 r = spanset(repo, m, n + 1)
399 409 else:
400 410 r = spanset(repo, m, n - 1)
401 411
402 412 if order == defineorder:
403 413 return r & subset
404 414 else:
405 415 # carrying the sorting over when possible would be more efficient
406 416 return subset & r
407 417
408 418 def dagrange(repo, subset, x, y, order):
409 419 r = fullreposet(repo)
410 420 xs = reachableroots(repo, getset(repo, r, x), getset(repo, r, y),
411 421 includepath=True)
412 422 return subset & xs
413 423
414 424 def andset(repo, subset, x, y, order):
415 425 return getset(repo, getset(repo, subset, x), y)
416 426
417 427 def differenceset(repo, subset, x, y, order):
418 428 return getset(repo, subset, x) - getset(repo, subset, y)
419 429
420 430 def _orsetlist(repo, subset, xs):
421 431 assert xs
422 432 if len(xs) == 1:
423 433 return getset(repo, subset, xs[0])
424 434 p = len(xs) // 2
425 435 a = _orsetlist(repo, subset, xs[:p])
426 436 b = _orsetlist(repo, subset, xs[p:])
427 437 return a + b
428 438
429 439 def orset(repo, subset, x, order):
430 440 xs = getlist(x)
431 441 if order == followorder:
432 442 # slow path to take the subset order
433 443 return subset & _orsetlist(repo, fullreposet(repo), xs)
434 444 else:
435 445 return _orsetlist(repo, subset, xs)
436 446
437 447 def notset(repo, subset, x, order):
438 448 return subset - getset(repo, subset, x)
439 449
440 450 def listset(repo, subset, *xs):
441 451 raise error.ParseError(_("can't use a list in this context"),
442 452 hint=_('see hg help "revsets.x or y"'))
443 453
444 454 def keyvaluepair(repo, subset, k, v):
445 455 raise error.ParseError(_("can't use a key-value pair in this context"))
446 456
447 457 def func(repo, subset, a, b, order):
448 458 f = getsymbol(a)
449 459 if f in symbols:
450 460 func = symbols[f]
451 461 if getattr(func, '_takeorder', False):
452 462 return func(repo, subset, b, order)
453 463 return func(repo, subset, b)
454 464
455 465 keep = lambda fn: getattr(fn, '__doc__', None) is not None
456 466
457 467 syms = [s for (s, fn) in symbols.items() if keep(fn)]
458 468 raise error.UnknownIdentifier(f, syms)
459 469
460 470 # functions
461 471
462 472 # symbols are callables like:
463 473 # fn(repo, subset, x)
464 474 # with:
465 475 # repo - current repository instance
466 476 # subset - of revisions to be examined
467 477 # x - argument in tree form
468 478 symbols = {}
469 479
470 480 # symbols which can't be used for a DoS attack for any given input
471 481 # (e.g. those which accept regexes as plain strings shouldn't be included)
472 482 # functions that just return a lot of changesets (like all) don't count here
473 483 safesymbols = set()
474 484
475 485 predicate = registrar.revsetpredicate()
476 486
477 487 @predicate('_destupdate')
478 488 def _destupdate(repo, subset, x):
479 489 # experimental revset for update destination
480 490 args = getargsdict(x, 'limit', 'clean check')
481 491 return subset & baseset([destutil.destupdate(repo, **args)[0]])
482 492
483 493 @predicate('_destmerge')
484 494 def _destmerge(repo, subset, x):
485 495 # experimental revset for merge destination
486 496 sourceset = None
487 497 if x is not None:
488 498 sourceset = getset(repo, fullreposet(repo), x)
489 499 return subset & baseset([destutil.destmerge(repo, sourceset=sourceset)])
490 500
491 501 @predicate('adds(pattern)', safe=True)
492 502 def adds(repo, subset, x):
493 503 """Changesets that add a file matching pattern.
494 504
495 505 The pattern without explicit kind like ``glob:`` is expected to be
496 506 relative to the current directory and match against a file or a
497 507 directory.
498 508 """
499 509 # i18n: "adds" is a keyword
500 510 pat = getstring(x, _("adds requires a pattern"))
501 511 return checkstatus(repo, subset, pat, 1)
502 512
503 513 @predicate('ancestor(*changeset)', safe=True)
504 514 def ancestor(repo, subset, x):
505 515 """A greatest common ancestor of the changesets.
506 516
507 517 Accepts 0 or more changesets.
508 518 Will return empty list when passed no args.
509 519 Greatest common ancestor of a single changeset is that changeset.
510 520 """
511 521 # i18n: "ancestor" is a keyword
512 522 l = getlist(x)
513 523 rl = fullreposet(repo)
514 524 anc = None
515 525
516 526 # (getset(repo, rl, i) for i in l) generates a list of lists
517 527 for revs in (getset(repo, rl, i) for i in l):
518 528 for r in revs:
519 529 if anc is None:
520 530 anc = repo[r]
521 531 else:
522 532 anc = anc.ancestor(repo[r])
523 533
524 534 if anc is not None and anc.rev() in subset:
525 535 return baseset([anc.rev()])
526 536 return baseset()
527 537
528 538 def _ancestors(repo, subset, x, followfirst=False):
529 539 heads = getset(repo, fullreposet(repo), x)
530 540 if not heads:
531 541 return baseset()
532 542 s = _revancestors(repo, heads, followfirst)
533 543 return subset & s
534 544
535 545 @predicate('ancestors(set)', safe=True)
536 546 def ancestors(repo, subset, x):
537 547 """Changesets that are ancestors of a changeset in set.
538 548 """
539 549 return _ancestors(repo, subset, x)
540 550
541 551 @predicate('_firstancestors', safe=True)
542 552 def _firstancestors(repo, subset, x):
543 553 # ``_firstancestors(set)``
544 554 # Like ``ancestors(set)`` but follows only the first parents.
545 555 return _ancestors(repo, subset, x, followfirst=True)
546 556
547 557 def ancestorspec(repo, subset, x, n, order):
548 558 """``set~n``
549 559 Changesets that are the Nth ancestor (first parents only) of a changeset
550 560 in set.
551 561 """
552 562 n = getinteger(n, _("~ expects a number"))
553 563 ps = set()
554 564 cl = repo.changelog
555 565 for r in getset(repo, fullreposet(repo), x):
556 566 for i in range(n):
557 567 r = cl.parentrevs(r)[0]
558 568 ps.add(r)
559 569 return subset & ps
560 570
561 571 @predicate('author(string)', safe=True)
562 572 def author(repo, subset, x):
563 573 """Alias for ``user(string)``.
564 574 """
565 575 # i18n: "author" is a keyword
566 576 n = getstring(x, _("author requires a string"))
567 577 kind, pattern, matcher = _substringmatcher(n, casesensitive=False)
568 578 return subset.filter(lambda x: matcher(repo[x].user()),
569 579 condrepr=('<user %r>', n))
570 580
571 581 @predicate('bisect(string)', safe=True)
572 582 def bisect(repo, subset, x):
573 583 """Changesets marked in the specified bisect status:
574 584
575 585 - ``good``, ``bad``, ``skip``: csets explicitly marked as good/bad/skip
576 586 - ``goods``, ``bads`` : csets topologically good/bad
577 587 - ``range`` : csets taking part in the bisection
578 588 - ``pruned`` : csets that are goods, bads or skipped
579 589 - ``untested`` : csets whose fate is yet unknown
580 590 - ``ignored`` : csets ignored due to DAG topology
581 591 - ``current`` : the cset currently being bisected
582 592 """
583 593 # i18n: "bisect" is a keyword
584 594 status = getstring(x, _("bisect requires a string")).lower()
585 595 state = set(hbisect.get(repo, status))
586 596 return subset & state
587 597
588 598 # Backward-compatibility
589 599 # - no help entry so that we do not advertise it any more
590 600 @predicate('bisected', safe=True)
591 601 def bisected(repo, subset, x):
592 602 return bisect(repo, subset, x)
593 603
594 604 @predicate('bookmark([name])', safe=True)
595 605 def bookmark(repo, subset, x):
596 606 """The named bookmark or all bookmarks.
597 607
598 608 Pattern matching is supported for `name`. See :hg:`help revisions.patterns`.
599 609 """
600 610 # i18n: "bookmark" is a keyword
601 611 args = getargs(x, 0, 1, _('bookmark takes one or no arguments'))
602 612 if args:
603 613 bm = getstring(args[0],
604 614 # i18n: "bookmark" is a keyword
605 615 _('the argument to bookmark must be a string'))
606 616 kind, pattern, matcher = util.stringmatcher(bm)
607 617 bms = set()
608 618 if kind == 'literal':
609 619 bmrev = repo._bookmarks.get(pattern, None)
610 620 if not bmrev:
611 621 raise error.RepoLookupError(_("bookmark '%s' does not exist")
612 622 % pattern)
613 623 bms.add(repo[bmrev].rev())
614 624 else:
615 625 matchrevs = set()
616 626 for name, bmrev in repo._bookmarks.iteritems():
617 627 if matcher(name):
618 628 matchrevs.add(bmrev)
619 629 if not matchrevs:
620 630 raise error.RepoLookupError(_("no bookmarks exist"
621 631 " that match '%s'") % pattern)
622 632 for bmrev in matchrevs:
623 633 bms.add(repo[bmrev].rev())
624 634 else:
625 635 bms = set([repo[r].rev()
626 636 for r in repo._bookmarks.values()])
627 637 bms -= set([node.nullrev])
628 638 return subset & bms
629 639
630 640 @predicate('branch(string or set)', safe=True)
631 641 def branch(repo, subset, x):
632 642 """
633 643 All changesets belonging to the given branch or the branches of the given
634 644 changesets.
635 645
636 646 Pattern matching is supported for `string`. See
637 647 :hg:`help revisions.patterns`.
638 648 """
639 649 getbi = repo.revbranchcache().branchinfo
640 650
641 651 try:
642 652 b = getstring(x, '')
643 653 except error.ParseError:
644 654 # not a string, but another revspec, e.g. tip()
645 655 pass
646 656 else:
647 657 kind, pattern, matcher = util.stringmatcher(b)
648 658 if kind == 'literal':
649 659 # note: falls through to the revspec case if no branch with
650 660 # this name exists and pattern kind is not specified explicitly
651 661 if pattern in repo.branchmap():
652 662 return subset.filter(lambda r: matcher(getbi(r)[0]),
653 663 condrepr=('<branch %r>', b))
654 664 if b.startswith('literal:'):
655 665 raise error.RepoLookupError(_("branch '%s' does not exist")
656 666 % pattern)
657 667 else:
658 668 return subset.filter(lambda r: matcher(getbi(r)[0]),
659 669 condrepr=('<branch %r>', b))
660 670
661 671 s = getset(repo, fullreposet(repo), x)
662 672 b = set()
663 673 for r in s:
664 674 b.add(getbi(r)[0])
665 675 c = s.__contains__
666 676 return subset.filter(lambda r: c(r) or getbi(r)[0] in b,
667 677 condrepr=lambda: '<branch %r>' % sorted(b))
668 678
669 679 @predicate('bumped()', safe=True)
670 680 def bumped(repo, subset, x):
671 681 """Mutable changesets marked as successors of public changesets.
672 682
673 683 Only non-public and non-obsolete changesets can be `bumped`.
674 684 """
675 685 # i18n: "bumped" is a keyword
676 686 getargs(x, 0, 0, _("bumped takes no arguments"))
677 687 bumped = obsmod.getrevs(repo, 'bumped')
678 688 return subset & bumped
679 689
680 690 @predicate('bundle()', safe=True)
681 691 def bundle(repo, subset, x):
682 692 """Changesets in the bundle.
683 693
684 694 Bundle must be specified by the -R option."""
685 695
686 696 try:
687 697 bundlerevs = repo.changelog.bundlerevs
688 698 except AttributeError:
689 699 raise error.Abort(_("no bundle provided - specify with -R"))
690 700 return subset & bundlerevs
691 701
692 702 def checkstatus(repo, subset, pat, field):
693 703 hasset = matchmod.patkind(pat) == 'set'
694 704
695 705 mcache = [None]
696 706 def matches(x):
697 707 c = repo[x]
698 708 if not mcache[0] or hasset:
699 709 mcache[0] = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=c)
700 710 m = mcache[0]
701 711 fname = None
702 712 if not m.anypats() and len(m.files()) == 1:
703 713 fname = m.files()[0]
704 714 if fname is not None:
705 715 if fname not in c.files():
706 716 return False
707 717 else:
708 718 for f in c.files():
709 719 if m(f):
710 720 break
711 721 else:
712 722 return False
713 723 files = repo.status(c.p1().node(), c.node())[field]
714 724 if fname is not None:
715 725 if fname in files:
716 726 return True
717 727 else:
718 728 for f in files:
719 729 if m(f):
720 730 return True
721 731
722 732 return subset.filter(matches, condrepr=('<status[%r] %r>', field, pat))
723 733
724 734 def _children(repo, subset, parentset):
725 735 if not parentset:
726 736 return baseset()
727 737 cs = set()
728 738 pr = repo.changelog.parentrevs
729 739 minrev = parentset.min()
730 740 nullrev = node.nullrev
731 741 for r in subset:
732 742 if r <= minrev:
733 743 continue
734 744 p1, p2 = pr(r)
735 745 if p1 in parentset:
736 746 cs.add(r)
737 747 if p2 != nullrev and p2 in parentset:
738 748 cs.add(r)
739 749 return baseset(cs)
740 750
741 751 @predicate('children(set)', safe=True)
742 752 def children(repo, subset, x):
743 753 """Child changesets of changesets in set.
744 754 """
745 755 s = getset(repo, fullreposet(repo), x)
746 756 cs = _children(repo, subset, s)
747 757 return subset & cs
748 758
749 759 @predicate('closed()', safe=True)
750 760 def closed(repo, subset, x):
751 761 """Changeset is closed.
752 762 """
753 763 # i18n: "closed" is a keyword
754 764 getargs(x, 0, 0, _("closed takes no arguments"))
755 765 return subset.filter(lambda r: repo[r].closesbranch(),
756 766 condrepr='<branch closed>')
757 767
758 768 @predicate('contains(pattern)')
759 769 def contains(repo, subset, x):
760 770 """The revision's manifest contains a file matching pattern (but might not
761 771 modify it). See :hg:`help patterns` for information about file patterns.
762 772
763 773 The pattern without explicit kind like ``glob:`` is expected to be
764 774 relative to the current directory and match against a file exactly
765 775 for efficiency.
766 776 """
767 777 # i18n: "contains" is a keyword
768 778 pat = getstring(x, _("contains requires a pattern"))
769 779
770 780 def matches(x):
771 781 if not matchmod.patkind(pat):
772 782 pats = pathutil.canonpath(repo.root, repo.getcwd(), pat)
773 783 if pats in repo[x]:
774 784 return True
775 785 else:
776 786 c = repo[x]
777 787 m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=c)
778 788 for f in c.manifest():
779 789 if m(f):
780 790 return True
781 791 return False
782 792
783 793 return subset.filter(matches, condrepr=('<contains %r>', pat))
784 794
785 795 @predicate('converted([id])', safe=True)
786 796 def converted(repo, subset, x):
787 797 """Changesets converted from the given identifier in the old repository if
788 798 present, or all converted changesets if no identifier is specified.
789 799 """
790 800
791 801 # There is exactly no chance of resolving the revision, so do a simple
792 802 # string compare and hope for the best
793 803
794 804 rev = None
795 805 # i18n: "converted" is a keyword
796 806 l = getargs(x, 0, 1, _('converted takes one or no arguments'))
797 807 if l:
798 808 # i18n: "converted" is a keyword
799 809 rev = getstring(l[0], _('converted requires a revision'))
800 810
801 811 def _matchvalue(r):
802 812 source = repo[r].extra().get('convert_revision', None)
803 813 return source is not None and (rev is None or source.startswith(rev))
804 814
805 815 return subset.filter(lambda r: _matchvalue(r),
806 816 condrepr=('<converted %r>', rev))
807 817
808 818 @predicate('date(interval)', safe=True)
809 819 def date(repo, subset, x):
810 820 """Changesets within the interval, see :hg:`help dates`.
811 821 """
812 822 # i18n: "date" is a keyword
813 823 ds = getstring(x, _("date requires a string"))
814 824 dm = util.matchdate(ds)
815 825 return subset.filter(lambda x: dm(repo[x].date()[0]),
816 826 condrepr=('<date %r>', ds))
817 827
818 828 @predicate('desc(string)', safe=True)
819 829 def desc(repo, subset, x):
820 830 """Search commit message for string. The match is case-insensitive.
821 831
822 832 Pattern matching is supported for `string`. See
823 833 :hg:`help revisions.patterns`.
824 834 """
825 835 # i18n: "desc" is a keyword
826 836 ds = getstring(x, _("desc requires a string"))
827 837
828 838 kind, pattern, matcher = _substringmatcher(ds, casesensitive=False)
829 839
830 840 return subset.filter(lambda r: matcher(repo[r].description()),
831 841 condrepr=('<desc %r>', ds))
832 842
833 843 def _descendants(repo, subset, x, followfirst=False):
834 844 roots = getset(repo, fullreposet(repo), x)
835 845 if not roots:
836 846 return baseset()
837 847 s = _revdescendants(repo, roots, followfirst)
838 848
839 849 # Both sets need to be ascending in order to lazily return the union
840 850 # in the correct order.
841 851 base = subset & roots
842 852 desc = subset & s
843 853 result = base + desc
844 854 if subset.isascending():
845 855 result.sort()
846 856 elif subset.isdescending():
847 857 result.sort(reverse=True)
848 858 else:
849 859 result = subset & result
850 860 return result
851 861
852 862 @predicate('descendants(set)', safe=True)
853 863 def descendants(repo, subset, x):
854 864 """Changesets which are descendants of changesets in set.
855 865 """
856 866 return _descendants(repo, subset, x)
857 867
858 868 @predicate('_firstdescendants', safe=True)
859 869 def _firstdescendants(repo, subset, x):
860 870 # ``_firstdescendants(set)``
861 871 # Like ``descendants(set)`` but follows only the first parents.
862 872 return _descendants(repo, subset, x, followfirst=True)
863 873
864 874 @predicate('destination([set])', safe=True)
865 875 def destination(repo, subset, x):
866 876 """Changesets that were created by a graft, transplant or rebase operation,
867 877 with the given revisions specified as the source. Omitting the optional set
868 878 is the same as passing all().
869 879 """
870 880 if x is not None:
871 881 sources = getset(repo, fullreposet(repo), x)
872 882 else:
873 883 sources = fullreposet(repo)
874 884
875 885 dests = set()
876 886
877 887 # subset contains all of the possible destinations that can be returned, so
878 888 # iterate over them and see if their source(s) were provided in the arg set.
879 889 # Even if the immediate src of r is not in the arg set, src's source (or
880 890 # further back) may be. Scanning back further than the immediate src allows
881 891 # transitive transplants and rebases to yield the same results as transitive
882 892 # grafts.
883 893 for r in subset:
884 894 src = _getrevsource(repo, r)
885 895 lineage = None
886 896
887 897 while src is not None:
888 898 if lineage is None:
889 899 lineage = list()
890 900
891 901 lineage.append(r)
892 902
893 903 # The visited lineage is a match if the current source is in the arg
894 904 # set. Since every candidate dest is visited by way of iterating
895 905 # subset, any dests further back in the lineage will be tested by a
896 906 # different iteration over subset. Likewise, if the src was already
897 907 # selected, the current lineage can be selected without going back
898 908 # further.
899 909 if src in sources or src in dests:
900 910 dests.update(lineage)
901 911 break
902 912
903 913 r = src
904 914 src = _getrevsource(repo, r)
905 915
906 916 return subset.filter(dests.__contains__,
907 917 condrepr=lambda: '<destination %r>' % sorted(dests))
908 918
909 919 @predicate('divergent()', safe=True)
910 920 def divergent(repo, subset, x):
911 921 """
912 922 Final successors of changesets with an alternative set of final successors.
913 923 """
914 924 # i18n: "divergent" is a keyword
915 925 getargs(x, 0, 0, _("divergent takes no arguments"))
916 926 divergent = obsmod.getrevs(repo, 'divergent')
917 927 return subset & divergent
918 928
919 929 @predicate('extinct()', safe=True)
920 930 def extinct(repo, subset, x):
921 931 """Obsolete changesets with obsolete descendants only.
922 932 """
923 933 # i18n: "extinct" is a keyword
924 934 getargs(x, 0, 0, _("extinct takes no arguments"))
925 935 extincts = obsmod.getrevs(repo, 'extinct')
926 936 return subset & extincts
927 937
928 938 @predicate('extra(label, [value])', safe=True)
929 939 def extra(repo, subset, x):
930 940 """Changesets with the given label in the extra metadata, with the given
931 941 optional value.
932 942
933 943 Pattern matching is supported for `value`. See
934 944 :hg:`help revisions.patterns`.
935 945 """
936 946 args = getargsdict(x, 'extra', 'label value')
937 947 if 'label' not in args:
938 948 # i18n: "extra" is a keyword
939 949 raise error.ParseError(_('extra takes at least 1 argument'))
940 950 # i18n: "extra" is a keyword
941 951 label = getstring(args['label'], _('first argument to extra must be '
942 952 'a string'))
943 953 value = None
944 954
945 955 if 'value' in args:
946 956 # i18n: "extra" is a keyword
947 957 value = getstring(args['value'], _('second argument to extra must be '
948 958 'a string'))
949 959 kind, value, matcher = util.stringmatcher(value)
950 960
951 961 def _matchvalue(r):
952 962 extra = repo[r].extra()
953 963 return label in extra and (value is None or matcher(extra[label]))
954 964
955 965 return subset.filter(lambda r: _matchvalue(r),
956 966 condrepr=('<extra[%r] %r>', label, value))
957 967
958 968 @predicate('filelog(pattern)', safe=True)
959 969 def filelog(repo, subset, x):
960 970 """Changesets connected to the specified filelog.
961 971
962 972 For performance reasons, visits only revisions mentioned in the file-level
963 973 filelog, rather than filtering through all changesets (much faster, but
964 974 doesn't include deletes or duplicate changes). For a slower, more accurate
965 975 result, use ``file()``.
966 976
967 977 The pattern without explicit kind like ``glob:`` is expected to be
968 978 relative to the current directory and match against a file exactly
969 979 for efficiency.
970 980
971 981 If some linkrev points to revisions filtered by the current repoview, we'll
972 982 work around it to return a non-filtered value.
973 983 """
974 984
975 985 # i18n: "filelog" is a keyword
976 986 pat = getstring(x, _("filelog requires a pattern"))
977 987 s = set()
978 988 cl = repo.changelog
979 989
980 990 if not matchmod.patkind(pat):
981 991 f = pathutil.canonpath(repo.root, repo.getcwd(), pat)
982 992 files = [f]
983 993 else:
984 994 m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=repo[None])
985 995 files = (f for f in repo[None] if m(f))
986 996
987 997 for f in files:
988 998 fl = repo.file(f)
989 999 known = {}
990 1000 scanpos = 0
991 1001 for fr in list(fl):
992 1002 fn = fl.node(fr)
993 1003 if fn in known:
994 1004 s.add(known[fn])
995 1005 continue
996 1006
997 1007 lr = fl.linkrev(fr)
998 1008 if lr in cl:
999 1009 s.add(lr)
1000 1010 elif scanpos is not None:
1001 1011 # lowest matching changeset is filtered, scan further
1002 1012 # ahead in changelog
1003 1013 start = max(lr, scanpos) + 1
1004 1014 scanpos = None
1005 1015 for r in cl.revs(start):
1006 1016 # minimize parsing of non-matching entries
1007 1017 if f in cl.revision(r) and f in cl.readfiles(r):
1008 1018 try:
1009 1019 # try to use manifest delta fastpath
1010 1020 n = repo[r].filenode(f)
1011 1021 if n not in known:
1012 1022 if n == fn:
1013 1023 s.add(r)
1014 1024 scanpos = r
1015 1025 break
1016 1026 else:
1017 1027 known[n] = r
1018 1028 except error.ManifestLookupError:
1019 1029 # deletion in changelog
1020 1030 continue
1021 1031
1022 1032 return subset & s
1023 1033
1024 1034 @predicate('first(set, [n])', safe=True)
1025 1035 def first(repo, subset, x):
1026 1036 """An alias for limit().
1027 1037 """
1028 1038 return limit(repo, subset, x)
1029 1039
1030 1040 def _follow(repo, subset, x, name, followfirst=False):
1031 1041 l = getargs(x, 0, 2, _("%s takes no arguments or a pattern "
1032 1042 "and an optional revset") % name)
1033 1043 c = repo['.']
1034 1044 if l:
1035 1045 x = getstring(l[0], _("%s expected a pattern") % name)
1036 1046 rev = None
1037 1047 if len(l) >= 2:
1038 1048 revs = getset(repo, fullreposet(repo), l[1])
1039 1049 if len(revs) != 1:
1040 1050 raise error.RepoLookupError(
1041 1051 _("%s expected one starting revision") % name)
1042 1052 rev = revs.last()
1043 1053 c = repo[rev]
1044 1054 matcher = matchmod.match(repo.root, repo.getcwd(), [x],
1045 1055 ctx=repo[rev], default='path')
1046 1056
1047 1057 files = c.manifest().walk(matcher)
1048 1058
1049 1059 s = set()
1050 1060 for fname in files:
1051 1061 fctx = c[fname]
1052 1062 s = s.union(set(c.rev() for c in fctx.ancestors(followfirst)))
1053 1063 # include the revision responsible for the most recent version
1054 1064 s.add(fctx.introrev())
1055 1065 else:
1056 1066 s = _revancestors(repo, baseset([c.rev()]), followfirst)
1057 1067
1058 1068 return subset & s
1059 1069
1060 1070 @predicate('follow([pattern[, startrev]])', safe=True)
1061 1071 def follow(repo, subset, x):
1062 1072 """
1063 1073 An alias for ``::.`` (ancestors of the working directory's first parent).
1064 1074 If pattern is specified, the histories of files matching given
1065 1075 pattern in the revision given by startrev are followed, including copies.
1066 1076 """
1067 1077 return _follow(repo, subset, x, 'follow')
1068 1078
1069 1079 @predicate('_followfirst', safe=True)
1070 1080 def _followfirst(repo, subset, x):
1071 1081 # ``followfirst([pattern[, startrev]])``
1072 1082 # Like ``follow([pattern[, startrev]])`` but follows only the first parent
1073 1083 # of every revisions or files revisions.
1074 1084 return _follow(repo, subset, x, '_followfirst', followfirst=True)
1075 1085
1076 1086 @predicate('followlines(file, fromline, toline[, startrev=.])', safe=True)
1077 1087 def followlines(repo, subset, x):
1078 1088 """Changesets modifying `file` in line range ('fromline', 'toline').
1079 1089
1080 1090 Line range corresponds to 'file' content at 'startrev' and should hence be
1081 1091 consistent with file size. If startrev is not specified, working directory's
1082 1092 parent is used.
1083 1093 """
1084 1094 from . import context # avoid circular import issues
1085 1095
1086 1096 args = getargsdict(x, 'followlines', 'file *lines startrev')
1087 1097 if len(args['lines']) != 2:
1088 1098 raise error.ParseError(_("followlines takes at least three arguments"))
1089 1099
1090 1100 rev = '.'
1091 1101 if 'startrev' in args:
1092 1102 revs = getset(repo, fullreposet(repo), args['startrev'])
1093 1103 if len(revs) != 1:
1094 1104 raise error.ParseError(
1095 1105 _("followlines expects exactly one revision"))
1096 1106 rev = revs.last()
1097 1107
1098 1108 pat = getstring(args['file'], _("followlines requires a pattern"))
1099 1109 if not matchmod.patkind(pat):
1100 1110 fname = pathutil.canonpath(repo.root, repo.getcwd(), pat)
1101 1111 else:
1102 1112 m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=repo[rev])
1103 1113 files = [f for f in repo[rev] if m(f)]
1104 1114 if len(files) != 1:
1105 1115 raise error.ParseError(_("followlines expects exactly one file"))
1106 1116 fname = files[0]
1107 1117
1108 1118 fromline, toline = [getinteger(a, _("line range bounds must be integers"))
1109 1119 for a in args['lines']]
1110 1120 if toline - fromline < 0:
1111 1121 raise error.ParseError(_("line range must be positive"))
1112 1122 if fromline < 1:
1113 1123 raise error.ParseError(_("fromline must be strictly positive"))
1114 1124 fromline -= 1
1115 1125
1116 1126 fctx = repo[rev].filectx(fname)
1117 1127 revs = (c.rev() for c in context.blockancestors(fctx, fromline, toline))
1118 1128 return subset & generatorset(revs, iterasc=False)
1119 1129
1120 1130 @predicate('all()', safe=True)
1121 1131 def getall(repo, subset, x):
1122 1132 """All changesets, the same as ``0:tip``.
1123 1133 """
1124 1134 # i18n: "all" is a keyword
1125 1135 getargs(x, 0, 0, _("all takes no arguments"))
1126 1136 return subset & spanset(repo) # drop "null" if any
1127 1137
1128 1138 @predicate('grep(regex)')
1129 1139 def grep(repo, subset, x):
1130 1140 """Like ``keyword(string)`` but accepts a regex. Use ``grep(r'...')``
1131 1141 to ensure special escape characters are handled correctly. Unlike
1132 1142 ``keyword(string)``, the match is case-sensitive.
1133 1143 """
1134 1144 try:
1135 1145 # i18n: "grep" is a keyword
1136 1146 gr = re.compile(getstring(x, _("grep requires a string")))
1137 1147 except re.error as e:
1138 1148 raise error.ParseError(_('invalid match pattern: %s') % e)
1139 1149
1140 1150 def matches(x):
1141 1151 c = repo[x]
1142 1152 for e in c.files() + [c.user(), c.description()]:
1143 1153 if gr.search(e):
1144 1154 return True
1145 1155 return False
1146 1156
1147 1157 return subset.filter(matches, condrepr=('<grep %r>', gr.pattern))
1148 1158
1149 1159 @predicate('_matchfiles', safe=True)
1150 1160 def _matchfiles(repo, subset, x):
1151 1161 # _matchfiles takes a revset list of prefixed arguments:
1152 1162 #
1153 1163 # [p:foo, i:bar, x:baz]
1154 1164 #
1155 1165 # builds a match object from them and filters subset. Allowed
1156 1166 # prefixes are 'p:' for regular patterns, 'i:' for include
1157 1167 # patterns and 'x:' for exclude patterns. Use 'r:' prefix to pass
1158 1168 # a revision identifier, or the empty string to reference the
1159 1169 # working directory, from which the match object is
1160 1170 # initialized. Use 'd:' to set the default matching mode, default
1161 1171 # to 'glob'. At most one 'r:' and 'd:' argument can be passed.
1162 1172
1163 1173 l = getargs(x, 1, -1, "_matchfiles requires at least one argument")
1164 1174 pats, inc, exc = [], [], []
1165 1175 rev, default = None, None
1166 1176 for arg in l:
1167 1177 s = getstring(arg, "_matchfiles requires string arguments")
1168 1178 prefix, value = s[:2], s[2:]
1169 1179 if prefix == 'p:':
1170 1180 pats.append(value)
1171 1181 elif prefix == 'i:':
1172 1182 inc.append(value)
1173 1183 elif prefix == 'x:':
1174 1184 exc.append(value)
1175 1185 elif prefix == 'r:':
1176 1186 if rev is not None:
1177 1187 raise error.ParseError('_matchfiles expected at most one '
1178 1188 'revision')
1179 1189 if value != '': # empty means working directory; leave rev as None
1180 1190 rev = value
1181 1191 elif prefix == 'd:':
1182 1192 if default is not None:
1183 1193 raise error.ParseError('_matchfiles expected at most one '
1184 1194 'default mode')
1185 1195 default = value
1186 1196 else:
1187 1197 raise error.ParseError('invalid _matchfiles prefix: %s' % prefix)
1188 1198 if not default:
1189 1199 default = 'glob'
1190 1200
1191 1201 m = matchmod.match(repo.root, repo.getcwd(), pats, include=inc,
1192 1202 exclude=exc, ctx=repo[rev], default=default)
1193 1203
1194 1204 # This directly read the changelog data as creating changectx for all
1195 1205 # revisions is quite expensive.
1196 1206 getfiles = repo.changelog.readfiles
1197 1207 wdirrev = node.wdirrev
1198 1208 def matches(x):
1199 1209 if x == wdirrev:
1200 1210 files = repo[x].files()
1201 1211 else:
1202 1212 files = getfiles(x)
1203 1213 for f in files:
1204 1214 if m(f):
1205 1215 return True
1206 1216 return False
1207 1217
1208 1218 return subset.filter(matches,
1209 1219 condrepr=('<matchfiles patterns=%r, include=%r '
1210 1220 'exclude=%r, default=%r, rev=%r>',
1211 1221 pats, inc, exc, default, rev))
1212 1222
1213 1223 @predicate('file(pattern)', safe=True)
1214 1224 def hasfile(repo, subset, x):
1215 1225 """Changesets affecting files matched by pattern.
1216 1226
1217 1227 For a faster but less accurate result, consider using ``filelog()``
1218 1228 instead.
1219 1229
1220 1230 This predicate uses ``glob:`` as the default kind of pattern.
1221 1231 """
1222 1232 # i18n: "file" is a keyword
1223 1233 pat = getstring(x, _("file requires a pattern"))
1224 1234 return _matchfiles(repo, subset, ('string', 'p:' + pat))
1225 1235
1226 1236 @predicate('head()', safe=True)
1227 1237 def head(repo, subset, x):
1228 1238 """Changeset is a named branch head.
1229 1239 """
1230 1240 # i18n: "head" is a keyword
1231 1241 getargs(x, 0, 0, _("head takes no arguments"))
1232 1242 hs = set()
1233 1243 cl = repo.changelog
1234 1244 for ls in repo.branchmap().itervalues():
1235 1245 hs.update(cl.rev(h) for h in ls)
1236 1246 return subset & baseset(hs)
1237 1247
1238 1248 @predicate('heads(set)', safe=True)
1239 1249 def heads(repo, subset, x):
1240 1250 """Members of set with no children in set.
1241 1251 """
1242 1252 s = getset(repo, subset, x)
1243 1253 ps = parents(repo, subset, x)
1244 1254 return s - ps
1245 1255
1246 1256 @predicate('hidden()', safe=True)
1247 1257 def hidden(repo, subset, x):
1248 1258 """Hidden changesets.
1249 1259 """
1250 1260 # i18n: "hidden" is a keyword
1251 1261 getargs(x, 0, 0, _("hidden takes no arguments"))
1252 1262 hiddenrevs = repoview.filterrevs(repo, 'visible')
1253 1263 return subset & hiddenrevs
1254 1264
1255 1265 @predicate('keyword(string)', safe=True)
1256 1266 def keyword(repo, subset, x):
1257 1267 """Search commit message, user name, and names of changed files for
1258 1268 string. The match is case-insensitive.
1259 1269
1260 1270 For a regular expression or case sensitive search of these fields, use
1261 1271 ``grep(regex)``.
1262 1272 """
1263 1273 # i18n: "keyword" is a keyword
1264 1274 kw = encoding.lower(getstring(x, _("keyword requires a string")))
1265 1275
1266 1276 def matches(r):
1267 1277 c = repo[r]
1268 1278 return any(kw in encoding.lower(t)
1269 1279 for t in c.files() + [c.user(), c.description()])
1270 1280
1271 1281 return subset.filter(matches, condrepr=('<keyword %r>', kw))
1272 1282
1273 1283 @predicate('limit(set[, n[, offset]])', safe=True)
1274 1284 def limit(repo, subset, x):
1275 1285 """First n members of set, defaulting to 1, starting from offset.
1276 1286 """
1277 1287 args = getargsdict(x, 'limit', 'set n offset')
1278 1288 if 'set' not in args:
1279 1289 # i18n: "limit" is a keyword
1280 1290 raise error.ParseError(_("limit requires one to three arguments"))
1281 1291 # i18n: "limit" is a keyword
1282 1292 lim = getinteger(args.get('n'), _("limit expects a number"), default=1)
1283 1293 # i18n: "limit" is a keyword
1284 1294 ofs = getinteger(args.get('offset'), _("limit expects a number"), default=0)
1285 1295 if ofs < 0:
1286 1296 raise error.ParseError(_("negative offset"))
1287 1297 os = getset(repo, fullreposet(repo), args['set'])
1288 1298 result = []
1289 1299 it = iter(os)
1290 1300 for x in xrange(ofs):
1291 1301 y = next(it, None)
1292 1302 if y is None:
1293 1303 break
1294 1304 for x in xrange(lim):
1295 1305 y = next(it, None)
1296 1306 if y is None:
1297 1307 break
1298 1308 elif y in subset:
1299 1309 result.append(y)
1300 1310 return baseset(result, datarepr=('<limit n=%d, offset=%d, %r, %r>',
1301 1311 lim, ofs, subset, os))
1302 1312
1303 1313 @predicate('last(set, [n])', safe=True)
1304 1314 def last(repo, subset, x):
1305 1315 """Last n members of set, defaulting to 1.
1306 1316 """
1307 1317 # i18n: "last" is a keyword
1308 1318 l = getargs(x, 1, 2, _("last requires one or two arguments"))
1309 1319 lim = 1
1310 1320 if len(l) == 2:
1311 1321 # i18n: "last" is a keyword
1312 1322 lim = getinteger(l[1], _("last expects a number"))
1313 1323 os = getset(repo, fullreposet(repo), l[0])
1314 1324 os.reverse()
1315 1325 result = []
1316 1326 it = iter(os)
1317 1327 for x in xrange(lim):
1318 1328 y = next(it, None)
1319 1329 if y is None:
1320 1330 break
1321 1331 elif y in subset:
1322 1332 result.append(y)
1323 1333 return baseset(result, datarepr=('<last n=%d, %r, %r>', lim, subset, os))
1324 1334
1325 1335 @predicate('max(set)', safe=True)
1326 1336 def maxrev(repo, subset, x):
1327 1337 """Changeset with highest revision number in set.
1328 1338 """
1329 1339 os = getset(repo, fullreposet(repo), x)
1330 1340 try:
1331 1341 m = os.max()
1332 1342 if m in subset:
1333 1343 return baseset([m], datarepr=('<max %r, %r>', subset, os))
1334 1344 except ValueError:
1335 1345 # os.max() throws a ValueError when the collection is empty.
1336 1346 # Same as python's max().
1337 1347 pass
1338 1348 return baseset(datarepr=('<max %r, %r>', subset, os))
1339 1349
1340 1350 @predicate('merge()', safe=True)
1341 1351 def merge(repo, subset, x):
1342 1352 """Changeset is a merge changeset.
1343 1353 """
1344 1354 # i18n: "merge" is a keyword
1345 1355 getargs(x, 0, 0, _("merge takes no arguments"))
1346 1356 cl = repo.changelog
1347 1357 return subset.filter(lambda r: cl.parentrevs(r)[1] != -1,
1348 1358 condrepr='<merge>')
1349 1359
1350 1360 @predicate('branchpoint()', safe=True)
1351 1361 def branchpoint(repo, subset, x):
1352 1362 """Changesets with more than one child.
1353 1363 """
1354 1364 # i18n: "branchpoint" is a keyword
1355 1365 getargs(x, 0, 0, _("branchpoint takes no arguments"))
1356 1366 cl = repo.changelog
1357 1367 if not subset:
1358 1368 return baseset()
1359 1369 # XXX this should be 'parentset.min()' assuming 'parentset' is a smartset
1360 1370 # (and if it is not, it should.)
1361 1371 baserev = min(subset)
1362 1372 parentscount = [0]*(len(repo) - baserev)
1363 1373 for r in cl.revs(start=baserev + 1):
1364 1374 for p in cl.parentrevs(r):
1365 1375 if p >= baserev:
1366 1376 parentscount[p - baserev] += 1
1367 1377 return subset.filter(lambda r: parentscount[r - baserev] > 1,
1368 1378 condrepr='<branchpoint>')
1369 1379
1370 1380 @predicate('min(set)', safe=True)
1371 1381 def minrev(repo, subset, x):
1372 1382 """Changeset with lowest revision number in set.
1373 1383 """
1374 1384 os = getset(repo, fullreposet(repo), x)
1375 1385 try:
1376 1386 m = os.min()
1377 1387 if m in subset:
1378 1388 return baseset([m], datarepr=('<min %r, %r>', subset, os))
1379 1389 except ValueError:
1380 1390 # os.min() throws a ValueError when the collection is empty.
1381 1391 # Same as python's min().
1382 1392 pass
1383 1393 return baseset(datarepr=('<min %r, %r>', subset, os))
1384 1394
1385 1395 @predicate('modifies(pattern)', safe=True)
1386 1396 def modifies(repo, subset, x):
1387 1397 """Changesets modifying files matched by pattern.
1388 1398
1389 1399 The pattern without explicit kind like ``glob:`` is expected to be
1390 1400 relative to the current directory and match against a file or a
1391 1401 directory.
1392 1402 """
1393 1403 # i18n: "modifies" is a keyword
1394 1404 pat = getstring(x, _("modifies requires a pattern"))
1395 1405 return checkstatus(repo, subset, pat, 0)
1396 1406
1397 1407 @predicate('named(namespace)')
1398 1408 def named(repo, subset, x):
1399 1409 """The changesets in a given namespace.
1400 1410
1401 1411 Pattern matching is supported for `namespace`. See
1402 1412 :hg:`help revisions.patterns`.
1403 1413 """
1404 1414 # i18n: "named" is a keyword
1405 1415 args = getargs(x, 1, 1, _('named requires a namespace argument'))
1406 1416
1407 1417 ns = getstring(args[0],
1408 1418 # i18n: "named" is a keyword
1409 1419 _('the argument to named must be a string'))
1410 1420 kind, pattern, matcher = util.stringmatcher(ns)
1411 1421 namespaces = set()
1412 1422 if kind == 'literal':
1413 1423 if pattern not in repo.names:
1414 1424 raise error.RepoLookupError(_("namespace '%s' does not exist")
1415 1425 % ns)
1416 1426 namespaces.add(repo.names[pattern])
1417 1427 else:
1418 1428 for name, ns in repo.names.iteritems():
1419 1429 if matcher(name):
1420 1430 namespaces.add(ns)
1421 1431 if not namespaces:
1422 1432 raise error.RepoLookupError(_("no namespace exists"
1423 1433 " that match '%s'") % pattern)
1424 1434
1425 1435 names = set()
1426 1436 for ns in namespaces:
1427 1437 for name in ns.listnames(repo):
1428 1438 if name not in ns.deprecated:
1429 1439 names.update(repo[n].rev() for n in ns.nodes(repo, name))
1430 1440
1431 1441 names -= set([node.nullrev])
1432 1442 return subset & names
1433 1443
1434 1444 @predicate('id(string)', safe=True)
1435 1445 def node_(repo, subset, x):
1436 1446 """Revision non-ambiguously specified by the given hex string prefix.
1437 1447 """
1438 1448 # i18n: "id" is a keyword
1439 1449 l = getargs(x, 1, 1, _("id requires one argument"))
1440 1450 # i18n: "id" is a keyword
1441 1451 n = getstring(l[0], _("id requires a string"))
1442 1452 if len(n) == 40:
1443 1453 try:
1444 1454 rn = repo.changelog.rev(node.bin(n))
1445 1455 except (LookupError, TypeError):
1446 1456 rn = None
1447 1457 else:
1448 1458 rn = None
1449 1459 pm = repo.changelog._partialmatch(n)
1450 1460 if pm is not None:
1451 1461 rn = repo.changelog.rev(pm)
1452 1462
1453 1463 if rn is None:
1454 1464 return baseset()
1455 1465 result = baseset([rn])
1456 1466 return result & subset
1457 1467
1458 1468 @predicate('obsolete()', safe=True)
1459 1469 def obsolete(repo, subset, x):
1460 1470 """Mutable changeset with a newer version."""
1461 1471 # i18n: "obsolete" is a keyword
1462 1472 getargs(x, 0, 0, _("obsolete takes no arguments"))
1463 1473 obsoletes = obsmod.getrevs(repo, 'obsolete')
1464 1474 return subset & obsoletes
1465 1475
1466 1476 @predicate('only(set, [set])', safe=True)
1467 1477 def only(repo, subset, x):
1468 1478 """Changesets that are ancestors of the first set that are not ancestors
1469 1479 of any other head in the repo. If a second set is specified, the result
1470 1480 is ancestors of the first set that are not ancestors of the second set
1471 1481 (i.e. ::<set1> - ::<set2>).
1472 1482 """
1473 1483 cl = repo.changelog
1474 1484 # i18n: "only" is a keyword
1475 1485 args = getargs(x, 1, 2, _('only takes one or two arguments'))
1476 1486 include = getset(repo, fullreposet(repo), args[0])
1477 1487 if len(args) == 1:
1478 1488 if not include:
1479 1489 return baseset()
1480 1490
1481 1491 descendants = set(_revdescendants(repo, include, False))
1482 1492 exclude = [rev for rev in cl.headrevs()
1483 1493 if not rev in descendants and not rev in include]
1484 1494 else:
1485 1495 exclude = getset(repo, fullreposet(repo), args[1])
1486 1496
1487 1497 results = set(cl.findmissingrevs(common=exclude, heads=include))
1488 1498 # XXX we should turn this into a baseset instead of a set, smartset may do
1489 1499 # some optimizations from the fact this is a baseset.
1490 1500 return subset & results
1491 1501
1492 1502 @predicate('origin([set])', safe=True)
1493 1503 def origin(repo, subset, x):
1494 1504 """
1495 1505 Changesets that were specified as a source for the grafts, transplants or
1496 1506 rebases that created the given revisions. Omitting the optional set is the
1497 1507 same as passing all(). If a changeset created by these operations is itself
1498 1508 specified as a source for one of these operations, only the source changeset
1499 1509 for the first operation is selected.
1500 1510 """
1501 1511 if x is not None:
1502 1512 dests = getset(repo, fullreposet(repo), x)
1503 1513 else:
1504 1514 dests = fullreposet(repo)
1505 1515
1506 1516 def _firstsrc(rev):
1507 1517 src = _getrevsource(repo, rev)
1508 1518 if src is None:
1509 1519 return None
1510 1520
1511 1521 while True:
1512 1522 prev = _getrevsource(repo, src)
1513 1523
1514 1524 if prev is None:
1515 1525 return src
1516 1526 src = prev
1517 1527
1518 1528 o = set([_firstsrc(r) for r in dests])
1519 1529 o -= set([None])
1520 1530 # XXX we should turn this into a baseset instead of a set, smartset may do
1521 1531 # some optimizations from the fact this is a baseset.
1522 1532 return subset & o
1523 1533
1524 1534 @predicate('outgoing([path])', safe=True)
1525 1535 def outgoing(repo, subset, x):
1526 1536 """Changesets not found in the specified destination repository, or the
1527 1537 default push location.
1528 1538 """
1529 1539 # Avoid cycles.
1530 1540 from . import (
1531 1541 discovery,
1532 1542 hg,
1533 1543 )
1534 1544 # i18n: "outgoing" is a keyword
1535 1545 l = getargs(x, 0, 1, _("outgoing takes one or no arguments"))
1536 1546 # i18n: "outgoing" is a keyword
1537 1547 dest = l and getstring(l[0], _("outgoing requires a repository path")) or ''
1538 1548 dest = repo.ui.expandpath(dest or 'default-push', dest or 'default')
1539 1549 dest, branches = hg.parseurl(dest)
1540 1550 revs, checkout = hg.addbranchrevs(repo, repo, branches, [])
1541 1551 if revs:
1542 1552 revs = [repo.lookup(rev) for rev in revs]
1543 1553 other = hg.peer(repo, {}, dest)
1544 1554 repo.ui.pushbuffer()
1545 1555 outgoing = discovery.findcommonoutgoing(repo, other, onlyheads=revs)
1546 1556 repo.ui.popbuffer()
1547 1557 cl = repo.changelog
1548 1558 o = set([cl.rev(r) for r in outgoing.missing])
1549 1559 return subset & o
1550 1560
1551 1561 @predicate('p1([set])', safe=True)
1552 1562 def p1(repo, subset, x):
1553 1563 """First parent of changesets in set, or the working directory.
1554 1564 """
1555 1565 if x is None:
1556 1566 p = repo[x].p1().rev()
1557 1567 if p >= 0:
1558 1568 return subset & baseset([p])
1559 1569 return baseset()
1560 1570
1561 1571 ps = set()
1562 1572 cl = repo.changelog
1563 1573 for r in getset(repo, fullreposet(repo), x):
1564 1574 ps.add(cl.parentrevs(r)[0])
1565 1575 ps -= set([node.nullrev])
1566 1576 # XXX we should turn this into a baseset instead of a set, smartset may do
1567 1577 # some optimizations from the fact this is a baseset.
1568 1578 return subset & ps
1569 1579
1570 1580 @predicate('p2([set])', safe=True)
1571 1581 def p2(repo, subset, x):
1572 1582 """Second parent of changesets in set, or the working directory.
1573 1583 """
1574 1584 if x is None:
1575 1585 ps = repo[x].parents()
1576 1586 try:
1577 1587 p = ps[1].rev()
1578 1588 if p >= 0:
1579 1589 return subset & baseset([p])
1580 1590 return baseset()
1581 1591 except IndexError:
1582 1592 return baseset()
1583 1593
1584 1594 ps = set()
1585 1595 cl = repo.changelog
1586 1596 for r in getset(repo, fullreposet(repo), x):
1587 1597 ps.add(cl.parentrevs(r)[1])
1588 1598 ps -= set([node.nullrev])
1589 1599 # XXX we should turn this into a baseset instead of a set, smartset may do
1590 1600 # some optimizations from the fact this is a baseset.
1591 1601 return subset & ps
1592 1602
1593 1603 def parentpost(repo, subset, x, order):
1594 1604 return p1(repo, subset, x)
1595 1605
1596 1606 @predicate('parents([set])', safe=True)
1597 1607 def parents(repo, subset, x):
1598 1608 """
1599 1609 The set of all parents for all changesets in set, or the working directory.
1600 1610 """
1601 1611 if x is None:
1602 1612 ps = set(p.rev() for p in repo[x].parents())
1603 1613 else:
1604 1614 ps = set()
1605 1615 cl = repo.changelog
1606 1616 up = ps.update
1607 1617 parentrevs = cl.parentrevs
1608 1618 for r in getset(repo, fullreposet(repo), x):
1609 1619 if r == node.wdirrev:
1610 1620 up(p.rev() for p in repo[r].parents())
1611 1621 else:
1612 1622 up(parentrevs(r))
1613 1623 ps -= set([node.nullrev])
1614 1624 return subset & ps
1615 1625
1616 1626 def _phase(repo, subset, target):
1617 1627 """helper to select all rev in phase <target>"""
1618 1628 repo._phasecache.loadphaserevs(repo) # ensure phase's sets are loaded
1619 1629 if repo._phasecache._phasesets:
1620 1630 s = repo._phasecache._phasesets[target] - repo.changelog.filteredrevs
1621 1631 s = baseset(s)
1622 1632 s.sort() # set are non ordered, so we enforce ascending
1623 1633 return subset & s
1624 1634 else:
1625 1635 phase = repo._phasecache.phase
1626 1636 condition = lambda r: phase(repo, r) == target
1627 1637 return subset.filter(condition, condrepr=('<phase %r>', target),
1628 1638 cache=False)
1629 1639
1630 1640 @predicate('draft()', safe=True)
1631 1641 def draft(repo, subset, x):
1632 1642 """Changeset in draft phase."""
1633 1643 # i18n: "draft" is a keyword
1634 1644 getargs(x, 0, 0, _("draft takes no arguments"))
1635 1645 target = phases.draft
1636 1646 return _phase(repo, subset, target)
1637 1647
1638 1648 @predicate('secret()', safe=True)
1639 1649 def secret(repo, subset, x):
1640 1650 """Changeset in secret phase."""
1641 1651 # i18n: "secret" is a keyword
1642 1652 getargs(x, 0, 0, _("secret takes no arguments"))
1643 1653 target = phases.secret
1644 1654 return _phase(repo, subset, target)
1645 1655
1646 1656 def parentspec(repo, subset, x, n, order):
1647 1657 """``set^0``
1648 1658 The set.
1649 1659 ``set^1`` (or ``set^``), ``set^2``
1650 1660 First or second parent, respectively, of all changesets in set.
1651 1661 """
1652 1662 try:
1653 1663 n = int(n[1])
1654 1664 if n not in (0, 1, 2):
1655 1665 raise ValueError
1656 1666 except (TypeError, ValueError):
1657 1667 raise error.ParseError(_("^ expects a number 0, 1, or 2"))
1658 1668 ps = set()
1659 1669 cl = repo.changelog
1660 1670 for r in getset(repo, fullreposet(repo), x):
1661 1671 if n == 0:
1662 1672 ps.add(r)
1663 1673 elif n == 1:
1664 1674 ps.add(cl.parentrevs(r)[0])
1665 1675 elif n == 2:
1666 1676 parents = cl.parentrevs(r)
1667 1677 if parents[1] != node.nullrev:
1668 1678 ps.add(parents[1])
1669 1679 return subset & ps
1670 1680
1671 1681 @predicate('present(set)', safe=True)
1672 1682 def present(repo, subset, x):
1673 1683 """An empty set, if any revision in set isn't found; otherwise,
1674 1684 all revisions in set.
1675 1685
1676 1686 If any of specified revisions is not present in the local repository,
1677 1687 the query is normally aborted. But this predicate allows the query
1678 1688 to continue even in such cases.
1679 1689 """
1680 1690 try:
1681 1691 return getset(repo, subset, x)
1682 1692 except error.RepoLookupError:
1683 1693 return baseset()
1684 1694
1685 1695 # for internal use
1686 1696 @predicate('_notpublic', safe=True)
1687 1697 def _notpublic(repo, subset, x):
1688 1698 getargs(x, 0, 0, "_notpublic takes no arguments")
1689 1699 repo._phasecache.loadphaserevs(repo) # ensure phase's sets are loaded
1690 1700 if repo._phasecache._phasesets:
1691 1701 s = set()
1692 1702 for u in repo._phasecache._phasesets[1:]:
1693 1703 s.update(u)
1694 1704 s = baseset(s - repo.changelog.filteredrevs)
1695 1705 s.sort()
1696 1706 return subset & s
1697 1707 else:
1698 1708 phase = repo._phasecache.phase
1699 1709 target = phases.public
1700 1710 condition = lambda r: phase(repo, r) != target
1701 1711 return subset.filter(condition, condrepr=('<phase %r>', target),
1702 1712 cache=False)
1703 1713
1704 1714 @predicate('public()', safe=True)
1705 1715 def public(repo, subset, x):
1706 1716 """Changeset in public phase."""
1707 1717 # i18n: "public" is a keyword
1708 1718 getargs(x, 0, 0, _("public takes no arguments"))
1709 1719 phase = repo._phasecache.phase
1710 1720 target = phases.public
1711 1721 condition = lambda r: phase(repo, r) == target
1712 1722 return subset.filter(condition, condrepr=('<phase %r>', target),
1713 1723 cache=False)
1714 1724
1715 1725 @predicate('remote([id [,path]])', safe=True)
1716 1726 def remote(repo, subset, x):
1717 1727 """Local revision that corresponds to the given identifier in a
1718 1728 remote repository, if present. Here, the '.' identifier is a
1719 1729 synonym for the current local branch.
1720 1730 """
1721 1731
1722 1732 from . import hg # avoid start-up nasties
1723 1733 # i18n: "remote" is a keyword
1724 1734 l = getargs(x, 0, 2, _("remote takes zero, one, or two arguments"))
1725 1735
1726 1736 q = '.'
1727 1737 if len(l) > 0:
1728 1738 # i18n: "remote" is a keyword
1729 1739 q = getstring(l[0], _("remote requires a string id"))
1730 1740 if q == '.':
1731 1741 q = repo['.'].branch()
1732 1742
1733 1743 dest = ''
1734 1744 if len(l) > 1:
1735 1745 # i18n: "remote" is a keyword
1736 1746 dest = getstring(l[1], _("remote requires a repository path"))
1737 1747 dest = repo.ui.expandpath(dest or 'default')
1738 1748 dest, branches = hg.parseurl(dest)
1739 1749 revs, checkout = hg.addbranchrevs(repo, repo, branches, [])
1740 1750 if revs:
1741 1751 revs = [repo.lookup(rev) for rev in revs]
1742 1752 other = hg.peer(repo, {}, dest)
1743 1753 n = other.lookup(q)
1744 1754 if n in repo:
1745 1755 r = repo[n].rev()
1746 1756 if r in subset:
1747 1757 return baseset([r])
1748 1758 return baseset()
1749 1759
1750 1760 @predicate('removes(pattern)', safe=True)
1751 1761 def removes(repo, subset, x):
1752 1762 """Changesets which remove files matching pattern.
1753 1763
1754 1764 The pattern without explicit kind like ``glob:`` is expected to be
1755 1765 relative to the current directory and match against a file or a
1756 1766 directory.
1757 1767 """
1758 1768 # i18n: "removes" is a keyword
1759 1769 pat = getstring(x, _("removes requires a pattern"))
1760 1770 return checkstatus(repo, subset, pat, 2)
1761 1771
1762 1772 @predicate('rev(number)', safe=True)
1763 1773 def rev(repo, subset, x):
1764 1774 """Revision with the given numeric identifier.
1765 1775 """
1766 1776 # i18n: "rev" is a keyword
1767 1777 l = getargs(x, 1, 1, _("rev requires one argument"))
1768 1778 try:
1769 1779 # i18n: "rev" is a keyword
1770 1780 l = int(getstring(l[0], _("rev requires a number")))
1771 1781 except (TypeError, ValueError):
1772 1782 # i18n: "rev" is a keyword
1773 1783 raise error.ParseError(_("rev expects a number"))
1774 1784 if l not in repo.changelog and l != node.nullrev:
1775 1785 return baseset()
1776 1786 return subset & baseset([l])
1777 1787
1778 1788 @predicate('matching(revision [, field])', safe=True)
1779 1789 def matching(repo, subset, x):
1780 1790 """Changesets in which a given set of fields match the set of fields in the
1781 1791 selected revision or set.
1782 1792
1783 1793 To match more than one field pass the list of fields to match separated
1784 1794 by spaces (e.g. ``author description``).
1785 1795
1786 1796 Valid fields are most regular revision fields and some special fields.
1787 1797
1788 1798 Regular revision fields are ``description``, ``author``, ``branch``,
1789 1799 ``date``, ``files``, ``phase``, ``parents``, ``substate``, ``user``
1790 1800 and ``diff``.
1791 1801 Note that ``author`` and ``user`` are synonyms. ``diff`` refers to the
1792 1802 contents of the revision. Two revisions matching their ``diff`` will
1793 1803 also match their ``files``.
1794 1804
1795 1805 Special fields are ``summary`` and ``metadata``:
1796 1806 ``summary`` matches the first line of the description.
1797 1807 ``metadata`` is equivalent to matching ``description user date``
1798 1808 (i.e. it matches the main metadata fields).
1799 1809
1800 1810 ``metadata`` is the default field which is used when no fields are
1801 1811 specified. You can match more than one field at a time.
1802 1812 """
1803 1813 # i18n: "matching" is a keyword
1804 1814 l = getargs(x, 1, 2, _("matching takes 1 or 2 arguments"))
1805 1815
1806 1816 revs = getset(repo, fullreposet(repo), l[0])
1807 1817
1808 1818 fieldlist = ['metadata']
1809 1819 if len(l) > 1:
1810 1820 fieldlist = getstring(l[1],
1811 1821 # i18n: "matching" is a keyword
1812 1822 _("matching requires a string "
1813 1823 "as its second argument")).split()
1814 1824
1815 1825 # Make sure that there are no repeated fields,
1816 1826 # expand the 'special' 'metadata' field type
1817 1827 # and check the 'files' whenever we check the 'diff'
1818 1828 fields = []
1819 1829 for field in fieldlist:
1820 1830 if field == 'metadata':
1821 1831 fields += ['user', 'description', 'date']
1822 1832 elif field == 'diff':
1823 1833 # a revision matching the diff must also match the files
1824 1834 # since matching the diff is very costly, make sure to
1825 1835 # also match the files first
1826 1836 fields += ['files', 'diff']
1827 1837 else:
1828 1838 if field == 'author':
1829 1839 field = 'user'
1830 1840 fields.append(field)
1831 1841 fields = set(fields)
1832 1842 if 'summary' in fields and 'description' in fields:
1833 1843 # If a revision matches its description it also matches its summary
1834 1844 fields.discard('summary')
1835 1845
1836 1846 # We may want to match more than one field
1837 1847 # Not all fields take the same amount of time to be matched
1838 1848 # Sort the selected fields in order of increasing matching cost
1839 1849 fieldorder = ['phase', 'parents', 'user', 'date', 'branch', 'summary',
1840 1850 'files', 'description', 'substate', 'diff']
1841 1851 def fieldkeyfunc(f):
1842 1852 try:
1843 1853 return fieldorder.index(f)
1844 1854 except ValueError:
1845 1855 # assume an unknown field is very costly
1846 1856 return len(fieldorder)
1847 1857 fields = list(fields)
1848 1858 fields.sort(key=fieldkeyfunc)
1849 1859
1850 1860 # Each field will be matched with its own "getfield" function
1851 1861 # which will be added to the getfieldfuncs array of functions
1852 1862 getfieldfuncs = []
1853 1863 _funcs = {
1854 1864 'user': lambda r: repo[r].user(),
1855 1865 'branch': lambda r: repo[r].branch(),
1856 1866 'date': lambda r: repo[r].date(),
1857 1867 'description': lambda r: repo[r].description(),
1858 1868 'files': lambda r: repo[r].files(),
1859 1869 'parents': lambda r: repo[r].parents(),
1860 1870 'phase': lambda r: repo[r].phase(),
1861 1871 'substate': lambda r: repo[r].substate,
1862 1872 'summary': lambda r: repo[r].description().splitlines()[0],
1863 1873 'diff': lambda r: list(repo[r].diff(git=True),)
1864 1874 }
1865 1875 for info in fields:
1866 1876 getfield = _funcs.get(info, None)
1867 1877 if getfield is None:
1868 1878 raise error.ParseError(
1869 1879 # i18n: "matching" is a keyword
1870 1880 _("unexpected field name passed to matching: %s") % info)
1871 1881 getfieldfuncs.append(getfield)
1872 1882 # convert the getfield array of functions into a "getinfo" function
1873 1883 # which returns an array of field values (or a single value if there
1874 1884 # is only one field to match)
1875 1885 getinfo = lambda r: [f(r) for f in getfieldfuncs]
1876 1886
1877 1887 def matches(x):
1878 1888 for rev in revs:
1879 1889 target = getinfo(rev)
1880 1890 match = True
1881 1891 for n, f in enumerate(getfieldfuncs):
1882 1892 if target[n] != f(x):
1883 1893 match = False
1884 1894 if match:
1885 1895 return True
1886 1896 return False
1887 1897
1888 1898 return subset.filter(matches, condrepr=('<matching%r %r>', fields, revs))
1889 1899
1890 1900 @predicate('reverse(set)', safe=True, takeorder=True)
1891 1901 def reverse(repo, subset, x, order):
1892 1902 """Reverse order of set.
1893 1903 """
1894 1904 l = getset(repo, subset, x)
1895 1905 if order == defineorder:
1896 1906 l.reverse()
1897 1907 return l
1898 1908
1899 1909 @predicate('roots(set)', safe=True)
1900 1910 def roots(repo, subset, x):
1901 1911 """Changesets in set with no parent changeset in set.
1902 1912 """
1903 1913 s = getset(repo, fullreposet(repo), x)
1904 1914 parents = repo.changelog.parentrevs
1905 1915 def filter(r):
1906 1916 for p in parents(r):
1907 1917 if 0 <= p and p in s:
1908 1918 return False
1909 1919 return True
1910 1920 return subset & s.filter(filter, condrepr='<roots>')
1911 1921
1912 1922 _sortkeyfuncs = {
1913 1923 'rev': lambda c: c.rev(),
1914 1924 'branch': lambda c: c.branch(),
1915 1925 'desc': lambda c: c.description(),
1916 1926 'user': lambda c: c.user(),
1917 1927 'author': lambda c: c.user(),
1918 1928 'date': lambda c: c.date()[0],
1919 1929 }
1920 1930
1921 1931 def _getsortargs(x):
1922 1932 """Parse sort options into (set, [(key, reverse)], opts)"""
1923 1933 args = getargsdict(x, 'sort', 'set keys topo.firstbranch')
1924 1934 if 'set' not in args:
1925 1935 # i18n: "sort" is a keyword
1926 1936 raise error.ParseError(_('sort requires one or two arguments'))
1927 1937 keys = "rev"
1928 1938 if 'keys' in args:
1929 1939 # i18n: "sort" is a keyword
1930 1940 keys = getstring(args['keys'], _("sort spec must be a string"))
1931 1941
1932 1942 keyflags = []
1933 1943 for k in keys.split():
1934 1944 fk = k
1935 1945 reverse = (k[0] == '-')
1936 1946 if reverse:
1937 1947 k = k[1:]
1938 1948 if k not in _sortkeyfuncs and k != 'topo':
1939 1949 raise error.ParseError(_("unknown sort key %r") % fk)
1940 1950 keyflags.append((k, reverse))
1941 1951
1942 1952 if len(keyflags) > 1 and any(k == 'topo' for k, reverse in keyflags):
1943 1953 # i18n: "topo" is a keyword
1944 1954 raise error.ParseError(_('topo sort order cannot be combined '
1945 1955 'with other sort keys'))
1946 1956
1947 1957 opts = {}
1948 1958 if 'topo.firstbranch' in args:
1949 1959 if any(k == 'topo' for k, reverse in keyflags):
1950 1960 opts['topo.firstbranch'] = args['topo.firstbranch']
1951 1961 else:
1952 1962 # i18n: "topo" and "topo.firstbranch" are keywords
1953 1963 raise error.ParseError(_('topo.firstbranch can only be used '
1954 1964 'when using the topo sort key'))
1955 1965
1956 1966 return args['set'], keyflags, opts
1957 1967
1958 1968 @predicate('sort(set[, [-]key... [, ...]])', safe=True, takeorder=True)
1959 1969 def sort(repo, subset, x, order):
1960 1970 """Sort set by keys. The default sort order is ascending, specify a key
1961 1971 as ``-key`` to sort in descending order.
1962 1972
1963 1973 The keys can be:
1964 1974
1965 1975 - ``rev`` for the revision number,
1966 1976 - ``branch`` for the branch name,
1967 1977 - ``desc`` for the commit message (description),
1968 1978 - ``user`` for user name (``author`` can be used as an alias),
1969 1979 - ``date`` for the commit date
1970 1980 - ``topo`` for a reverse topographical sort
1971 1981
1972 1982 The ``topo`` sort order cannot be combined with other sort keys. This sort
1973 1983 takes one optional argument, ``topo.firstbranch``, which takes a revset that
1974 1984 specifies what topographical branches to prioritize in the sort.
1975 1985
1976 1986 """
1977 1987 s, keyflags, opts = _getsortargs(x)
1978 1988 revs = getset(repo, subset, s)
1979 1989
1980 1990 if not keyflags or order != defineorder:
1981 1991 return revs
1982 1992 if len(keyflags) == 1 and keyflags[0][0] == "rev":
1983 1993 revs.sort(reverse=keyflags[0][1])
1984 1994 return revs
1985 1995 elif keyflags[0][0] == "topo":
1986 1996 firstbranch = ()
1987 1997 if 'topo.firstbranch' in opts:
1988 1998 firstbranch = getset(repo, subset, opts['topo.firstbranch'])
1989 1999 revs = baseset(_toposort(revs, repo.changelog.parentrevs, firstbranch),
1990 2000 istopo=True)
1991 2001 if keyflags[0][1]:
1992 2002 revs.reverse()
1993 2003 return revs
1994 2004
1995 2005 # sort() is guaranteed to be stable
1996 2006 ctxs = [repo[r] for r in revs]
1997 2007 for k, reverse in reversed(keyflags):
1998 2008 ctxs.sort(key=_sortkeyfuncs[k], reverse=reverse)
1999 2009 return baseset([c.rev() for c in ctxs])
2000 2010
2001 2011 def _toposort(revs, parentsfunc, firstbranch=()):
2002 2012 """Yield revisions from heads to roots one (topo) branch at a time.
2003 2013
2004 2014 This function aims to be used by a graph generator that wishes to minimize
2005 2015 the number of parallel branches and their interleaving.
2006 2016
2007 2017 Example iteration order (numbers show the "true" order in a changelog):
2008 2018
2009 2019 o 4
2010 2020 |
2011 2021 o 1
2012 2022 |
2013 2023 | o 3
2014 2024 | |
2015 2025 | o 2
2016 2026 |/
2017 2027 o 0
2018 2028
2019 2029 Note that the ancestors of merges are understood by the current
2020 2030 algorithm to be on the same branch. This means no reordering will
2021 2031 occur behind a merge.
2022 2032 """
2023 2033
2024 2034 ### Quick summary of the algorithm
2025 2035 #
2026 2036 # This function is based around a "retention" principle. We keep revisions
2027 2037 # in memory until we are ready to emit a whole branch that immediately
2028 2038 # "merges" into an existing one. This reduces the number of parallel
2029 2039 # branches with interleaved revisions.
2030 2040 #
2031 2041 # During iteration revs are split into two groups:
2032 2042 # A) revision already emitted
2033 2043 # B) revision in "retention". They are stored as different subgroups.
2034 2044 #
2035 2045 # for each REV, we do the following logic:
2036 2046 #
2037 2047 # 1) if REV is a parent of (A), we will emit it. If there is a
2038 2048 # retention group ((B) above) that is blocked on REV being
2039 2049 # available, we emit all the revisions out of that retention
2040 2050 # group first.
2041 2051 #
2042 2052 # 2) else, we'll search for a subgroup in (B) awaiting for REV to be
2043 2053 # available, if such subgroup exist, we add REV to it and the subgroup is
2044 2054 # now awaiting for REV.parents() to be available.
2045 2055 #
2046 2056 # 3) finally if no such group existed in (B), we create a new subgroup.
2047 2057 #
2048 2058 #
2049 2059 # To bootstrap the algorithm, we emit the tipmost revision (which
2050 2060 # puts it in group (A) from above).
2051 2061
2052 2062 revs.sort(reverse=True)
2053 2063
2054 2064 # Set of parents of revision that have been emitted. They can be considered
2055 2065 # unblocked as the graph generator is already aware of them so there is no
2056 2066 # need to delay the revisions that reference them.
2057 2067 #
2058 2068 # If someone wants to prioritize a branch over the others, pre-filling this
2059 2069 # set will force all other branches to wait until this branch is ready to be
2060 2070 # emitted.
2061 2071 unblocked = set(firstbranch)
2062 2072
2063 2073 # list of groups waiting to be displayed, each group is defined by:
2064 2074 #
2065 2075 # (revs: lists of revs waiting to be displayed,
2066 2076 # blocked: set of that cannot be displayed before those in 'revs')
2067 2077 #
2068 2078 # The second value ('blocked') correspond to parents of any revision in the
2069 2079 # group ('revs') that is not itself contained in the group. The main idea
2070 2080 # of this algorithm is to delay as much as possible the emission of any
2071 2081 # revision. This means waiting for the moment we are about to display
2072 2082 # these parents to display the revs in a group.
2073 2083 #
2074 2084 # This first implementation is smart until it encounters a merge: it will
2075 2085 # emit revs as soon as any parent is about to be emitted and can grow an
2076 2086 # arbitrary number of revs in 'blocked'. In practice this mean we properly
2077 2087 # retains new branches but gives up on any special ordering for ancestors
2078 2088 # of merges. The implementation can be improved to handle this better.
2079 2089 #
2080 2090 # The first subgroup is special. It corresponds to all the revision that
2081 2091 # were already emitted. The 'revs' lists is expected to be empty and the
2082 2092 # 'blocked' set contains the parents revisions of already emitted revision.
2083 2093 #
2084 2094 # You could pre-seed the <parents> set of groups[0] to a specific
2085 2095 # changesets to select what the first emitted branch should be.
2086 2096 groups = [([], unblocked)]
2087 2097 pendingheap = []
2088 2098 pendingset = set()
2089 2099
2090 2100 heapq.heapify(pendingheap)
2091 2101 heappop = heapq.heappop
2092 2102 heappush = heapq.heappush
2093 2103 for currentrev in revs:
2094 2104 # Heap works with smallest element, we want highest so we invert
2095 2105 if currentrev not in pendingset:
2096 2106 heappush(pendingheap, -currentrev)
2097 2107 pendingset.add(currentrev)
2098 2108 # iterates on pending rev until after the current rev have been
2099 2109 # processed.
2100 2110 rev = None
2101 2111 while rev != currentrev:
2102 2112 rev = -heappop(pendingheap)
2103 2113 pendingset.remove(rev)
2104 2114
2105 2115 # Seek for a subgroup blocked, waiting for the current revision.
2106 2116 matching = [i for i, g in enumerate(groups) if rev in g[1]]
2107 2117
2108 2118 if matching:
2109 2119 # The main idea is to gather together all sets that are blocked
2110 2120 # on the same revision.
2111 2121 #
2112 2122 # Groups are merged when a common blocking ancestor is
2113 2123 # observed. For example, given two groups:
2114 2124 #
2115 2125 # revs [5, 4] waiting for 1
2116 2126 # revs [3, 2] waiting for 1
2117 2127 #
2118 2128 # These two groups will be merged when we process
2119 2129 # 1. In theory, we could have merged the groups when
2120 2130 # we added 2 to the group it is now in (we could have
2121 2131 # noticed the groups were both blocked on 1 then), but
2122 2132 # the way it works now makes the algorithm simpler.
2123 2133 #
2124 2134 # We also always keep the oldest subgroup first. We can
2125 2135 # probably improve the behavior by having the longest set
2126 2136 # first. That way, graph algorithms could minimise the length
2127 2137 # of parallel lines their drawing. This is currently not done.
2128 2138 targetidx = matching.pop(0)
2129 2139 trevs, tparents = groups[targetidx]
2130 2140 for i in matching:
2131 2141 gr = groups[i]
2132 2142 trevs.extend(gr[0])
2133 2143 tparents |= gr[1]
2134 2144 # delete all merged subgroups (except the one we kept)
2135 2145 # (starting from the last subgroup for performance and
2136 2146 # sanity reasons)
2137 2147 for i in reversed(matching):
2138 2148 del groups[i]
2139 2149 else:
2140 2150 # This is a new head. We create a new subgroup for it.
2141 2151 targetidx = len(groups)
2142 2152 groups.append(([], set([rev])))
2143 2153
2144 2154 gr = groups[targetidx]
2145 2155
2146 2156 # We now add the current nodes to this subgroups. This is done
2147 2157 # after the subgroup merging because all elements from a subgroup
2148 2158 # that relied on this rev must precede it.
2149 2159 #
2150 2160 # we also update the <parents> set to include the parents of the
2151 2161 # new nodes.
2152 2162 if rev == currentrev: # only display stuff in rev
2153 2163 gr[0].append(rev)
2154 2164 gr[1].remove(rev)
2155 2165 parents = [p for p in parentsfunc(rev) if p > node.nullrev]
2156 2166 gr[1].update(parents)
2157 2167 for p in parents:
2158 2168 if p not in pendingset:
2159 2169 pendingset.add(p)
2160 2170 heappush(pendingheap, -p)
2161 2171
2162 2172 # Look for a subgroup to display
2163 2173 #
2164 2174 # When unblocked is empty (if clause), we were not waiting for any
2165 2175 # revisions during the first iteration (if no priority was given) or
2166 2176 # if we emitted a whole disconnected set of the graph (reached a
2167 2177 # root). In that case we arbitrarily take the oldest known
2168 2178 # subgroup. The heuristic could probably be better.
2169 2179 #
2170 2180 # Otherwise (elif clause) if the subgroup is blocked on
2171 2181 # a revision we just emitted, we can safely emit it as
2172 2182 # well.
2173 2183 if not unblocked:
2174 2184 if len(groups) > 1: # display other subset
2175 2185 targetidx = 1
2176 2186 gr = groups[1]
2177 2187 elif not gr[1] & unblocked:
2178 2188 gr = None
2179 2189
2180 2190 if gr is not None:
2181 2191 # update the set of awaited revisions with the one from the
2182 2192 # subgroup
2183 2193 unblocked |= gr[1]
2184 2194 # output all revisions in the subgroup
2185 2195 for r in gr[0]:
2186 2196 yield r
2187 2197 # delete the subgroup that you just output
2188 2198 # unless it is groups[0] in which case you just empty it.
2189 2199 if targetidx:
2190 2200 del groups[targetidx]
2191 2201 else:
2192 2202 gr[0][:] = []
2193 2203 # Check if we have some subgroup waiting for revisions we are not going to
2194 2204 # iterate over
2195 2205 for g in groups:
2196 2206 for r in g[0]:
2197 2207 yield r
2198 2208
2199 2209 @predicate('subrepo([pattern])')
2200 2210 def subrepo(repo, subset, x):
2201 2211 """Changesets that add, modify or remove the given subrepo. If no subrepo
2202 2212 pattern is named, any subrepo changes are returned.
2203 2213 """
2204 2214 # i18n: "subrepo" is a keyword
2205 2215 args = getargs(x, 0, 1, _('subrepo takes at most one argument'))
2206 2216 pat = None
2207 2217 if len(args) != 0:
2208 2218 pat = getstring(args[0], _("subrepo requires a pattern"))
2209 2219
2210 2220 m = matchmod.exact(repo.root, repo.root, ['.hgsubstate'])
2211 2221
2212 2222 def submatches(names):
2213 2223 k, p, m = util.stringmatcher(pat)
2214 2224 for name in names:
2215 2225 if m(name):
2216 2226 yield name
2217 2227
2218 2228 def matches(x):
2219 2229 c = repo[x]
2220 2230 s = repo.status(c.p1().node(), c.node(), match=m)
2221 2231
2222 2232 if pat is None:
2223 2233 return s.added or s.modified or s.removed
2224 2234
2225 2235 if s.added:
2226 2236 return any(submatches(c.substate.keys()))
2227 2237
2228 2238 if s.modified:
2229 2239 subs = set(c.p1().substate.keys())
2230 2240 subs.update(c.substate.keys())
2231 2241
2232 2242 for path in submatches(subs):
2233 2243 if c.p1().substate.get(path) != c.substate.get(path):
2234 2244 return True
2235 2245
2236 2246 if s.removed:
2237 2247 return any(submatches(c.p1().substate.keys()))
2238 2248
2239 2249 return False
2240 2250
2241 2251 return subset.filter(matches, condrepr=('<subrepo %r>', pat))
2242 2252
2243 2253 def _substringmatcher(pattern, casesensitive=True):
2244 2254 kind, pattern, matcher = util.stringmatcher(pattern,
2245 2255 casesensitive=casesensitive)
2246 2256 if kind == 'literal':
2247 2257 if not casesensitive:
2248 2258 pattern = encoding.lower(pattern)
2249 2259 matcher = lambda s: pattern in encoding.lower(s)
2250 2260 else:
2251 2261 matcher = lambda s: pattern in s
2252 2262 return kind, pattern, matcher
2253 2263
2254 2264 @predicate('tag([name])', safe=True)
2255 2265 def tag(repo, subset, x):
2256 2266 """The specified tag by name, or all tagged revisions if no name is given.
2257 2267
2258 2268 Pattern matching is supported for `name`. See
2259 2269 :hg:`help revisions.patterns`.
2260 2270 """
2261 2271 # i18n: "tag" is a keyword
2262 2272 args = getargs(x, 0, 1, _("tag takes one or no arguments"))
2263 2273 cl = repo.changelog
2264 2274 if args:
2265 2275 pattern = getstring(args[0],
2266 2276 # i18n: "tag" is a keyword
2267 2277 _('the argument to tag must be a string'))
2268 2278 kind, pattern, matcher = util.stringmatcher(pattern)
2269 2279 if kind == 'literal':
2270 2280 # avoid resolving all tags
2271 2281 tn = repo._tagscache.tags.get(pattern, None)
2272 2282 if tn is None:
2273 2283 raise error.RepoLookupError(_("tag '%s' does not exist")
2274 2284 % pattern)
2275 2285 s = set([repo[tn].rev()])
2276 2286 else:
2277 2287 s = set([cl.rev(n) for t, n in repo.tagslist() if matcher(t)])
2278 2288 else:
2279 2289 s = set([cl.rev(n) for t, n in repo.tagslist() if t != 'tip'])
2280 2290 return subset & s
2281 2291
2282 2292 @predicate('tagged', safe=True)
2283 2293 def tagged(repo, subset, x):
2284 2294 return tag(repo, subset, x)
2285 2295
2286 2296 @predicate('unstable()', safe=True)
2287 2297 def unstable(repo, subset, x):
2288 2298 """Non-obsolete changesets with obsolete ancestors.
2289 2299 """
2290 2300 # i18n: "unstable" is a keyword
2291 2301 getargs(x, 0, 0, _("unstable takes no arguments"))
2292 2302 unstables = obsmod.getrevs(repo, 'unstable')
2293 2303 return subset & unstables
2294 2304
2295 2305
2296 2306 @predicate('user(string)', safe=True)
2297 2307 def user(repo, subset, x):
2298 2308 """User name contains string. The match is case-insensitive.
2299 2309
2300 2310 Pattern matching is supported for `string`. See
2301 2311 :hg:`help revisions.patterns`.
2302 2312 """
2303 2313 return author(repo, subset, x)
2304 2314
2305 2315 @predicate('wdir', safe=True)
2306 2316 def wdir(repo, subset, x):
2307 2317 """Working directory. (EXPERIMENTAL)"""
2308 2318 # i18n: "wdir" is a keyword
2309 2319 getargs(x, 0, 0, _("wdir takes no arguments"))
2310 2320 if node.wdirrev in subset or isinstance(subset, fullreposet):
2311 2321 return baseset([node.wdirrev])
2312 2322 return baseset()
2313 2323
2314 2324 def _orderedlist(repo, subset, x):
2315 2325 s = getstring(x, "internal error")
2316 2326 if not s:
2317 2327 return baseset()
2318 2328 # remove duplicates here. it's difficult for caller to deduplicate sets
2319 2329 # because different symbols can point to the same rev.
2320 2330 cl = repo.changelog
2321 2331 ls = []
2322 2332 seen = set()
2323 2333 for t in s.split('\0'):
2324 2334 try:
2325 2335 # fast path for integer revision
2326 2336 r = int(t)
2327 2337 if str(r) != t or r not in cl:
2328 2338 raise ValueError
2329 2339 revs = [r]
2330 2340 except ValueError:
2331 2341 revs = stringset(repo, subset, t)
2332 2342
2333 2343 for r in revs:
2334 2344 if r in seen:
2335 2345 continue
2336 2346 if (r in subset
2337 2347 or r == node.nullrev and isinstance(subset, fullreposet)):
2338 2348 ls.append(r)
2339 2349 seen.add(r)
2340 2350 return baseset(ls)
2341 2351
2342 2352 # for internal use
2343 2353 @predicate('_list', safe=True, takeorder=True)
2344 2354 def _list(repo, subset, x, order):
2345 2355 if order == followorder:
2346 2356 # slow path to take the subset order
2347 2357 return subset & _orderedlist(repo, fullreposet(repo), x)
2348 2358 else:
2349 2359 return _orderedlist(repo, subset, x)
2350 2360
2351 2361 def _orderedintlist(repo, subset, x):
2352 2362 s = getstring(x, "internal error")
2353 2363 if not s:
2354 2364 return baseset()
2355 2365 ls = [int(r) for r in s.split('\0')]
2356 2366 s = subset
2357 2367 return baseset([r for r in ls if r in s])
2358 2368
2359 2369 # for internal use
2360 2370 @predicate('_intlist', safe=True, takeorder=True)
2361 2371 def _intlist(repo, subset, x, order):
2362 2372 if order == followorder:
2363 2373 # slow path to take the subset order
2364 2374 return subset & _orderedintlist(repo, fullreposet(repo), x)
2365 2375 else:
2366 2376 return _orderedintlist(repo, subset, x)
2367 2377
2368 2378 def _orderedhexlist(repo, subset, x):
2369 2379 s = getstring(x, "internal error")
2370 2380 if not s:
2371 2381 return baseset()
2372 2382 cl = repo.changelog
2373 2383 ls = [cl.rev(node.bin(r)) for r in s.split('\0')]
2374 2384 s = subset
2375 2385 return baseset([r for r in ls if r in s])
2376 2386
2377 2387 # for internal use
2378 2388 @predicate('_hexlist', safe=True, takeorder=True)
2379 2389 def _hexlist(repo, subset, x, order):
2380 2390 if order == followorder:
2381 2391 # slow path to take the subset order
2382 2392 return subset & _orderedhexlist(repo, fullreposet(repo), x)
2383 2393 else:
2384 2394 return _orderedhexlist(repo, subset, x)
2385 2395
2386 2396 methods = {
2387 2397 "range": rangeset,
2398 "rangeall": rangeall,
2388 2399 "rangepre": rangepre,
2400 "rangepost": rangepost,
2389 2401 "dagrange": dagrange,
2390 2402 "string": stringset,
2391 2403 "symbol": stringset,
2392 2404 "and": andset,
2393 2405 "or": orset,
2394 2406 "not": notset,
2395 2407 "difference": differenceset,
2396 2408 "list": listset,
2397 2409 "keyvalue": keyvaluepair,
2398 2410 "func": func,
2399 2411 "ancestor": ancestorspec,
2400 2412 "parent": parentspec,
2401 2413 "parentpost": parentpost,
2402 2414 }
2403 2415
2404 2416 # Constants for ordering requirement, used in _analyze():
2405 2417 #
2406 2418 # If 'define', any nested functions and operations can change the ordering of
2407 2419 # the entries in the set. If 'follow', any nested functions and operations
2408 2420 # should take the ordering specified by the first operand to the '&' operator.
2409 2421 #
2410 2422 # For instance,
2411 2423 #
2412 2424 # X & (Y | Z)
2413 2425 # ^ ^^^^^^^
2414 2426 # | follow
2415 2427 # define
2416 2428 #
2417 2429 # will be evaluated as 'or(y(x()), z(x()))', where 'x()' can change the order
2418 2430 # of the entries in the set, but 'y()', 'z()' and 'or()' shouldn't.
2419 2431 #
2420 2432 # 'any' means the order doesn't matter. For instance,
2421 2433 #
2422 2434 # X & !Y
2423 2435 # ^
2424 2436 # any
2425 2437 #
2426 2438 # 'y()' can either enforce its ordering requirement or take the ordering
2427 2439 # specified by 'x()' because 'not()' doesn't care the order.
2428 2440 #
2429 2441 # Transition of ordering requirement:
2430 2442 #
2431 2443 # 1. starts with 'define'
2432 2444 # 2. shifts to 'follow' by 'x & y'
2433 2445 # 3. changes back to 'define' on function call 'f(x)' or function-like
2434 2446 # operation 'x (f) y' because 'f' may have its own ordering requirement
2435 2447 # for 'x' and 'y' (e.g. 'first(x)')
2436 2448 #
2437 2449 anyorder = 'any' # don't care the order
2438 2450 defineorder = 'define' # should define the order
2439 2451 followorder = 'follow' # must follow the current order
2440 2452
2441 2453 # transition table for 'x & y', from the current expression 'x' to 'y'
2442 2454 _tofolloworder = {
2443 2455 anyorder: anyorder,
2444 2456 defineorder: followorder,
2445 2457 followorder: followorder,
2446 2458 }
2447 2459
2448 2460 def _matchonly(revs, bases):
2449 2461 """
2450 2462 >>> f = lambda *args: _matchonly(*map(parse, args))
2451 2463 >>> f('ancestors(A)', 'not ancestors(B)')
2452 2464 ('list', ('symbol', 'A'), ('symbol', 'B'))
2453 2465 """
2454 2466 if (revs is not None
2455 2467 and revs[0] == 'func'
2456 2468 and getsymbol(revs[1]) == 'ancestors'
2457 2469 and bases is not None
2458 2470 and bases[0] == 'not'
2459 2471 and bases[1][0] == 'func'
2460 2472 and getsymbol(bases[1][1]) == 'ancestors'):
2461 2473 return ('list', revs[2], bases[1][2])
2462 2474
2463 2475 def _fixops(x):
2464 2476 """Rewrite raw parsed tree to resolve ambiguous syntax which cannot be
2465 2477 handled well by our simple top-down parser"""
2466 2478 if not isinstance(x, tuple):
2467 2479 return x
2468 2480
2469 2481 op = x[0]
2470 2482 if op == 'parent':
2471 2483 # x^:y means (x^) : y, not x ^ (:y)
2472 2484 # x^: means (x^) :, not x ^ (:)
2473 2485 post = ('parentpost', x[1])
2474 2486 if x[2][0] == 'dagrangepre':
2475 2487 return _fixops(('dagrange', post, x[2][1]))
2476 2488 elif x[2][0] == 'rangepre':
2477 2489 return _fixops(('range', post, x[2][1]))
2478 2490 elif x[2][0] == 'rangeall':
2479 2491 return _fixops(('rangepost', post))
2480 2492 elif op == 'or':
2481 2493 # make number of arguments deterministic:
2482 2494 # x + y + z -> (or x y z) -> (or (list x y z))
2483 2495 return (op, _fixops(('list',) + x[1:]))
2484 2496
2485 2497 return (op,) + tuple(_fixops(y) for y in x[1:])
2486 2498
2487 2499 def _analyze(x, order):
2488 2500 if x is None:
2489 2501 return x
2490 2502
2491 2503 op = x[0]
2492 2504 if op == 'minus':
2493 2505 return _analyze(('and', x[1], ('not', x[2])), order)
2494 2506 elif op == 'only':
2495 2507 t = ('func', ('symbol', 'only'), ('list', x[1], x[2]))
2496 2508 return _analyze(t, order)
2497 2509 elif op == 'onlypost':
2498 2510 return _analyze(('func', ('symbol', 'only'), x[1]), order)
2499 2511 elif op == 'dagrangepre':
2500 2512 return _analyze(('func', ('symbol', 'ancestors'), x[1]), order)
2501 2513 elif op == 'dagrangepost':
2502 2514 return _analyze(('func', ('symbol', 'descendants'), x[1]), order)
2503 elif op == 'rangeall':
2504 return _analyze(('rangepre', ('string', 'tip')), order)
2505 elif op == 'rangepost':
2506 return _analyze(('range', x[1], ('string', 'tip')), order)
2507 2515 elif op == 'negate':
2508 2516 s = getstring(x[1], _("can't negate that"))
2509 2517 return _analyze(('string', '-' + s), order)
2510 2518 elif op in ('string', 'symbol'):
2511 2519 return x
2512 2520 elif op == 'and':
2513 2521 ta = _analyze(x[1], order)
2514 2522 tb = _analyze(x[2], _tofolloworder[order])
2515 2523 return (op, ta, tb, order)
2516 2524 elif op == 'or':
2517 2525 return (op, _analyze(x[1], order), order)
2518 2526 elif op == 'not':
2519 2527 return (op, _analyze(x[1], anyorder), order)
2520 elif op in ('rangepre', 'parentpost'):
2528 elif op == 'rangeall':
2529 return (op, None, order)
2530 elif op in ('rangepre', 'rangepost', 'parentpost'):
2521 2531 return (op, _analyze(x[1], defineorder), order)
2522 2532 elif op == 'group':
2523 2533 return _analyze(x[1], order)
2524 2534 elif op in ('dagrange', 'range', 'parent', 'ancestor'):
2525 2535 ta = _analyze(x[1], defineorder)
2526 2536 tb = _analyze(x[2], defineorder)
2527 2537 return (op, ta, tb, order)
2528 2538 elif op == 'list':
2529 2539 return (op,) + tuple(_analyze(y, order) for y in x[1:])
2530 2540 elif op == 'keyvalue':
2531 2541 return (op, x[1], _analyze(x[2], order))
2532 2542 elif op == 'func':
2533 2543 f = getsymbol(x[1])
2534 2544 d = defineorder
2535 2545 if f == 'present':
2536 2546 # 'present(set)' is known to return the argument set with no
2537 2547 # modification, so forward the current order to its argument
2538 2548 d = order
2539 2549 return (op, x[1], _analyze(x[2], d), order)
2540 2550 raise ValueError('invalid operator %r' % op)
2541 2551
2542 2552 def analyze(x, order=defineorder):
2543 2553 """Transform raw parsed tree to evaluatable tree which can be fed to
2544 2554 optimize() or getset()
2545 2555
2546 2556 All pseudo operations should be mapped to real operations or functions
2547 2557 defined in methods or symbols table respectively.
2548 2558
2549 2559 'order' specifies how the current expression 'x' is ordered (see the
2550 2560 constants defined above.)
2551 2561 """
2552 2562 return _analyze(x, order)
2553 2563
2554 2564 def _optimize(x, small):
2555 2565 if x is None:
2556 2566 return 0, x
2557 2567
2558 2568 smallbonus = 1
2559 2569 if small:
2560 2570 smallbonus = .5
2561 2571
2562 2572 op = x[0]
2563 2573 if op in ('string', 'symbol'):
2564 2574 return smallbonus, x # single revisions are small
2565 2575 elif op == 'and':
2566 2576 wa, ta = _optimize(x[1], True)
2567 2577 wb, tb = _optimize(x[2], True)
2568 2578 order = x[3]
2569 2579 w = min(wa, wb)
2570 2580
2571 2581 # (::x and not ::y)/(not ::y and ::x) have a fast path
2572 2582 tm = _matchonly(ta, tb) or _matchonly(tb, ta)
2573 2583 if tm:
2574 2584 return w, ('func', ('symbol', 'only'), tm, order)
2575 2585
2576 2586 if tb is not None and tb[0] == 'not':
2577 2587 return wa, ('difference', ta, tb[1], order)
2578 2588
2579 2589 if wa > wb:
2580 2590 return w, (op, tb, ta, order)
2581 2591 return w, (op, ta, tb, order)
2582 2592 elif op == 'or':
2583 2593 # fast path for machine-generated expression, that is likely to have
2584 2594 # lots of trivial revisions: 'a + b + c()' to '_list(a b) + c()'
2585 2595 order = x[2]
2586 2596 ws, ts, ss = [], [], []
2587 2597 def flushss():
2588 2598 if not ss:
2589 2599 return
2590 2600 if len(ss) == 1:
2591 2601 w, t = ss[0]
2592 2602 else:
2593 2603 s = '\0'.join(t[1] for w, t in ss)
2594 2604 y = ('func', ('symbol', '_list'), ('string', s), order)
2595 2605 w, t = _optimize(y, False)
2596 2606 ws.append(w)
2597 2607 ts.append(t)
2598 2608 del ss[:]
2599 2609 for y in getlist(x[1]):
2600 2610 w, t = _optimize(y, False)
2601 2611 if t is not None and (t[0] == 'string' or t[0] == 'symbol'):
2602 2612 ss.append((w, t))
2603 2613 continue
2604 2614 flushss()
2605 2615 ws.append(w)
2606 2616 ts.append(t)
2607 2617 flushss()
2608 2618 if len(ts) == 1:
2609 2619 return ws[0], ts[0] # 'or' operation is fully optimized out
2610 2620 # we can't reorder trees by weight because it would change the order.
2611 2621 # ("sort(a + b)" == "sort(b + a)", but "a + b" != "b + a")
2612 2622 # ts = tuple(t for w, t in sorted(zip(ws, ts), key=lambda wt: wt[0]))
2613 2623 return max(ws), (op, ('list',) + tuple(ts), order)
2614 2624 elif op == 'not':
2615 2625 # Optimize not public() to _notpublic() because we have a fast version
2616 2626 if x[1][:3] == ('func', ('symbol', 'public'), None):
2617 2627 order = x[1][3]
2618 2628 newsym = ('func', ('symbol', '_notpublic'), None, order)
2619 2629 o = _optimize(newsym, not small)
2620 2630 return o[0], o[1]
2621 2631 else:
2622 2632 o = _optimize(x[1], not small)
2623 2633 order = x[2]
2624 2634 return o[0], (op, o[1], order)
2625 elif op in ('rangepre', 'parentpost'):
2635 elif op == 'rangeall':
2636 return smallbonus, x
2637 elif op in ('rangepre', 'rangepost', 'parentpost'):
2626 2638 o = _optimize(x[1], small)
2627 2639 order = x[2]
2628 2640 return o[0], (op, o[1], order)
2629 2641 elif op in ('dagrange', 'range', 'parent', 'ancestor'):
2630 2642 wa, ta = _optimize(x[1], small)
2631 2643 wb, tb = _optimize(x[2], small)
2632 2644 order = x[3]
2633 2645 return wa + wb, (op, ta, tb, order)
2634 2646 elif op == 'list':
2635 2647 ws, ts = zip(*(_optimize(y, small) for y in x[1:]))
2636 2648 return sum(ws), (op,) + ts
2637 2649 elif op == 'keyvalue':
2638 2650 w, t = _optimize(x[2], small)
2639 2651 return w, (op, x[1], t)
2640 2652 elif op == 'func':
2641 2653 f = getsymbol(x[1])
2642 2654 wa, ta = _optimize(x[2], small)
2643 2655 if f in ('author', 'branch', 'closed', 'date', 'desc', 'file', 'grep',
2644 2656 'keyword', 'outgoing', 'user', 'destination'):
2645 2657 w = 10 # slow
2646 2658 elif f in ('modifies', 'adds', 'removes'):
2647 2659 w = 30 # slower
2648 2660 elif f == "contains":
2649 2661 w = 100 # very slow
2650 2662 elif f == "ancestor":
2651 2663 w = 1 * smallbonus
2652 2664 elif f in ('reverse', 'limit', 'first', 'wdir', '_intlist'):
2653 2665 w = 0
2654 2666 elif f == "sort":
2655 2667 w = 10 # assume most sorts look at changelog
2656 2668 else:
2657 2669 w = 1
2658 2670 order = x[3]
2659 2671 return w + wa, (op, x[1], ta, order)
2660 2672 raise ValueError('invalid operator %r' % op)
2661 2673
2662 2674 def optimize(tree):
2663 2675 """Optimize evaluatable tree
2664 2676
2665 2677 All pseudo operations should be transformed beforehand.
2666 2678 """
2667 2679 _weight, newtree = _optimize(tree, small=True)
2668 2680 return newtree
2669 2681
2670 2682 # the set of valid characters for the initial letter of symbols in
2671 2683 # alias declarations and definitions
2672 2684 _aliassyminitletters = _syminitletters | set(pycompat.sysstr('$'))
2673 2685
2674 2686 def _parsewith(spec, lookup=None, syminitletters=None):
2675 2687 """Generate a parse tree of given spec with given tokenizing options
2676 2688
2677 2689 >>> _parsewith('foo($1)', syminitletters=_aliassyminitletters)
2678 2690 ('func', ('symbol', 'foo'), ('symbol', '$1'))
2679 2691 >>> _parsewith('$1')
2680 2692 Traceback (most recent call last):
2681 2693 ...
2682 2694 ParseError: ("syntax error in revset '$1'", 0)
2683 2695 >>> _parsewith('foo bar')
2684 2696 Traceback (most recent call last):
2685 2697 ...
2686 2698 ParseError: ('invalid token', 4)
2687 2699 """
2688 2700 p = parser.parser(elements)
2689 2701 tree, pos = p.parse(tokenize(spec, lookup=lookup,
2690 2702 syminitletters=syminitletters))
2691 2703 if pos != len(spec):
2692 2704 raise error.ParseError(_('invalid token'), pos)
2693 2705 return _fixops(parser.simplifyinfixops(tree, ('list', 'or')))
2694 2706
2695 2707 class _aliasrules(parser.basealiasrules):
2696 2708 """Parsing and expansion rule set of revset aliases"""
2697 2709 _section = _('revset alias')
2698 2710
2699 2711 @staticmethod
2700 2712 def _parse(spec):
2701 2713 """Parse alias declaration/definition ``spec``
2702 2714
2703 2715 This allows symbol names to use also ``$`` as an initial letter
2704 2716 (for backward compatibility), and callers of this function should
2705 2717 examine whether ``$`` is used also for unexpected symbols or not.
2706 2718 """
2707 2719 return _parsewith(spec, syminitletters=_aliassyminitletters)
2708 2720
2709 2721 @staticmethod
2710 2722 def _trygetfunc(tree):
2711 2723 if tree[0] == 'func' and tree[1][0] == 'symbol':
2712 2724 return tree[1][1], getlist(tree[2])
2713 2725
2714 2726 def expandaliases(ui, tree):
2715 2727 aliases = _aliasrules.buildmap(ui.configitems('revsetalias'))
2716 2728 tree = _aliasrules.expand(aliases, tree)
2717 2729 # warn about problematic (but not referred) aliases
2718 2730 for name, alias in sorted(aliases.iteritems()):
2719 2731 if alias.error and not alias.warned:
2720 2732 ui.warn(_('warning: %s\n') % (alias.error))
2721 2733 alias.warned = True
2722 2734 return tree
2723 2735
2724 2736 def foldconcat(tree):
2725 2737 """Fold elements to be concatenated by `##`
2726 2738 """
2727 2739 if not isinstance(tree, tuple) or tree[0] in ('string', 'symbol'):
2728 2740 return tree
2729 2741 if tree[0] == '_concat':
2730 2742 pending = [tree]
2731 2743 l = []
2732 2744 while pending:
2733 2745 e = pending.pop()
2734 2746 if e[0] == '_concat':
2735 2747 pending.extend(reversed(e[1:]))
2736 2748 elif e[0] in ('string', 'symbol'):
2737 2749 l.append(e[1])
2738 2750 else:
2739 2751 msg = _("\"##\" can't concatenate \"%s\" element") % (e[0])
2740 2752 raise error.ParseError(msg)
2741 2753 return ('string', ''.join(l))
2742 2754 else:
2743 2755 return tuple(foldconcat(t) for t in tree)
2744 2756
2745 2757 def parse(spec, lookup=None):
2746 2758 return _parsewith(spec, lookup=lookup)
2747 2759
2748 2760 def posttreebuilthook(tree, repo):
2749 2761 # hook for extensions to execute code on the optimized tree
2750 2762 pass
2751 2763
2752 2764 def match(ui, spec, repo=None, order=defineorder):
2753 2765 """Create a matcher for a single revision spec
2754 2766
2755 2767 If order=followorder, a matcher takes the ordering specified by the input
2756 2768 set.
2757 2769 """
2758 2770 return matchany(ui, [spec], repo=repo, order=order)
2759 2771
2760 2772 def matchany(ui, specs, repo=None, order=defineorder):
2761 2773 """Create a matcher that will include any revisions matching one of the
2762 2774 given specs
2763 2775
2764 2776 If order=followorder, a matcher takes the ordering specified by the input
2765 2777 set.
2766 2778 """
2767 2779 if not specs:
2768 2780 def mfunc(repo, subset=None):
2769 2781 return baseset()
2770 2782 return mfunc
2771 2783 if not all(specs):
2772 2784 raise error.ParseError(_("empty query"))
2773 2785 lookup = None
2774 2786 if repo:
2775 2787 lookup = repo.__contains__
2776 2788 if len(specs) == 1:
2777 2789 tree = parse(specs[0], lookup)
2778 2790 else:
2779 2791 tree = ('or', ('list',) + tuple(parse(s, lookup) for s in specs))
2780 2792
2781 2793 if ui:
2782 2794 tree = expandaliases(ui, tree)
2783 2795 tree = foldconcat(tree)
2784 2796 tree = analyze(tree, order)
2785 2797 tree = optimize(tree)
2786 2798 posttreebuilthook(tree, repo)
2787 2799 return makematcher(tree)
2788 2800
2789 2801 def makematcher(tree):
2790 2802 """Create a matcher from an evaluatable tree"""
2791 2803 def mfunc(repo, subset=None):
2792 2804 if subset is None:
2793 2805 subset = fullreposet(repo)
2794 2806 if util.safehasattr(subset, 'isascending'):
2795 2807 result = getset(repo, subset, tree)
2796 2808 else:
2797 2809 result = getset(repo, baseset(subset), tree)
2798 2810 return result
2799 2811 return mfunc
2800 2812
2801 2813 def formatspec(expr, *args):
2802 2814 '''
2803 2815 This is a convenience function for using revsets internally, and
2804 2816 escapes arguments appropriately. Aliases are intentionally ignored
2805 2817 so that intended expression behavior isn't accidentally subverted.
2806 2818
2807 2819 Supported arguments:
2808 2820
2809 2821 %r = revset expression, parenthesized
2810 2822 %d = int(arg), no quoting
2811 2823 %s = string(arg), escaped and single-quoted
2812 2824 %b = arg.branch(), escaped and single-quoted
2813 2825 %n = hex(arg), single-quoted
2814 2826 %% = a literal '%'
2815 2827
2816 2828 Prefixing the type with 'l' specifies a parenthesized list of that type.
2817 2829
2818 2830 >>> formatspec('%r:: and %lr', '10 or 11', ("this()", "that()"))
2819 2831 '(10 or 11):: and ((this()) or (that()))'
2820 2832 >>> formatspec('%d:: and not %d::', 10, 20)
2821 2833 '10:: and not 20::'
2822 2834 >>> formatspec('%ld or %ld', [], [1])
2823 2835 "_list('') or 1"
2824 2836 >>> formatspec('keyword(%s)', 'foo\\xe9')
2825 2837 "keyword('foo\\\\xe9')"
2826 2838 >>> b = lambda: 'default'
2827 2839 >>> b.branch = b
2828 2840 >>> formatspec('branch(%b)', b)
2829 2841 "branch('default')"
2830 2842 >>> formatspec('root(%ls)', ['a', 'b', 'c', 'd'])
2831 2843 "root(_list('a\\x00b\\x00c\\x00d'))"
2832 2844 '''
2833 2845
2834 2846 def quote(s):
2835 2847 return repr(str(s))
2836 2848
2837 2849 def argtype(c, arg):
2838 2850 if c == 'd':
2839 2851 return str(int(arg))
2840 2852 elif c == 's':
2841 2853 return quote(arg)
2842 2854 elif c == 'r':
2843 2855 parse(arg) # make sure syntax errors are confined
2844 2856 return '(%s)' % arg
2845 2857 elif c == 'n':
2846 2858 return quote(node.hex(arg))
2847 2859 elif c == 'b':
2848 2860 return quote(arg.branch())
2849 2861
2850 2862 def listexp(s, t):
2851 2863 l = len(s)
2852 2864 if l == 0:
2853 2865 return "_list('')"
2854 2866 elif l == 1:
2855 2867 return argtype(t, s[0])
2856 2868 elif t == 'd':
2857 2869 return "_intlist('%s')" % "\0".join(str(int(a)) for a in s)
2858 2870 elif t == 's':
2859 2871 return "_list('%s')" % "\0".join(s)
2860 2872 elif t == 'n':
2861 2873 return "_hexlist('%s')" % "\0".join(node.hex(a) for a in s)
2862 2874 elif t == 'b':
2863 2875 return "_list('%s')" % "\0".join(a.branch() for a in s)
2864 2876
2865 2877 m = l // 2
2866 2878 return '(%s or %s)' % (listexp(s[:m], t), listexp(s[m:], t))
2867 2879
2868 2880 ret = ''
2869 2881 pos = 0
2870 2882 arg = 0
2871 2883 while pos < len(expr):
2872 2884 c = expr[pos]
2873 2885 if c == '%':
2874 2886 pos += 1
2875 2887 d = expr[pos]
2876 2888 if d == '%':
2877 2889 ret += d
2878 2890 elif d in 'dsnbr':
2879 2891 ret += argtype(d, args[arg])
2880 2892 arg += 1
2881 2893 elif d == 'l':
2882 2894 # a list of some type
2883 2895 pos += 1
2884 2896 d = expr[pos]
2885 2897 ret += listexp(list(args[arg]), d)
2886 2898 arg += 1
2887 2899 else:
2888 2900 raise error.Abort(_('unexpected revspec format character %s')
2889 2901 % d)
2890 2902 else:
2891 2903 ret += c
2892 2904 pos += 1
2893 2905
2894 2906 return ret
2895 2907
2896 2908 def prettyformat(tree):
2897 2909 return parser.prettyformat(tree, ('string', 'symbol'))
2898 2910
2899 2911 def depth(tree):
2900 2912 if isinstance(tree, tuple):
2901 2913 return max(map(depth, tree)) + 1
2902 2914 else:
2903 2915 return 0
2904 2916
2905 2917 def funcsused(tree):
2906 2918 if not isinstance(tree, tuple) or tree[0] in ('string', 'symbol'):
2907 2919 return set()
2908 2920 else:
2909 2921 funcs = set()
2910 2922 for s in tree[1:]:
2911 2923 funcs |= funcsused(s)
2912 2924 if tree[0] == 'func':
2913 2925 funcs.add(tree[1][1])
2914 2926 return funcs
2915 2927
2916 2928 def _formatsetrepr(r):
2917 2929 """Format an optional printable representation of a set
2918 2930
2919 2931 ======== =================================
2920 2932 type(r) example
2921 2933 ======== =================================
2922 2934 tuple ('<not %r>', other)
2923 2935 str '<branch closed>'
2924 2936 callable lambda: '<branch %r>' % sorted(b)
2925 2937 object other
2926 2938 ======== =================================
2927 2939 """
2928 2940 if r is None:
2929 2941 return ''
2930 2942 elif isinstance(r, tuple):
2931 2943 return r[0] % r[1:]
2932 2944 elif isinstance(r, str):
2933 2945 return r
2934 2946 elif callable(r):
2935 2947 return r()
2936 2948 else:
2937 2949 return repr(r)
2938 2950
2939 2951 class abstractsmartset(object):
2940 2952
2941 2953 def __nonzero__(self):
2942 2954 """True if the smartset is not empty"""
2943 2955 raise NotImplementedError()
2944 2956
2945 2957 def __contains__(self, rev):
2946 2958 """provide fast membership testing"""
2947 2959 raise NotImplementedError()
2948 2960
2949 2961 def __iter__(self):
2950 2962 """iterate the set in the order it is supposed to be iterated"""
2951 2963 raise NotImplementedError()
2952 2964
2953 2965 # Attributes containing a function to perform a fast iteration in a given
2954 2966 # direction. A smartset can have none, one, or both defined.
2955 2967 #
2956 2968 # Default value is None instead of a function returning None to avoid
2957 2969 # initializing an iterator just for testing if a fast method exists.
2958 2970 fastasc = None
2959 2971 fastdesc = None
2960 2972
2961 2973 def isascending(self):
2962 2974 """True if the set will iterate in ascending order"""
2963 2975 raise NotImplementedError()
2964 2976
2965 2977 def isdescending(self):
2966 2978 """True if the set will iterate in descending order"""
2967 2979 raise NotImplementedError()
2968 2980
2969 2981 def istopo(self):
2970 2982 """True if the set will iterate in topographical order"""
2971 2983 raise NotImplementedError()
2972 2984
2973 2985 def min(self):
2974 2986 """return the minimum element in the set"""
2975 2987 if self.fastasc is None:
2976 2988 v = min(self)
2977 2989 else:
2978 2990 for v in self.fastasc():
2979 2991 break
2980 2992 else:
2981 2993 raise ValueError('arg is an empty sequence')
2982 2994 self.min = lambda: v
2983 2995 return v
2984 2996
2985 2997 def max(self):
2986 2998 """return the maximum element in the set"""
2987 2999 if self.fastdesc is None:
2988 3000 return max(self)
2989 3001 else:
2990 3002 for v in self.fastdesc():
2991 3003 break
2992 3004 else:
2993 3005 raise ValueError('arg is an empty sequence')
2994 3006 self.max = lambda: v
2995 3007 return v
2996 3008
2997 3009 def first(self):
2998 3010 """return the first element in the set (user iteration perspective)
2999 3011
3000 3012 Return None if the set is empty"""
3001 3013 raise NotImplementedError()
3002 3014
3003 3015 def last(self):
3004 3016 """return the last element in the set (user iteration perspective)
3005 3017
3006 3018 Return None if the set is empty"""
3007 3019 raise NotImplementedError()
3008 3020
3009 3021 def __len__(self):
3010 3022 """return the length of the smartsets
3011 3023
3012 3024 This can be expensive on smartset that could be lazy otherwise."""
3013 3025 raise NotImplementedError()
3014 3026
3015 3027 def reverse(self):
3016 3028 """reverse the expected iteration order"""
3017 3029 raise NotImplementedError()
3018 3030
3019 3031 def sort(self, reverse=True):
3020 3032 """get the set to iterate in an ascending or descending order"""
3021 3033 raise NotImplementedError()
3022 3034
3023 3035 def __and__(self, other):
3024 3036 """Returns a new object with the intersection of the two collections.
3025 3037
3026 3038 This is part of the mandatory API for smartset."""
3027 3039 if isinstance(other, fullreposet):
3028 3040 return self
3029 3041 return self.filter(other.__contains__, condrepr=other, cache=False)
3030 3042
3031 3043 def __add__(self, other):
3032 3044 """Returns a new object with the union of the two collections.
3033 3045
3034 3046 This is part of the mandatory API for smartset."""
3035 3047 return addset(self, other)
3036 3048
3037 3049 def __sub__(self, other):
3038 3050 """Returns a new object with the substraction of the two collections.
3039 3051
3040 3052 This is part of the mandatory API for smartset."""
3041 3053 c = other.__contains__
3042 3054 return self.filter(lambda r: not c(r), condrepr=('<not %r>', other),
3043 3055 cache=False)
3044 3056
3045 3057 def filter(self, condition, condrepr=None, cache=True):
3046 3058 """Returns this smartset filtered by condition as a new smartset.
3047 3059
3048 3060 `condition` is a callable which takes a revision number and returns a
3049 3061 boolean. Optional `condrepr` provides a printable representation of
3050 3062 the given `condition`.
3051 3063
3052 3064 This is part of the mandatory API for smartset."""
3053 3065 # builtin cannot be cached. but do not needs to
3054 3066 if cache and util.safehasattr(condition, 'func_code'):
3055 3067 condition = util.cachefunc(condition)
3056 3068 return filteredset(self, condition, condrepr)
3057 3069
3058 3070 class baseset(abstractsmartset):
3059 3071 """Basic data structure that represents a revset and contains the basic
3060 3072 operation that it should be able to perform.
3061 3073
3062 3074 Every method in this class should be implemented by any smartset class.
3063 3075 """
3064 3076 def __init__(self, data=(), datarepr=None, istopo=False):
3065 3077 """
3066 3078 datarepr: a tuple of (format, obj, ...), a function or an object that
3067 3079 provides a printable representation of the given data.
3068 3080 """
3069 3081 self._ascending = None
3070 3082 self._istopo = istopo
3071 3083 if not isinstance(data, list):
3072 3084 if isinstance(data, set):
3073 3085 self._set = data
3074 3086 # set has no order we pick one for stability purpose
3075 3087 self._ascending = True
3076 3088 data = list(data)
3077 3089 self._list = data
3078 3090 self._datarepr = datarepr
3079 3091
3080 3092 @util.propertycache
3081 3093 def _set(self):
3082 3094 return set(self._list)
3083 3095
3084 3096 @util.propertycache
3085 3097 def _asclist(self):
3086 3098 asclist = self._list[:]
3087 3099 asclist.sort()
3088 3100 return asclist
3089 3101
3090 3102 def __iter__(self):
3091 3103 if self._ascending is None:
3092 3104 return iter(self._list)
3093 3105 elif self._ascending:
3094 3106 return iter(self._asclist)
3095 3107 else:
3096 3108 return reversed(self._asclist)
3097 3109
3098 3110 def fastasc(self):
3099 3111 return iter(self._asclist)
3100 3112
3101 3113 def fastdesc(self):
3102 3114 return reversed(self._asclist)
3103 3115
3104 3116 @util.propertycache
3105 3117 def __contains__(self):
3106 3118 return self._set.__contains__
3107 3119
3108 3120 def __nonzero__(self):
3109 3121 return bool(self._list)
3110 3122
3111 3123 def sort(self, reverse=False):
3112 3124 self._ascending = not bool(reverse)
3113 3125 self._istopo = False
3114 3126
3115 3127 def reverse(self):
3116 3128 if self._ascending is None:
3117 3129 self._list.reverse()
3118 3130 else:
3119 3131 self._ascending = not self._ascending
3120 3132 self._istopo = False
3121 3133
3122 3134 def __len__(self):
3123 3135 return len(self._list)
3124 3136
3125 3137 def isascending(self):
3126 3138 """Returns True if the collection is ascending order, False if not.
3127 3139
3128 3140 This is part of the mandatory API for smartset."""
3129 3141 if len(self) <= 1:
3130 3142 return True
3131 3143 return self._ascending is not None and self._ascending
3132 3144
3133 3145 def isdescending(self):
3134 3146 """Returns True if the collection is descending order, False if not.
3135 3147
3136 3148 This is part of the mandatory API for smartset."""
3137 3149 if len(self) <= 1:
3138 3150 return True
3139 3151 return self._ascending is not None and not self._ascending
3140 3152
3141 3153 def istopo(self):
3142 3154 """Is the collection is in topographical order or not.
3143 3155
3144 3156 This is part of the mandatory API for smartset."""
3145 3157 if len(self) <= 1:
3146 3158 return True
3147 3159 return self._istopo
3148 3160
3149 3161 def first(self):
3150 3162 if self:
3151 3163 if self._ascending is None:
3152 3164 return self._list[0]
3153 3165 elif self._ascending:
3154 3166 return self._asclist[0]
3155 3167 else:
3156 3168 return self._asclist[-1]
3157 3169 return None
3158 3170
3159 3171 def last(self):
3160 3172 if self:
3161 3173 if self._ascending is None:
3162 3174 return self._list[-1]
3163 3175 elif self._ascending:
3164 3176 return self._asclist[-1]
3165 3177 else:
3166 3178 return self._asclist[0]
3167 3179 return None
3168 3180
3169 3181 def __repr__(self):
3170 3182 d = {None: '', False: '-', True: '+'}[self._ascending]
3171 3183 s = _formatsetrepr(self._datarepr)
3172 3184 if not s:
3173 3185 l = self._list
3174 3186 # if _list has been built from a set, it might have a different
3175 3187 # order from one python implementation to another.
3176 3188 # We fallback to the sorted version for a stable output.
3177 3189 if self._ascending is not None:
3178 3190 l = self._asclist
3179 3191 s = repr(l)
3180 3192 return '<%s%s %s>' % (type(self).__name__, d, s)
3181 3193
3182 3194 class filteredset(abstractsmartset):
3183 3195 """Duck type for baseset class which iterates lazily over the revisions in
3184 3196 the subset and contains a function which tests for membership in the
3185 3197 revset
3186 3198 """
3187 3199 def __init__(self, subset, condition=lambda x: True, condrepr=None):
3188 3200 """
3189 3201 condition: a function that decide whether a revision in the subset
3190 3202 belongs to the revset or not.
3191 3203 condrepr: a tuple of (format, obj, ...), a function or an object that
3192 3204 provides a printable representation of the given condition.
3193 3205 """
3194 3206 self._subset = subset
3195 3207 self._condition = condition
3196 3208 self._condrepr = condrepr
3197 3209
3198 3210 def __contains__(self, x):
3199 3211 return x in self._subset and self._condition(x)
3200 3212
3201 3213 def __iter__(self):
3202 3214 return self._iterfilter(self._subset)
3203 3215
3204 3216 def _iterfilter(self, it):
3205 3217 cond = self._condition
3206 3218 for x in it:
3207 3219 if cond(x):
3208 3220 yield x
3209 3221
3210 3222 @property
3211 3223 def fastasc(self):
3212 3224 it = self._subset.fastasc
3213 3225 if it is None:
3214 3226 return None
3215 3227 return lambda: self._iterfilter(it())
3216 3228
3217 3229 @property
3218 3230 def fastdesc(self):
3219 3231 it = self._subset.fastdesc
3220 3232 if it is None:
3221 3233 return None
3222 3234 return lambda: self._iterfilter(it())
3223 3235
3224 3236 def __nonzero__(self):
3225 3237 fast = None
3226 3238 candidates = [self.fastasc if self.isascending() else None,
3227 3239 self.fastdesc if self.isdescending() else None,
3228 3240 self.fastasc,
3229 3241 self.fastdesc]
3230 3242 for candidate in candidates:
3231 3243 if candidate is not None:
3232 3244 fast = candidate
3233 3245 break
3234 3246
3235 3247 if fast is not None:
3236 3248 it = fast()
3237 3249 else:
3238 3250 it = self
3239 3251
3240 3252 for r in it:
3241 3253 return True
3242 3254 return False
3243 3255
3244 3256 def __len__(self):
3245 3257 # Basic implementation to be changed in future patches.
3246 3258 # until this gets improved, we use generator expression
3247 3259 # here, since list comprehensions are free to call __len__ again
3248 3260 # causing infinite recursion
3249 3261 l = baseset(r for r in self)
3250 3262 return len(l)
3251 3263
3252 3264 def sort(self, reverse=False):
3253 3265 self._subset.sort(reverse=reverse)
3254 3266
3255 3267 def reverse(self):
3256 3268 self._subset.reverse()
3257 3269
3258 3270 def isascending(self):
3259 3271 return self._subset.isascending()
3260 3272
3261 3273 def isdescending(self):
3262 3274 return self._subset.isdescending()
3263 3275
3264 3276 def istopo(self):
3265 3277 return self._subset.istopo()
3266 3278
3267 3279 def first(self):
3268 3280 for x in self:
3269 3281 return x
3270 3282 return None
3271 3283
3272 3284 def last(self):
3273 3285 it = None
3274 3286 if self.isascending():
3275 3287 it = self.fastdesc
3276 3288 elif self.isdescending():
3277 3289 it = self.fastasc
3278 3290 if it is not None:
3279 3291 for x in it():
3280 3292 return x
3281 3293 return None #empty case
3282 3294 else:
3283 3295 x = None
3284 3296 for x in self:
3285 3297 pass
3286 3298 return x
3287 3299
3288 3300 def __repr__(self):
3289 3301 xs = [repr(self._subset)]
3290 3302 s = _formatsetrepr(self._condrepr)
3291 3303 if s:
3292 3304 xs.append(s)
3293 3305 return '<%s %s>' % (type(self).__name__, ', '.join(xs))
3294 3306
3295 3307 def _iterordered(ascending, iter1, iter2):
3296 3308 """produce an ordered iteration from two iterators with the same order
3297 3309
3298 3310 The ascending is used to indicated the iteration direction.
3299 3311 """
3300 3312 choice = max
3301 3313 if ascending:
3302 3314 choice = min
3303 3315
3304 3316 val1 = None
3305 3317 val2 = None
3306 3318 try:
3307 3319 # Consume both iterators in an ordered way until one is empty
3308 3320 while True:
3309 3321 if val1 is None:
3310 3322 val1 = next(iter1)
3311 3323 if val2 is None:
3312 3324 val2 = next(iter2)
3313 3325 n = choice(val1, val2)
3314 3326 yield n
3315 3327 if val1 == n:
3316 3328 val1 = None
3317 3329 if val2 == n:
3318 3330 val2 = None
3319 3331 except StopIteration:
3320 3332 # Flush any remaining values and consume the other one
3321 3333 it = iter2
3322 3334 if val1 is not None:
3323 3335 yield val1
3324 3336 it = iter1
3325 3337 elif val2 is not None:
3326 3338 # might have been equality and both are empty
3327 3339 yield val2
3328 3340 for val in it:
3329 3341 yield val
3330 3342
3331 3343 class addset(abstractsmartset):
3332 3344 """Represent the addition of two sets
3333 3345
3334 3346 Wrapper structure for lazily adding two structures without losing much
3335 3347 performance on the __contains__ method
3336 3348
3337 3349 If the ascending attribute is set, that means the two structures are
3338 3350 ordered in either an ascending or descending way. Therefore, we can add
3339 3351 them maintaining the order by iterating over both at the same time
3340 3352
3341 3353 >>> xs = baseset([0, 3, 2])
3342 3354 >>> ys = baseset([5, 2, 4])
3343 3355
3344 3356 >>> rs = addset(xs, ys)
3345 3357 >>> bool(rs), 0 in rs, 1 in rs, 5 in rs, rs.first(), rs.last()
3346 3358 (True, True, False, True, 0, 4)
3347 3359 >>> rs = addset(xs, baseset([]))
3348 3360 >>> bool(rs), 0 in rs, 1 in rs, rs.first(), rs.last()
3349 3361 (True, True, False, 0, 2)
3350 3362 >>> rs = addset(baseset([]), baseset([]))
3351 3363 >>> bool(rs), 0 in rs, rs.first(), rs.last()
3352 3364 (False, False, None, None)
3353 3365
3354 3366 iterate unsorted:
3355 3367 >>> rs = addset(xs, ys)
3356 3368 >>> # (use generator because pypy could call len())
3357 3369 >>> list(x for x in rs) # without _genlist
3358 3370 [0, 3, 2, 5, 4]
3359 3371 >>> assert not rs._genlist
3360 3372 >>> len(rs)
3361 3373 5
3362 3374 >>> [x for x in rs] # with _genlist
3363 3375 [0, 3, 2, 5, 4]
3364 3376 >>> assert rs._genlist
3365 3377
3366 3378 iterate ascending:
3367 3379 >>> rs = addset(xs, ys, ascending=True)
3368 3380 >>> # (use generator because pypy could call len())
3369 3381 >>> list(x for x in rs), list(x for x in rs.fastasc()) # without _asclist
3370 3382 ([0, 2, 3, 4, 5], [0, 2, 3, 4, 5])
3371 3383 >>> assert not rs._asclist
3372 3384 >>> len(rs)
3373 3385 5
3374 3386 >>> [x for x in rs], [x for x in rs.fastasc()]
3375 3387 ([0, 2, 3, 4, 5], [0, 2, 3, 4, 5])
3376 3388 >>> assert rs._asclist
3377 3389
3378 3390 iterate descending:
3379 3391 >>> rs = addset(xs, ys, ascending=False)
3380 3392 >>> # (use generator because pypy could call len())
3381 3393 >>> list(x for x in rs), list(x for x in rs.fastdesc()) # without _asclist
3382 3394 ([5, 4, 3, 2, 0], [5, 4, 3, 2, 0])
3383 3395 >>> assert not rs._asclist
3384 3396 >>> len(rs)
3385 3397 5
3386 3398 >>> [x for x in rs], [x for x in rs.fastdesc()]
3387 3399 ([5, 4, 3, 2, 0], [5, 4, 3, 2, 0])
3388 3400 >>> assert rs._asclist
3389 3401
3390 3402 iterate ascending without fastasc:
3391 3403 >>> rs = addset(xs, generatorset(ys), ascending=True)
3392 3404 >>> assert rs.fastasc is None
3393 3405 >>> [x for x in rs]
3394 3406 [0, 2, 3, 4, 5]
3395 3407
3396 3408 iterate descending without fastdesc:
3397 3409 >>> rs = addset(generatorset(xs), ys, ascending=False)
3398 3410 >>> assert rs.fastdesc is None
3399 3411 >>> [x for x in rs]
3400 3412 [5, 4, 3, 2, 0]
3401 3413 """
3402 3414 def __init__(self, revs1, revs2, ascending=None):
3403 3415 self._r1 = revs1
3404 3416 self._r2 = revs2
3405 3417 self._iter = None
3406 3418 self._ascending = ascending
3407 3419 self._genlist = None
3408 3420 self._asclist = None
3409 3421
3410 3422 def __len__(self):
3411 3423 return len(self._list)
3412 3424
3413 3425 def __nonzero__(self):
3414 3426 return bool(self._r1) or bool(self._r2)
3415 3427
3416 3428 @util.propertycache
3417 3429 def _list(self):
3418 3430 if not self._genlist:
3419 3431 self._genlist = baseset(iter(self))
3420 3432 return self._genlist
3421 3433
3422 3434 def __iter__(self):
3423 3435 """Iterate over both collections without repeating elements
3424 3436
3425 3437 If the ascending attribute is not set, iterate over the first one and
3426 3438 then over the second one checking for membership on the first one so we
3427 3439 dont yield any duplicates.
3428 3440
3429 3441 If the ascending attribute is set, iterate over both collections at the
3430 3442 same time, yielding only one value at a time in the given order.
3431 3443 """
3432 3444 if self._ascending is None:
3433 3445 if self._genlist:
3434 3446 return iter(self._genlist)
3435 3447 def arbitraryordergen():
3436 3448 for r in self._r1:
3437 3449 yield r
3438 3450 inr1 = self._r1.__contains__
3439 3451 for r in self._r2:
3440 3452 if not inr1(r):
3441 3453 yield r
3442 3454 return arbitraryordergen()
3443 3455 # try to use our own fast iterator if it exists
3444 3456 self._trysetasclist()
3445 3457 if self._ascending:
3446 3458 attr = 'fastasc'
3447 3459 else:
3448 3460 attr = 'fastdesc'
3449 3461 it = getattr(self, attr)
3450 3462 if it is not None:
3451 3463 return it()
3452 3464 # maybe half of the component supports fast
3453 3465 # get iterator for _r1
3454 3466 iter1 = getattr(self._r1, attr)
3455 3467 if iter1 is None:
3456 3468 # let's avoid side effect (not sure it matters)
3457 3469 iter1 = iter(sorted(self._r1, reverse=not self._ascending))
3458 3470 else:
3459 3471 iter1 = iter1()
3460 3472 # get iterator for _r2
3461 3473 iter2 = getattr(self._r2, attr)
3462 3474 if iter2 is None:
3463 3475 # let's avoid side effect (not sure it matters)
3464 3476 iter2 = iter(sorted(self._r2, reverse=not self._ascending))
3465 3477 else:
3466 3478 iter2 = iter2()
3467 3479 return _iterordered(self._ascending, iter1, iter2)
3468 3480
3469 3481 def _trysetasclist(self):
3470 3482 """populate the _asclist attribute if possible and necessary"""
3471 3483 if self._genlist is not None and self._asclist is None:
3472 3484 self._asclist = sorted(self._genlist)
3473 3485
3474 3486 @property
3475 3487 def fastasc(self):
3476 3488 self._trysetasclist()
3477 3489 if self._asclist is not None:
3478 3490 return self._asclist.__iter__
3479 3491 iter1 = self._r1.fastasc
3480 3492 iter2 = self._r2.fastasc
3481 3493 if None in (iter1, iter2):
3482 3494 return None
3483 3495 return lambda: _iterordered(True, iter1(), iter2())
3484 3496
3485 3497 @property
3486 3498 def fastdesc(self):
3487 3499 self._trysetasclist()
3488 3500 if self._asclist is not None:
3489 3501 return self._asclist.__reversed__
3490 3502 iter1 = self._r1.fastdesc
3491 3503 iter2 = self._r2.fastdesc
3492 3504 if None in (iter1, iter2):
3493 3505 return None
3494 3506 return lambda: _iterordered(False, iter1(), iter2())
3495 3507
3496 3508 def __contains__(self, x):
3497 3509 return x in self._r1 or x in self._r2
3498 3510
3499 3511 def sort(self, reverse=False):
3500 3512 """Sort the added set
3501 3513
3502 3514 For this we use the cached list with all the generated values and if we
3503 3515 know they are ascending or descending we can sort them in a smart way.
3504 3516 """
3505 3517 self._ascending = not reverse
3506 3518
3507 3519 def isascending(self):
3508 3520 return self._ascending is not None and self._ascending
3509 3521
3510 3522 def isdescending(self):
3511 3523 return self._ascending is not None and not self._ascending
3512 3524
3513 3525 def istopo(self):
3514 3526 # not worth the trouble asserting if the two sets combined are still
3515 3527 # in topographical order. Use the sort() predicate to explicitly sort
3516 3528 # again instead.
3517 3529 return False
3518 3530
3519 3531 def reverse(self):
3520 3532 if self._ascending is None:
3521 3533 self._list.reverse()
3522 3534 else:
3523 3535 self._ascending = not self._ascending
3524 3536
3525 3537 def first(self):
3526 3538 for x in self:
3527 3539 return x
3528 3540 return None
3529 3541
3530 3542 def last(self):
3531 3543 self.reverse()
3532 3544 val = self.first()
3533 3545 self.reverse()
3534 3546 return val
3535 3547
3536 3548 def __repr__(self):
3537 3549 d = {None: '', False: '-', True: '+'}[self._ascending]
3538 3550 return '<%s%s %r, %r>' % (type(self).__name__, d, self._r1, self._r2)
3539 3551
3540 3552 class generatorset(abstractsmartset):
3541 3553 """Wrap a generator for lazy iteration
3542 3554
3543 3555 Wrapper structure for generators that provides lazy membership and can
3544 3556 be iterated more than once.
3545 3557 When asked for membership it generates values until either it finds the
3546 3558 requested one or has gone through all the elements in the generator
3547 3559 """
3548 3560 def __init__(self, gen, iterasc=None):
3549 3561 """
3550 3562 gen: a generator producing the values for the generatorset.
3551 3563 """
3552 3564 self._gen = gen
3553 3565 self._asclist = None
3554 3566 self._cache = {}
3555 3567 self._genlist = []
3556 3568 self._finished = False
3557 3569 self._ascending = True
3558 3570 if iterasc is not None:
3559 3571 if iterasc:
3560 3572 self.fastasc = self._iterator
3561 3573 self.__contains__ = self._asccontains
3562 3574 else:
3563 3575 self.fastdesc = self._iterator
3564 3576 self.__contains__ = self._desccontains
3565 3577
3566 3578 def __nonzero__(self):
3567 3579 # Do not use 'for r in self' because it will enforce the iteration
3568 3580 # order (default ascending), possibly unrolling a whole descending
3569 3581 # iterator.
3570 3582 if self._genlist:
3571 3583 return True
3572 3584 for r in self._consumegen():
3573 3585 return True
3574 3586 return False
3575 3587
3576 3588 def __contains__(self, x):
3577 3589 if x in self._cache:
3578 3590 return self._cache[x]
3579 3591
3580 3592 # Use new values only, as existing values would be cached.
3581 3593 for l in self._consumegen():
3582 3594 if l == x:
3583 3595 return True
3584 3596
3585 3597 self._cache[x] = False
3586 3598 return False
3587 3599
3588 3600 def _asccontains(self, x):
3589 3601 """version of contains optimised for ascending generator"""
3590 3602 if x in self._cache:
3591 3603 return self._cache[x]
3592 3604
3593 3605 # Use new values only, as existing values would be cached.
3594 3606 for l in self._consumegen():
3595 3607 if l == x:
3596 3608 return True
3597 3609 if l > x:
3598 3610 break
3599 3611
3600 3612 self._cache[x] = False
3601 3613 return False
3602 3614
3603 3615 def _desccontains(self, x):
3604 3616 """version of contains optimised for descending generator"""
3605 3617 if x in self._cache:
3606 3618 return self._cache[x]
3607 3619
3608 3620 # Use new values only, as existing values would be cached.
3609 3621 for l in self._consumegen():
3610 3622 if l == x:
3611 3623 return True
3612 3624 if l < x:
3613 3625 break
3614 3626
3615 3627 self._cache[x] = False
3616 3628 return False
3617 3629
3618 3630 def __iter__(self):
3619 3631 if self._ascending:
3620 3632 it = self.fastasc
3621 3633 else:
3622 3634 it = self.fastdesc
3623 3635 if it is not None:
3624 3636 return it()
3625 3637 # we need to consume the iterator
3626 3638 for x in self._consumegen():
3627 3639 pass
3628 3640 # recall the same code
3629 3641 return iter(self)
3630 3642
3631 3643 def _iterator(self):
3632 3644 if self._finished:
3633 3645 return iter(self._genlist)
3634 3646
3635 3647 # We have to use this complex iteration strategy to allow multiple
3636 3648 # iterations at the same time. We need to be able to catch revision
3637 3649 # removed from _consumegen and added to genlist in another instance.
3638 3650 #
3639 3651 # Getting rid of it would provide an about 15% speed up on this
3640 3652 # iteration.
3641 3653 genlist = self._genlist
3642 3654 nextrev = self._consumegen().next
3643 3655 _len = len # cache global lookup
3644 3656 def gen():
3645 3657 i = 0
3646 3658 while True:
3647 3659 if i < _len(genlist):
3648 3660 yield genlist[i]
3649 3661 else:
3650 3662 yield nextrev()
3651 3663 i += 1
3652 3664 return gen()
3653 3665
3654 3666 def _consumegen(self):
3655 3667 cache = self._cache
3656 3668 genlist = self._genlist.append
3657 3669 for item in self._gen:
3658 3670 cache[item] = True
3659 3671 genlist(item)
3660 3672 yield item
3661 3673 if not self._finished:
3662 3674 self._finished = True
3663 3675 asc = self._genlist[:]
3664 3676 asc.sort()
3665 3677 self._asclist = asc
3666 3678 self.fastasc = asc.__iter__
3667 3679 self.fastdesc = asc.__reversed__
3668 3680
3669 3681 def __len__(self):
3670 3682 for x in self._consumegen():
3671 3683 pass
3672 3684 return len(self._genlist)
3673 3685
3674 3686 def sort(self, reverse=False):
3675 3687 self._ascending = not reverse
3676 3688
3677 3689 def reverse(self):
3678 3690 self._ascending = not self._ascending
3679 3691
3680 3692 def isascending(self):
3681 3693 return self._ascending
3682 3694
3683 3695 def isdescending(self):
3684 3696 return not self._ascending
3685 3697
3686 3698 def istopo(self):
3687 3699 # not worth the trouble asserting if the two sets combined are still
3688 3700 # in topographical order. Use the sort() predicate to explicitly sort
3689 3701 # again instead.
3690 3702 return False
3691 3703
3692 3704 def first(self):
3693 3705 if self._ascending:
3694 3706 it = self.fastasc
3695 3707 else:
3696 3708 it = self.fastdesc
3697 3709 if it is None:
3698 3710 # we need to consume all and try again
3699 3711 for x in self._consumegen():
3700 3712 pass
3701 3713 return self.first()
3702 3714 return next(it(), None)
3703 3715
3704 3716 def last(self):
3705 3717 if self._ascending:
3706 3718 it = self.fastdesc
3707 3719 else:
3708 3720 it = self.fastasc
3709 3721 if it is None:
3710 3722 # we need to consume all and try again
3711 3723 for x in self._consumegen():
3712 3724 pass
3713 3725 return self.first()
3714 3726 return next(it(), None)
3715 3727
3716 3728 def __repr__(self):
3717 3729 d = {False: '-', True: '+'}[self._ascending]
3718 3730 return '<%s%s>' % (type(self).__name__, d)
3719 3731
3720 3732 class spanset(abstractsmartset):
3721 3733 """Duck type for baseset class which represents a range of revisions and
3722 3734 can work lazily and without having all the range in memory
3723 3735
3724 3736 Note that spanset(x, y) behave almost like xrange(x, y) except for two
3725 3737 notable points:
3726 3738 - when x < y it will be automatically descending,
3727 3739 - revision filtered with this repoview will be skipped.
3728 3740
3729 3741 """
3730 3742 def __init__(self, repo, start=0, end=None):
3731 3743 """
3732 3744 start: first revision included the set
3733 3745 (default to 0)
3734 3746 end: first revision excluded (last+1)
3735 3747 (default to len(repo)
3736 3748
3737 3749 Spanset will be descending if `end` < `start`.
3738 3750 """
3739 3751 if end is None:
3740 3752 end = len(repo)
3741 3753 self._ascending = start <= end
3742 3754 if not self._ascending:
3743 3755 start, end = end + 1, start +1
3744 3756 self._start = start
3745 3757 self._end = end
3746 3758 self._hiddenrevs = repo.changelog.filteredrevs
3747 3759
3748 3760 def sort(self, reverse=False):
3749 3761 self._ascending = not reverse
3750 3762
3751 3763 def reverse(self):
3752 3764 self._ascending = not self._ascending
3753 3765
3754 3766 def istopo(self):
3755 3767 # not worth the trouble asserting if the two sets combined are still
3756 3768 # in topographical order. Use the sort() predicate to explicitly sort
3757 3769 # again instead.
3758 3770 return False
3759 3771
3760 3772 def _iterfilter(self, iterrange):
3761 3773 s = self._hiddenrevs
3762 3774 for r in iterrange:
3763 3775 if r not in s:
3764 3776 yield r
3765 3777
3766 3778 def __iter__(self):
3767 3779 if self._ascending:
3768 3780 return self.fastasc()
3769 3781 else:
3770 3782 return self.fastdesc()
3771 3783
3772 3784 def fastasc(self):
3773 3785 iterrange = xrange(self._start, self._end)
3774 3786 if self._hiddenrevs:
3775 3787 return self._iterfilter(iterrange)
3776 3788 return iter(iterrange)
3777 3789
3778 3790 def fastdesc(self):
3779 3791 iterrange = xrange(self._end - 1, self._start - 1, -1)
3780 3792 if self._hiddenrevs:
3781 3793 return self._iterfilter(iterrange)
3782 3794 return iter(iterrange)
3783 3795
3784 3796 def __contains__(self, rev):
3785 3797 hidden = self._hiddenrevs
3786 3798 return ((self._start <= rev < self._end)
3787 3799 and not (hidden and rev in hidden))
3788 3800
3789 3801 def __nonzero__(self):
3790 3802 for r in self:
3791 3803 return True
3792 3804 return False
3793 3805
3794 3806 def __len__(self):
3795 3807 if not self._hiddenrevs:
3796 3808 return abs(self._end - self._start)
3797 3809 else:
3798 3810 count = 0
3799 3811 start = self._start
3800 3812 end = self._end
3801 3813 for rev in self._hiddenrevs:
3802 3814 if (end < rev <= start) or (start <= rev < end):
3803 3815 count += 1
3804 3816 return abs(self._end - self._start) - count
3805 3817
3806 3818 def isascending(self):
3807 3819 return self._ascending
3808 3820
3809 3821 def isdescending(self):
3810 3822 return not self._ascending
3811 3823
3812 3824 def first(self):
3813 3825 if self._ascending:
3814 3826 it = self.fastasc
3815 3827 else:
3816 3828 it = self.fastdesc
3817 3829 for x in it():
3818 3830 return x
3819 3831 return None
3820 3832
3821 3833 def last(self):
3822 3834 if self._ascending:
3823 3835 it = self.fastdesc
3824 3836 else:
3825 3837 it = self.fastasc
3826 3838 for x in it():
3827 3839 return x
3828 3840 return None
3829 3841
3830 3842 def __repr__(self):
3831 3843 d = {False: '-', True: '+'}[self._ascending]
3832 3844 return '<%s%s %d:%d>' % (type(self).__name__, d,
3833 3845 self._start, self._end - 1)
3834 3846
3835 3847 class fullreposet(spanset):
3836 3848 """a set containing all revisions in the repo
3837 3849
3838 3850 This class exists to host special optimization and magic to handle virtual
3839 3851 revisions such as "null".
3840 3852 """
3841 3853
3842 3854 def __init__(self, repo):
3843 3855 super(fullreposet, self).__init__(repo)
3844 3856
3845 3857 def __and__(self, other):
3846 3858 """As self contains the whole repo, all of the other set should also be
3847 3859 in self. Therefore `self & other = other`.
3848 3860
3849 3861 This boldly assumes the other contains valid revs only.
3850 3862 """
3851 3863 # other not a smartset, make is so
3852 3864 if not util.safehasattr(other, 'isascending'):
3853 3865 # filter out hidden revision
3854 3866 # (this boldly assumes all smartset are pure)
3855 3867 #
3856 3868 # `other` was used with "&", let's assume this is a set like
3857 3869 # object.
3858 3870 other = baseset(other - self._hiddenrevs)
3859 3871
3860 3872 other.sort(reverse=self.isdescending())
3861 3873 return other
3862 3874
3863 3875 def prettyformatset(revs):
3864 3876 lines = []
3865 3877 rs = repr(revs)
3866 3878 p = 0
3867 3879 while p < len(rs):
3868 3880 q = rs.find('<', p + 1)
3869 3881 if q < 0:
3870 3882 q = len(rs)
3871 3883 l = rs.count('<', 0, p) - rs.count('>', 0, p)
3872 3884 assert l >= 0
3873 3885 lines.append((l, rs[p:q].rstrip()))
3874 3886 p = q
3875 3887 return '\n'.join(' ' * l + s for l, s in lines)
3876 3888
3877 3889 def loadpredicate(ui, extname, registrarobj):
3878 3890 """Load revset predicates from specified registrarobj
3879 3891 """
3880 3892 for name, func in registrarobj._table.iteritems():
3881 3893 symbols[name] = func
3882 3894 if func._safe:
3883 3895 safesymbols.add(name)
3884 3896
3885 3897 # load built-in predicates explicitly to setup safesymbols
3886 3898 loadpredicate(None, None, predicate)
3887 3899
3888 3900 # tell hggettext to extract docstrings from these functions:
3889 3901 i18nfunctions = symbols.values()
@@ -1,3654 +1,3654 b''
1 1 $ HGENCODING=utf-8
2 2 $ export HGENCODING
3 3 $ cat > testrevset.py << EOF
4 4 > import mercurial.revset
5 5 >
6 6 > baseset = mercurial.revset.baseset
7 7 >
8 8 > def r3232(repo, subset, x):
9 9 > """"simple revset that return [3,2,3,2]
10 10 >
11 11 > revisions duplicated on purpose.
12 12 > """
13 13 > if 3 not in subset:
14 14 > if 2 in subset:
15 15 > return baseset([2,2])
16 16 > return baseset()
17 17 > return baseset([3,3,2,2])
18 18 >
19 19 > mercurial.revset.symbols['r3232'] = r3232
20 20 > EOF
21 21 $ cat >> $HGRCPATH << EOF
22 22 > [extensions]
23 23 > testrevset=$TESTTMP/testrevset.py
24 24 > EOF
25 25
26 26 $ try() {
27 27 > hg debugrevspec --debug "$@"
28 28 > }
29 29
30 30 $ log() {
31 31 > hg log --template '{rev}\n' -r "$1"
32 32 > }
33 33
34 34 extension to build '_intlist()' and '_hexlist()', which is necessary because
35 35 these predicates use '\0' as a separator:
36 36
37 37 $ cat <<EOF > debugrevlistspec.py
38 38 > from __future__ import absolute_import
39 39 > from mercurial import (
40 40 > cmdutil,
41 41 > node as nodemod,
42 42 > revset,
43 43 > )
44 44 > cmdtable = {}
45 45 > command = cmdutil.command(cmdtable)
46 46 > @command('debugrevlistspec',
47 47 > [('', 'optimize', None, 'print parsed tree after optimizing'),
48 48 > ('', 'bin', None, 'unhexlify arguments')])
49 49 > def debugrevlistspec(ui, repo, fmt, *args, **opts):
50 50 > if opts['bin']:
51 51 > args = map(nodemod.bin, args)
52 52 > expr = revset.formatspec(fmt, list(args))
53 53 > if ui.verbose:
54 54 > tree = revset.parse(expr, lookup=repo.__contains__)
55 55 > ui.note(revset.prettyformat(tree), "\n")
56 56 > if opts["optimize"]:
57 57 > opttree = revset.optimize(revset.analyze(tree))
58 58 > ui.note("* optimized:\n", revset.prettyformat(opttree), "\n")
59 59 > func = revset.match(ui, expr, repo)
60 60 > revs = func(repo)
61 61 > if ui.verbose:
62 62 > ui.note("* set:\n", revset.prettyformatset(revs), "\n")
63 63 > for c in revs:
64 64 > ui.write("%s\n" % c)
65 65 > EOF
66 66 $ cat <<EOF >> $HGRCPATH
67 67 > [extensions]
68 68 > debugrevlistspec = $TESTTMP/debugrevlistspec.py
69 69 > EOF
70 70 $ trylist() {
71 71 > hg debugrevlistspec --debug "$@"
72 72 > }
73 73
74 74 $ hg init repo
75 75 $ cd repo
76 76
77 77 $ echo a > a
78 78 $ hg branch a
79 79 marked working directory as branch a
80 80 (branches are permanent and global, did you want a bookmark?)
81 81 $ hg ci -Aqm0
82 82
83 83 $ echo b > b
84 84 $ hg branch b
85 85 marked working directory as branch b
86 86 $ hg ci -Aqm1
87 87
88 88 $ rm a
89 89 $ hg branch a-b-c-
90 90 marked working directory as branch a-b-c-
91 91 $ hg ci -Aqm2 -u Bob
92 92
93 93 $ hg log -r "extra('branch', 'a-b-c-')" --template '{rev}\n'
94 94 2
95 95 $ hg log -r "extra('branch')" --template '{rev}\n'
96 96 0
97 97 1
98 98 2
99 99 $ hg log -r "extra('branch', 're:a')" --template '{rev} {branch}\n'
100 100 0 a
101 101 2 a-b-c-
102 102
103 103 $ hg co 1
104 104 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
105 105 $ hg branch +a+b+c+
106 106 marked working directory as branch +a+b+c+
107 107 $ hg ci -Aqm3
108 108
109 109 $ hg co 2 # interleave
110 110 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
111 111 $ echo bb > b
112 112 $ hg branch -- -a-b-c-
113 113 marked working directory as branch -a-b-c-
114 114 $ hg ci -Aqm4 -d "May 12 2005"
115 115
116 116 $ hg co 3
117 117 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
118 118 $ hg branch !a/b/c/
119 119 marked working directory as branch !a/b/c/
120 120 $ hg ci -Aqm"5 bug"
121 121
122 122 $ hg merge 4
123 123 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
124 124 (branch merge, don't forget to commit)
125 125 $ hg branch _a_b_c_
126 126 marked working directory as branch _a_b_c_
127 127 $ hg ci -Aqm"6 issue619"
128 128
129 129 $ hg branch .a.b.c.
130 130 marked working directory as branch .a.b.c.
131 131 $ hg ci -Aqm7
132 132
133 133 $ hg branch all
134 134 marked working directory as branch all
135 135
136 136 $ hg co 4
137 137 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
138 138 $ hg branch Γ©
139 139 marked working directory as branch \xc3\xa9 (esc)
140 140 $ hg ci -Aqm9
141 141
142 142 $ hg tag -r6 1.0
143 143 $ hg bookmark -r6 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
144 144
145 145 $ hg clone --quiet -U -r 7 . ../remote1
146 146 $ hg clone --quiet -U -r 8 . ../remote2
147 147 $ echo "[paths]" >> .hg/hgrc
148 148 $ echo "default = ../remote1" >> .hg/hgrc
149 149
150 150 trivial
151 151
152 152 $ try 0:1
153 153 (range
154 154 ('symbol', '0')
155 155 ('symbol', '1'))
156 156 * set:
157 157 <spanset+ 0:1>
158 158 0
159 159 1
160 160 $ try --optimize :
161 161 (rangeall
162 162 None)
163 163 * optimized:
164 (rangepre
165 ('string', 'tip')
164 (rangeall
165 None
166 166 define)
167 167 * set:
168 168 <spanset+ 0:9>
169 169 0
170 170 1
171 171 2
172 172 3
173 173 4
174 174 5
175 175 6
176 176 7
177 177 8
178 178 9
179 179 $ try 3::6
180 180 (dagrange
181 181 ('symbol', '3')
182 182 ('symbol', '6'))
183 183 * set:
184 184 <baseset+ [3, 5, 6]>
185 185 3
186 186 5
187 187 6
188 188 $ try '0|1|2'
189 189 (or
190 190 (list
191 191 ('symbol', '0')
192 192 ('symbol', '1')
193 193 ('symbol', '2')))
194 194 * set:
195 195 <baseset [0, 1, 2]>
196 196 0
197 197 1
198 198 2
199 199
200 200 names that should work without quoting
201 201
202 202 $ try a
203 203 ('symbol', 'a')
204 204 * set:
205 205 <baseset [0]>
206 206 0
207 207 $ try b-a
208 208 (minus
209 209 ('symbol', 'b')
210 210 ('symbol', 'a'))
211 211 * set:
212 212 <filteredset
213 213 <baseset [1]>,
214 214 <not
215 215 <baseset [0]>>>
216 216 1
217 217 $ try _a_b_c_
218 218 ('symbol', '_a_b_c_')
219 219 * set:
220 220 <baseset [6]>
221 221 6
222 222 $ try _a_b_c_-a
223 223 (minus
224 224 ('symbol', '_a_b_c_')
225 225 ('symbol', 'a'))
226 226 * set:
227 227 <filteredset
228 228 <baseset [6]>,
229 229 <not
230 230 <baseset [0]>>>
231 231 6
232 232 $ try .a.b.c.
233 233 ('symbol', '.a.b.c.')
234 234 * set:
235 235 <baseset [7]>
236 236 7
237 237 $ try .a.b.c.-a
238 238 (minus
239 239 ('symbol', '.a.b.c.')
240 240 ('symbol', 'a'))
241 241 * set:
242 242 <filteredset
243 243 <baseset [7]>,
244 244 <not
245 245 <baseset [0]>>>
246 246 7
247 247
248 248 names that should be caught by fallback mechanism
249 249
250 250 $ try -- '-a-b-c-'
251 251 ('symbol', '-a-b-c-')
252 252 * set:
253 253 <baseset [4]>
254 254 4
255 255 $ log -a-b-c-
256 256 4
257 257 $ try '+a+b+c+'
258 258 ('symbol', '+a+b+c+')
259 259 * set:
260 260 <baseset [3]>
261 261 3
262 262 $ try '+a+b+c+:'
263 263 (rangepost
264 264 ('symbol', '+a+b+c+'))
265 265 * set:
266 266 <spanset+ 3:9>
267 267 3
268 268 4
269 269 5
270 270 6
271 271 7
272 272 8
273 273 9
274 274 $ try ':+a+b+c+'
275 275 (rangepre
276 276 ('symbol', '+a+b+c+'))
277 277 * set:
278 278 <spanset+ 0:3>
279 279 0
280 280 1
281 281 2
282 282 3
283 283 $ try -- '-a-b-c-:+a+b+c+'
284 284 (range
285 285 ('symbol', '-a-b-c-')
286 286 ('symbol', '+a+b+c+'))
287 287 * set:
288 288 <spanset- 3:4>
289 289 4
290 290 3
291 291 $ log '-a-b-c-:+a+b+c+'
292 292 4
293 293 3
294 294
295 295 $ try -- -a-b-c--a # complains
296 296 (minus
297 297 (minus
298 298 (minus
299 299 (negate
300 300 ('symbol', 'a'))
301 301 ('symbol', 'b'))
302 302 ('symbol', 'c'))
303 303 (negate
304 304 ('symbol', 'a')))
305 305 abort: unknown revision '-a'!
306 306 [255]
307 307 $ try Γ©
308 308 ('symbol', '\xc3\xa9')
309 309 * set:
310 310 <baseset [9]>
311 311 9
312 312
313 313 no quoting needed
314 314
315 315 $ log ::a-b-c-
316 316 0
317 317 1
318 318 2
319 319
320 320 quoting needed
321 321
322 322 $ try '"-a-b-c-"-a'
323 323 (minus
324 324 ('string', '-a-b-c-')
325 325 ('symbol', 'a'))
326 326 * set:
327 327 <filteredset
328 328 <baseset [4]>,
329 329 <not
330 330 <baseset [0]>>>
331 331 4
332 332
333 333 $ log '1 or 2'
334 334 1
335 335 2
336 336 $ log '1|2'
337 337 1
338 338 2
339 339 $ log '1 and 2'
340 340 $ log '1&2'
341 341 $ try '1&2|3' # precedence - and is higher
342 342 (or
343 343 (list
344 344 (and
345 345 ('symbol', '1')
346 346 ('symbol', '2'))
347 347 ('symbol', '3')))
348 348 * set:
349 349 <addset
350 350 <baseset []>,
351 351 <baseset [3]>>
352 352 3
353 353 $ try '1|2&3'
354 354 (or
355 355 (list
356 356 ('symbol', '1')
357 357 (and
358 358 ('symbol', '2')
359 359 ('symbol', '3'))))
360 360 * set:
361 361 <addset
362 362 <baseset [1]>,
363 363 <baseset []>>
364 364 1
365 365 $ try '1&2&3' # associativity
366 366 (and
367 367 (and
368 368 ('symbol', '1')
369 369 ('symbol', '2'))
370 370 ('symbol', '3'))
371 371 * set:
372 372 <baseset []>
373 373 $ try '1|(2|3)'
374 374 (or
375 375 (list
376 376 ('symbol', '1')
377 377 (group
378 378 (or
379 379 (list
380 380 ('symbol', '2')
381 381 ('symbol', '3'))))))
382 382 * set:
383 383 <addset
384 384 <baseset [1]>,
385 385 <baseset [2, 3]>>
386 386 1
387 387 2
388 388 3
389 389 $ log '1.0' # tag
390 390 6
391 391 $ log 'a' # branch
392 392 0
393 393 $ log '2785f51ee'
394 394 0
395 395 $ log 'date(2005)'
396 396 4
397 397 $ log 'date(this is a test)'
398 398 hg: parse error at 10: unexpected token: symbol
399 399 [255]
400 400 $ log 'date()'
401 401 hg: parse error: date requires a string
402 402 [255]
403 403 $ log 'date'
404 404 abort: unknown revision 'date'!
405 405 [255]
406 406 $ log 'date('
407 407 hg: parse error at 5: not a prefix: end
408 408 [255]
409 409 $ log 'date("\xy")'
410 410 hg: parse error: invalid \x escape
411 411 [255]
412 412 $ log 'date(tip)'
413 413 abort: invalid date: 'tip'
414 414 [255]
415 415 $ log '0:date'
416 416 abort: unknown revision 'date'!
417 417 [255]
418 418 $ log '::"date"'
419 419 abort: unknown revision 'date'!
420 420 [255]
421 421 $ hg book date -r 4
422 422 $ log '0:date'
423 423 0
424 424 1
425 425 2
426 426 3
427 427 4
428 428 $ log '::date'
429 429 0
430 430 1
431 431 2
432 432 4
433 433 $ log '::"date"'
434 434 0
435 435 1
436 436 2
437 437 4
438 438 $ log 'date(2005) and 1::'
439 439 4
440 440 $ hg book -d date
441 441
442 442 function name should be a symbol
443 443
444 444 $ log '"date"(2005)'
445 445 hg: parse error: not a symbol
446 446 [255]
447 447
448 448 keyword arguments
449 449
450 450 $ log 'extra(branch, value=a)'
451 451 0
452 452
453 453 $ log 'extra(branch, a, b)'
454 454 hg: parse error: extra takes at most 2 arguments
455 455 [255]
456 456 $ log 'extra(a, label=b)'
457 457 hg: parse error: extra got multiple values for keyword argument 'label'
458 458 [255]
459 459 $ log 'extra(label=branch, default)'
460 460 hg: parse error: extra got an invalid argument
461 461 [255]
462 462 $ log 'extra(branch, foo+bar=baz)'
463 463 hg: parse error: extra got an invalid argument
464 464 [255]
465 465 $ log 'extra(unknown=branch)'
466 466 hg: parse error: extra got an unexpected keyword argument 'unknown'
467 467 [255]
468 468
469 469 $ try 'foo=bar|baz'
470 470 (keyvalue
471 471 ('symbol', 'foo')
472 472 (or
473 473 (list
474 474 ('symbol', 'bar')
475 475 ('symbol', 'baz'))))
476 476 hg: parse error: can't use a key-value pair in this context
477 477 [255]
478 478
479 479 right-hand side should be optimized recursively
480 480
481 481 $ try --optimize 'foo=(not public())'
482 482 (keyvalue
483 483 ('symbol', 'foo')
484 484 (group
485 485 (not
486 486 (func
487 487 ('symbol', 'public')
488 488 None))))
489 489 * optimized:
490 490 (keyvalue
491 491 ('symbol', 'foo')
492 492 (func
493 493 ('symbol', '_notpublic')
494 494 None
495 495 any))
496 496 hg: parse error: can't use a key-value pair in this context
497 497 [255]
498 498
499 499 parsed tree at stages:
500 500
501 501 $ hg debugrevspec -p all '()'
502 502 * parsed:
503 503 (group
504 504 None)
505 505 * expanded:
506 506 (group
507 507 None)
508 508 * concatenated:
509 509 (group
510 510 None)
511 511 * analyzed:
512 512 None
513 513 * optimized:
514 514 None
515 515 hg: parse error: missing argument
516 516 [255]
517 517
518 518 $ hg debugrevspec --no-optimized -p all '()'
519 519 * parsed:
520 520 (group
521 521 None)
522 522 * expanded:
523 523 (group
524 524 None)
525 525 * concatenated:
526 526 (group
527 527 None)
528 528 * analyzed:
529 529 None
530 530 hg: parse error: missing argument
531 531 [255]
532 532
533 533 $ hg debugrevspec -p parsed -p analyzed -p optimized '(0|1)-1'
534 534 * parsed:
535 535 (minus
536 536 (group
537 537 (or
538 538 (list
539 539 ('symbol', '0')
540 540 ('symbol', '1'))))
541 541 ('symbol', '1'))
542 542 * analyzed:
543 543 (and
544 544 (or
545 545 (list
546 546 ('symbol', '0')
547 547 ('symbol', '1'))
548 548 define)
549 549 (not
550 550 ('symbol', '1')
551 551 follow)
552 552 define)
553 553 * optimized:
554 554 (difference
555 555 (func
556 556 ('symbol', '_list')
557 557 ('string', '0\x001')
558 558 define)
559 559 ('symbol', '1')
560 560 define)
561 561 0
562 562
563 563 $ hg debugrevspec -p unknown '0'
564 564 abort: invalid stage name: unknown
565 565 [255]
566 566
567 567 $ hg debugrevspec -p all --optimize '0'
568 568 abort: cannot use --optimize with --show-stage
569 569 [255]
570 570
571 571 verify optimized tree:
572 572
573 573 $ hg debugrevspec --verify '0|1'
574 574
575 575 $ hg debugrevspec --verify -v -p analyzed -p optimized 'r3232() & 2'
576 576 * analyzed:
577 577 (and
578 578 (func
579 579 ('symbol', 'r3232')
580 580 None
581 581 define)
582 582 ('symbol', '2')
583 583 define)
584 584 * optimized:
585 585 (and
586 586 ('symbol', '2')
587 587 (func
588 588 ('symbol', 'r3232')
589 589 None
590 590 define)
591 591 define)
592 592 * analyzed set:
593 593 <baseset [2]>
594 594 * optimized set:
595 595 <baseset [2, 2]>
596 596 --- analyzed
597 597 +++ optimized
598 598 2
599 599 +2
600 600 [1]
601 601
602 602 $ hg debugrevspec --no-optimized --verify-optimized '0'
603 603 abort: cannot use --verify-optimized with --no-optimized
604 604 [255]
605 605
606 606 Test that symbols only get parsed as functions if there's an opening
607 607 parenthesis.
608 608
609 609 $ hg book only -r 9
610 610 $ log 'only(only)' # Outer "only" is a function, inner "only" is the bookmark
611 611 8
612 612 9
613 613
614 614 ':y' behaves like '0:y', but can't be rewritten as such since the revision '0'
615 615 may be hidden (issue5385)
616 616
617 617 $ try -p parsed -p analyzed ':'
618 618 * parsed:
619 619 (rangeall
620 620 None)
621 621 * analyzed:
622 (rangepre
623 ('string', 'tip')
622 (rangeall
623 None
624 624 define)
625 625 * set:
626 626 <spanset+ 0:9>
627 627 0
628 628 1
629 629 2
630 630 3
631 631 4
632 632 5
633 633 6
634 634 7
635 635 8
636 636 9
637 637 $ try -p analyzed ':1'
638 638 * analyzed:
639 639 (rangepre
640 640 ('symbol', '1')
641 641 define)
642 642 * set:
643 643 <spanset+ 0:1>
644 644 0
645 645 1
646 646 $ try -p analyzed ':(1|2)'
647 647 * analyzed:
648 648 (rangepre
649 649 (or
650 650 (list
651 651 ('symbol', '1')
652 652 ('symbol', '2'))
653 653 define)
654 654 define)
655 655 * set:
656 656 <spanset+ 0:2>
657 657 0
658 658 1
659 659 2
660 660 $ try -p analyzed ':(1&2)'
661 661 * analyzed:
662 662 (rangepre
663 663 (and
664 664 ('symbol', '1')
665 665 ('symbol', '2')
666 666 define)
667 667 define)
668 668 * set:
669 669 <baseset []>
670 670
671 671 infix/suffix resolution of ^ operator (issue2884):
672 672
673 673 x^:y means (x^):y
674 674
675 675 $ try '1^:2'
676 676 (range
677 677 (parentpost
678 678 ('symbol', '1'))
679 679 ('symbol', '2'))
680 680 * set:
681 681 <spanset+ 0:2>
682 682 0
683 683 1
684 684 2
685 685
686 686 $ try '1^::2'
687 687 (dagrange
688 688 (parentpost
689 689 ('symbol', '1'))
690 690 ('symbol', '2'))
691 691 * set:
692 692 <baseset+ [0, 1, 2]>
693 693 0
694 694 1
695 695 2
696 696
697 697 $ try '9^:'
698 698 (rangepost
699 699 (parentpost
700 700 ('symbol', '9')))
701 701 * set:
702 702 <spanset+ 8:9>
703 703 8
704 704 9
705 705
706 706 x^:y should be resolved before omitting group operators
707 707
708 708 $ try '1^(:2)'
709 709 (parent
710 710 ('symbol', '1')
711 711 (group
712 712 (rangepre
713 713 ('symbol', '2'))))
714 714 hg: parse error: ^ expects a number 0, 1, or 2
715 715 [255]
716 716
717 717 x^:y should be resolved recursively
718 718
719 719 $ try 'sort(1^:2)'
720 720 (func
721 721 ('symbol', 'sort')
722 722 (range
723 723 (parentpost
724 724 ('symbol', '1'))
725 725 ('symbol', '2')))
726 726 * set:
727 727 <spanset+ 0:2>
728 728 0
729 729 1
730 730 2
731 731
732 732 $ try '(3^:4)^:2'
733 733 (range
734 734 (parentpost
735 735 (group
736 736 (range
737 737 (parentpost
738 738 ('symbol', '3'))
739 739 ('symbol', '4'))))
740 740 ('symbol', '2'))
741 741 * set:
742 742 <spanset+ 0:2>
743 743 0
744 744 1
745 745 2
746 746
747 747 $ try '(3^::4)^::2'
748 748 (dagrange
749 749 (parentpost
750 750 (group
751 751 (dagrange
752 752 (parentpost
753 753 ('symbol', '3'))
754 754 ('symbol', '4'))))
755 755 ('symbol', '2'))
756 756 * set:
757 757 <baseset+ [0, 1, 2]>
758 758 0
759 759 1
760 760 2
761 761
762 762 $ try '(9^:)^:'
763 763 (rangepost
764 764 (parentpost
765 765 (group
766 766 (rangepost
767 767 (parentpost
768 768 ('symbol', '9'))))))
769 769 * set:
770 770 <spanset+ 4:9>
771 771 4
772 772 5
773 773 6
774 774 7
775 775 8
776 776 9
777 777
778 778 x^ in alias should also be resolved
779 779
780 780 $ try 'A' --config 'revsetalias.A=1^:2'
781 781 ('symbol', 'A')
782 782 * expanded:
783 783 (range
784 784 (parentpost
785 785 ('symbol', '1'))
786 786 ('symbol', '2'))
787 787 * set:
788 788 <spanset+ 0:2>
789 789 0
790 790 1
791 791 2
792 792
793 793 $ try 'A:2' --config 'revsetalias.A=1^'
794 794 (range
795 795 ('symbol', 'A')
796 796 ('symbol', '2'))
797 797 * expanded:
798 798 (range
799 799 (parentpost
800 800 ('symbol', '1'))
801 801 ('symbol', '2'))
802 802 * set:
803 803 <spanset+ 0:2>
804 804 0
805 805 1
806 806 2
807 807
808 808 but not beyond the boundary of alias expansion, because the resolution should
809 809 be made at the parsing stage
810 810
811 811 $ try '1^A' --config 'revsetalias.A=:2'
812 812 (parent
813 813 ('symbol', '1')
814 814 ('symbol', 'A'))
815 815 * expanded:
816 816 (parent
817 817 ('symbol', '1')
818 818 (rangepre
819 819 ('symbol', '2')))
820 820 hg: parse error: ^ expects a number 0, 1, or 2
821 821 [255]
822 822
823 823 ancestor can accept 0 or more arguments
824 824
825 825 $ log 'ancestor()'
826 826 $ log 'ancestor(1)'
827 827 1
828 828 $ log 'ancestor(4,5)'
829 829 1
830 830 $ log 'ancestor(4,5) and 4'
831 831 $ log 'ancestor(0,0,1,3)'
832 832 0
833 833 $ log 'ancestor(3,1,5,3,5,1)'
834 834 1
835 835 $ log 'ancestor(0,1,3,5)'
836 836 0
837 837 $ log 'ancestor(1,2,3,4,5)'
838 838 1
839 839
840 840 test ancestors
841 841
842 842 $ log 'ancestors(5)'
843 843 0
844 844 1
845 845 3
846 846 5
847 847 $ log 'ancestor(ancestors(5))'
848 848 0
849 849 $ log '::r3232()'
850 850 0
851 851 1
852 852 2
853 853 3
854 854
855 855 $ log 'author(bob)'
856 856 2
857 857 $ log 'author("re:bob|test")'
858 858 0
859 859 1
860 860 2
861 861 3
862 862 4
863 863 5
864 864 6
865 865 7
866 866 8
867 867 9
868 868 $ log 'author(r"re:\S")'
869 869 0
870 870 1
871 871 2
872 872 3
873 873 4
874 874 5
875 875 6
876 876 7
877 877 8
878 878 9
879 879 $ log 'branch(Γ©)'
880 880 8
881 881 9
882 882 $ log 'branch(a)'
883 883 0
884 884 $ hg log -r 'branch("re:a")' --template '{rev} {branch}\n'
885 885 0 a
886 886 2 a-b-c-
887 887 3 +a+b+c+
888 888 4 -a-b-c-
889 889 5 !a/b/c/
890 890 6 _a_b_c_
891 891 7 .a.b.c.
892 892 $ log 'children(ancestor(4,5))'
893 893 2
894 894 3
895 895
896 896 $ log 'children(4)'
897 897 6
898 898 8
899 899 $ log 'children(null)'
900 900 0
901 901
902 902 $ log 'closed()'
903 903 $ log 'contains(a)'
904 904 0
905 905 1
906 906 3
907 907 5
908 908 $ log 'contains("../repo/a")'
909 909 0
910 910 1
911 911 3
912 912 5
913 913 $ log 'desc(B)'
914 914 5
915 915 $ hg log -r 'desc(r"re:S?u")' --template "{rev} {desc|firstline}\n"
916 916 5 5 bug
917 917 6 6 issue619
918 918 $ log 'descendants(2 or 3)'
919 919 2
920 920 3
921 921 4
922 922 5
923 923 6
924 924 7
925 925 8
926 926 9
927 927 $ log 'file("b*")'
928 928 1
929 929 4
930 930 $ log 'filelog("b")'
931 931 1
932 932 4
933 933 $ log 'filelog("../repo/b")'
934 934 1
935 935 4
936 936 $ log 'follow()'
937 937 0
938 938 1
939 939 2
940 940 4
941 941 8
942 942 9
943 943 $ log 'grep("issue\d+")'
944 944 6
945 945 $ try 'grep("(")' # invalid regular expression
946 946 (func
947 947 ('symbol', 'grep')
948 948 ('string', '('))
949 949 hg: parse error: invalid match pattern: unbalanced parenthesis
950 950 [255]
951 951 $ try 'grep("\bissue\d+")'
952 952 (func
953 953 ('symbol', 'grep')
954 954 ('string', '\x08issue\\d+'))
955 955 * set:
956 956 <filteredset
957 957 <fullreposet+ 0:9>,
958 958 <grep '\x08issue\\d+'>>
959 959 $ try 'grep(r"\bissue\d+")'
960 960 (func
961 961 ('symbol', 'grep')
962 962 ('string', '\\bissue\\d+'))
963 963 * set:
964 964 <filteredset
965 965 <fullreposet+ 0:9>,
966 966 <grep '\\bissue\\d+'>>
967 967 6
968 968 $ try 'grep(r"\")'
969 969 hg: parse error at 7: unterminated string
970 970 [255]
971 971 $ log 'head()'
972 972 0
973 973 1
974 974 2
975 975 3
976 976 4
977 977 5
978 978 6
979 979 7
980 980 9
981 981 $ log 'heads(6::)'
982 982 7
983 983 $ log 'keyword(issue)'
984 984 6
985 985 $ log 'keyword("test a")'
986 986 $ log 'limit(head(), 1)'
987 987 0
988 988 $ log 'limit(author("re:bob|test"), 3, 5)'
989 989 5
990 990 6
991 991 7
992 992 $ log 'limit(author("re:bob|test"), offset=6)'
993 993 6
994 994 $ log 'limit(author("re:bob|test"), offset=10)'
995 995 $ log 'limit(all(), 1, -1)'
996 996 hg: parse error: negative offset
997 997 [255]
998 998 $ log 'matching(6)'
999 999 6
1000 1000 $ log 'matching(6:7, "phase parents user date branch summary files description substate")'
1001 1001 6
1002 1002 7
1003 1003
1004 1004 Testing min and max
1005 1005
1006 1006 max: simple
1007 1007
1008 1008 $ log 'max(contains(a))'
1009 1009 5
1010 1010
1011 1011 max: simple on unordered set)
1012 1012
1013 1013 $ log 'max((4+0+2+5+7) and contains(a))'
1014 1014 5
1015 1015
1016 1016 max: no result
1017 1017
1018 1018 $ log 'max(contains(stringthatdoesnotappearanywhere))'
1019 1019
1020 1020 max: no result on unordered set
1021 1021
1022 1022 $ log 'max((4+0+2+5+7) and contains(stringthatdoesnotappearanywhere))'
1023 1023
1024 1024 min: simple
1025 1025
1026 1026 $ log 'min(contains(a))'
1027 1027 0
1028 1028
1029 1029 min: simple on unordered set
1030 1030
1031 1031 $ log 'min((4+0+2+5+7) and contains(a))'
1032 1032 0
1033 1033
1034 1034 min: empty
1035 1035
1036 1036 $ log 'min(contains(stringthatdoesnotappearanywhere))'
1037 1037
1038 1038 min: empty on unordered set
1039 1039
1040 1040 $ log 'min((4+0+2+5+7) and contains(stringthatdoesnotappearanywhere))'
1041 1041
1042 1042
1043 1043 $ log 'merge()'
1044 1044 6
1045 1045 $ log 'branchpoint()'
1046 1046 1
1047 1047 4
1048 1048 $ log 'modifies(b)'
1049 1049 4
1050 1050 $ log 'modifies("path:b")'
1051 1051 4
1052 1052 $ log 'modifies("*")'
1053 1053 4
1054 1054 6
1055 1055 $ log 'modifies("set:modified()")'
1056 1056 4
1057 1057 $ log 'id(5)'
1058 1058 2
1059 1059 $ log 'only(9)'
1060 1060 8
1061 1061 9
1062 1062 $ log 'only(8)'
1063 1063 8
1064 1064 $ log 'only(9, 5)'
1065 1065 2
1066 1066 4
1067 1067 8
1068 1068 9
1069 1069 $ log 'only(7 + 9, 5 + 2)'
1070 1070 4
1071 1071 6
1072 1072 7
1073 1073 8
1074 1074 9
1075 1075
1076 1076 Test empty set input
1077 1077 $ log 'only(p2())'
1078 1078 $ log 'only(p1(), p2())'
1079 1079 0
1080 1080 1
1081 1081 2
1082 1082 4
1083 1083 8
1084 1084 9
1085 1085
1086 1086 Test '%' operator
1087 1087
1088 1088 $ log '9%'
1089 1089 8
1090 1090 9
1091 1091 $ log '9%5'
1092 1092 2
1093 1093 4
1094 1094 8
1095 1095 9
1096 1096 $ log '(7 + 9)%(5 + 2)'
1097 1097 4
1098 1098 6
1099 1099 7
1100 1100 8
1101 1101 9
1102 1102
1103 1103 Test operand of '%' is optimized recursively (issue4670)
1104 1104
1105 1105 $ try --optimize '8:9-8%'
1106 1106 (onlypost
1107 1107 (minus
1108 1108 (range
1109 1109 ('symbol', '8')
1110 1110 ('symbol', '9'))
1111 1111 ('symbol', '8')))
1112 1112 * optimized:
1113 1113 (func
1114 1114 ('symbol', 'only')
1115 1115 (difference
1116 1116 (range
1117 1117 ('symbol', '8')
1118 1118 ('symbol', '9')
1119 1119 define)
1120 1120 ('symbol', '8')
1121 1121 define)
1122 1122 define)
1123 1123 * set:
1124 1124 <baseset+ [8, 9]>
1125 1125 8
1126 1126 9
1127 1127 $ try --optimize '(9)%(5)'
1128 1128 (only
1129 1129 (group
1130 1130 ('symbol', '9'))
1131 1131 (group
1132 1132 ('symbol', '5')))
1133 1133 * optimized:
1134 1134 (func
1135 1135 ('symbol', 'only')
1136 1136 (list
1137 1137 ('symbol', '9')
1138 1138 ('symbol', '5'))
1139 1139 define)
1140 1140 * set:
1141 1141 <baseset+ [2, 4, 8, 9]>
1142 1142 2
1143 1143 4
1144 1144 8
1145 1145 9
1146 1146
1147 1147 Test the order of operations
1148 1148
1149 1149 $ log '7 + 9%5 + 2'
1150 1150 7
1151 1151 2
1152 1152 4
1153 1153 8
1154 1154 9
1155 1155
1156 1156 Test explicit numeric revision
1157 1157 $ log 'rev(-2)'
1158 1158 $ log 'rev(-1)'
1159 1159 -1
1160 1160 $ log 'rev(0)'
1161 1161 0
1162 1162 $ log 'rev(9)'
1163 1163 9
1164 1164 $ log 'rev(10)'
1165 1165 $ log 'rev(tip)'
1166 1166 hg: parse error: rev expects a number
1167 1167 [255]
1168 1168
1169 1169 Test hexadecimal revision
1170 1170 $ log 'id(2)'
1171 1171 abort: 00changelog.i@2: ambiguous identifier!
1172 1172 [255]
1173 1173 $ log 'id(23268)'
1174 1174 4
1175 1175 $ log 'id(2785f51eece)'
1176 1176 0
1177 1177 $ log 'id(d5d0dcbdc4d9ff5dbb2d336f32f0bb561c1a532c)'
1178 1178 8
1179 1179 $ log 'id(d5d0dcbdc4a)'
1180 1180 $ log 'id(d5d0dcbdc4w)'
1181 1181 $ log 'id(d5d0dcbdc4d9ff5dbb2d336f32f0bb561c1a532d)'
1182 1182 $ log 'id(d5d0dcbdc4d9ff5dbb2d336f32f0bb561c1a532q)'
1183 1183 $ log 'id(1.0)'
1184 1184 $ log 'id(xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)'
1185 1185
1186 1186 Test null revision
1187 1187 $ log '(null)'
1188 1188 -1
1189 1189 $ log '(null:0)'
1190 1190 -1
1191 1191 0
1192 1192 $ log '(0:null)'
1193 1193 0
1194 1194 -1
1195 1195 $ log 'null::0'
1196 1196 -1
1197 1197 0
1198 1198 $ log 'null:tip - 0:'
1199 1199 -1
1200 1200 $ log 'null: and null::' | head -1
1201 1201 -1
1202 1202 $ log 'null: or 0:' | head -2
1203 1203 -1
1204 1204 0
1205 1205 $ log 'ancestors(null)'
1206 1206 -1
1207 1207 $ log 'reverse(null:)' | tail -2
1208 1208 0
1209 1209 -1
1210 1210 BROKEN: should be '-1'
1211 1211 $ log 'first(null:)'
1212 1212 BROKEN: should be '-1'
1213 1213 $ log 'min(null:)'
1214 1214 $ log 'tip:null and all()' | tail -2
1215 1215 1
1216 1216 0
1217 1217
1218 1218 Test working-directory revision
1219 1219 $ hg debugrevspec 'wdir()'
1220 1220 2147483647
1221 1221 $ hg debugrevspec 'tip or wdir()'
1222 1222 9
1223 1223 2147483647
1224 1224 $ hg debugrevspec '0:tip and wdir()'
1225 1225 $ log '0:wdir()' | tail -3
1226 1226 8
1227 1227 9
1228 1228 2147483647
1229 1229 $ log 'wdir():0' | head -3
1230 1230 2147483647
1231 1231 9
1232 1232 8
1233 1233 $ log 'wdir():wdir()'
1234 1234 2147483647
1235 1235 $ log '(all() + wdir()) & min(. + wdir())'
1236 1236 9
1237 1237 $ log '(all() + wdir()) & max(. + wdir())'
1238 1238 2147483647
1239 1239 $ log '(all() + wdir()) & first(wdir() + .)'
1240 1240 2147483647
1241 1241 $ log '(all() + wdir()) & last(. + wdir())'
1242 1242 2147483647
1243 1243
1244 1244 $ log 'outgoing()'
1245 1245 8
1246 1246 9
1247 1247 $ log 'outgoing("../remote1")'
1248 1248 8
1249 1249 9
1250 1250 $ log 'outgoing("../remote2")'
1251 1251 3
1252 1252 5
1253 1253 6
1254 1254 7
1255 1255 9
1256 1256 $ log 'p1(merge())'
1257 1257 5
1258 1258 $ log 'p2(merge())'
1259 1259 4
1260 1260 $ log 'parents(merge())'
1261 1261 4
1262 1262 5
1263 1263 $ log 'p1(branchpoint())'
1264 1264 0
1265 1265 2
1266 1266 $ log 'p2(branchpoint())'
1267 1267 $ log 'parents(branchpoint())'
1268 1268 0
1269 1269 2
1270 1270 $ log 'removes(a)'
1271 1271 2
1272 1272 6
1273 1273 $ log 'roots(all())'
1274 1274 0
1275 1275 $ log 'reverse(2 or 3 or 4 or 5)'
1276 1276 5
1277 1277 4
1278 1278 3
1279 1279 2
1280 1280 $ log 'reverse(all())'
1281 1281 9
1282 1282 8
1283 1283 7
1284 1284 6
1285 1285 5
1286 1286 4
1287 1287 3
1288 1288 2
1289 1289 1
1290 1290 0
1291 1291 $ log 'reverse(all()) & filelog(b)'
1292 1292 4
1293 1293 1
1294 1294 $ log 'rev(5)'
1295 1295 5
1296 1296 $ log 'sort(limit(reverse(all()), 3))'
1297 1297 7
1298 1298 8
1299 1299 9
1300 1300 $ log 'sort(2 or 3 or 4 or 5, date)'
1301 1301 2
1302 1302 3
1303 1303 5
1304 1304 4
1305 1305 $ log 'tagged()'
1306 1306 6
1307 1307 $ log 'tag()'
1308 1308 6
1309 1309 $ log 'tag(1.0)'
1310 1310 6
1311 1311 $ log 'tag(tip)'
1312 1312 9
1313 1313
1314 1314 Test order of revisions in compound expression
1315 1315 ----------------------------------------------
1316 1316
1317 1317 The general rule is that only the outermost (= leftmost) predicate can
1318 1318 enforce its ordering requirement. The other predicates should take the
1319 1319 ordering defined by it.
1320 1320
1321 1321 'A & B' should follow the order of 'A':
1322 1322
1323 1323 $ log '2:0 & 0::2'
1324 1324 2
1325 1325 1
1326 1326 0
1327 1327
1328 1328 'head()' combines sets in right order:
1329 1329
1330 1330 $ log '2:0 & head()'
1331 1331 2
1332 1332 1
1333 1333 0
1334 1334
1335 1335 'x:y' takes ordering parameter into account:
1336 1336
1337 1337 $ try -p optimized '3:0 & 0:3 & not 2:1'
1338 1338 * optimized:
1339 1339 (difference
1340 1340 (and
1341 1341 (range
1342 1342 ('symbol', '3')
1343 1343 ('symbol', '0')
1344 1344 define)
1345 1345 (range
1346 1346 ('symbol', '0')
1347 1347 ('symbol', '3')
1348 1348 follow)
1349 1349 define)
1350 1350 (range
1351 1351 ('symbol', '2')
1352 1352 ('symbol', '1')
1353 1353 any)
1354 1354 define)
1355 1355 * set:
1356 1356 <filteredset
1357 1357 <filteredset
1358 1358 <spanset- 0:3>,
1359 1359 <spanset+ 0:3>>,
1360 1360 <not
1361 1361 <spanset+ 1:2>>>
1362 1362 3
1363 1363 0
1364 1364
1365 1365 'a + b', which is optimized to '_list(a b)', should take the ordering of
1366 1366 the left expression:
1367 1367
1368 1368 $ try --optimize '2:0 & (0 + 1 + 2)'
1369 1369 (and
1370 1370 (range
1371 1371 ('symbol', '2')
1372 1372 ('symbol', '0'))
1373 1373 (group
1374 1374 (or
1375 1375 (list
1376 1376 ('symbol', '0')
1377 1377 ('symbol', '1')
1378 1378 ('symbol', '2')))))
1379 1379 * optimized:
1380 1380 (and
1381 1381 (range
1382 1382 ('symbol', '2')
1383 1383 ('symbol', '0')
1384 1384 define)
1385 1385 (func
1386 1386 ('symbol', '_list')
1387 1387 ('string', '0\x001\x002')
1388 1388 follow)
1389 1389 define)
1390 1390 * set:
1391 1391 <filteredset
1392 1392 <spanset- 0:2>,
1393 1393 <baseset [0, 1, 2]>>
1394 1394 2
1395 1395 1
1396 1396 0
1397 1397
1398 1398 'A + B' should take the ordering of the left expression:
1399 1399
1400 1400 $ try --optimize '2:0 & (0:1 + 2)'
1401 1401 (and
1402 1402 (range
1403 1403 ('symbol', '2')
1404 1404 ('symbol', '0'))
1405 1405 (group
1406 1406 (or
1407 1407 (list
1408 1408 (range
1409 1409 ('symbol', '0')
1410 1410 ('symbol', '1'))
1411 1411 ('symbol', '2')))))
1412 1412 * optimized:
1413 1413 (and
1414 1414 (range
1415 1415 ('symbol', '2')
1416 1416 ('symbol', '0')
1417 1417 define)
1418 1418 (or
1419 1419 (list
1420 1420 (range
1421 1421 ('symbol', '0')
1422 1422 ('symbol', '1')
1423 1423 follow)
1424 1424 ('symbol', '2'))
1425 1425 follow)
1426 1426 define)
1427 1427 * set:
1428 1428 <filteredset
1429 1429 <spanset- 0:2>,
1430 1430 <addset
1431 1431 <spanset+ 0:1>,
1432 1432 <baseset [2]>>>
1433 1433 2
1434 1434 1
1435 1435 0
1436 1436
1437 1437 '_intlist(a b)' should behave like 'a + b':
1438 1438
1439 1439 $ trylist --optimize '2:0 & %ld' 0 1 2
1440 1440 (and
1441 1441 (range
1442 1442 ('symbol', '2')
1443 1443 ('symbol', '0'))
1444 1444 (func
1445 1445 ('symbol', '_intlist')
1446 1446 ('string', '0\x001\x002')))
1447 1447 * optimized:
1448 1448 (and
1449 1449 (func
1450 1450 ('symbol', '_intlist')
1451 1451 ('string', '0\x001\x002')
1452 1452 follow)
1453 1453 (range
1454 1454 ('symbol', '2')
1455 1455 ('symbol', '0')
1456 1456 define)
1457 1457 define)
1458 1458 * set:
1459 1459 <filteredset
1460 1460 <spanset- 0:2>,
1461 1461 <baseset+ [0, 1, 2]>>
1462 1462 2
1463 1463 1
1464 1464 0
1465 1465
1466 1466 $ trylist --optimize '%ld & 2:0' 0 2 1
1467 1467 (and
1468 1468 (func
1469 1469 ('symbol', '_intlist')
1470 1470 ('string', '0\x002\x001'))
1471 1471 (range
1472 1472 ('symbol', '2')
1473 1473 ('symbol', '0')))
1474 1474 * optimized:
1475 1475 (and
1476 1476 (func
1477 1477 ('symbol', '_intlist')
1478 1478 ('string', '0\x002\x001')
1479 1479 define)
1480 1480 (range
1481 1481 ('symbol', '2')
1482 1482 ('symbol', '0')
1483 1483 follow)
1484 1484 define)
1485 1485 * set:
1486 1486 <filteredset
1487 1487 <baseset [0, 2, 1]>,
1488 1488 <spanset- 0:2>>
1489 1489 0
1490 1490 2
1491 1491 1
1492 1492
1493 1493 '_hexlist(a b)' should behave like 'a + b':
1494 1494
1495 1495 $ trylist --optimize --bin '2:0 & %ln' `hg log -T '{node} ' -r0:2`
1496 1496 (and
1497 1497 (range
1498 1498 ('symbol', '2')
1499 1499 ('symbol', '0'))
1500 1500 (func
1501 1501 ('symbol', '_hexlist')
1502 1502 ('string', '*'))) (glob)
1503 1503 * optimized:
1504 1504 (and
1505 1505 (range
1506 1506 ('symbol', '2')
1507 1507 ('symbol', '0')
1508 1508 define)
1509 1509 (func
1510 1510 ('symbol', '_hexlist')
1511 1511 ('string', '*') (glob)
1512 1512 follow)
1513 1513 define)
1514 1514 * set:
1515 1515 <filteredset
1516 1516 <spanset- 0:2>,
1517 1517 <baseset [0, 1, 2]>>
1518 1518 2
1519 1519 1
1520 1520 0
1521 1521
1522 1522 $ trylist --optimize --bin '%ln & 2:0' `hg log -T '{node} ' -r0+2+1`
1523 1523 (and
1524 1524 (func
1525 1525 ('symbol', '_hexlist')
1526 1526 ('string', '*')) (glob)
1527 1527 (range
1528 1528 ('symbol', '2')
1529 1529 ('symbol', '0')))
1530 1530 * optimized:
1531 1531 (and
1532 1532 (range
1533 1533 ('symbol', '2')
1534 1534 ('symbol', '0')
1535 1535 follow)
1536 1536 (func
1537 1537 ('symbol', '_hexlist')
1538 1538 ('string', '*') (glob)
1539 1539 define)
1540 1540 define)
1541 1541 * set:
1542 1542 <baseset [0, 2, 1]>
1543 1543 0
1544 1544 2
1545 1545 1
1546 1546
1547 1547 '_list' should not go through the slow follow-order path if order doesn't
1548 1548 matter:
1549 1549
1550 1550 $ try -p optimized '2:0 & not (0 + 1)'
1551 1551 * optimized:
1552 1552 (difference
1553 1553 (range
1554 1554 ('symbol', '2')
1555 1555 ('symbol', '0')
1556 1556 define)
1557 1557 (func
1558 1558 ('symbol', '_list')
1559 1559 ('string', '0\x001')
1560 1560 any)
1561 1561 define)
1562 1562 * set:
1563 1563 <filteredset
1564 1564 <spanset- 0:2>,
1565 1565 <not
1566 1566 <baseset [0, 1]>>>
1567 1567 2
1568 1568
1569 1569 $ try -p optimized '2:0 & not (0:2 & (0 + 1))'
1570 1570 * optimized:
1571 1571 (difference
1572 1572 (range
1573 1573 ('symbol', '2')
1574 1574 ('symbol', '0')
1575 1575 define)
1576 1576 (and
1577 1577 (range
1578 1578 ('symbol', '0')
1579 1579 ('symbol', '2')
1580 1580 any)
1581 1581 (func
1582 1582 ('symbol', '_list')
1583 1583 ('string', '0\x001')
1584 1584 any)
1585 1585 any)
1586 1586 define)
1587 1587 * set:
1588 1588 <filteredset
1589 1589 <spanset- 0:2>,
1590 1590 <not
1591 1591 <baseset [0, 1]>>>
1592 1592 2
1593 1593
1594 1594 because 'present()' does nothing other than suppressing an error, the
1595 1595 ordering requirement should be forwarded to the nested expression
1596 1596
1597 1597 $ try -p optimized 'present(2 + 0 + 1)'
1598 1598 * optimized:
1599 1599 (func
1600 1600 ('symbol', 'present')
1601 1601 (func
1602 1602 ('symbol', '_list')
1603 1603 ('string', '2\x000\x001')
1604 1604 define)
1605 1605 define)
1606 1606 * set:
1607 1607 <baseset [2, 0, 1]>
1608 1608 2
1609 1609 0
1610 1610 1
1611 1611
1612 1612 $ try --optimize '2:0 & present(0 + 1 + 2)'
1613 1613 (and
1614 1614 (range
1615 1615 ('symbol', '2')
1616 1616 ('symbol', '0'))
1617 1617 (func
1618 1618 ('symbol', 'present')
1619 1619 (or
1620 1620 (list
1621 1621 ('symbol', '0')
1622 1622 ('symbol', '1')
1623 1623 ('symbol', '2')))))
1624 1624 * optimized:
1625 1625 (and
1626 1626 (range
1627 1627 ('symbol', '2')
1628 1628 ('symbol', '0')
1629 1629 define)
1630 1630 (func
1631 1631 ('symbol', 'present')
1632 1632 (func
1633 1633 ('symbol', '_list')
1634 1634 ('string', '0\x001\x002')
1635 1635 follow)
1636 1636 follow)
1637 1637 define)
1638 1638 * set:
1639 1639 <filteredset
1640 1640 <spanset- 0:2>,
1641 1641 <baseset [0, 1, 2]>>
1642 1642 2
1643 1643 1
1644 1644 0
1645 1645
1646 1646 'reverse()' should take effect only if it is the outermost expression:
1647 1647
1648 1648 $ try --optimize '0:2 & reverse(all())'
1649 1649 (and
1650 1650 (range
1651 1651 ('symbol', '0')
1652 1652 ('symbol', '2'))
1653 1653 (func
1654 1654 ('symbol', 'reverse')
1655 1655 (func
1656 1656 ('symbol', 'all')
1657 1657 None)))
1658 1658 * optimized:
1659 1659 (and
1660 1660 (range
1661 1661 ('symbol', '0')
1662 1662 ('symbol', '2')
1663 1663 define)
1664 1664 (func
1665 1665 ('symbol', 'reverse')
1666 1666 (func
1667 1667 ('symbol', 'all')
1668 1668 None
1669 1669 define)
1670 1670 follow)
1671 1671 define)
1672 1672 * set:
1673 1673 <filteredset
1674 1674 <spanset+ 0:2>,
1675 1675 <spanset+ 0:9>>
1676 1676 0
1677 1677 1
1678 1678 2
1679 1679
1680 1680 'sort()' should take effect only if it is the outermost expression:
1681 1681
1682 1682 $ try --optimize '0:2 & sort(all(), -rev)'
1683 1683 (and
1684 1684 (range
1685 1685 ('symbol', '0')
1686 1686 ('symbol', '2'))
1687 1687 (func
1688 1688 ('symbol', 'sort')
1689 1689 (list
1690 1690 (func
1691 1691 ('symbol', 'all')
1692 1692 None)
1693 1693 (negate
1694 1694 ('symbol', 'rev')))))
1695 1695 * optimized:
1696 1696 (and
1697 1697 (range
1698 1698 ('symbol', '0')
1699 1699 ('symbol', '2')
1700 1700 define)
1701 1701 (func
1702 1702 ('symbol', 'sort')
1703 1703 (list
1704 1704 (func
1705 1705 ('symbol', 'all')
1706 1706 None
1707 1707 define)
1708 1708 ('string', '-rev'))
1709 1709 follow)
1710 1710 define)
1711 1711 * set:
1712 1712 <filteredset
1713 1713 <spanset+ 0:2>,
1714 1714 <spanset+ 0:9>>
1715 1715 0
1716 1716 1
1717 1717 2
1718 1718
1719 1719 invalid argument passed to noop sort():
1720 1720
1721 1721 $ log '0:2 & sort()'
1722 1722 hg: parse error: sort requires one or two arguments
1723 1723 [255]
1724 1724 $ log '0:2 & sort(all(), -invalid)'
1725 1725 hg: parse error: unknown sort key '-invalid'
1726 1726 [255]
1727 1727
1728 1728 for 'A & f(B)', 'B' should not be affected by the order of 'A':
1729 1729
1730 1730 $ try --optimize '2:0 & first(1 + 0 + 2)'
1731 1731 (and
1732 1732 (range
1733 1733 ('symbol', '2')
1734 1734 ('symbol', '0'))
1735 1735 (func
1736 1736 ('symbol', 'first')
1737 1737 (or
1738 1738 (list
1739 1739 ('symbol', '1')
1740 1740 ('symbol', '0')
1741 1741 ('symbol', '2')))))
1742 1742 * optimized:
1743 1743 (and
1744 1744 (range
1745 1745 ('symbol', '2')
1746 1746 ('symbol', '0')
1747 1747 define)
1748 1748 (func
1749 1749 ('symbol', 'first')
1750 1750 (func
1751 1751 ('symbol', '_list')
1752 1752 ('string', '1\x000\x002')
1753 1753 define)
1754 1754 follow)
1755 1755 define)
1756 1756 * set:
1757 1757 <baseset
1758 1758 <limit n=1, offset=0,
1759 1759 <spanset- 0:2>,
1760 1760 <baseset [1, 0, 2]>>>
1761 1761 1
1762 1762
1763 1763 $ try --optimize '2:0 & not last(0 + 2 + 1)'
1764 1764 (and
1765 1765 (range
1766 1766 ('symbol', '2')
1767 1767 ('symbol', '0'))
1768 1768 (not
1769 1769 (func
1770 1770 ('symbol', 'last')
1771 1771 (or
1772 1772 (list
1773 1773 ('symbol', '0')
1774 1774 ('symbol', '2')
1775 1775 ('symbol', '1'))))))
1776 1776 * optimized:
1777 1777 (difference
1778 1778 (range
1779 1779 ('symbol', '2')
1780 1780 ('symbol', '0')
1781 1781 define)
1782 1782 (func
1783 1783 ('symbol', 'last')
1784 1784 (func
1785 1785 ('symbol', '_list')
1786 1786 ('string', '0\x002\x001')
1787 1787 define)
1788 1788 any)
1789 1789 define)
1790 1790 * set:
1791 1791 <filteredset
1792 1792 <spanset- 0:2>,
1793 1793 <not
1794 1794 <baseset
1795 1795 <last n=1,
1796 1796 <fullreposet+ 0:9>,
1797 1797 <baseset [1, 2, 0]>>>>>
1798 1798 2
1799 1799 0
1800 1800
1801 1801 for 'A & (op)(B)', 'B' should not be affected by the order of 'A':
1802 1802
1803 1803 $ try --optimize '2:0 & (1 + 0 + 2):(0 + 2 + 1)'
1804 1804 (and
1805 1805 (range
1806 1806 ('symbol', '2')
1807 1807 ('symbol', '0'))
1808 1808 (range
1809 1809 (group
1810 1810 (or
1811 1811 (list
1812 1812 ('symbol', '1')
1813 1813 ('symbol', '0')
1814 1814 ('symbol', '2'))))
1815 1815 (group
1816 1816 (or
1817 1817 (list
1818 1818 ('symbol', '0')
1819 1819 ('symbol', '2')
1820 1820 ('symbol', '1'))))))
1821 1821 * optimized:
1822 1822 (and
1823 1823 (range
1824 1824 ('symbol', '2')
1825 1825 ('symbol', '0')
1826 1826 define)
1827 1827 (range
1828 1828 (func
1829 1829 ('symbol', '_list')
1830 1830 ('string', '1\x000\x002')
1831 1831 define)
1832 1832 (func
1833 1833 ('symbol', '_list')
1834 1834 ('string', '0\x002\x001')
1835 1835 define)
1836 1836 follow)
1837 1837 define)
1838 1838 * set:
1839 1839 <filteredset
1840 1840 <spanset- 0:2>,
1841 1841 <baseset [1]>>
1842 1842 1
1843 1843
1844 1844 'A & B' can be rewritten as 'B & A' by weight, but that's fine as long as
1845 1845 the ordering rule is determined before the rewrite; in this example,
1846 1846 'B' follows the order of the initial set, which is the same order as 'A'
1847 1847 since 'A' also follows the order:
1848 1848
1849 1849 $ try --optimize 'contains("glob:*") & (2 + 0 + 1)'
1850 1850 (and
1851 1851 (func
1852 1852 ('symbol', 'contains')
1853 1853 ('string', 'glob:*'))
1854 1854 (group
1855 1855 (or
1856 1856 (list
1857 1857 ('symbol', '2')
1858 1858 ('symbol', '0')
1859 1859 ('symbol', '1')))))
1860 1860 * optimized:
1861 1861 (and
1862 1862 (func
1863 1863 ('symbol', '_list')
1864 1864 ('string', '2\x000\x001')
1865 1865 follow)
1866 1866 (func
1867 1867 ('symbol', 'contains')
1868 1868 ('string', 'glob:*')
1869 1869 define)
1870 1870 define)
1871 1871 * set:
1872 1872 <filteredset
1873 1873 <baseset+ [0, 1, 2]>,
1874 1874 <contains 'glob:*'>>
1875 1875 0
1876 1876 1
1877 1877 2
1878 1878
1879 1879 and in this example, 'A & B' is rewritten as 'B & A', but 'A' overrides
1880 1880 the order appropriately:
1881 1881
1882 1882 $ try --optimize 'reverse(contains("glob:*")) & (0 + 2 + 1)'
1883 1883 (and
1884 1884 (func
1885 1885 ('symbol', 'reverse')
1886 1886 (func
1887 1887 ('symbol', 'contains')
1888 1888 ('string', 'glob:*')))
1889 1889 (group
1890 1890 (or
1891 1891 (list
1892 1892 ('symbol', '0')
1893 1893 ('symbol', '2')
1894 1894 ('symbol', '1')))))
1895 1895 * optimized:
1896 1896 (and
1897 1897 (func
1898 1898 ('symbol', '_list')
1899 1899 ('string', '0\x002\x001')
1900 1900 follow)
1901 1901 (func
1902 1902 ('symbol', 'reverse')
1903 1903 (func
1904 1904 ('symbol', 'contains')
1905 1905 ('string', 'glob:*')
1906 1906 define)
1907 1907 define)
1908 1908 define)
1909 1909 * set:
1910 1910 <filteredset
1911 1911 <baseset- [0, 1, 2]>,
1912 1912 <contains 'glob:*'>>
1913 1913 2
1914 1914 1
1915 1915 0
1916 1916
1917 1917 test sort revset
1918 1918 --------------------------------------------
1919 1919
1920 1920 test when adding two unordered revsets
1921 1921
1922 1922 $ log 'sort(keyword(issue) or modifies(b))'
1923 1923 4
1924 1924 6
1925 1925
1926 1926 test when sorting a reversed collection in the same way it is
1927 1927
1928 1928 $ log 'sort(reverse(all()), -rev)'
1929 1929 9
1930 1930 8
1931 1931 7
1932 1932 6
1933 1933 5
1934 1934 4
1935 1935 3
1936 1936 2
1937 1937 1
1938 1938 0
1939 1939
1940 1940 test when sorting a reversed collection
1941 1941
1942 1942 $ log 'sort(reverse(all()), rev)'
1943 1943 0
1944 1944 1
1945 1945 2
1946 1946 3
1947 1947 4
1948 1948 5
1949 1949 6
1950 1950 7
1951 1951 8
1952 1952 9
1953 1953
1954 1954
1955 1955 test sorting two sorted collections in different orders
1956 1956
1957 1957 $ log 'sort(outgoing() or reverse(removes(a)), rev)'
1958 1958 2
1959 1959 6
1960 1960 8
1961 1961 9
1962 1962
1963 1963 test sorting two sorted collections in different orders backwards
1964 1964
1965 1965 $ log 'sort(outgoing() or reverse(removes(a)), -rev)'
1966 1966 9
1967 1967 8
1968 1968 6
1969 1969 2
1970 1970
1971 1971 test empty sort key which is noop
1972 1972
1973 1973 $ log 'sort(0 + 2 + 1, "")'
1974 1974 0
1975 1975 2
1976 1976 1
1977 1977
1978 1978 test invalid sort keys
1979 1979
1980 1980 $ log 'sort(all(), -invalid)'
1981 1981 hg: parse error: unknown sort key '-invalid'
1982 1982 [255]
1983 1983
1984 1984 $ cd ..
1985 1985
1986 1986 test sorting by multiple keys including variable-length strings
1987 1987
1988 1988 $ hg init sorting
1989 1989 $ cd sorting
1990 1990 $ cat <<EOF >> .hg/hgrc
1991 1991 > [ui]
1992 1992 > logtemplate = '{rev} {branch|p5}{desc|p5}{author|p5}{date|hgdate}\n'
1993 1993 > [templatealias]
1994 1994 > p5(s) = pad(s, 5)
1995 1995 > EOF
1996 1996 $ hg branch -qf b12
1997 1997 $ hg ci -m m111 -u u112 -d '111 10800'
1998 1998 $ hg branch -qf b11
1999 1999 $ hg ci -m m12 -u u111 -d '112 7200'
2000 2000 $ hg branch -qf b111
2001 2001 $ hg ci -m m11 -u u12 -d '111 3600'
2002 2002 $ hg branch -qf b112
2003 2003 $ hg ci -m m111 -u u11 -d '120 0'
2004 2004 $ hg branch -qf b111
2005 2005 $ hg ci -m m112 -u u111 -d '110 14400'
2006 2006 created new head
2007 2007
2008 2008 compare revisions (has fast path):
2009 2009
2010 2010 $ hg log -r 'sort(all(), rev)'
2011 2011 0 b12 m111 u112 111 10800
2012 2012 1 b11 m12 u111 112 7200
2013 2013 2 b111 m11 u12 111 3600
2014 2014 3 b112 m111 u11 120 0
2015 2015 4 b111 m112 u111 110 14400
2016 2016
2017 2017 $ hg log -r 'sort(all(), -rev)'
2018 2018 4 b111 m112 u111 110 14400
2019 2019 3 b112 m111 u11 120 0
2020 2020 2 b111 m11 u12 111 3600
2021 2021 1 b11 m12 u111 112 7200
2022 2022 0 b12 m111 u112 111 10800
2023 2023
2024 2024 compare variable-length strings (issue5218):
2025 2025
2026 2026 $ hg log -r 'sort(all(), branch)'
2027 2027 1 b11 m12 u111 112 7200
2028 2028 2 b111 m11 u12 111 3600
2029 2029 4 b111 m112 u111 110 14400
2030 2030 3 b112 m111 u11 120 0
2031 2031 0 b12 m111 u112 111 10800
2032 2032
2033 2033 $ hg log -r 'sort(all(), -branch)'
2034 2034 0 b12 m111 u112 111 10800
2035 2035 3 b112 m111 u11 120 0
2036 2036 2 b111 m11 u12 111 3600
2037 2037 4 b111 m112 u111 110 14400
2038 2038 1 b11 m12 u111 112 7200
2039 2039
2040 2040 $ hg log -r 'sort(all(), desc)'
2041 2041 2 b111 m11 u12 111 3600
2042 2042 0 b12 m111 u112 111 10800
2043 2043 3 b112 m111 u11 120 0
2044 2044 4 b111 m112 u111 110 14400
2045 2045 1 b11 m12 u111 112 7200
2046 2046
2047 2047 $ hg log -r 'sort(all(), -desc)'
2048 2048 1 b11 m12 u111 112 7200
2049 2049 4 b111 m112 u111 110 14400
2050 2050 0 b12 m111 u112 111 10800
2051 2051 3 b112 m111 u11 120 0
2052 2052 2 b111 m11 u12 111 3600
2053 2053
2054 2054 $ hg log -r 'sort(all(), user)'
2055 2055 3 b112 m111 u11 120 0
2056 2056 1 b11 m12 u111 112 7200
2057 2057 4 b111 m112 u111 110 14400
2058 2058 0 b12 m111 u112 111 10800
2059 2059 2 b111 m11 u12 111 3600
2060 2060
2061 2061 $ hg log -r 'sort(all(), -user)'
2062 2062 2 b111 m11 u12 111 3600
2063 2063 0 b12 m111 u112 111 10800
2064 2064 1 b11 m12 u111 112 7200
2065 2065 4 b111 m112 u111 110 14400
2066 2066 3 b112 m111 u11 120 0
2067 2067
2068 2068 compare dates (tz offset should have no effect):
2069 2069
2070 2070 $ hg log -r 'sort(all(), date)'
2071 2071 4 b111 m112 u111 110 14400
2072 2072 0 b12 m111 u112 111 10800
2073 2073 2 b111 m11 u12 111 3600
2074 2074 1 b11 m12 u111 112 7200
2075 2075 3 b112 m111 u11 120 0
2076 2076
2077 2077 $ hg log -r 'sort(all(), -date)'
2078 2078 3 b112 m111 u11 120 0
2079 2079 1 b11 m12 u111 112 7200
2080 2080 0 b12 m111 u112 111 10800
2081 2081 2 b111 m11 u12 111 3600
2082 2082 4 b111 m112 u111 110 14400
2083 2083
2084 2084 be aware that 'sort(x, -k)' is not exactly the same as 'reverse(sort(x, k))'
2085 2085 because '-k' reverses the comparison, not the list itself:
2086 2086
2087 2087 $ hg log -r 'sort(0 + 2, date)'
2088 2088 0 b12 m111 u112 111 10800
2089 2089 2 b111 m11 u12 111 3600
2090 2090
2091 2091 $ hg log -r 'sort(0 + 2, -date)'
2092 2092 0 b12 m111 u112 111 10800
2093 2093 2 b111 m11 u12 111 3600
2094 2094
2095 2095 $ hg log -r 'reverse(sort(0 + 2, date))'
2096 2096 2 b111 m11 u12 111 3600
2097 2097 0 b12 m111 u112 111 10800
2098 2098
2099 2099 sort by multiple keys:
2100 2100
2101 2101 $ hg log -r 'sort(all(), "branch -rev")'
2102 2102 1 b11 m12 u111 112 7200
2103 2103 4 b111 m112 u111 110 14400
2104 2104 2 b111 m11 u12 111 3600
2105 2105 3 b112 m111 u11 120 0
2106 2106 0 b12 m111 u112 111 10800
2107 2107
2108 2108 $ hg log -r 'sort(all(), "-desc -date")'
2109 2109 1 b11 m12 u111 112 7200
2110 2110 4 b111 m112 u111 110 14400
2111 2111 3 b112 m111 u11 120 0
2112 2112 0 b12 m111 u112 111 10800
2113 2113 2 b111 m11 u12 111 3600
2114 2114
2115 2115 $ hg log -r 'sort(all(), "user -branch date rev")'
2116 2116 3 b112 m111 u11 120 0
2117 2117 4 b111 m112 u111 110 14400
2118 2118 1 b11 m12 u111 112 7200
2119 2119 0 b12 m111 u112 111 10800
2120 2120 2 b111 m11 u12 111 3600
2121 2121
2122 2122 toposort prioritises graph branches
2123 2123
2124 2124 $ hg up 2
2125 2125 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
2126 2126 $ touch a
2127 2127 $ hg addremove
2128 2128 adding a
2129 2129 $ hg ci -m 't1' -u 'tu' -d '130 0'
2130 2130 created new head
2131 2131 $ echo 'a' >> a
2132 2132 $ hg ci -m 't2' -u 'tu' -d '130 0'
2133 2133 $ hg book book1
2134 2134 $ hg up 4
2135 2135 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
2136 2136 (leaving bookmark book1)
2137 2137 $ touch a
2138 2138 $ hg addremove
2139 2139 adding a
2140 2140 $ hg ci -m 't3' -u 'tu' -d '130 0'
2141 2141
2142 2142 $ hg log -r 'sort(all(), topo)'
2143 2143 7 b111 t3 tu 130 0
2144 2144 4 b111 m112 u111 110 14400
2145 2145 3 b112 m111 u11 120 0
2146 2146 6 b111 t2 tu 130 0
2147 2147 5 b111 t1 tu 130 0
2148 2148 2 b111 m11 u12 111 3600
2149 2149 1 b11 m12 u111 112 7200
2150 2150 0 b12 m111 u112 111 10800
2151 2151
2152 2152 $ hg log -r 'sort(all(), -topo)'
2153 2153 0 b12 m111 u112 111 10800
2154 2154 1 b11 m12 u111 112 7200
2155 2155 2 b111 m11 u12 111 3600
2156 2156 5 b111 t1 tu 130 0
2157 2157 6 b111 t2 tu 130 0
2158 2158 3 b112 m111 u11 120 0
2159 2159 4 b111 m112 u111 110 14400
2160 2160 7 b111 t3 tu 130 0
2161 2161
2162 2162 $ hg log -r 'sort(all(), topo, topo.firstbranch=book1)'
2163 2163 6 b111 t2 tu 130 0
2164 2164 5 b111 t1 tu 130 0
2165 2165 7 b111 t3 tu 130 0
2166 2166 4 b111 m112 u111 110 14400
2167 2167 3 b112 m111 u11 120 0
2168 2168 2 b111 m11 u12 111 3600
2169 2169 1 b11 m12 u111 112 7200
2170 2170 0 b12 m111 u112 111 10800
2171 2171
2172 2172 topographical sorting can't be combined with other sort keys, and you can't
2173 2173 use the topo.firstbranch option when topo sort is not active:
2174 2174
2175 2175 $ hg log -r 'sort(all(), "topo user")'
2176 2176 hg: parse error: topo sort order cannot be combined with other sort keys
2177 2177 [255]
2178 2178
2179 2179 $ hg log -r 'sort(all(), user, topo.firstbranch=book1)'
2180 2180 hg: parse error: topo.firstbranch can only be used when using the topo sort key
2181 2181 [255]
2182 2182
2183 2183 topo.firstbranch should accept any kind of expressions:
2184 2184
2185 2185 $ hg log -r 'sort(0, topo, topo.firstbranch=(book1))'
2186 2186 0 b12 m111 u112 111 10800
2187 2187
2188 2188 $ cd ..
2189 2189 $ cd repo
2190 2190
2191 2191 test subtracting something from an addset
2192 2192
2193 2193 $ log '(outgoing() or removes(a)) - removes(a)'
2194 2194 8
2195 2195 9
2196 2196
2197 2197 test intersecting something with an addset
2198 2198
2199 2199 $ log 'parents(outgoing() or removes(a))'
2200 2200 1
2201 2201 4
2202 2202 5
2203 2203 8
2204 2204
2205 2205 test that `or` operation combines elements in the right order:
2206 2206
2207 2207 $ log '3:4 or 2:5'
2208 2208 3
2209 2209 4
2210 2210 2
2211 2211 5
2212 2212 $ log '3:4 or 5:2'
2213 2213 3
2214 2214 4
2215 2215 5
2216 2216 2
2217 2217 $ log 'sort(3:4 or 2:5)'
2218 2218 2
2219 2219 3
2220 2220 4
2221 2221 5
2222 2222 $ log 'sort(3:4 or 5:2)'
2223 2223 2
2224 2224 3
2225 2225 4
2226 2226 5
2227 2227
2228 2228 test that more than one `-r`s are combined in the right order and deduplicated:
2229 2229
2230 2230 $ hg log -T '{rev}\n' -r 3 -r 3 -r 4 -r 5:2 -r 'ancestors(4)'
2231 2231 3
2232 2232 4
2233 2233 5
2234 2234 2
2235 2235 0
2236 2236 1
2237 2237
2238 2238 test that `or` operation skips duplicated revisions from right-hand side
2239 2239
2240 2240 $ try 'reverse(1::5) or ancestors(4)'
2241 2241 (or
2242 2242 (list
2243 2243 (func
2244 2244 ('symbol', 'reverse')
2245 2245 (dagrange
2246 2246 ('symbol', '1')
2247 2247 ('symbol', '5')))
2248 2248 (func
2249 2249 ('symbol', 'ancestors')
2250 2250 ('symbol', '4'))))
2251 2251 * set:
2252 2252 <addset
2253 2253 <baseset- [1, 3, 5]>,
2254 2254 <generatorset+>>
2255 2255 5
2256 2256 3
2257 2257 1
2258 2258 0
2259 2259 2
2260 2260 4
2261 2261 $ try 'sort(ancestors(4) or reverse(1::5))'
2262 2262 (func
2263 2263 ('symbol', 'sort')
2264 2264 (or
2265 2265 (list
2266 2266 (func
2267 2267 ('symbol', 'ancestors')
2268 2268 ('symbol', '4'))
2269 2269 (func
2270 2270 ('symbol', 'reverse')
2271 2271 (dagrange
2272 2272 ('symbol', '1')
2273 2273 ('symbol', '5'))))))
2274 2274 * set:
2275 2275 <addset+
2276 2276 <generatorset+>,
2277 2277 <baseset- [1, 3, 5]>>
2278 2278 0
2279 2279 1
2280 2280 2
2281 2281 3
2282 2282 4
2283 2283 5
2284 2284
2285 2285 test optimization of trivial `or` operation
2286 2286
2287 2287 $ try --optimize '0|(1)|"2"|-2|tip|null'
2288 2288 (or
2289 2289 (list
2290 2290 ('symbol', '0')
2291 2291 (group
2292 2292 ('symbol', '1'))
2293 2293 ('string', '2')
2294 2294 (negate
2295 2295 ('symbol', '2'))
2296 2296 ('symbol', 'tip')
2297 2297 ('symbol', 'null')))
2298 2298 * optimized:
2299 2299 (func
2300 2300 ('symbol', '_list')
2301 2301 ('string', '0\x001\x002\x00-2\x00tip\x00null')
2302 2302 define)
2303 2303 * set:
2304 2304 <baseset [0, 1, 2, 8, 9, -1]>
2305 2305 0
2306 2306 1
2307 2307 2
2308 2308 8
2309 2309 9
2310 2310 -1
2311 2311
2312 2312 $ try --optimize '0|1|2:3'
2313 2313 (or
2314 2314 (list
2315 2315 ('symbol', '0')
2316 2316 ('symbol', '1')
2317 2317 (range
2318 2318 ('symbol', '2')
2319 2319 ('symbol', '3'))))
2320 2320 * optimized:
2321 2321 (or
2322 2322 (list
2323 2323 (func
2324 2324 ('symbol', '_list')
2325 2325 ('string', '0\x001')
2326 2326 define)
2327 2327 (range
2328 2328 ('symbol', '2')
2329 2329 ('symbol', '3')
2330 2330 define))
2331 2331 define)
2332 2332 * set:
2333 2333 <addset
2334 2334 <baseset [0, 1]>,
2335 2335 <spanset+ 2:3>>
2336 2336 0
2337 2337 1
2338 2338 2
2339 2339 3
2340 2340
2341 2341 $ try --optimize '0:1|2|3:4|5|6'
2342 2342 (or
2343 2343 (list
2344 2344 (range
2345 2345 ('symbol', '0')
2346 2346 ('symbol', '1'))
2347 2347 ('symbol', '2')
2348 2348 (range
2349 2349 ('symbol', '3')
2350 2350 ('symbol', '4'))
2351 2351 ('symbol', '5')
2352 2352 ('symbol', '6')))
2353 2353 * optimized:
2354 2354 (or
2355 2355 (list
2356 2356 (range
2357 2357 ('symbol', '0')
2358 2358 ('symbol', '1')
2359 2359 define)
2360 2360 ('symbol', '2')
2361 2361 (range
2362 2362 ('symbol', '3')
2363 2363 ('symbol', '4')
2364 2364 define)
2365 2365 (func
2366 2366 ('symbol', '_list')
2367 2367 ('string', '5\x006')
2368 2368 define))
2369 2369 define)
2370 2370 * set:
2371 2371 <addset
2372 2372 <addset
2373 2373 <spanset+ 0:1>,
2374 2374 <baseset [2]>>,
2375 2375 <addset
2376 2376 <spanset+ 3:4>,
2377 2377 <baseset [5, 6]>>>
2378 2378 0
2379 2379 1
2380 2380 2
2381 2381 3
2382 2382 4
2383 2383 5
2384 2384 6
2385 2385
2386 2386 unoptimized `or` looks like this
2387 2387
2388 2388 $ try --no-optimized -p analyzed '0|1|2|3|4'
2389 2389 * analyzed:
2390 2390 (or
2391 2391 (list
2392 2392 ('symbol', '0')
2393 2393 ('symbol', '1')
2394 2394 ('symbol', '2')
2395 2395 ('symbol', '3')
2396 2396 ('symbol', '4'))
2397 2397 define)
2398 2398 * set:
2399 2399 <addset
2400 2400 <addset
2401 2401 <baseset [0]>,
2402 2402 <baseset [1]>>,
2403 2403 <addset
2404 2404 <baseset [2]>,
2405 2405 <addset
2406 2406 <baseset [3]>,
2407 2407 <baseset [4]>>>>
2408 2408 0
2409 2409 1
2410 2410 2
2411 2411 3
2412 2412 4
2413 2413
2414 2414 test that `_list` should be narrowed by provided `subset`
2415 2415
2416 2416 $ log '0:2 and (null|1|2|3)'
2417 2417 1
2418 2418 2
2419 2419
2420 2420 test that `_list` should remove duplicates
2421 2421
2422 2422 $ log '0|1|2|1|2|-1|tip'
2423 2423 0
2424 2424 1
2425 2425 2
2426 2426 9
2427 2427
2428 2428 test unknown revision in `_list`
2429 2429
2430 2430 $ log '0|unknown'
2431 2431 abort: unknown revision 'unknown'!
2432 2432 [255]
2433 2433
2434 2434 test integer range in `_list`
2435 2435
2436 2436 $ log '-1|-10'
2437 2437 9
2438 2438 0
2439 2439
2440 2440 $ log '-10|-11'
2441 2441 abort: unknown revision '-11'!
2442 2442 [255]
2443 2443
2444 2444 $ log '9|10'
2445 2445 abort: unknown revision '10'!
2446 2446 [255]
2447 2447
2448 2448 test '0000' != '0' in `_list`
2449 2449
2450 2450 $ log '0|0000'
2451 2451 0
2452 2452 -1
2453 2453
2454 2454 test ',' in `_list`
2455 2455 $ log '0,1'
2456 2456 hg: parse error: can't use a list in this context
2457 2457 (see hg help "revsets.x or y")
2458 2458 [255]
2459 2459 $ try '0,1,2'
2460 2460 (list
2461 2461 ('symbol', '0')
2462 2462 ('symbol', '1')
2463 2463 ('symbol', '2'))
2464 2464 hg: parse error: can't use a list in this context
2465 2465 (see hg help "revsets.x or y")
2466 2466 [255]
2467 2467
2468 2468 test that chained `or` operations make balanced addsets
2469 2469
2470 2470 $ try '0:1|1:2|2:3|3:4|4:5'
2471 2471 (or
2472 2472 (list
2473 2473 (range
2474 2474 ('symbol', '0')
2475 2475 ('symbol', '1'))
2476 2476 (range
2477 2477 ('symbol', '1')
2478 2478 ('symbol', '2'))
2479 2479 (range
2480 2480 ('symbol', '2')
2481 2481 ('symbol', '3'))
2482 2482 (range
2483 2483 ('symbol', '3')
2484 2484 ('symbol', '4'))
2485 2485 (range
2486 2486 ('symbol', '4')
2487 2487 ('symbol', '5'))))
2488 2488 * set:
2489 2489 <addset
2490 2490 <addset
2491 2491 <spanset+ 0:1>,
2492 2492 <spanset+ 1:2>>,
2493 2493 <addset
2494 2494 <spanset+ 2:3>,
2495 2495 <addset
2496 2496 <spanset+ 3:4>,
2497 2497 <spanset+ 4:5>>>>
2498 2498 0
2499 2499 1
2500 2500 2
2501 2501 3
2502 2502 4
2503 2503 5
2504 2504
2505 2505 no crash by empty group "()" while optimizing `or` operations
2506 2506
2507 2507 $ try --optimize '0|()'
2508 2508 (or
2509 2509 (list
2510 2510 ('symbol', '0')
2511 2511 (group
2512 2512 None)))
2513 2513 * optimized:
2514 2514 (or
2515 2515 (list
2516 2516 ('symbol', '0')
2517 2517 None)
2518 2518 define)
2519 2519 hg: parse error: missing argument
2520 2520 [255]
2521 2521
2522 2522 test that chained `or` operations never eat up stack (issue4624)
2523 2523 (uses `0:1` instead of `0` to avoid future optimization of trivial revisions)
2524 2524
2525 2525 $ hg log -T '{rev}\n' -r `python -c "print '+'.join(['0:1'] * 500)"`
2526 2526 0
2527 2527 1
2528 2528
2529 2529 test that repeated `-r` options never eat up stack (issue4565)
2530 2530 (uses `-r 0::1` to avoid possible optimization at old-style parser)
2531 2531
2532 2532 $ hg log -T '{rev}\n' `python -c "for i in xrange(500): print '-r 0::1 ',"`
2533 2533 0
2534 2534 1
2535 2535
2536 2536 check that conversion to only works
2537 2537 $ try --optimize '::3 - ::1'
2538 2538 (minus
2539 2539 (dagrangepre
2540 2540 ('symbol', '3'))
2541 2541 (dagrangepre
2542 2542 ('symbol', '1')))
2543 2543 * optimized:
2544 2544 (func
2545 2545 ('symbol', 'only')
2546 2546 (list
2547 2547 ('symbol', '3')
2548 2548 ('symbol', '1'))
2549 2549 define)
2550 2550 * set:
2551 2551 <baseset+ [3]>
2552 2552 3
2553 2553 $ try --optimize 'ancestors(1) - ancestors(3)'
2554 2554 (minus
2555 2555 (func
2556 2556 ('symbol', 'ancestors')
2557 2557 ('symbol', '1'))
2558 2558 (func
2559 2559 ('symbol', 'ancestors')
2560 2560 ('symbol', '3')))
2561 2561 * optimized:
2562 2562 (func
2563 2563 ('symbol', 'only')
2564 2564 (list
2565 2565 ('symbol', '1')
2566 2566 ('symbol', '3'))
2567 2567 define)
2568 2568 * set:
2569 2569 <baseset+ []>
2570 2570 $ try --optimize 'not ::2 and ::6'
2571 2571 (and
2572 2572 (not
2573 2573 (dagrangepre
2574 2574 ('symbol', '2')))
2575 2575 (dagrangepre
2576 2576 ('symbol', '6')))
2577 2577 * optimized:
2578 2578 (func
2579 2579 ('symbol', 'only')
2580 2580 (list
2581 2581 ('symbol', '6')
2582 2582 ('symbol', '2'))
2583 2583 define)
2584 2584 * set:
2585 2585 <baseset+ [3, 4, 5, 6]>
2586 2586 3
2587 2587 4
2588 2588 5
2589 2589 6
2590 2590 $ try --optimize 'ancestors(6) and not ancestors(4)'
2591 2591 (and
2592 2592 (func
2593 2593 ('symbol', 'ancestors')
2594 2594 ('symbol', '6'))
2595 2595 (not
2596 2596 (func
2597 2597 ('symbol', 'ancestors')
2598 2598 ('symbol', '4'))))
2599 2599 * optimized:
2600 2600 (func
2601 2601 ('symbol', 'only')
2602 2602 (list
2603 2603 ('symbol', '6')
2604 2604 ('symbol', '4'))
2605 2605 define)
2606 2606 * set:
2607 2607 <baseset+ [3, 5, 6]>
2608 2608 3
2609 2609 5
2610 2610 6
2611 2611
2612 2612 no crash by empty group "()" while optimizing to "only()"
2613 2613
2614 2614 $ try --optimize '::1 and ()'
2615 2615 (and
2616 2616 (dagrangepre
2617 2617 ('symbol', '1'))
2618 2618 (group
2619 2619 None))
2620 2620 * optimized:
2621 2621 (and
2622 2622 None
2623 2623 (func
2624 2624 ('symbol', 'ancestors')
2625 2625 ('symbol', '1')
2626 2626 define)
2627 2627 define)
2628 2628 hg: parse error: missing argument
2629 2629 [255]
2630 2630
2631 2631 invalid function call should not be optimized to only()
2632 2632
2633 2633 $ log '"ancestors"(6) and not ancestors(4)'
2634 2634 hg: parse error: not a symbol
2635 2635 [255]
2636 2636
2637 2637 $ log 'ancestors(6) and not "ancestors"(4)'
2638 2638 hg: parse error: not a symbol
2639 2639 [255]
2640 2640
2641 2641 we can use patterns when searching for tags
2642 2642
2643 2643 $ log 'tag("1..*")'
2644 2644 abort: tag '1..*' does not exist!
2645 2645 [255]
2646 2646 $ log 'tag("re:1..*")'
2647 2647 6
2648 2648 $ log 'tag("re:[0-9].[0-9]")'
2649 2649 6
2650 2650 $ log 'tag("literal:1.0")'
2651 2651 6
2652 2652 $ log 'tag("re:0..*")'
2653 2653
2654 2654 $ log 'tag(unknown)'
2655 2655 abort: tag 'unknown' does not exist!
2656 2656 [255]
2657 2657 $ log 'tag("re:unknown")'
2658 2658 $ log 'present(tag("unknown"))'
2659 2659 $ log 'present(tag("re:unknown"))'
2660 2660 $ log 'branch(unknown)'
2661 2661 abort: unknown revision 'unknown'!
2662 2662 [255]
2663 2663 $ log 'branch("literal:unknown")'
2664 2664 abort: branch 'unknown' does not exist!
2665 2665 [255]
2666 2666 $ log 'branch("re:unknown")'
2667 2667 $ log 'present(branch("unknown"))'
2668 2668 $ log 'present(branch("re:unknown"))'
2669 2669 $ log 'user(bob)'
2670 2670 2
2671 2671
2672 2672 $ log '4::8'
2673 2673 4
2674 2674 8
2675 2675 $ log '4:8'
2676 2676 4
2677 2677 5
2678 2678 6
2679 2679 7
2680 2680 8
2681 2681
2682 2682 $ log 'sort(!merge() & (modifies(b) | user(bob) | keyword(bug) | keyword(issue) & 1::9), "-date")'
2683 2683 4
2684 2684 2
2685 2685 5
2686 2686
2687 2687 $ log 'not 0 and 0:2'
2688 2688 1
2689 2689 2
2690 2690 $ log 'not 1 and 0:2'
2691 2691 0
2692 2692 2
2693 2693 $ log 'not 2 and 0:2'
2694 2694 0
2695 2695 1
2696 2696 $ log '(1 and 2)::'
2697 2697 $ log '(1 and 2):'
2698 2698 $ log '(1 and 2):3'
2699 2699 $ log 'sort(head(), -rev)'
2700 2700 9
2701 2701 7
2702 2702 6
2703 2703 5
2704 2704 4
2705 2705 3
2706 2706 2
2707 2707 1
2708 2708 0
2709 2709 $ log '4::8 - 8'
2710 2710 4
2711 2711
2712 2712 matching() should preserve the order of the input set:
2713 2713
2714 2714 $ log '(2 or 3 or 1) and matching(1 or 2 or 3)'
2715 2715 2
2716 2716 3
2717 2717 1
2718 2718
2719 2719 $ log 'named("unknown")'
2720 2720 abort: namespace 'unknown' does not exist!
2721 2721 [255]
2722 2722 $ log 'named("re:unknown")'
2723 2723 abort: no namespace exists that match 'unknown'!
2724 2724 [255]
2725 2725 $ log 'present(named("unknown"))'
2726 2726 $ log 'present(named("re:unknown"))'
2727 2727
2728 2728 $ log 'tag()'
2729 2729 6
2730 2730 $ log 'named("tags")'
2731 2731 6
2732 2732
2733 2733 issue2437
2734 2734
2735 2735 $ log '3 and p1(5)'
2736 2736 3
2737 2737 $ log '4 and p2(6)'
2738 2738 4
2739 2739 $ log '1 and parents(:2)'
2740 2740 1
2741 2741 $ log '2 and children(1:)'
2742 2742 2
2743 2743 $ log 'roots(all()) or roots(all())'
2744 2744 0
2745 2745 $ hg debugrevspec 'roots(all()) or roots(all())'
2746 2746 0
2747 2747 $ log 'heads(branch(Γ©)) or heads(branch(Γ©))'
2748 2748 9
2749 2749 $ log 'ancestors(8) and (heads(branch("-a-b-c-")) or heads(branch(Γ©)))'
2750 2750 4
2751 2751
2752 2752 issue2654: report a parse error if the revset was not completely parsed
2753 2753
2754 2754 $ log '1 OR 2'
2755 2755 hg: parse error at 2: invalid token
2756 2756 [255]
2757 2757
2758 2758 or operator should preserve ordering:
2759 2759 $ log 'reverse(2::4) or tip'
2760 2760 4
2761 2761 2
2762 2762 9
2763 2763
2764 2764 parentrevspec
2765 2765
2766 2766 $ log 'merge()^0'
2767 2767 6
2768 2768 $ log 'merge()^'
2769 2769 5
2770 2770 $ log 'merge()^1'
2771 2771 5
2772 2772 $ log 'merge()^2'
2773 2773 4
2774 2774 $ log '(not merge())^2'
2775 2775 $ log 'merge()^^'
2776 2776 3
2777 2777 $ log 'merge()^1^'
2778 2778 3
2779 2779 $ log 'merge()^^^'
2780 2780 1
2781 2781
2782 2782 $ log 'merge()~0'
2783 2783 6
2784 2784 $ log 'merge()~1'
2785 2785 5
2786 2786 $ log 'merge()~2'
2787 2787 3
2788 2788 $ log 'merge()~2^1'
2789 2789 1
2790 2790 $ log 'merge()~3'
2791 2791 1
2792 2792
2793 2793 $ log '(-3:tip)^'
2794 2794 4
2795 2795 6
2796 2796 8
2797 2797
2798 2798 $ log 'tip^foo'
2799 2799 hg: parse error: ^ expects a number 0, 1, or 2
2800 2800 [255]
2801 2801
2802 2802 Bogus function gets suggestions
2803 2803 $ log 'add()'
2804 2804 hg: parse error: unknown identifier: add
2805 2805 (did you mean adds?)
2806 2806 [255]
2807 2807 $ log 'added()'
2808 2808 hg: parse error: unknown identifier: added
2809 2809 (did you mean adds?)
2810 2810 [255]
2811 2811 $ log 'remo()'
2812 2812 hg: parse error: unknown identifier: remo
2813 2813 (did you mean one of remote, removes?)
2814 2814 [255]
2815 2815 $ log 'babar()'
2816 2816 hg: parse error: unknown identifier: babar
2817 2817 [255]
2818 2818
2819 2819 Bogus function with a similar internal name doesn't suggest the internal name
2820 2820 $ log 'matches()'
2821 2821 hg: parse error: unknown identifier: matches
2822 2822 (did you mean matching?)
2823 2823 [255]
2824 2824
2825 2825 Undocumented functions aren't suggested as similar either
2826 2826 $ log 'tagged2()'
2827 2827 hg: parse error: unknown identifier: tagged2
2828 2828 [255]
2829 2829
2830 2830 multiple revspecs
2831 2831
2832 2832 $ hg log -r 'tip~1:tip' -r 'tip~2:tip~1' --template '{rev}\n'
2833 2833 8
2834 2834 9
2835 2835 4
2836 2836 5
2837 2837 6
2838 2838 7
2839 2839
2840 2840 test usage in revpair (with "+")
2841 2841
2842 2842 (real pair)
2843 2843
2844 2844 $ hg diff -r 'tip^^' -r 'tip'
2845 2845 diff -r 2326846efdab -r 24286f4ae135 .hgtags
2846 2846 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2847 2847 +++ b/.hgtags Thu Jan 01 00:00:00 1970 +0000
2848 2848 @@ -0,0 +1,1 @@
2849 2849 +e0cc66ef77e8b6f711815af4e001a6594fde3ba5 1.0
2850 2850 $ hg diff -r 'tip^^::tip'
2851 2851 diff -r 2326846efdab -r 24286f4ae135 .hgtags
2852 2852 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2853 2853 +++ b/.hgtags Thu Jan 01 00:00:00 1970 +0000
2854 2854 @@ -0,0 +1,1 @@
2855 2855 +e0cc66ef77e8b6f711815af4e001a6594fde3ba5 1.0
2856 2856
2857 2857 (single rev)
2858 2858
2859 2859 $ hg diff -r 'tip^' -r 'tip^'
2860 2860 $ hg diff -r 'tip^:tip^'
2861 2861
2862 2862 (single rev that does not looks like a range)
2863 2863
2864 2864 $ hg diff -r 'tip^::tip^ or tip^'
2865 2865 diff -r d5d0dcbdc4d9 .hgtags
2866 2866 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2867 2867 +++ b/.hgtags * (glob)
2868 2868 @@ -0,0 +1,1 @@
2869 2869 +e0cc66ef77e8b6f711815af4e001a6594fde3ba5 1.0
2870 2870 $ hg diff -r 'tip^ or tip^'
2871 2871 diff -r d5d0dcbdc4d9 .hgtags
2872 2872 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2873 2873 +++ b/.hgtags * (glob)
2874 2874 @@ -0,0 +1,1 @@
2875 2875 +e0cc66ef77e8b6f711815af4e001a6594fde3ba5 1.0
2876 2876
2877 2877 (no rev)
2878 2878
2879 2879 $ hg diff -r 'author("babar") or author("celeste")'
2880 2880 abort: empty revision range
2881 2881 [255]
2882 2882
2883 2883 aliases:
2884 2884
2885 2885 $ echo '[revsetalias]' >> .hg/hgrc
2886 2886 $ echo 'm = merge()' >> .hg/hgrc
2887 2887 (revset aliases can override builtin revsets)
2888 2888 $ echo 'p2($1) = p1($1)' >> .hg/hgrc
2889 2889 $ echo 'sincem = descendants(m)' >> .hg/hgrc
2890 2890 $ echo 'd($1) = reverse(sort($1, date))' >> .hg/hgrc
2891 2891 $ echo 'rs(ARG1, ARG2) = reverse(sort(ARG1, ARG2))' >> .hg/hgrc
2892 2892 $ echo 'rs4(ARG1, ARGA, ARGB, ARG2) = reverse(sort(ARG1, ARG2))' >> .hg/hgrc
2893 2893
2894 2894 $ try m
2895 2895 ('symbol', 'm')
2896 2896 * expanded:
2897 2897 (func
2898 2898 ('symbol', 'merge')
2899 2899 None)
2900 2900 * set:
2901 2901 <filteredset
2902 2902 <fullreposet+ 0:9>,
2903 2903 <merge>>
2904 2904 6
2905 2905
2906 2906 $ HGPLAIN=1
2907 2907 $ export HGPLAIN
2908 2908 $ try m
2909 2909 ('symbol', 'm')
2910 2910 abort: unknown revision 'm'!
2911 2911 [255]
2912 2912
2913 2913 $ HGPLAINEXCEPT=revsetalias
2914 2914 $ export HGPLAINEXCEPT
2915 2915 $ try m
2916 2916 ('symbol', 'm')
2917 2917 * expanded:
2918 2918 (func
2919 2919 ('symbol', 'merge')
2920 2920 None)
2921 2921 * set:
2922 2922 <filteredset
2923 2923 <fullreposet+ 0:9>,
2924 2924 <merge>>
2925 2925 6
2926 2926
2927 2927 $ unset HGPLAIN
2928 2928 $ unset HGPLAINEXCEPT
2929 2929
2930 2930 $ try 'p2(.)'
2931 2931 (func
2932 2932 ('symbol', 'p2')
2933 2933 ('symbol', '.'))
2934 2934 * expanded:
2935 2935 (func
2936 2936 ('symbol', 'p1')
2937 2937 ('symbol', '.'))
2938 2938 * set:
2939 2939 <baseset+ [8]>
2940 2940 8
2941 2941
2942 2942 $ HGPLAIN=1
2943 2943 $ export HGPLAIN
2944 2944 $ try 'p2(.)'
2945 2945 (func
2946 2946 ('symbol', 'p2')
2947 2947 ('symbol', '.'))
2948 2948 * set:
2949 2949 <baseset+ []>
2950 2950
2951 2951 $ HGPLAINEXCEPT=revsetalias
2952 2952 $ export HGPLAINEXCEPT
2953 2953 $ try 'p2(.)'
2954 2954 (func
2955 2955 ('symbol', 'p2')
2956 2956 ('symbol', '.'))
2957 2957 * expanded:
2958 2958 (func
2959 2959 ('symbol', 'p1')
2960 2960 ('symbol', '.'))
2961 2961 * set:
2962 2962 <baseset+ [8]>
2963 2963 8
2964 2964
2965 2965 $ unset HGPLAIN
2966 2966 $ unset HGPLAINEXCEPT
2967 2967
2968 2968 test alias recursion
2969 2969
2970 2970 $ try sincem
2971 2971 ('symbol', 'sincem')
2972 2972 * expanded:
2973 2973 (func
2974 2974 ('symbol', 'descendants')
2975 2975 (func
2976 2976 ('symbol', 'merge')
2977 2977 None))
2978 2978 * set:
2979 2979 <addset+
2980 2980 <filteredset
2981 2981 <fullreposet+ 0:9>,
2982 2982 <merge>>,
2983 2983 <generatorset+>>
2984 2984 6
2985 2985 7
2986 2986
2987 2987 test infinite recursion
2988 2988
2989 2989 $ echo 'recurse1 = recurse2' >> .hg/hgrc
2990 2990 $ echo 'recurse2 = recurse1' >> .hg/hgrc
2991 2991 $ try recurse1
2992 2992 ('symbol', 'recurse1')
2993 2993 hg: parse error: infinite expansion of revset alias "recurse1" detected
2994 2994 [255]
2995 2995
2996 2996 $ echo 'level1($1, $2) = $1 or $2' >> .hg/hgrc
2997 2997 $ echo 'level2($1, $2) = level1($2, $1)' >> .hg/hgrc
2998 2998 $ try "level2(level1(1, 2), 3)"
2999 2999 (func
3000 3000 ('symbol', 'level2')
3001 3001 (list
3002 3002 (func
3003 3003 ('symbol', 'level1')
3004 3004 (list
3005 3005 ('symbol', '1')
3006 3006 ('symbol', '2')))
3007 3007 ('symbol', '3')))
3008 3008 * expanded:
3009 3009 (or
3010 3010 (list
3011 3011 ('symbol', '3')
3012 3012 (or
3013 3013 (list
3014 3014 ('symbol', '1')
3015 3015 ('symbol', '2')))))
3016 3016 * set:
3017 3017 <addset
3018 3018 <baseset [3]>,
3019 3019 <baseset [1, 2]>>
3020 3020 3
3021 3021 1
3022 3022 2
3023 3023
3024 3024 test nesting and variable passing
3025 3025
3026 3026 $ echo 'nested($1) = nested2($1)' >> .hg/hgrc
3027 3027 $ echo 'nested2($1) = nested3($1)' >> .hg/hgrc
3028 3028 $ echo 'nested3($1) = max($1)' >> .hg/hgrc
3029 3029 $ try 'nested(2:5)'
3030 3030 (func
3031 3031 ('symbol', 'nested')
3032 3032 (range
3033 3033 ('symbol', '2')
3034 3034 ('symbol', '5')))
3035 3035 * expanded:
3036 3036 (func
3037 3037 ('symbol', 'max')
3038 3038 (range
3039 3039 ('symbol', '2')
3040 3040 ('symbol', '5')))
3041 3041 * set:
3042 3042 <baseset
3043 3043 <max
3044 3044 <fullreposet+ 0:9>,
3045 3045 <spanset+ 2:5>>>
3046 3046 5
3047 3047
3048 3048 test chained `or` operations are flattened at parsing phase
3049 3049
3050 3050 $ echo 'chainedorops($1, $2, $3) = $1|$2|$3' >> .hg/hgrc
3051 3051 $ try 'chainedorops(0:1, 1:2, 2:3)'
3052 3052 (func
3053 3053 ('symbol', 'chainedorops')
3054 3054 (list
3055 3055 (range
3056 3056 ('symbol', '0')
3057 3057 ('symbol', '1'))
3058 3058 (range
3059 3059 ('symbol', '1')
3060 3060 ('symbol', '2'))
3061 3061 (range
3062 3062 ('symbol', '2')
3063 3063 ('symbol', '3'))))
3064 3064 * expanded:
3065 3065 (or
3066 3066 (list
3067 3067 (range
3068 3068 ('symbol', '0')
3069 3069 ('symbol', '1'))
3070 3070 (range
3071 3071 ('symbol', '1')
3072 3072 ('symbol', '2'))
3073 3073 (range
3074 3074 ('symbol', '2')
3075 3075 ('symbol', '3'))))
3076 3076 * set:
3077 3077 <addset
3078 3078 <spanset+ 0:1>,
3079 3079 <addset
3080 3080 <spanset+ 1:2>,
3081 3081 <spanset+ 2:3>>>
3082 3082 0
3083 3083 1
3084 3084 2
3085 3085 3
3086 3086
3087 3087 test variable isolation, variable placeholders are rewritten as string
3088 3088 then parsed and matched again as string. Check they do not leak too
3089 3089 far away.
3090 3090
3091 3091 $ echo 'injectparamasstring = max("$1")' >> .hg/hgrc
3092 3092 $ echo 'callinjection($1) = descendants(injectparamasstring)' >> .hg/hgrc
3093 3093 $ try 'callinjection(2:5)'
3094 3094 (func
3095 3095 ('symbol', 'callinjection')
3096 3096 (range
3097 3097 ('symbol', '2')
3098 3098 ('symbol', '5')))
3099 3099 * expanded:
3100 3100 (func
3101 3101 ('symbol', 'descendants')
3102 3102 (func
3103 3103 ('symbol', 'max')
3104 3104 ('string', '$1')))
3105 3105 abort: unknown revision '$1'!
3106 3106 [255]
3107 3107
3108 3108 test scope of alias expansion: 'universe' is expanded prior to 'shadowall(0)',
3109 3109 but 'all()' should never be substituted to '0()'.
3110 3110
3111 3111 $ echo 'universe = all()' >> .hg/hgrc
3112 3112 $ echo 'shadowall(all) = all and universe' >> .hg/hgrc
3113 3113 $ try 'shadowall(0)'
3114 3114 (func
3115 3115 ('symbol', 'shadowall')
3116 3116 ('symbol', '0'))
3117 3117 * expanded:
3118 3118 (and
3119 3119 ('symbol', '0')
3120 3120 (func
3121 3121 ('symbol', 'all')
3122 3122 None))
3123 3123 * set:
3124 3124 <filteredset
3125 3125 <baseset [0]>,
3126 3126 <spanset+ 0:9>>
3127 3127 0
3128 3128
3129 3129 test unknown reference:
3130 3130
3131 3131 $ try "unknownref(0)" --config 'revsetalias.unknownref($1)=$1:$2'
3132 3132 (func
3133 3133 ('symbol', 'unknownref')
3134 3134 ('symbol', '0'))
3135 3135 abort: bad definition of revset alias "unknownref": invalid symbol '$2'
3136 3136 [255]
3137 3137
3138 3138 $ hg debugrevspec --debug --config revsetalias.anotherbadone='branch(' "tip"
3139 3139 ('symbol', 'tip')
3140 3140 warning: bad definition of revset alias "anotherbadone": at 7: not a prefix: end
3141 3141 * set:
3142 3142 <baseset [9]>
3143 3143 9
3144 3144
3145 3145 $ try 'tip'
3146 3146 ('symbol', 'tip')
3147 3147 * set:
3148 3148 <baseset [9]>
3149 3149 9
3150 3150
3151 3151 $ hg debugrevspec --debug --config revsetalias.'bad name'='tip' "tip"
3152 3152 ('symbol', 'tip')
3153 3153 warning: bad declaration of revset alias "bad name": at 4: invalid token
3154 3154 * set:
3155 3155 <baseset [9]>
3156 3156 9
3157 3157 $ echo 'strictreplacing($1, $10) = $10 or desc("$1")' >> .hg/hgrc
3158 3158 $ try 'strictreplacing("foo", tip)'
3159 3159 (func
3160 3160 ('symbol', 'strictreplacing')
3161 3161 (list
3162 3162 ('string', 'foo')
3163 3163 ('symbol', 'tip')))
3164 3164 * expanded:
3165 3165 (or
3166 3166 (list
3167 3167 ('symbol', 'tip')
3168 3168 (func
3169 3169 ('symbol', 'desc')
3170 3170 ('string', '$1'))))
3171 3171 * set:
3172 3172 <addset
3173 3173 <baseset [9]>,
3174 3174 <filteredset
3175 3175 <fullreposet+ 0:9>,
3176 3176 <desc '$1'>>>
3177 3177 9
3178 3178
3179 3179 $ try 'd(2:5)'
3180 3180 (func
3181 3181 ('symbol', 'd')
3182 3182 (range
3183 3183 ('symbol', '2')
3184 3184 ('symbol', '5')))
3185 3185 * expanded:
3186 3186 (func
3187 3187 ('symbol', 'reverse')
3188 3188 (func
3189 3189 ('symbol', 'sort')
3190 3190 (list
3191 3191 (range
3192 3192 ('symbol', '2')
3193 3193 ('symbol', '5'))
3194 3194 ('symbol', 'date'))))
3195 3195 * set:
3196 3196 <baseset [4, 5, 3, 2]>
3197 3197 4
3198 3198 5
3199 3199 3
3200 3200 2
3201 3201 $ try 'rs(2 or 3, date)'
3202 3202 (func
3203 3203 ('symbol', 'rs')
3204 3204 (list
3205 3205 (or
3206 3206 (list
3207 3207 ('symbol', '2')
3208 3208 ('symbol', '3')))
3209 3209 ('symbol', 'date')))
3210 3210 * expanded:
3211 3211 (func
3212 3212 ('symbol', 'reverse')
3213 3213 (func
3214 3214 ('symbol', 'sort')
3215 3215 (list
3216 3216 (or
3217 3217 (list
3218 3218 ('symbol', '2')
3219 3219 ('symbol', '3')))
3220 3220 ('symbol', 'date'))))
3221 3221 * set:
3222 3222 <baseset [3, 2]>
3223 3223 3
3224 3224 2
3225 3225 $ try 'rs()'
3226 3226 (func
3227 3227 ('symbol', 'rs')
3228 3228 None)
3229 3229 hg: parse error: invalid number of arguments: 0
3230 3230 [255]
3231 3231 $ try 'rs(2)'
3232 3232 (func
3233 3233 ('symbol', 'rs')
3234 3234 ('symbol', '2'))
3235 3235 hg: parse error: invalid number of arguments: 1
3236 3236 [255]
3237 3237 $ try 'rs(2, data, 7)'
3238 3238 (func
3239 3239 ('symbol', 'rs')
3240 3240 (list
3241 3241 ('symbol', '2')
3242 3242 ('symbol', 'data')
3243 3243 ('symbol', '7')))
3244 3244 hg: parse error: invalid number of arguments: 3
3245 3245 [255]
3246 3246 $ try 'rs4(2 or 3, x, x, date)'
3247 3247 (func
3248 3248 ('symbol', 'rs4')
3249 3249 (list
3250 3250 (or
3251 3251 (list
3252 3252 ('symbol', '2')
3253 3253 ('symbol', '3')))
3254 3254 ('symbol', 'x')
3255 3255 ('symbol', 'x')
3256 3256 ('symbol', 'date')))
3257 3257 * expanded:
3258 3258 (func
3259 3259 ('symbol', 'reverse')
3260 3260 (func
3261 3261 ('symbol', 'sort')
3262 3262 (list
3263 3263 (or
3264 3264 (list
3265 3265 ('symbol', '2')
3266 3266 ('symbol', '3')))
3267 3267 ('symbol', 'date'))))
3268 3268 * set:
3269 3269 <baseset [3, 2]>
3270 3270 3
3271 3271 2
3272 3272
3273 3273 issue4553: check that revset aliases override existing hash prefix
3274 3274
3275 3275 $ hg log -qr e
3276 3276 6:e0cc66ef77e8
3277 3277
3278 3278 $ hg log -qr e --config revsetalias.e="all()"
3279 3279 0:2785f51eece5
3280 3280 1:d75937da8da0
3281 3281 2:5ed5505e9f1c
3282 3282 3:8528aa5637f2
3283 3283 4:2326846efdab
3284 3284 5:904fa392b941
3285 3285 6:e0cc66ef77e8
3286 3286 7:013af1973af4
3287 3287 8:d5d0dcbdc4d9
3288 3288 9:24286f4ae135
3289 3289
3290 3290 $ hg log -qr e: --config revsetalias.e="0"
3291 3291 0:2785f51eece5
3292 3292 1:d75937da8da0
3293 3293 2:5ed5505e9f1c
3294 3294 3:8528aa5637f2
3295 3295 4:2326846efdab
3296 3296 5:904fa392b941
3297 3297 6:e0cc66ef77e8
3298 3298 7:013af1973af4
3299 3299 8:d5d0dcbdc4d9
3300 3300 9:24286f4ae135
3301 3301
3302 3302 $ hg log -qr :e --config revsetalias.e="9"
3303 3303 0:2785f51eece5
3304 3304 1:d75937da8da0
3305 3305 2:5ed5505e9f1c
3306 3306 3:8528aa5637f2
3307 3307 4:2326846efdab
3308 3308 5:904fa392b941
3309 3309 6:e0cc66ef77e8
3310 3310 7:013af1973af4
3311 3311 8:d5d0dcbdc4d9
3312 3312 9:24286f4ae135
3313 3313
3314 3314 $ hg log -qr e:
3315 3315 6:e0cc66ef77e8
3316 3316 7:013af1973af4
3317 3317 8:d5d0dcbdc4d9
3318 3318 9:24286f4ae135
3319 3319
3320 3320 $ hg log -qr :e
3321 3321 0:2785f51eece5
3322 3322 1:d75937da8da0
3323 3323 2:5ed5505e9f1c
3324 3324 3:8528aa5637f2
3325 3325 4:2326846efdab
3326 3326 5:904fa392b941
3327 3327 6:e0cc66ef77e8
3328 3328
3329 3329 issue2549 - correct optimizations
3330 3330
3331 3331 $ try 'limit(1 or 2 or 3, 2) and not 2'
3332 3332 (and
3333 3333 (func
3334 3334 ('symbol', 'limit')
3335 3335 (list
3336 3336 (or
3337 3337 (list
3338 3338 ('symbol', '1')
3339 3339 ('symbol', '2')
3340 3340 ('symbol', '3')))
3341 3341 ('symbol', '2')))
3342 3342 (not
3343 3343 ('symbol', '2')))
3344 3344 * set:
3345 3345 <filteredset
3346 3346 <baseset
3347 3347 <limit n=2, offset=0,
3348 3348 <fullreposet+ 0:9>,
3349 3349 <baseset [1, 2, 3]>>>,
3350 3350 <not
3351 3351 <baseset [2]>>>
3352 3352 1
3353 3353 $ try 'max(1 or 2) and not 2'
3354 3354 (and
3355 3355 (func
3356 3356 ('symbol', 'max')
3357 3357 (or
3358 3358 (list
3359 3359 ('symbol', '1')
3360 3360 ('symbol', '2'))))
3361 3361 (not
3362 3362 ('symbol', '2')))
3363 3363 * set:
3364 3364 <filteredset
3365 3365 <baseset
3366 3366 <max
3367 3367 <fullreposet+ 0:9>,
3368 3368 <baseset [1, 2]>>>,
3369 3369 <not
3370 3370 <baseset [2]>>>
3371 3371 $ try 'min(1 or 2) and not 1'
3372 3372 (and
3373 3373 (func
3374 3374 ('symbol', 'min')
3375 3375 (or
3376 3376 (list
3377 3377 ('symbol', '1')
3378 3378 ('symbol', '2'))))
3379 3379 (not
3380 3380 ('symbol', '1')))
3381 3381 * set:
3382 3382 <filteredset
3383 3383 <baseset
3384 3384 <min
3385 3385 <fullreposet+ 0:9>,
3386 3386 <baseset [1, 2]>>>,
3387 3387 <not
3388 3388 <baseset [1]>>>
3389 3389 $ try 'last(1 or 2, 1) and not 2'
3390 3390 (and
3391 3391 (func
3392 3392 ('symbol', 'last')
3393 3393 (list
3394 3394 (or
3395 3395 (list
3396 3396 ('symbol', '1')
3397 3397 ('symbol', '2')))
3398 3398 ('symbol', '1')))
3399 3399 (not
3400 3400 ('symbol', '2')))
3401 3401 * set:
3402 3402 <filteredset
3403 3403 <baseset
3404 3404 <last n=1,
3405 3405 <fullreposet+ 0:9>,
3406 3406 <baseset [2, 1]>>>,
3407 3407 <not
3408 3408 <baseset [2]>>>
3409 3409
3410 3410 issue4289 - ordering of built-ins
3411 3411 $ hg log -M -q -r 3:2
3412 3412 3:8528aa5637f2
3413 3413 2:5ed5505e9f1c
3414 3414
3415 3415 test revsets started with 40-chars hash (issue3669)
3416 3416
3417 3417 $ ISSUE3669_TIP=`hg tip --template '{node}'`
3418 3418 $ hg log -r "${ISSUE3669_TIP}" --template '{rev}\n'
3419 3419 9
3420 3420 $ hg log -r "${ISSUE3669_TIP}^" --template '{rev}\n'
3421 3421 8
3422 3422
3423 3423 test or-ed indirect predicates (issue3775)
3424 3424
3425 3425 $ log '6 or 6^1' | sort
3426 3426 5
3427 3427 6
3428 3428 $ log '6^1 or 6' | sort
3429 3429 5
3430 3430 6
3431 3431 $ log '4 or 4~1' | sort
3432 3432 2
3433 3433 4
3434 3434 $ log '4~1 or 4' | sort
3435 3435 2
3436 3436 4
3437 3437 $ log '(0 or 2):(4 or 6) or 0 or 6' | sort
3438 3438 0
3439 3439 1
3440 3440 2
3441 3441 3
3442 3442 4
3443 3443 5
3444 3444 6
3445 3445 $ log '0 or 6 or (0 or 2):(4 or 6)' | sort
3446 3446 0
3447 3447 1
3448 3448 2
3449 3449 3
3450 3450 4
3451 3451 5
3452 3452 6
3453 3453
3454 3454 tests for 'remote()' predicate:
3455 3455 #. (csets in remote) (id) (remote)
3456 3456 1. less than local current branch "default"
3457 3457 2. same with local specified "default"
3458 3458 3. more than local specified specified
3459 3459
3460 3460 $ hg clone --quiet -U . ../remote3
3461 3461 $ cd ../remote3
3462 3462 $ hg update -q 7
3463 3463 $ echo r > r
3464 3464 $ hg ci -Aqm 10
3465 3465 $ log 'remote()'
3466 3466 7
3467 3467 $ log 'remote("a-b-c-")'
3468 3468 2
3469 3469 $ cd ../repo
3470 3470 $ log 'remote(".a.b.c.", "../remote3")'
3471 3471
3472 3472 tests for concatenation of strings/symbols by "##"
3473 3473
3474 3474 $ try "278 ## '5f5' ## 1ee ## 'ce5'"
3475 3475 (_concat
3476 3476 (_concat
3477 3477 (_concat
3478 3478 ('symbol', '278')
3479 3479 ('string', '5f5'))
3480 3480 ('symbol', '1ee'))
3481 3481 ('string', 'ce5'))
3482 3482 * concatenated:
3483 3483 ('string', '2785f51eece5')
3484 3484 * set:
3485 3485 <baseset [0]>
3486 3486 0
3487 3487
3488 3488 $ echo 'cat4($1, $2, $3, $4) = $1 ## $2 ## $3 ## $4' >> .hg/hgrc
3489 3489 $ try "cat4(278, '5f5', 1ee, 'ce5')"
3490 3490 (func
3491 3491 ('symbol', 'cat4')
3492 3492 (list
3493 3493 ('symbol', '278')
3494 3494 ('string', '5f5')
3495 3495 ('symbol', '1ee')
3496 3496 ('string', 'ce5')))
3497 3497 * expanded:
3498 3498 (_concat
3499 3499 (_concat
3500 3500 (_concat
3501 3501 ('symbol', '278')
3502 3502 ('string', '5f5'))
3503 3503 ('symbol', '1ee'))
3504 3504 ('string', 'ce5'))
3505 3505 * concatenated:
3506 3506 ('string', '2785f51eece5')
3507 3507 * set:
3508 3508 <baseset [0]>
3509 3509 0
3510 3510
3511 3511 (check concatenation in alias nesting)
3512 3512
3513 3513 $ echo 'cat2($1, $2) = $1 ## $2' >> .hg/hgrc
3514 3514 $ echo 'cat2x2($1, $2, $3, $4) = cat2($1 ## $2, $3 ## $4)' >> .hg/hgrc
3515 3515 $ log "cat2x2(278, '5f5', 1ee, 'ce5')"
3516 3516 0
3517 3517
3518 3518 (check operator priority)
3519 3519
3520 3520 $ echo 'cat2n2($1, $2, $3, $4) = $1 ## $2 or $3 ## $4~2' >> .hg/hgrc
3521 3521 $ log "cat2n2(2785f5, 1eece5, 24286f, 4ae135)"
3522 3522 0
3523 3523 4
3524 3524
3525 3525 $ cd ..
3526 3526
3527 3527 prepare repository that has "default" branches of multiple roots
3528 3528
3529 3529 $ hg init namedbranch
3530 3530 $ cd namedbranch
3531 3531
3532 3532 $ echo default0 >> a
3533 3533 $ hg ci -Aqm0
3534 3534 $ echo default1 >> a
3535 3535 $ hg ci -m1
3536 3536
3537 3537 $ hg branch -q stable
3538 3538 $ echo stable2 >> a
3539 3539 $ hg ci -m2
3540 3540 $ echo stable3 >> a
3541 3541 $ hg ci -m3
3542 3542
3543 3543 $ hg update -q null
3544 3544 $ echo default4 >> a
3545 3545 $ hg ci -Aqm4
3546 3546 $ echo default5 >> a
3547 3547 $ hg ci -m5
3548 3548
3549 3549 "null" revision belongs to "default" branch (issue4683)
3550 3550
3551 3551 $ log 'branch(null)'
3552 3552 0
3553 3553 1
3554 3554 4
3555 3555 5
3556 3556
3557 3557 "null" revision belongs to "default" branch, but it shouldn't appear in set
3558 3558 unless explicitly specified (issue4682)
3559 3559
3560 3560 $ log 'children(branch(default))'
3561 3561 1
3562 3562 2
3563 3563 5
3564 3564
3565 3565 $ cd ..
3566 3566
3567 3567 test author/desc/keyword in problematic encoding
3568 3568 # unicode: cp932:
3569 3569 # u30A2 0x83 0x41(= 'A')
3570 3570 # u30C2 0x83 0x61(= 'a')
3571 3571
3572 3572 $ hg init problematicencoding
3573 3573 $ cd problematicencoding
3574 3574
3575 3575 $ python > setup.sh <<EOF
3576 3576 > print u'''
3577 3577 > echo a > text
3578 3578 > hg add text
3579 3579 > hg --encoding utf-8 commit -u '\u30A2' -m none
3580 3580 > echo b > text
3581 3581 > hg --encoding utf-8 commit -u '\u30C2' -m none
3582 3582 > echo c > text
3583 3583 > hg --encoding utf-8 commit -u none -m '\u30A2'
3584 3584 > echo d > text
3585 3585 > hg --encoding utf-8 commit -u none -m '\u30C2'
3586 3586 > '''.encode('utf-8')
3587 3587 > EOF
3588 3588 $ sh < setup.sh
3589 3589
3590 3590 test in problematic encoding
3591 3591 $ python > test.sh <<EOF
3592 3592 > print u'''
3593 3593 > hg --encoding cp932 log --template '{rev}\\n' -r 'author(\u30A2)'
3594 3594 > echo ====
3595 3595 > hg --encoding cp932 log --template '{rev}\\n' -r 'author(\u30C2)'
3596 3596 > echo ====
3597 3597 > hg --encoding cp932 log --template '{rev}\\n' -r 'desc(\u30A2)'
3598 3598 > echo ====
3599 3599 > hg --encoding cp932 log --template '{rev}\\n' -r 'desc(\u30C2)'
3600 3600 > echo ====
3601 3601 > hg --encoding cp932 log --template '{rev}\\n' -r 'keyword(\u30A2)'
3602 3602 > echo ====
3603 3603 > hg --encoding cp932 log --template '{rev}\\n' -r 'keyword(\u30C2)'
3604 3604 > '''.encode('cp932')
3605 3605 > EOF
3606 3606 $ sh < test.sh
3607 3607 0
3608 3608 ====
3609 3609 1
3610 3610 ====
3611 3611 2
3612 3612 ====
3613 3613 3
3614 3614 ====
3615 3615 0
3616 3616 2
3617 3617 ====
3618 3618 1
3619 3619 3
3620 3620
3621 3621 test error message of bad revset
3622 3622 $ hg log -r 'foo\\'
3623 3623 hg: parse error at 3: syntax error in revset 'foo\\'
3624 3624 [255]
3625 3625
3626 3626 $ cd ..
3627 3627
3628 3628 Test that revset predicate of extension isn't loaded at failure of
3629 3629 loading it
3630 3630
3631 3631 $ cd repo
3632 3632
3633 3633 $ cat <<EOF > $TESTTMP/custompredicate.py
3634 3634 > from mercurial import error, registrar, revset
3635 3635 >
3636 3636 > revsetpredicate = registrar.revsetpredicate()
3637 3637 >
3638 3638 > @revsetpredicate('custom1()')
3639 3639 > def custom1(repo, subset, x):
3640 3640 > return revset.baseset([1])
3641 3641 >
3642 3642 > raise error.Abort('intentional failure of loading extension')
3643 3643 > EOF
3644 3644 $ cat <<EOF > .hg/hgrc
3645 3645 > [extensions]
3646 3646 > custompredicate = $TESTTMP/custompredicate.py
3647 3647 > EOF
3648 3648
3649 3649 $ hg debugrevspec "custom1()"
3650 3650 *** failed to import extension custompredicate from $TESTTMP/custompredicate.py: intentional failure of loading extension
3651 3651 hg: parse error: unknown identifier: custom1
3652 3652 [255]
3653 3653
3654 3654 $ cd ..
General Comments 0
You need to be logged in to leave comments. Login now