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