##// END OF EJS Templates
revset: introduce a `nodefromfile` revset...
marmoute -
r47566:56d44125 default
parent child Browse files
Show More
@@ -1,2782 +1,2811 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 re
11 11
12 12 from .i18n import _
13 13 from .pycompat import getattr
14 14 from .node import (
15 15 bin,
16 16 nullrev,
17 17 wdirrev,
18 18 )
19 19 from . import (
20 20 dagop,
21 21 destutil,
22 22 diffutil,
23 23 encoding,
24 24 error,
25 25 grep as grepmod,
26 26 hbisect,
27 27 match as matchmod,
28 28 obsolete as obsmod,
29 29 obsutil,
30 30 pathutil,
31 31 phases,
32 32 pycompat,
33 33 registrar,
34 34 repoview,
35 35 revsetlang,
36 36 scmutil,
37 37 smartset,
38 38 stack as stackmod,
39 39 util,
40 40 )
41 41 from .utils import (
42 42 dateutil,
43 43 stringutil,
44 44 )
45 45
46 46 # helpers for processing parsed tree
47 47 getsymbol = revsetlang.getsymbol
48 48 getstring = revsetlang.getstring
49 49 getinteger = revsetlang.getinteger
50 50 getboolean = revsetlang.getboolean
51 51 getlist = revsetlang.getlist
52 52 getintrange = revsetlang.getintrange
53 53 getargs = revsetlang.getargs
54 54 getargsdict = revsetlang.getargsdict
55 55
56 56 baseset = smartset.baseset
57 57 generatorset = smartset.generatorset
58 58 spanset = smartset.spanset
59 59 fullreposet = smartset.fullreposet
60 60
61 61 # revisions not included in all(), but populated if specified
62 62 _virtualrevs = (nullrev, wdirrev)
63 63
64 64 # Constants for ordering requirement, used in getset():
65 65 #
66 66 # If 'define', any nested functions and operations MAY change the ordering of
67 67 # the entries in the set (but if changes the ordering, it MUST ALWAYS change
68 68 # it). If 'follow', any nested functions and operations MUST take the ordering
69 69 # specified by the first operand to the '&' operator.
70 70 #
71 71 # For instance,
72 72 #
73 73 # X & (Y | Z)
74 74 # ^ ^^^^^^^
75 75 # | follow
76 76 # define
77 77 #
78 78 # will be evaluated as 'or(y(x()), z(x()))', where 'x()' can change the order
79 79 # of the entries in the set, but 'y()', 'z()' and 'or()' shouldn't.
80 80 #
81 81 # 'any' means the order doesn't matter. For instance,
82 82 #
83 83 # (X & !Y) | ancestors(Z)
84 84 # ^ ^
85 85 # any any
86 86 #
87 87 # For 'X & !Y', 'X' decides the order and 'Y' is subtracted from 'X', so the
88 88 # order of 'Y' does not matter. For 'ancestors(Z)', Z's order does not matter
89 89 # since 'ancestors' does not care about the order of its argument.
90 90 #
91 91 # Currently, most revsets do not care about the order, so 'define' is
92 92 # equivalent to 'follow' for them, and the resulting order is based on the
93 93 # 'subset' parameter passed down to them:
94 94 #
95 95 # m = revset.match(...)
96 96 # m(repo, subset, order=defineorder)
97 97 # ^^^^^^
98 98 # For most revsets, 'define' means using the order this subset provides
99 99 #
100 100 # There are a few revsets that always redefine the order if 'define' is
101 101 # specified: 'sort(X)', 'reverse(X)', 'x:y'.
102 102 anyorder = b'any' # don't care the order, could be even random-shuffled
103 103 defineorder = b'define' # ALWAYS redefine, or ALWAYS follow the current order
104 104 followorder = b'follow' # MUST follow the current order
105 105
106 106 # helpers
107 107
108 108
109 109 def getset(repo, subset, x, order=defineorder):
110 110 if not x:
111 111 raise error.ParseError(_(b"missing argument"))
112 112 return methods[x[0]](repo, subset, *x[1:], order=order)
113 113
114 114
115 115 def _getrevsource(repo, r):
116 116 extra = repo[r].extra()
117 117 for label in (b'source', b'transplant_source', b'rebase_source'):
118 118 if label in extra:
119 119 try:
120 120 return repo[extra[label]].rev()
121 121 except error.RepoLookupError:
122 122 pass
123 123 return None
124 124
125 125
126 126 def _sortedb(xs):
127 127 return sorted(pycompat.rapply(pycompat.maybebytestr, xs))
128 128
129 129
130 130 # operator methods
131 131
132 132
133 133 def stringset(repo, subset, x, order):
134 134 if not x:
135 135 raise error.ParseError(_(b"empty string is not a valid revision"))
136 136 x = scmutil.intrev(scmutil.revsymbol(repo, x))
137 137 if x in subset or x in _virtualrevs and isinstance(subset, fullreposet):
138 138 return baseset([x])
139 139 return baseset()
140 140
141 141
142 142 def rawsmartset(repo, subset, x, order):
143 143 """argument is already a smartset, use that directly"""
144 144 if order == followorder:
145 145 return subset & x
146 146 else:
147 147 return x & subset
148 148
149 149
150 150 def rangeset(repo, subset, x, y, order):
151 151 m = getset(repo, fullreposet(repo), x)
152 152 n = getset(repo, fullreposet(repo), y)
153 153
154 154 if not m or not n:
155 155 return baseset()
156 156 return _makerangeset(repo, subset, m.first(), n.last(), order)
157 157
158 158
159 159 def rangeall(repo, subset, x, order):
160 160 assert x is None
161 161 return _makerangeset(repo, subset, 0, repo.changelog.tiprev(), order)
162 162
163 163
164 164 def rangepre(repo, subset, y, order):
165 165 # ':y' can't be rewritten to '0:y' since '0' may be hidden
166 166 n = getset(repo, fullreposet(repo), y)
167 167 if not n:
168 168 return baseset()
169 169 return _makerangeset(repo, subset, 0, n.last(), order)
170 170
171 171
172 172 def rangepost(repo, subset, x, order):
173 173 m = getset(repo, fullreposet(repo), x)
174 174 if not m:
175 175 return baseset()
176 176 return _makerangeset(
177 177 repo, subset, m.first(), repo.changelog.tiprev(), order
178 178 )
179 179
180 180
181 181 def _makerangeset(repo, subset, m, n, order):
182 182 if m == n:
183 183 r = baseset([m])
184 184 elif n == wdirrev:
185 185 r = spanset(repo, m, len(repo)) + baseset([n])
186 186 elif m == wdirrev:
187 187 r = baseset([m]) + spanset(repo, repo.changelog.tiprev(), n - 1)
188 188 elif m < n:
189 189 r = spanset(repo, m, n + 1)
190 190 else:
191 191 r = spanset(repo, m, n - 1)
192 192
193 193 if order == defineorder:
194 194 return r & subset
195 195 else:
196 196 # carrying the sorting over when possible would be more efficient
197 197 return subset & r
198 198
199 199
200 200 def dagrange(repo, subset, x, y, order):
201 201 r = fullreposet(repo)
202 202 xs = dagop.reachableroots(
203 203 repo, getset(repo, r, x), getset(repo, r, y), includepath=True
204 204 )
205 205 return subset & xs
206 206
207 207
208 208 def andset(repo, subset, x, y, order):
209 209 if order == anyorder:
210 210 yorder = anyorder
211 211 else:
212 212 yorder = followorder
213 213 return getset(repo, getset(repo, subset, x, order), y, yorder)
214 214
215 215
216 216 def andsmallyset(repo, subset, x, y, order):
217 217 # 'andsmally(x, y)' is equivalent to 'and(x, y)', but faster when y is small
218 218 if order == anyorder:
219 219 yorder = anyorder
220 220 else:
221 221 yorder = followorder
222 222 return getset(repo, getset(repo, subset, y, yorder), x, order)
223 223
224 224
225 225 def differenceset(repo, subset, x, y, order):
226 226 return getset(repo, subset, x, order) - getset(repo, subset, y, anyorder)
227 227
228 228
229 229 def _orsetlist(repo, subset, xs, order):
230 230 assert xs
231 231 if len(xs) == 1:
232 232 return getset(repo, subset, xs[0], order)
233 233 p = len(xs) // 2
234 234 a = _orsetlist(repo, subset, xs[:p], order)
235 235 b = _orsetlist(repo, subset, xs[p:], order)
236 236 return a + b
237 237
238 238
239 239 def orset(repo, subset, x, order):
240 240 xs = getlist(x)
241 241 if not xs:
242 242 return baseset()
243 243 if order == followorder:
244 244 # slow path to take the subset order
245 245 return subset & _orsetlist(repo, fullreposet(repo), xs, anyorder)
246 246 else:
247 247 return _orsetlist(repo, subset, xs, order)
248 248
249 249
250 250 def notset(repo, subset, x, order):
251 251 return subset - getset(repo, subset, x, anyorder)
252 252
253 253
254 254 def relationset(repo, subset, x, y, order):
255 255 # this is pretty basic implementation of 'x#y' operator, still
256 256 # experimental so undocumented. see the wiki for further ideas.
257 257 # https://www.mercurial-scm.org/wiki/RevsetOperatorPlan
258 258 rel = getsymbol(y)
259 259 if rel in relations:
260 260 return relations[rel](repo, subset, x, rel, order)
261 261
262 262 relnames = [r for r in relations.keys() if len(r) > 1]
263 263 raise error.UnknownIdentifier(rel, relnames)
264 264
265 265
266 266 def _splitrange(a, b):
267 267 """Split range with bounds a and b into two ranges at 0 and return two
268 268 tuples of numbers for use as startdepth and stopdepth arguments of
269 269 revancestors and revdescendants.
270 270
271 271 >>> _splitrange(-10, -5) # [-10:-5]
272 272 ((5, 11), (None, None))
273 273 >>> _splitrange(5, 10) # [5:10]
274 274 ((None, None), (5, 11))
275 275 >>> _splitrange(-10, 10) # [-10:10]
276 276 ((0, 11), (0, 11))
277 277 >>> _splitrange(-10, 0) # [-10:0]
278 278 ((0, 11), (None, None))
279 279 >>> _splitrange(0, 10) # [0:10]
280 280 ((None, None), (0, 11))
281 281 >>> _splitrange(0, 0) # [0:0]
282 282 ((0, 1), (None, None))
283 283 >>> _splitrange(1, -1) # [1:-1]
284 284 ((None, None), (None, None))
285 285 """
286 286 ancdepths = (None, None)
287 287 descdepths = (None, None)
288 288 if a == b == 0:
289 289 ancdepths = (0, 1)
290 290 if a < 0:
291 291 ancdepths = (-min(b, 0), -a + 1)
292 292 if b > 0:
293 293 descdepths = (max(a, 0), b + 1)
294 294 return ancdepths, descdepths
295 295
296 296
297 297 def generationsrel(repo, subset, x, rel, order):
298 298 z = (b'rangeall', None)
299 299 return generationssubrel(repo, subset, x, rel, z, order)
300 300
301 301
302 302 def generationssubrel(repo, subset, x, rel, z, order):
303 303 # TODO: rewrite tests, and drop startdepth argument from ancestors() and
304 304 # descendants() predicates
305 305 a, b = getintrange(
306 306 z,
307 307 _(b'relation subscript must be an integer or a range'),
308 308 _(b'relation subscript bounds must be integers'),
309 309 deffirst=-(dagop.maxlogdepth - 1),
310 310 deflast=+(dagop.maxlogdepth - 1),
311 311 )
312 312 (ancstart, ancstop), (descstart, descstop) = _splitrange(a, b)
313 313
314 314 if ancstart is None and descstart is None:
315 315 return baseset()
316 316
317 317 revs = getset(repo, fullreposet(repo), x)
318 318 if not revs:
319 319 return baseset()
320 320
321 321 if ancstart is not None and descstart is not None:
322 322 s = dagop.revancestors(repo, revs, False, ancstart, ancstop)
323 323 s += dagop.revdescendants(repo, revs, False, descstart, descstop)
324 324 elif ancstart is not None:
325 325 s = dagop.revancestors(repo, revs, False, ancstart, ancstop)
326 326 elif descstart is not None:
327 327 s = dagop.revdescendants(repo, revs, False, descstart, descstop)
328 328
329 329 return subset & s
330 330
331 331
332 332 def relsubscriptset(repo, subset, x, y, z, order):
333 333 # this is pretty basic implementation of 'x#y[z]' operator, still
334 334 # experimental so undocumented. see the wiki for further ideas.
335 335 # https://www.mercurial-scm.org/wiki/RevsetOperatorPlan
336 336 rel = getsymbol(y)
337 337 if rel in subscriptrelations:
338 338 return subscriptrelations[rel](repo, subset, x, rel, z, order)
339 339
340 340 relnames = [r for r in subscriptrelations.keys() if len(r) > 1]
341 341 raise error.UnknownIdentifier(rel, relnames)
342 342
343 343
344 344 def subscriptset(repo, subset, x, y, order):
345 345 raise error.ParseError(_(b"can't use a subscript in this context"))
346 346
347 347
348 348 def listset(repo, subset, *xs, **opts):
349 349 raise error.ParseError(
350 350 _(b"can't use a list in this context"),
351 351 hint=_(b'see \'hg help "revsets.x or y"\''),
352 352 )
353 353
354 354
355 355 def keyvaluepair(repo, subset, k, v, order):
356 356 raise error.ParseError(_(b"can't use a key-value pair in this context"))
357 357
358 358
359 359 def func(repo, subset, a, b, order):
360 360 f = getsymbol(a)
361 361 if f in symbols:
362 362 func = symbols[f]
363 363 if getattr(func, '_takeorder', False):
364 364 return func(repo, subset, b, order)
365 365 return func(repo, subset, b)
366 366
367 367 keep = lambda fn: getattr(fn, '__doc__', None) is not None
368 368
369 369 syms = [s for (s, fn) in symbols.items() if keep(fn)]
370 370 raise error.UnknownIdentifier(f, syms)
371 371
372 372
373 373 # functions
374 374
375 375 # symbols are callables like:
376 376 # fn(repo, subset, x)
377 377 # with:
378 378 # repo - current repository instance
379 379 # subset - of revisions to be examined
380 380 # x - argument in tree form
381 381 symbols = revsetlang.symbols
382 382
383 383 # symbols which can't be used for a DoS attack for any given input
384 384 # (e.g. those which accept regexes as plain strings shouldn't be included)
385 385 # functions that just return a lot of changesets (like all) don't count here
386 386 safesymbols = set()
387 387
388 388 predicate = registrar.revsetpredicate()
389 389
390 390
391 391 @predicate(b'_destupdate')
392 392 def _destupdate(repo, subset, x):
393 393 # experimental revset for update destination
394 394 args = getargsdict(x, b'limit', b'clean')
395 395 return subset & baseset(
396 396 [destutil.destupdate(repo, **pycompat.strkwargs(args))[0]]
397 397 )
398 398
399 399
400 400 @predicate(b'_destmerge')
401 401 def _destmerge(repo, subset, x):
402 402 # experimental revset for merge destination
403 403 sourceset = None
404 404 if x is not None:
405 405 sourceset = getset(repo, fullreposet(repo), x)
406 406 return subset & baseset([destutil.destmerge(repo, sourceset=sourceset)])
407 407
408 408
409 409 @predicate(b'adds(pattern)', safe=True, weight=30)
410 410 def adds(repo, subset, x):
411 411 """Changesets that add a file matching pattern.
412 412
413 413 The pattern without explicit kind like ``glob:`` is expected to be
414 414 relative to the current directory and match against a file or a
415 415 directory.
416 416 """
417 417 # i18n: "adds" is a keyword
418 418 pat = getstring(x, _(b"adds requires a pattern"))
419 419 return checkstatus(repo, subset, pat, 'added')
420 420
421 421
422 422 @predicate(b'ancestor(*changeset)', safe=True, weight=0.5)
423 423 def ancestor(repo, subset, x):
424 424 """A greatest common ancestor of the changesets.
425 425
426 426 Accepts 0 or more changesets.
427 427 Will return empty list when passed no args.
428 428 Greatest common ancestor of a single changeset is that changeset.
429 429 """
430 430 reviter = iter(orset(repo, fullreposet(repo), x, order=anyorder))
431 431 try:
432 432 anc = repo[next(reviter)]
433 433 except StopIteration:
434 434 return baseset()
435 435 for r in reviter:
436 436 anc = anc.ancestor(repo[r])
437 437
438 438 r = scmutil.intrev(anc)
439 439 if r in subset:
440 440 return baseset([r])
441 441 return baseset()
442 442
443 443
444 444 def _ancestors(
445 445 repo, subset, x, followfirst=False, startdepth=None, stopdepth=None
446 446 ):
447 447 heads = getset(repo, fullreposet(repo), x)
448 448 if not heads:
449 449 return baseset()
450 450 s = dagop.revancestors(repo, heads, followfirst, startdepth, stopdepth)
451 451 return subset & s
452 452
453 453
454 454 @predicate(b'ancestors(set[, depth])', safe=True)
455 455 def ancestors(repo, subset, x):
456 456 """Changesets that are ancestors of changesets in set, including the
457 457 given changesets themselves.
458 458
459 459 If depth is specified, the result only includes changesets up to
460 460 the specified generation.
461 461 """
462 462 # startdepth is for internal use only until we can decide the UI
463 463 args = getargsdict(x, b'ancestors', b'set depth startdepth')
464 464 if b'set' not in args:
465 465 # i18n: "ancestors" is a keyword
466 466 raise error.ParseError(_(b'ancestors takes at least 1 argument'))
467 467 startdepth = stopdepth = None
468 468 if b'startdepth' in args:
469 469 n = getinteger(
470 470 args[b'startdepth'], b"ancestors expects an integer startdepth"
471 471 )
472 472 if n < 0:
473 473 raise error.ParseError(b"negative startdepth")
474 474 startdepth = n
475 475 if b'depth' in args:
476 476 # i18n: "ancestors" is a keyword
477 477 n = getinteger(args[b'depth'], _(b"ancestors expects an integer depth"))
478 478 if n < 0:
479 479 raise error.ParseError(_(b"negative depth"))
480 480 stopdepth = n + 1
481 481 return _ancestors(
482 482 repo, subset, args[b'set'], startdepth=startdepth, stopdepth=stopdepth
483 483 )
484 484
485 485
486 486 @predicate(b'_firstancestors', safe=True)
487 487 def _firstancestors(repo, subset, x):
488 488 # ``_firstancestors(set)``
489 489 # Like ``ancestors(set)`` but follows only the first parents.
490 490 return _ancestors(repo, subset, x, followfirst=True)
491 491
492 492
493 493 def _childrenspec(repo, subset, x, n, order):
494 494 """Changesets that are the Nth child of a changeset
495 495 in set.
496 496 """
497 497 cs = set()
498 498 for r in getset(repo, fullreposet(repo), x):
499 499 for i in range(n):
500 500 c = repo[r].children()
501 501 if len(c) == 0:
502 502 break
503 503 if len(c) > 1:
504 504 raise error.RepoLookupError(
505 505 _(b"revision in set has more than one child")
506 506 )
507 507 r = c[0].rev()
508 508 else:
509 509 cs.add(r)
510 510 return subset & cs
511 511
512 512
513 513 def ancestorspec(repo, subset, x, n, order):
514 514 """``set~n``
515 515 Changesets that are the Nth ancestor (first parents only) of a changeset
516 516 in set.
517 517 """
518 518 n = getinteger(n, _(b"~ expects a number"))
519 519 if n < 0:
520 520 # children lookup
521 521 return _childrenspec(repo, subset, x, -n, order)
522 522 ps = set()
523 523 cl = repo.changelog
524 524 for r in getset(repo, fullreposet(repo), x):
525 525 for i in range(n):
526 526 try:
527 527 r = cl.parentrevs(r)[0]
528 528 except error.WdirUnsupported:
529 529 r = repo[r].p1().rev()
530 530 ps.add(r)
531 531 return subset & ps
532 532
533 533
534 534 @predicate(b'author(string)', safe=True, weight=10)
535 535 def author(repo, subset, x):
536 536 """Alias for ``user(string)``."""
537 537 # i18n: "author" is a keyword
538 538 n = getstring(x, _(b"author requires a string"))
539 539 kind, pattern, matcher = _substringmatcher(n, casesensitive=False)
540 540 return subset.filter(
541 541 lambda x: matcher(repo[x].user()), condrepr=(b'<user %r>', n)
542 542 )
543 543
544 544
545 545 @predicate(b'bisect(string)', safe=True)
546 546 def bisect(repo, subset, x):
547 547 """Changesets marked in the specified bisect status:
548 548
549 549 - ``good``, ``bad``, ``skip``: csets explicitly marked as good/bad/skip
550 550 - ``goods``, ``bads`` : csets topologically good/bad
551 551 - ``range`` : csets taking part in the bisection
552 552 - ``pruned`` : csets that are goods, bads or skipped
553 553 - ``untested`` : csets whose fate is yet unknown
554 554 - ``ignored`` : csets ignored due to DAG topology
555 555 - ``current`` : the cset currently being bisected
556 556 """
557 557 # i18n: "bisect" is a keyword
558 558 status = getstring(x, _(b"bisect requires a string")).lower()
559 559 state = set(hbisect.get(repo, status))
560 560 return subset & state
561 561
562 562
563 563 # Backward-compatibility
564 564 # - no help entry so that we do not advertise it any more
565 565 @predicate(b'bisected', safe=True)
566 566 def bisected(repo, subset, x):
567 567 return bisect(repo, subset, x)
568 568
569 569
570 570 @predicate(b'bookmark([name])', safe=True)
571 571 def bookmark(repo, subset, x):
572 572 """The named bookmark or all bookmarks.
573 573
574 574 Pattern matching is supported for `name`. See :hg:`help revisions.patterns`.
575 575 """
576 576 # i18n: "bookmark" is a keyword
577 577 args = getargs(x, 0, 1, _(b'bookmark takes one or no arguments'))
578 578 if args:
579 579 bm = getstring(
580 580 args[0],
581 581 # i18n: "bookmark" is a keyword
582 582 _(b'the argument to bookmark must be a string'),
583 583 )
584 584 kind, pattern, matcher = stringutil.stringmatcher(bm)
585 585 bms = set()
586 586 if kind == b'literal':
587 587 if bm == pattern:
588 588 pattern = repo._bookmarks.expandname(pattern)
589 589 bmrev = repo._bookmarks.get(pattern, None)
590 590 if not bmrev:
591 591 raise error.RepoLookupError(
592 592 _(b"bookmark '%s' does not exist") % pattern
593 593 )
594 594 bms.add(repo[bmrev].rev())
595 595 else:
596 596 matchrevs = set()
597 597 for name, bmrev in pycompat.iteritems(repo._bookmarks):
598 598 if matcher(name):
599 599 matchrevs.add(bmrev)
600 600 for bmrev in matchrevs:
601 601 bms.add(repo[bmrev].rev())
602 602 else:
603 603 bms = {repo[r].rev() for r in repo._bookmarks.values()}
604 604 bms -= {nullrev}
605 605 return subset & bms
606 606
607 607
608 608 @predicate(b'branch(string or set)', safe=True, weight=10)
609 609 def branch(repo, subset, x):
610 610 """
611 611 All changesets belonging to the given branch or the branches of the given
612 612 changesets.
613 613
614 614 Pattern matching is supported for `string`. See
615 615 :hg:`help revisions.patterns`.
616 616 """
617 617 getbi = repo.revbranchcache().branchinfo
618 618
619 619 def getbranch(r):
620 620 try:
621 621 return getbi(r)[0]
622 622 except error.WdirUnsupported:
623 623 return repo[r].branch()
624 624
625 625 try:
626 626 b = getstring(x, b'')
627 627 except error.ParseError:
628 628 # not a string, but another revspec, e.g. tip()
629 629 pass
630 630 else:
631 631 kind, pattern, matcher = stringutil.stringmatcher(b)
632 632 if kind == b'literal':
633 633 # note: falls through to the revspec case if no branch with
634 634 # this name exists and pattern kind is not specified explicitly
635 635 if repo.branchmap().hasbranch(pattern):
636 636 return subset.filter(
637 637 lambda r: matcher(getbranch(r)),
638 638 condrepr=(b'<branch %r>', b),
639 639 )
640 640 if b.startswith(b'literal:'):
641 641 raise error.RepoLookupError(
642 642 _(b"branch '%s' does not exist") % pattern
643 643 )
644 644 else:
645 645 return subset.filter(
646 646 lambda r: matcher(getbranch(r)), condrepr=(b'<branch %r>', b)
647 647 )
648 648
649 649 s = getset(repo, fullreposet(repo), x)
650 650 b = set()
651 651 for r in s:
652 652 b.add(getbranch(r))
653 653 c = s.__contains__
654 654 return subset.filter(
655 655 lambda r: c(r) or getbranch(r) in b,
656 656 condrepr=lambda: b'<branch %r>' % _sortedb(b),
657 657 )
658 658
659 659
660 660 @predicate(b'phasedivergent()', safe=True)
661 661 def phasedivergent(repo, subset, x):
662 662 """Mutable changesets marked as successors of public changesets.
663 663
664 664 Only non-public and non-obsolete changesets can be `phasedivergent`.
665 665 (EXPERIMENTAL)
666 666 """
667 667 # i18n: "phasedivergent" is a keyword
668 668 getargs(x, 0, 0, _(b"phasedivergent takes no arguments"))
669 669 phasedivergent = obsmod.getrevs(repo, b'phasedivergent')
670 670 return subset & phasedivergent
671 671
672 672
673 673 @predicate(b'bundle()', safe=True)
674 674 def bundle(repo, subset, x):
675 675 """Changesets in the bundle.
676 676
677 677 Bundle must be specified by the -R option."""
678 678
679 679 try:
680 680 bundlerevs = repo.changelog.bundlerevs
681 681 except AttributeError:
682 682 raise error.Abort(_(b"no bundle provided - specify with -R"))
683 683 return subset & bundlerevs
684 684
685 685
686 686 def checkstatus(repo, subset, pat, field):
687 687 """Helper for status-related revsets (adds, removes, modifies).
688 688 The field parameter says which kind is desired.
689 689 """
690 690 hasset = matchmod.patkind(pat) == b'set'
691 691
692 692 mcache = [None]
693 693
694 694 def matches(x):
695 695 c = repo[x]
696 696 if not mcache[0] or hasset:
697 697 mcache[0] = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=c)
698 698 m = mcache[0]
699 699 fname = None
700 700
701 701 assert m is not None # help pytype
702 702 if not m.anypats() and len(m.files()) == 1:
703 703 fname = m.files()[0]
704 704 if fname is not None:
705 705 if fname not in c.files():
706 706 return False
707 707 else:
708 708 if not any(m(f) for f in c.files()):
709 709 return False
710 710 files = getattr(repo.status(c.p1().node(), c.node()), field)
711 711 if fname is not None:
712 712 if fname in files:
713 713 return True
714 714 else:
715 715 if any(m(f) for f in files):
716 716 return True
717 717
718 718 return subset.filter(
719 719 matches, condrepr=(b'<status.%s %r>', pycompat.sysbytes(field), pat)
720 720 )
721 721
722 722
723 723 def _children(repo, subset, parentset):
724 724 if not parentset:
725 725 return baseset()
726 726 cs = set()
727 727 pr = repo.changelog.parentrevs
728 728 minrev = parentset.min()
729 729 for r in subset:
730 730 if r <= minrev:
731 731 continue
732 732 p1, p2 = pr(r)
733 733 if p1 in parentset:
734 734 cs.add(r)
735 735 if p2 != nullrev and p2 in parentset:
736 736 cs.add(r)
737 737 return baseset(cs)
738 738
739 739
740 740 @predicate(b'children(set)', safe=True)
741 741 def children(repo, subset, x):
742 742 """Child changesets of changesets in set."""
743 743 s = getset(repo, fullreposet(repo), x)
744 744 cs = _children(repo, subset, s)
745 745 return subset & cs
746 746
747 747
748 748 @predicate(b'closed()', safe=True, weight=10)
749 749 def closed(repo, subset, x):
750 750 """Changeset is closed."""
751 751 # i18n: "closed" is a keyword
752 752 getargs(x, 0, 0, _(b"closed takes no arguments"))
753 753 return subset.filter(
754 754 lambda r: repo[r].closesbranch(), condrepr=b'<branch closed>'
755 755 )
756 756
757 757
758 758 # for internal use
759 759 @predicate(b'_commonancestorheads(set)', safe=True)
760 760 def _commonancestorheads(repo, subset, x):
761 761 # This is an internal method is for quickly calculating "heads(::x and
762 762 # ::y)"
763 763
764 764 # These greatest common ancestors are the same ones that the consensus bid
765 765 # merge will find.
766 766 startrevs = getset(repo, fullreposet(repo), x, order=anyorder)
767 767
768 768 ancs = repo.changelog._commonancestorsheads(*list(startrevs))
769 769 return subset & baseset(ancs)
770 770
771 771
772 772 @predicate(b'commonancestors(set)', safe=True)
773 773 def commonancestors(repo, subset, x):
774 774 """Changesets that are ancestors of every changeset in set."""
775 775 startrevs = getset(repo, fullreposet(repo), x, order=anyorder)
776 776 if not startrevs:
777 777 return baseset()
778 778 for r in startrevs:
779 779 subset &= dagop.revancestors(repo, baseset([r]))
780 780 return subset
781 781
782 782
783 783 @predicate(b'conflictlocal()', safe=True)
784 784 def conflictlocal(repo, subset, x):
785 785 """The local side of the merge, if currently in an unresolved merge.
786 786
787 787 "merge" here includes merge conflicts from e.g. 'hg rebase' or 'hg graft'.
788 788 """
789 789 getargs(x, 0, 0, _(b"conflictlocal takes no arguments"))
790 790 from . import mergestate as mergestatemod
791 791
792 792 mergestate = mergestatemod.mergestate.read(repo)
793 793 if mergestate.active() and repo.changelog.hasnode(mergestate.local):
794 794 return subset & {repo.changelog.rev(mergestate.local)}
795 795
796 796 return baseset()
797 797
798 798
799 799 @predicate(b'conflictother()', safe=True)
800 800 def conflictother(repo, subset, x):
801 801 """The other side of the merge, if currently in an unresolved merge.
802 802
803 803 "merge" here includes merge conflicts from e.g. 'hg rebase' or 'hg graft'.
804 804 """
805 805 getargs(x, 0, 0, _(b"conflictother takes no arguments"))
806 806 from . import mergestate as mergestatemod
807 807
808 808 mergestate = mergestatemod.mergestate.read(repo)
809 809 if mergestate.active() and repo.changelog.hasnode(mergestate.other):
810 810 return subset & {repo.changelog.rev(mergestate.other)}
811 811
812 812 return baseset()
813 813
814 814
815 815 @predicate(b'contains(pattern)', weight=100)
816 816 def contains(repo, subset, x):
817 817 """The revision's manifest contains a file matching pattern (but might not
818 818 modify it). See :hg:`help patterns` for information about file patterns.
819 819
820 820 The pattern without explicit kind like ``glob:`` is expected to be
821 821 relative to the current directory and match against a file exactly
822 822 for efficiency.
823 823 """
824 824 # i18n: "contains" is a keyword
825 825 pat = getstring(x, _(b"contains requires a pattern"))
826 826
827 827 def matches(x):
828 828 if not matchmod.patkind(pat):
829 829 pats = pathutil.canonpath(repo.root, repo.getcwd(), pat)
830 830 if pats in repo[x]:
831 831 return True
832 832 else:
833 833 c = repo[x]
834 834 m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=c)
835 835 for f in c.manifest():
836 836 if m(f):
837 837 return True
838 838 return False
839 839
840 840 return subset.filter(matches, condrepr=(b'<contains %r>', pat))
841 841
842 842
843 843 @predicate(b'converted([id])', safe=True)
844 844 def converted(repo, subset, x):
845 845 """Changesets converted from the given identifier in the old repository if
846 846 present, or all converted changesets if no identifier is specified.
847 847 """
848 848
849 849 # There is exactly no chance of resolving the revision, so do a simple
850 850 # string compare and hope for the best
851 851
852 852 rev = None
853 853 # i18n: "converted" is a keyword
854 854 l = getargs(x, 0, 1, _(b'converted takes one or no arguments'))
855 855 if l:
856 856 # i18n: "converted" is a keyword
857 857 rev = getstring(l[0], _(b'converted requires a revision'))
858 858
859 859 def _matchvalue(r):
860 860 source = repo[r].extra().get(b'convert_revision', None)
861 861 return source is not None and (rev is None or source.startswith(rev))
862 862
863 863 return subset.filter(
864 864 lambda r: _matchvalue(r), condrepr=(b'<converted %r>', rev)
865 865 )
866 866
867 867
868 868 @predicate(b'date(interval)', safe=True, weight=10)
869 869 def date(repo, subset, x):
870 870 """Changesets within the interval, see :hg:`help dates`."""
871 871 # i18n: "date" is a keyword
872 872 ds = getstring(x, _(b"date requires a string"))
873 873 dm = dateutil.matchdate(ds)
874 874 return subset.filter(
875 875 lambda x: dm(repo[x].date()[0]), condrepr=(b'<date %r>', ds)
876 876 )
877 877
878 878
879 879 @predicate(b'desc(string)', safe=True, weight=10)
880 880 def desc(repo, subset, x):
881 881 """Search commit message for string. The match is case-insensitive.
882 882
883 883 Pattern matching is supported for `string`. See
884 884 :hg:`help revisions.patterns`.
885 885 """
886 886 # i18n: "desc" is a keyword
887 887 ds = getstring(x, _(b"desc requires a string"))
888 888
889 889 kind, pattern, matcher = _substringmatcher(ds, casesensitive=False)
890 890
891 891 return subset.filter(
892 892 lambda r: matcher(repo[r].description()), condrepr=(b'<desc %r>', ds)
893 893 )
894 894
895 895
896 896 def _descendants(
897 897 repo, subset, x, followfirst=False, startdepth=None, stopdepth=None
898 898 ):
899 899 roots = getset(repo, fullreposet(repo), x)
900 900 if not roots:
901 901 return baseset()
902 902 s = dagop.revdescendants(repo, roots, followfirst, startdepth, stopdepth)
903 903 return subset & s
904 904
905 905
906 906 @predicate(b'descendants(set[, depth])', safe=True)
907 907 def descendants(repo, subset, x):
908 908 """Changesets which are descendants of changesets in set, including the
909 909 given changesets themselves.
910 910
911 911 If depth is specified, the result only includes changesets up to
912 912 the specified generation.
913 913 """
914 914 # startdepth is for internal use only until we can decide the UI
915 915 args = getargsdict(x, b'descendants', b'set depth startdepth')
916 916 if b'set' not in args:
917 917 # i18n: "descendants" is a keyword
918 918 raise error.ParseError(_(b'descendants takes at least 1 argument'))
919 919 startdepth = stopdepth = None
920 920 if b'startdepth' in args:
921 921 n = getinteger(
922 922 args[b'startdepth'], b"descendants expects an integer startdepth"
923 923 )
924 924 if n < 0:
925 925 raise error.ParseError(b"negative startdepth")
926 926 startdepth = n
927 927 if b'depth' in args:
928 928 # i18n: "descendants" is a keyword
929 929 n = getinteger(
930 930 args[b'depth'], _(b"descendants expects an integer depth")
931 931 )
932 932 if n < 0:
933 933 raise error.ParseError(_(b"negative depth"))
934 934 stopdepth = n + 1
935 935 return _descendants(
936 936 repo, subset, args[b'set'], startdepth=startdepth, stopdepth=stopdepth
937 937 )
938 938
939 939
940 940 @predicate(b'_firstdescendants', safe=True)
941 941 def _firstdescendants(repo, subset, x):
942 942 # ``_firstdescendants(set)``
943 943 # Like ``descendants(set)`` but follows only the first parents.
944 944 return _descendants(repo, subset, x, followfirst=True)
945 945
946 946
947 947 @predicate(b'destination([set])', safe=True, weight=10)
948 948 def destination(repo, subset, x):
949 949 """Changesets that were created by a graft, transplant or rebase operation,
950 950 with the given revisions specified as the source. Omitting the optional set
951 951 is the same as passing all().
952 952 """
953 953 if x is not None:
954 954 sources = getset(repo, fullreposet(repo), x)
955 955 else:
956 956 sources = fullreposet(repo)
957 957
958 958 dests = set()
959 959
960 960 # subset contains all of the possible destinations that can be returned, so
961 961 # iterate over them and see if their source(s) were provided in the arg set.
962 962 # Even if the immediate src of r is not in the arg set, src's source (or
963 963 # further back) may be. Scanning back further than the immediate src allows
964 964 # transitive transplants and rebases to yield the same results as transitive
965 965 # grafts.
966 966 for r in subset:
967 967 src = _getrevsource(repo, r)
968 968 lineage = None
969 969
970 970 while src is not None:
971 971 if lineage is None:
972 972 lineage = list()
973 973
974 974 lineage.append(r)
975 975
976 976 # The visited lineage is a match if the current source is in the arg
977 977 # set. Since every candidate dest is visited by way of iterating
978 978 # subset, any dests further back in the lineage will be tested by a
979 979 # different iteration over subset. Likewise, if the src was already
980 980 # selected, the current lineage can be selected without going back
981 981 # further.
982 982 if src in sources or src in dests:
983 983 dests.update(lineage)
984 984 break
985 985
986 986 r = src
987 987 src = _getrevsource(repo, r)
988 988
989 989 return subset.filter(
990 990 dests.__contains__,
991 991 condrepr=lambda: b'<destination %r>' % _sortedb(dests),
992 992 )
993 993
994 994
995 995 @predicate(b'diffcontains(pattern)', weight=110)
996 996 def diffcontains(repo, subset, x):
997 997 """Search revision differences for when the pattern was added or removed.
998 998
999 999 The pattern may be a substring literal or a regular expression. See
1000 1000 :hg:`help revisions.patterns`.
1001 1001 """
1002 1002 args = getargsdict(x, b'diffcontains', b'pattern')
1003 1003 if b'pattern' not in args:
1004 1004 # i18n: "diffcontains" is a keyword
1005 1005 raise error.ParseError(_(b'diffcontains takes at least 1 argument'))
1006 1006
1007 1007 pattern = getstring(
1008 1008 args[b'pattern'], _(b'diffcontains requires a string pattern')
1009 1009 )
1010 1010 regexp = stringutil.substringregexp(pattern, re.M)
1011 1011
1012 1012 # TODO: add support for file pattern and --follow. For example,
1013 1013 # diffcontains(pattern[, set]) where set may be file(pattern) or
1014 1014 # follow(pattern), and we'll eventually add a support for narrowing
1015 1015 # files by revset?
1016 1016 fmatch = matchmod.always()
1017 1017
1018 1018 def makefilematcher(ctx):
1019 1019 return fmatch
1020 1020
1021 1021 # TODO: search in a windowed way
1022 1022 searcher = grepmod.grepsearcher(repo.ui, repo, regexp, diff=True)
1023 1023
1024 1024 def testdiff(rev):
1025 1025 # consume the generator to discard revfiles/matches cache
1026 1026 found = False
1027 1027 for fn, ctx, pstates, states in searcher.searchfiles(
1028 1028 baseset([rev]), makefilematcher
1029 1029 ):
1030 1030 if next(grepmod.difflinestates(pstates, states), None):
1031 1031 found = True
1032 1032 return found
1033 1033
1034 1034 return subset.filter(testdiff, condrepr=(b'<diffcontains %r>', pattern))
1035 1035
1036 1036
1037 1037 @predicate(b'contentdivergent()', safe=True)
1038 1038 def contentdivergent(repo, subset, x):
1039 1039 """
1040 1040 Final successors of changesets with an alternative set of final
1041 1041 successors. (EXPERIMENTAL)
1042 1042 """
1043 1043 # i18n: "contentdivergent" is a keyword
1044 1044 getargs(x, 0, 0, _(b"contentdivergent takes no arguments"))
1045 1045 contentdivergent = obsmod.getrevs(repo, b'contentdivergent')
1046 1046 return subset & contentdivergent
1047 1047
1048 1048
1049 1049 @predicate(b'expectsize(set[, size])', safe=True, takeorder=True)
1050 1050 def expectsize(repo, subset, x, order):
1051 1051 """Return the given revset if size matches the revset size.
1052 1052 Abort if the revset doesn't expect given size.
1053 1053 size can either be an integer range or an integer.
1054 1054
1055 1055 For example, ``expectsize(0:1, 3:5)`` will abort as revset size is 2 and
1056 1056 2 is not between 3 and 5 inclusive."""
1057 1057
1058 1058 args = getargsdict(x, b'expectsize', b'set size')
1059 1059 minsize = 0
1060 1060 maxsize = len(repo) + 1
1061 1061 err = b''
1062 1062 if b'size' not in args or b'set' not in args:
1063 1063 raise error.ParseError(_(b'invalid set of arguments'))
1064 1064 minsize, maxsize = getintrange(
1065 1065 args[b'size'],
1066 1066 _(b'expectsize requires a size range or a positive integer'),
1067 1067 _(b'size range bounds must be integers'),
1068 1068 minsize,
1069 1069 maxsize,
1070 1070 )
1071 1071 if minsize < 0 or maxsize < 0:
1072 1072 raise error.ParseError(_(b'negative size'))
1073 1073 rev = getset(repo, fullreposet(repo), args[b'set'], order=order)
1074 1074 if minsize != maxsize and (len(rev) < minsize or len(rev) > maxsize):
1075 1075 err = _(b'revset size mismatch. expected between %d and %d, got %d') % (
1076 1076 minsize,
1077 1077 maxsize,
1078 1078 len(rev),
1079 1079 )
1080 1080 elif minsize == maxsize and len(rev) != minsize:
1081 1081 err = _(b'revset size mismatch. expected %d, got %d') % (
1082 1082 minsize,
1083 1083 len(rev),
1084 1084 )
1085 1085 if err:
1086 1086 raise error.RepoLookupError(err)
1087 1087 if order == followorder:
1088 1088 return subset & rev
1089 1089 else:
1090 1090 return rev & subset
1091 1091
1092 1092
1093 1093 @predicate(b'extdata(source)', safe=False, weight=100)
1094 1094 def extdata(repo, subset, x):
1095 1095 """Changesets in the specified extdata source. (EXPERIMENTAL)"""
1096 1096 # i18n: "extdata" is a keyword
1097 1097 args = getargsdict(x, b'extdata', b'source')
1098 1098 source = getstring(
1099 1099 args.get(b'source'),
1100 1100 # i18n: "extdata" is a keyword
1101 1101 _(b'extdata takes at least 1 string argument'),
1102 1102 )
1103 1103 data = scmutil.extdatasource(repo, source)
1104 1104 return subset & baseset(data)
1105 1105
1106 1106
1107 1107 @predicate(b'extinct()', safe=True)
1108 1108 def extinct(repo, subset, x):
1109 1109 """Obsolete changesets with obsolete descendants only. (EXPERIMENTAL)"""
1110 1110 # i18n: "extinct" is a keyword
1111 1111 getargs(x, 0, 0, _(b"extinct takes no arguments"))
1112 1112 extincts = obsmod.getrevs(repo, b'extinct')
1113 1113 return subset & extincts
1114 1114
1115 1115
1116 1116 @predicate(b'extra(label, [value])', safe=True)
1117 1117 def extra(repo, subset, x):
1118 1118 """Changesets with the given label in the extra metadata, with the given
1119 1119 optional value.
1120 1120
1121 1121 Pattern matching is supported for `value`. See
1122 1122 :hg:`help revisions.patterns`.
1123 1123 """
1124 1124 args = getargsdict(x, b'extra', b'label value')
1125 1125 if b'label' not in args:
1126 1126 # i18n: "extra" is a keyword
1127 1127 raise error.ParseError(_(b'extra takes at least 1 argument'))
1128 1128 # i18n: "extra" is a keyword
1129 1129 label = getstring(
1130 1130 args[b'label'], _(b'first argument to extra must be a string')
1131 1131 )
1132 1132 value = None
1133 1133
1134 1134 if b'value' in args:
1135 1135 # i18n: "extra" is a keyword
1136 1136 value = getstring(
1137 1137 args[b'value'], _(b'second argument to extra must be a string')
1138 1138 )
1139 1139 kind, value, matcher = stringutil.stringmatcher(value)
1140 1140
1141 1141 def _matchvalue(r):
1142 1142 extra = repo[r].extra()
1143 1143 return label in extra and (value is None or matcher(extra[label]))
1144 1144
1145 1145 return subset.filter(
1146 1146 lambda r: _matchvalue(r), condrepr=(b'<extra[%r] %r>', label, value)
1147 1147 )
1148 1148
1149 1149
1150 1150 @predicate(b'filelog(pattern)', safe=True)
1151 1151 def filelog(repo, subset, x):
1152 1152 """Changesets connected to the specified filelog.
1153 1153
1154 1154 For performance reasons, visits only revisions mentioned in the file-level
1155 1155 filelog, rather than filtering through all changesets (much faster, but
1156 1156 doesn't include deletes or duplicate changes). For a slower, more accurate
1157 1157 result, use ``file()``.
1158 1158
1159 1159 The pattern without explicit kind like ``glob:`` is expected to be
1160 1160 relative to the current directory and match against a file exactly
1161 1161 for efficiency.
1162 1162 """
1163 1163
1164 1164 # i18n: "filelog" is a keyword
1165 1165 pat = getstring(x, _(b"filelog requires a pattern"))
1166 1166 s = set()
1167 1167 cl = repo.changelog
1168 1168
1169 1169 if not matchmod.patkind(pat):
1170 1170 f = pathutil.canonpath(repo.root, repo.getcwd(), pat)
1171 1171 files = [f]
1172 1172 else:
1173 1173 m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=repo[None])
1174 1174 files = (f for f in repo[None] if m(f))
1175 1175
1176 1176 for f in files:
1177 1177 fl = repo.file(f)
1178 1178 known = {}
1179 1179 scanpos = 0
1180 1180 for fr in list(fl):
1181 1181 fn = fl.node(fr)
1182 1182 if fn in known:
1183 1183 s.add(known[fn])
1184 1184 continue
1185 1185
1186 1186 lr = fl.linkrev(fr)
1187 1187 if lr in cl:
1188 1188 s.add(lr)
1189 1189 elif scanpos is not None:
1190 1190 # lowest matching changeset is filtered, scan further
1191 1191 # ahead in changelog
1192 1192 start = max(lr, scanpos) + 1
1193 1193 scanpos = None
1194 1194 for r in cl.revs(start):
1195 1195 # minimize parsing of non-matching entries
1196 1196 if f in cl.revision(r) and f in cl.readfiles(r):
1197 1197 try:
1198 1198 # try to use manifest delta fastpath
1199 1199 n = repo[r].filenode(f)
1200 1200 if n not in known:
1201 1201 if n == fn:
1202 1202 s.add(r)
1203 1203 scanpos = r
1204 1204 break
1205 1205 else:
1206 1206 known[n] = r
1207 1207 except error.ManifestLookupError:
1208 1208 # deletion in changelog
1209 1209 continue
1210 1210
1211 1211 return subset & s
1212 1212
1213 1213
1214 1214 @predicate(b'first(set, [n])', safe=True, takeorder=True, weight=0)
1215 1215 def first(repo, subset, x, order):
1216 1216 """An alias for limit()."""
1217 1217 return limit(repo, subset, x, order)
1218 1218
1219 1219
1220 1220 def _follow(repo, subset, x, name, followfirst=False):
1221 1221 args = getargsdict(x, name, b'file startrev')
1222 1222 revs = None
1223 1223 if b'startrev' in args:
1224 1224 revs = getset(repo, fullreposet(repo), args[b'startrev'])
1225 1225 if b'file' in args:
1226 1226 x = getstring(args[b'file'], _(b"%s expected a pattern") % name)
1227 1227 if revs is None:
1228 1228 revs = [None]
1229 1229 fctxs = []
1230 1230 for r in revs:
1231 1231 ctx = mctx = repo[r]
1232 1232 if r is None:
1233 1233 ctx = repo[b'.']
1234 1234 m = matchmod.match(
1235 1235 repo.root, repo.getcwd(), [x], ctx=mctx, default=b'path'
1236 1236 )
1237 1237 fctxs.extend(ctx[f].introfilectx() for f in ctx.manifest().walk(m))
1238 1238 s = dagop.filerevancestors(fctxs, followfirst)
1239 1239 else:
1240 1240 if revs is None:
1241 1241 revs = baseset([repo[b'.'].rev()])
1242 1242 s = dagop.revancestors(repo, revs, followfirst)
1243 1243
1244 1244 return subset & s
1245 1245
1246 1246
1247 1247 @predicate(b'follow([file[, startrev]])', safe=True)
1248 1248 def follow(repo, subset, x):
1249 1249 """
1250 1250 An alias for ``::.`` (ancestors of the working directory's first parent).
1251 1251 If file pattern is specified, the histories of files matching given
1252 1252 pattern in the revision given by startrev are followed, including copies.
1253 1253 """
1254 1254 return _follow(repo, subset, x, b'follow')
1255 1255
1256 1256
1257 1257 @predicate(b'_followfirst', safe=True)
1258 1258 def _followfirst(repo, subset, x):
1259 1259 # ``followfirst([file[, startrev]])``
1260 1260 # Like ``follow([file[, startrev]])`` but follows only the first parent
1261 1261 # of every revisions or files revisions.
1262 1262 return _follow(repo, subset, x, b'_followfirst', followfirst=True)
1263 1263
1264 1264
1265 1265 @predicate(
1266 1266 b'followlines(file, fromline:toline[, startrev=., descend=False])',
1267 1267 safe=True,
1268 1268 )
1269 1269 def followlines(repo, subset, x):
1270 1270 """Changesets modifying `file` in line range ('fromline', 'toline').
1271 1271
1272 1272 Line range corresponds to 'file' content at 'startrev' and should hence be
1273 1273 consistent with file size. If startrev is not specified, working directory's
1274 1274 parent is used.
1275 1275
1276 1276 By default, ancestors of 'startrev' are returned. If 'descend' is True,
1277 1277 descendants of 'startrev' are returned though renames are (currently) not
1278 1278 followed in this direction.
1279 1279 """
1280 1280 args = getargsdict(x, b'followlines', b'file *lines startrev descend')
1281 1281 if len(args[b'lines']) != 1:
1282 1282 raise error.ParseError(_(b"followlines requires a line range"))
1283 1283
1284 1284 rev = b'.'
1285 1285 if b'startrev' in args:
1286 1286 revs = getset(repo, fullreposet(repo), args[b'startrev'])
1287 1287 if len(revs) != 1:
1288 1288 raise error.ParseError(
1289 1289 # i18n: "followlines" is a keyword
1290 1290 _(b"followlines expects exactly one revision")
1291 1291 )
1292 1292 rev = revs.last()
1293 1293
1294 1294 pat = getstring(args[b'file'], _(b"followlines requires a pattern"))
1295 1295 # i18n: "followlines" is a keyword
1296 1296 msg = _(b"followlines expects exactly one file")
1297 1297 fname = scmutil.parsefollowlinespattern(repo, rev, pat, msg)
1298 1298 fromline, toline = util.processlinerange(
1299 1299 *getintrange(
1300 1300 args[b'lines'][0],
1301 1301 # i18n: "followlines" is a keyword
1302 1302 _(b"followlines expects a line number or a range"),
1303 1303 _(b"line range bounds must be integers"),
1304 1304 )
1305 1305 )
1306 1306
1307 1307 fctx = repo[rev].filectx(fname)
1308 1308 descend = False
1309 1309 if b'descend' in args:
1310 1310 descend = getboolean(
1311 1311 args[b'descend'],
1312 1312 # i18n: "descend" is a keyword
1313 1313 _(b"descend argument must be a boolean"),
1314 1314 )
1315 1315 if descend:
1316 1316 rs = generatorset(
1317 1317 (
1318 1318 c.rev()
1319 1319 for c, _linerange in dagop.blockdescendants(
1320 1320 fctx, fromline, toline
1321 1321 )
1322 1322 ),
1323 1323 iterasc=True,
1324 1324 )
1325 1325 else:
1326 1326 rs = generatorset(
1327 1327 (
1328 1328 c.rev()
1329 1329 for c, _linerange in dagop.blockancestors(
1330 1330 fctx, fromline, toline
1331 1331 )
1332 1332 ),
1333 1333 iterasc=False,
1334 1334 )
1335 1335 return subset & rs
1336 1336
1337 1337
1338 @predicate(b'nodefromfile(path)')
1339 def nodefromfile(repo, subset, x):
1340 """
1341 An alias for ``::.`` (ancestors of the working directory's first parent).
1342 If file pattern is specified, the histories of files matching given
1343 pattern in the revision given by startrev are followed, including copies.
1344 """
1345 path = getstring(x, _(b"nodefromfile require a file path"))
1346 listed_rev = set()
1347 try:
1348 with pycompat.open(path, 'rb') as f:
1349 for line in f:
1350 n = line.strip()
1351 rn = _node(repo, n)
1352 if rn is not None:
1353 listed_rev.add(rn)
1354 except IOError as exc:
1355 m = _(b'cannot open nodes file "%s": %s')
1356 m %= (path, encoding.strtolocal(exc.strerror))
1357 raise error.Abort(m)
1358 return subset & baseset(listed_rev)
1359
1360
1338 1361 @predicate(b'all()', safe=True)
1339 1362 def getall(repo, subset, x):
1340 1363 """All changesets, the same as ``0:tip``."""
1341 1364 # i18n: "all" is a keyword
1342 1365 getargs(x, 0, 0, _(b"all takes no arguments"))
1343 1366 return subset & spanset(repo) # drop "null" if any
1344 1367
1345 1368
1346 1369 @predicate(b'grep(regex)', weight=10)
1347 1370 def grep(repo, subset, x):
1348 1371 """Like ``keyword(string)`` but accepts a regex. Use ``grep(r'...')``
1349 1372 to ensure special escape characters are handled correctly. Unlike
1350 1373 ``keyword(string)``, the match is case-sensitive.
1351 1374 """
1352 1375 try:
1353 1376 # i18n: "grep" is a keyword
1354 1377 gr = re.compile(getstring(x, _(b"grep requires a string")))
1355 1378 except re.error as e:
1356 1379 raise error.ParseError(
1357 1380 _(b'invalid match pattern: %s') % stringutil.forcebytestr(e)
1358 1381 )
1359 1382
1360 1383 def matches(x):
1361 1384 c = repo[x]
1362 1385 for e in c.files() + [c.user(), c.description()]:
1363 1386 if gr.search(e):
1364 1387 return True
1365 1388 return False
1366 1389
1367 1390 return subset.filter(matches, condrepr=(b'<grep %r>', gr.pattern))
1368 1391
1369 1392
1370 1393 @predicate(b'_matchfiles', safe=True)
1371 1394 def _matchfiles(repo, subset, x):
1372 1395 # _matchfiles takes a revset list of prefixed arguments:
1373 1396 #
1374 1397 # [p:foo, i:bar, x:baz]
1375 1398 #
1376 1399 # builds a match object from them and filters subset. Allowed
1377 1400 # prefixes are 'p:' for regular patterns, 'i:' for include
1378 1401 # patterns and 'x:' for exclude patterns. Use 'r:' prefix to pass
1379 1402 # a revision identifier, or the empty string to reference the
1380 1403 # working directory, from which the match object is
1381 1404 # initialized. Use 'd:' to set the default matching mode, default
1382 1405 # to 'glob'. At most one 'r:' and 'd:' argument can be passed.
1383 1406
1384 1407 l = getargs(x, 1, -1, b"_matchfiles requires at least one argument")
1385 1408 pats, inc, exc = [], [], []
1386 1409 rev, default = None, None
1387 1410 for arg in l:
1388 1411 s = getstring(arg, b"_matchfiles requires string arguments")
1389 1412 prefix, value = s[:2], s[2:]
1390 1413 if prefix == b'p:':
1391 1414 pats.append(value)
1392 1415 elif prefix == b'i:':
1393 1416 inc.append(value)
1394 1417 elif prefix == b'x:':
1395 1418 exc.append(value)
1396 1419 elif prefix == b'r:':
1397 1420 if rev is not None:
1398 1421 raise error.ParseError(
1399 1422 b'_matchfiles expected at most one revision'
1400 1423 )
1401 1424 if value == b'': # empty means working directory
1402 1425 rev = wdirrev
1403 1426 else:
1404 1427 rev = value
1405 1428 elif prefix == b'd:':
1406 1429 if default is not None:
1407 1430 raise error.ParseError(
1408 1431 b'_matchfiles expected at most one default mode'
1409 1432 )
1410 1433 default = value
1411 1434 else:
1412 1435 raise error.ParseError(b'invalid _matchfiles prefix: %s' % prefix)
1413 1436 if not default:
1414 1437 default = b'glob'
1415 1438 hasset = any(matchmod.patkind(p) == b'set' for p in pats + inc + exc)
1416 1439
1417 1440 mcache = [None]
1418 1441
1419 1442 # This directly read the changelog data as creating changectx for all
1420 1443 # revisions is quite expensive.
1421 1444 getfiles = repo.changelog.readfiles
1422 1445
1423 1446 def matches(x):
1424 1447 if x == wdirrev:
1425 1448 files = repo[x].files()
1426 1449 else:
1427 1450 files = getfiles(x)
1428 1451
1429 1452 if not mcache[0] or (hasset and rev is None):
1430 1453 r = x if rev is None else rev
1431 1454 mcache[0] = matchmod.match(
1432 1455 repo.root,
1433 1456 repo.getcwd(),
1434 1457 pats,
1435 1458 include=inc,
1436 1459 exclude=exc,
1437 1460 ctx=repo[r],
1438 1461 default=default,
1439 1462 )
1440 1463 m = mcache[0]
1441 1464
1442 1465 for f in files:
1443 1466 if m(f):
1444 1467 return True
1445 1468 return False
1446 1469
1447 1470 return subset.filter(
1448 1471 matches,
1449 1472 condrepr=(
1450 1473 b'<matchfiles patterns=%r, include=%r '
1451 1474 b'exclude=%r, default=%r, rev=%r>',
1452 1475 pats,
1453 1476 inc,
1454 1477 exc,
1455 1478 default,
1456 1479 rev,
1457 1480 ),
1458 1481 )
1459 1482
1460 1483
1461 1484 @predicate(b'file(pattern)', safe=True, weight=10)
1462 1485 def hasfile(repo, subset, x):
1463 1486 """Changesets affecting files matched by pattern.
1464 1487
1465 1488 For a faster but less accurate result, consider using ``filelog()``
1466 1489 instead.
1467 1490
1468 1491 This predicate uses ``glob:`` as the default kind of pattern.
1469 1492 """
1470 1493 # i18n: "file" is a keyword
1471 1494 pat = getstring(x, _(b"file requires a pattern"))
1472 1495 return _matchfiles(repo, subset, (b'string', b'p:' + pat))
1473 1496
1474 1497
1475 1498 @predicate(b'head()', safe=True)
1476 1499 def head(repo, subset, x):
1477 1500 """Changeset is a named branch head."""
1478 1501 # i18n: "head" is a keyword
1479 1502 getargs(x, 0, 0, _(b"head takes no arguments"))
1480 1503 hs = set()
1481 1504 cl = repo.changelog
1482 1505 for ls in repo.branchmap().iterheads():
1483 1506 hs.update(cl.rev(h) for h in ls)
1484 1507 return subset & baseset(hs)
1485 1508
1486 1509
1487 1510 @predicate(b'heads(set)', safe=True, takeorder=True)
1488 1511 def heads(repo, subset, x, order):
1489 1512 """Members of set with no children in set."""
1490 1513 # argument set should never define order
1491 1514 if order == defineorder:
1492 1515 order = followorder
1493 1516 inputset = getset(repo, fullreposet(repo), x, order=order)
1494 1517 wdirparents = None
1495 1518 if wdirrev in inputset:
1496 1519 # a bit slower, but not common so good enough for now
1497 1520 wdirparents = [p.rev() for p in repo[None].parents()]
1498 1521 inputset = set(inputset)
1499 1522 inputset.discard(wdirrev)
1500 1523 heads = repo.changelog.headrevs(inputset)
1501 1524 if wdirparents is not None:
1502 1525 heads.difference_update(wdirparents)
1503 1526 heads.add(wdirrev)
1504 1527 heads = baseset(heads)
1505 1528 return subset & heads
1506 1529
1507 1530
1508 1531 @predicate(b'hidden()', safe=True)
1509 1532 def hidden(repo, subset, x):
1510 1533 """Hidden changesets."""
1511 1534 # i18n: "hidden" is a keyword
1512 1535 getargs(x, 0, 0, _(b"hidden takes no arguments"))
1513 1536 hiddenrevs = repoview.filterrevs(repo, b'visible')
1514 1537 return subset & hiddenrevs
1515 1538
1516 1539
1517 1540 @predicate(b'keyword(string)', safe=True, weight=10)
1518 1541 def keyword(repo, subset, x):
1519 1542 """Search commit message, user name, and names of changed files for
1520 1543 string. The match is case-insensitive.
1521 1544
1522 1545 For a regular expression or case sensitive search of these fields, use
1523 1546 ``grep(regex)``.
1524 1547 """
1525 1548 # i18n: "keyword" is a keyword
1526 1549 kw = encoding.lower(getstring(x, _(b"keyword requires a string")))
1527 1550
1528 1551 def matches(r):
1529 1552 c = repo[r]
1530 1553 return any(
1531 1554 kw in encoding.lower(t)
1532 1555 for t in c.files() + [c.user(), c.description()]
1533 1556 )
1534 1557
1535 1558 return subset.filter(matches, condrepr=(b'<keyword %r>', kw))
1536 1559
1537 1560
1538 1561 @predicate(b'limit(set[, n[, offset]])', safe=True, takeorder=True, weight=0)
1539 1562 def limit(repo, subset, x, order):
1540 1563 """First n members of set, defaulting to 1, starting from offset."""
1541 1564 args = getargsdict(x, b'limit', b'set n offset')
1542 1565 if b'set' not in args:
1543 1566 # i18n: "limit" is a keyword
1544 1567 raise error.ParseError(_(b"limit requires one to three arguments"))
1545 1568 # i18n: "limit" is a keyword
1546 1569 lim = getinteger(args.get(b'n'), _(b"limit expects a number"), default=1)
1547 1570 if lim < 0:
1548 1571 raise error.ParseError(_(b"negative number to select"))
1549 1572 # i18n: "limit" is a keyword
1550 1573 ofs = getinteger(
1551 1574 args.get(b'offset'), _(b"limit expects a number"), default=0
1552 1575 )
1553 1576 if ofs < 0:
1554 1577 raise error.ParseError(_(b"negative offset"))
1555 1578 os = getset(repo, fullreposet(repo), args[b'set'])
1556 1579 ls = os.slice(ofs, ofs + lim)
1557 1580 if order == followorder and lim > 1:
1558 1581 return subset & ls
1559 1582 return ls & subset
1560 1583
1561 1584
1562 1585 @predicate(b'last(set, [n])', safe=True, takeorder=True)
1563 1586 def last(repo, subset, x, order):
1564 1587 """Last n members of set, defaulting to 1."""
1565 1588 # i18n: "last" is a keyword
1566 1589 l = getargs(x, 1, 2, _(b"last requires one or two arguments"))
1567 1590 lim = 1
1568 1591 if len(l) == 2:
1569 1592 # i18n: "last" is a keyword
1570 1593 lim = getinteger(l[1], _(b"last expects a number"))
1571 1594 if lim < 0:
1572 1595 raise error.ParseError(_(b"negative number to select"))
1573 1596 os = getset(repo, fullreposet(repo), l[0])
1574 1597 os.reverse()
1575 1598 ls = os.slice(0, lim)
1576 1599 if order == followorder and lim > 1:
1577 1600 return subset & ls
1578 1601 ls.reverse()
1579 1602 return ls & subset
1580 1603
1581 1604
1582 1605 @predicate(b'max(set)', safe=True)
1583 1606 def maxrev(repo, subset, x):
1584 1607 """Changeset with highest revision number in set."""
1585 1608 os = getset(repo, fullreposet(repo), x)
1586 1609 try:
1587 1610 m = os.max()
1588 1611 if m in subset:
1589 1612 return baseset([m], datarepr=(b'<max %r, %r>', subset, os))
1590 1613 except ValueError:
1591 1614 # os.max() throws a ValueError when the collection is empty.
1592 1615 # Same as python's max().
1593 1616 pass
1594 1617 return baseset(datarepr=(b'<max %r, %r>', subset, os))
1595 1618
1596 1619
1597 1620 @predicate(b'merge()', safe=True)
1598 1621 def merge(repo, subset, x):
1599 1622 """Changeset is a merge changeset."""
1600 1623 # i18n: "merge" is a keyword
1601 1624 getargs(x, 0, 0, _(b"merge takes no arguments"))
1602 1625 cl = repo.changelog
1603 1626
1604 1627 def ismerge(r):
1605 1628 try:
1606 1629 return cl.parentrevs(r)[1] != nullrev
1607 1630 except error.WdirUnsupported:
1608 1631 return bool(repo[r].p2())
1609 1632
1610 1633 return subset.filter(ismerge, condrepr=b'<merge>')
1611 1634
1612 1635
1613 1636 @predicate(b'branchpoint()', safe=True)
1614 1637 def branchpoint(repo, subset, x):
1615 1638 """Changesets with more than one child."""
1616 1639 # i18n: "branchpoint" is a keyword
1617 1640 getargs(x, 0, 0, _(b"branchpoint takes no arguments"))
1618 1641 cl = repo.changelog
1619 1642 if not subset:
1620 1643 return baseset()
1621 1644 # XXX this should be 'parentset.min()' assuming 'parentset' is a smartset
1622 1645 # (and if it is not, it should.)
1623 1646 baserev = min(subset)
1624 1647 parentscount = [0] * (len(repo) - baserev)
1625 1648 for r in cl.revs(start=baserev + 1):
1626 1649 for p in cl.parentrevs(r):
1627 1650 if p >= baserev:
1628 1651 parentscount[p - baserev] += 1
1629 1652 return subset.filter(
1630 1653 lambda r: parentscount[r - baserev] > 1, condrepr=b'<branchpoint>'
1631 1654 )
1632 1655
1633 1656
1634 1657 @predicate(b'min(set)', safe=True)
1635 1658 def minrev(repo, subset, x):
1636 1659 """Changeset with lowest revision number in set."""
1637 1660 os = getset(repo, fullreposet(repo), x)
1638 1661 try:
1639 1662 m = os.min()
1640 1663 if m in subset:
1641 1664 return baseset([m], datarepr=(b'<min %r, %r>', subset, os))
1642 1665 except ValueError:
1643 1666 # os.min() throws a ValueError when the collection is empty.
1644 1667 # Same as python's min().
1645 1668 pass
1646 1669 return baseset(datarepr=(b'<min %r, %r>', subset, os))
1647 1670
1648 1671
1649 1672 @predicate(b'modifies(pattern)', safe=True, weight=30)
1650 1673 def modifies(repo, subset, x):
1651 1674 """Changesets modifying files matched by pattern.
1652 1675
1653 1676 The pattern without explicit kind like ``glob:`` is expected to be
1654 1677 relative to the current directory and match against a file or a
1655 1678 directory.
1656 1679 """
1657 1680 # i18n: "modifies" is a keyword
1658 1681 pat = getstring(x, _(b"modifies requires a pattern"))
1659 1682 return checkstatus(repo, subset, pat, 'modified')
1660 1683
1661 1684
1662 1685 @predicate(b'named(namespace)')
1663 1686 def named(repo, subset, x):
1664 1687 """The changesets in a given namespace.
1665 1688
1666 1689 Pattern matching is supported for `namespace`. See
1667 1690 :hg:`help revisions.patterns`.
1668 1691 """
1669 1692 # i18n: "named" is a keyword
1670 1693 args = getargs(x, 1, 1, _(b'named requires a namespace argument'))
1671 1694
1672 1695 ns = getstring(
1673 1696 args[0],
1674 1697 # i18n: "named" is a keyword
1675 1698 _(b'the argument to named must be a string'),
1676 1699 )
1677 1700 kind, pattern, matcher = stringutil.stringmatcher(ns)
1678 1701 namespaces = set()
1679 1702 if kind == b'literal':
1680 1703 if pattern not in repo.names:
1681 1704 raise error.RepoLookupError(
1682 1705 _(b"namespace '%s' does not exist") % ns
1683 1706 )
1684 1707 namespaces.add(repo.names[pattern])
1685 1708 else:
1686 1709 for name, ns in pycompat.iteritems(repo.names):
1687 1710 if matcher(name):
1688 1711 namespaces.add(ns)
1689 1712
1690 1713 names = set()
1691 1714 for ns in namespaces:
1692 1715 for name in ns.listnames(repo):
1693 1716 if name not in ns.deprecated:
1694 1717 names.update(repo[n].rev() for n in ns.nodes(repo, name))
1695 1718
1696 1719 names -= {nullrev}
1697 1720 return subset & names
1698 1721
1699 1722
1700 @predicate(b'id(string)', safe=True)
1701 def node_(repo, subset, x):
1702 """Revision non-ambiguously specified by the given hex string prefix."""
1703 # i18n: "id" is a keyword
1704 l = getargs(x, 1, 1, _(b"id requires one argument"))
1705 # i18n: "id" is a keyword
1706 n = getstring(l[0], _(b"id requires a string"))
1723 def _node(repo, n):
1724 """process a node input"""
1725 rn = None
1707 1726 if len(n) == 40:
1708 1727 try:
1709 1728 rn = repo.changelog.rev(bin(n))
1710 1729 except error.WdirUnsupported:
1711 1730 rn = wdirrev
1712 1731 except (LookupError, TypeError):
1713 1732 rn = None
1714 1733 else:
1715 rn = None
1716 1734 try:
1717 1735 pm = scmutil.resolvehexnodeidprefix(repo, n)
1718 1736 if pm is not None:
1719 1737 rn = repo.changelog.rev(pm)
1720 1738 except LookupError:
1721 1739 pass
1722 1740 except error.WdirUnsupported:
1723 1741 rn = wdirrev
1742 return rn
1743
1744
1745 @predicate(b'id(string)', safe=True)
1746 def node_(repo, subset, x):
1747 """Revision non-ambiguously specified by the given hex string prefix."""
1748 # i18n: "id" is a keyword
1749 l = getargs(x, 1, 1, _(b"id requires one argument"))
1750 # i18n: "id" is a keyword
1751 n = getstring(l[0], _(b"id requires a string"))
1752 rn = _node(repo, n)
1724 1753
1725 1754 if rn is None:
1726 1755 return baseset()
1727 1756 result = baseset([rn])
1728 1757 return result & subset
1729 1758
1730 1759
1731 1760 @predicate(b'none()', safe=True)
1732 1761 def none(repo, subset, x):
1733 1762 """No changesets."""
1734 1763 # i18n: "none" is a keyword
1735 1764 getargs(x, 0, 0, _(b"none takes no arguments"))
1736 1765 return baseset()
1737 1766
1738 1767
1739 1768 @predicate(b'obsolete()', safe=True)
1740 1769 def obsolete(repo, subset, x):
1741 1770 """Mutable changeset with a newer version. (EXPERIMENTAL)"""
1742 1771 # i18n: "obsolete" is a keyword
1743 1772 getargs(x, 0, 0, _(b"obsolete takes no arguments"))
1744 1773 obsoletes = obsmod.getrevs(repo, b'obsolete')
1745 1774 return subset & obsoletes
1746 1775
1747 1776
1748 1777 @predicate(b'only(set, [set])', safe=True)
1749 1778 def only(repo, subset, x):
1750 1779 """Changesets that are ancestors of the first set that are not ancestors
1751 1780 of any other head in the repo. If a second set is specified, the result
1752 1781 is ancestors of the first set that are not ancestors of the second set
1753 1782 (i.e. ::<set1> - ::<set2>).
1754 1783 """
1755 1784 cl = repo.changelog
1756 1785 # i18n: "only" is a keyword
1757 1786 args = getargs(x, 1, 2, _(b'only takes one or two arguments'))
1758 1787 include = getset(repo, fullreposet(repo), args[0])
1759 1788 if len(args) == 1:
1760 1789 if not include:
1761 1790 return baseset()
1762 1791
1763 1792 descendants = set(dagop.revdescendants(repo, include, False))
1764 1793 exclude = [
1765 1794 rev
1766 1795 for rev in cl.headrevs()
1767 1796 if not rev in descendants and not rev in include
1768 1797 ]
1769 1798 else:
1770 1799 exclude = getset(repo, fullreposet(repo), args[1])
1771 1800
1772 1801 results = set(cl.findmissingrevs(common=exclude, heads=include))
1773 1802 # XXX we should turn this into a baseset instead of a set, smartset may do
1774 1803 # some optimizations from the fact this is a baseset.
1775 1804 return subset & results
1776 1805
1777 1806
1778 1807 @predicate(b'origin([set])', safe=True)
1779 1808 def origin(repo, subset, x):
1780 1809 """
1781 1810 Changesets that were specified as a source for the grafts, transplants or
1782 1811 rebases that created the given revisions. Omitting the optional set is the
1783 1812 same as passing all(). If a changeset created by these operations is itself
1784 1813 specified as a source for one of these operations, only the source changeset
1785 1814 for the first operation is selected.
1786 1815 """
1787 1816 if x is not None:
1788 1817 dests = getset(repo, fullreposet(repo), x)
1789 1818 else:
1790 1819 dests = fullreposet(repo)
1791 1820
1792 1821 def _firstsrc(rev):
1793 1822 src = _getrevsource(repo, rev)
1794 1823 if src is None:
1795 1824 return None
1796 1825
1797 1826 while True:
1798 1827 prev = _getrevsource(repo, src)
1799 1828
1800 1829 if prev is None:
1801 1830 return src
1802 1831 src = prev
1803 1832
1804 1833 o = {_firstsrc(r) for r in dests}
1805 1834 o -= {None}
1806 1835 # XXX we should turn this into a baseset instead of a set, smartset may do
1807 1836 # some optimizations from the fact this is a baseset.
1808 1837 return subset & o
1809 1838
1810 1839
1811 1840 @predicate(b'outgoing([path])', safe=False, weight=10)
1812 1841 def outgoing(repo, subset, x):
1813 1842 """Changesets not found in the specified destination repository, or the
1814 1843 default push location.
1815 1844 """
1816 1845 # Avoid cycles.
1817 1846 from . import (
1818 1847 discovery,
1819 1848 hg,
1820 1849 )
1821 1850
1822 1851 # i18n: "outgoing" is a keyword
1823 1852 l = getargs(x, 0, 1, _(b"outgoing takes one or no arguments"))
1824 1853 # i18n: "outgoing" is a keyword
1825 1854 dest = (
1826 1855 l and getstring(l[0], _(b"outgoing requires a repository path")) or b''
1827 1856 )
1828 1857 if not dest:
1829 1858 # ui.getpath() explicitly tests for None, not just a boolean
1830 1859 dest = None
1831 1860 path = repo.ui.getpath(dest, default=(b'default-push', b'default'))
1832 1861 if not path:
1833 1862 raise error.Abort(
1834 1863 _(b'default repository not configured!'),
1835 1864 hint=_(b"see 'hg help config.paths'"),
1836 1865 )
1837 1866 dest = path.pushloc or path.loc
1838 1867 branches = path.branch, []
1839 1868
1840 1869 revs, checkout = hg.addbranchrevs(repo, repo, branches, [])
1841 1870 if revs:
1842 1871 revs = [repo.lookup(rev) for rev in revs]
1843 1872 other = hg.peer(repo, {}, dest)
1844 1873 try:
1845 1874 repo.ui.pushbuffer()
1846 1875 outgoing = discovery.findcommonoutgoing(repo, other, onlyheads=revs)
1847 1876 repo.ui.popbuffer()
1848 1877 finally:
1849 1878 other.close()
1850 1879 cl = repo.changelog
1851 1880 o = {cl.rev(r) for r in outgoing.missing}
1852 1881 return subset & o
1853 1882
1854 1883
1855 1884 @predicate(b'p1([set])', safe=True)
1856 1885 def p1(repo, subset, x):
1857 1886 """First parent of changesets in set, or the working directory."""
1858 1887 if x is None:
1859 1888 p = repo[x].p1().rev()
1860 1889 if p >= 0:
1861 1890 return subset & baseset([p])
1862 1891 return baseset()
1863 1892
1864 1893 ps = set()
1865 1894 cl = repo.changelog
1866 1895 for r in getset(repo, fullreposet(repo), x):
1867 1896 try:
1868 1897 ps.add(cl.parentrevs(r)[0])
1869 1898 except error.WdirUnsupported:
1870 1899 ps.add(repo[r].p1().rev())
1871 1900 ps -= {nullrev}
1872 1901 # XXX we should turn this into a baseset instead of a set, smartset may do
1873 1902 # some optimizations from the fact this is a baseset.
1874 1903 return subset & ps
1875 1904
1876 1905
1877 1906 @predicate(b'p2([set])', safe=True)
1878 1907 def p2(repo, subset, x):
1879 1908 """Second parent of changesets in set, or the working directory."""
1880 1909 if x is None:
1881 1910 ps = repo[x].parents()
1882 1911 try:
1883 1912 p = ps[1].rev()
1884 1913 if p >= 0:
1885 1914 return subset & baseset([p])
1886 1915 return baseset()
1887 1916 except IndexError:
1888 1917 return baseset()
1889 1918
1890 1919 ps = set()
1891 1920 cl = repo.changelog
1892 1921 for r in getset(repo, fullreposet(repo), x):
1893 1922 try:
1894 1923 ps.add(cl.parentrevs(r)[1])
1895 1924 except error.WdirUnsupported:
1896 1925 parents = repo[r].parents()
1897 1926 if len(parents) == 2:
1898 1927 ps.add(parents[1])
1899 1928 ps -= {nullrev}
1900 1929 # XXX we should turn this into a baseset instead of a set, smartset may do
1901 1930 # some optimizations from the fact this is a baseset.
1902 1931 return subset & ps
1903 1932
1904 1933
1905 1934 def parentpost(repo, subset, x, order):
1906 1935 return p1(repo, subset, x)
1907 1936
1908 1937
1909 1938 @predicate(b'parents([set])', safe=True)
1910 1939 def parents(repo, subset, x):
1911 1940 """
1912 1941 The set of all parents for all changesets in set, or the working directory.
1913 1942 """
1914 1943 if x is None:
1915 1944 ps = {p.rev() for p in repo[x].parents()}
1916 1945 else:
1917 1946 ps = set()
1918 1947 cl = repo.changelog
1919 1948 up = ps.update
1920 1949 parentrevs = cl.parentrevs
1921 1950 for r in getset(repo, fullreposet(repo), x):
1922 1951 try:
1923 1952 up(parentrevs(r))
1924 1953 except error.WdirUnsupported:
1925 1954 up(p.rev() for p in repo[r].parents())
1926 1955 ps -= {nullrev}
1927 1956 return subset & ps
1928 1957
1929 1958
1930 1959 def _phase(repo, subset, *targets):
1931 1960 """helper to select all rev in <targets> phases"""
1932 1961 return repo._phasecache.getrevset(repo, targets, subset)
1933 1962
1934 1963
1935 1964 @predicate(b'_phase(idx)', safe=True)
1936 1965 def phase(repo, subset, x):
1937 1966 l = getargs(x, 1, 1, b"_phase requires one argument")
1938 1967 target = getinteger(l[0], b"_phase expects a number")
1939 1968 return _phase(repo, subset, target)
1940 1969
1941 1970
1942 1971 @predicate(b'draft()', safe=True)
1943 1972 def draft(repo, subset, x):
1944 1973 """Changeset in draft phase."""
1945 1974 # i18n: "draft" is a keyword
1946 1975 getargs(x, 0, 0, _(b"draft takes no arguments"))
1947 1976 target = phases.draft
1948 1977 return _phase(repo, subset, target)
1949 1978
1950 1979
1951 1980 @predicate(b'secret()', safe=True)
1952 1981 def secret(repo, subset, x):
1953 1982 """Changeset in secret phase."""
1954 1983 # i18n: "secret" is a keyword
1955 1984 getargs(x, 0, 0, _(b"secret takes no arguments"))
1956 1985 target = phases.secret
1957 1986 return _phase(repo, subset, target)
1958 1987
1959 1988
1960 1989 @predicate(b'stack([revs])', safe=True)
1961 1990 def stack(repo, subset, x):
1962 1991 """Experimental revset for the stack of changesets or working directory
1963 1992 parent. (EXPERIMENTAL)
1964 1993 """
1965 1994 if x is None:
1966 1995 stacks = stackmod.getstack(repo)
1967 1996 else:
1968 1997 stacks = smartset.baseset([])
1969 1998 for revision in getset(repo, fullreposet(repo), x):
1970 1999 currentstack = stackmod.getstack(repo, revision)
1971 2000 stacks = stacks + currentstack
1972 2001
1973 2002 return subset & stacks
1974 2003
1975 2004
1976 2005 def parentspec(repo, subset, x, n, order):
1977 2006 """``set^0``
1978 2007 The set.
1979 2008 ``set^1`` (or ``set^``), ``set^2``
1980 2009 First or second parent, respectively, of all changesets in set.
1981 2010 """
1982 2011 try:
1983 2012 n = int(n[1])
1984 2013 if n not in (0, 1, 2):
1985 2014 raise ValueError
1986 2015 except (TypeError, ValueError):
1987 2016 raise error.ParseError(_(b"^ expects a number 0, 1, or 2"))
1988 2017 ps = set()
1989 2018 cl = repo.changelog
1990 2019 for r in getset(repo, fullreposet(repo), x):
1991 2020 if n == 0:
1992 2021 ps.add(r)
1993 2022 elif n == 1:
1994 2023 try:
1995 2024 ps.add(cl.parentrevs(r)[0])
1996 2025 except error.WdirUnsupported:
1997 2026 ps.add(repo[r].p1().rev())
1998 2027 else:
1999 2028 try:
2000 2029 parents = cl.parentrevs(r)
2001 2030 if parents[1] != nullrev:
2002 2031 ps.add(parents[1])
2003 2032 except error.WdirUnsupported:
2004 2033 parents = repo[r].parents()
2005 2034 if len(parents) == 2:
2006 2035 ps.add(parents[1].rev())
2007 2036 return subset & ps
2008 2037
2009 2038
2010 2039 @predicate(b'present(set)', safe=True, takeorder=True)
2011 2040 def present(repo, subset, x, order):
2012 2041 """An empty set, if any revision in set isn't found; otherwise,
2013 2042 all revisions in set.
2014 2043
2015 2044 If any of specified revisions is not present in the local repository,
2016 2045 the query is normally aborted. But this predicate allows the query
2017 2046 to continue even in such cases.
2018 2047 """
2019 2048 try:
2020 2049 return getset(repo, subset, x, order)
2021 2050 except error.RepoLookupError:
2022 2051 return baseset()
2023 2052
2024 2053
2025 2054 # for internal use
2026 2055 @predicate(b'_notpublic', safe=True)
2027 2056 def _notpublic(repo, subset, x):
2028 2057 getargs(x, 0, 0, b"_notpublic takes no arguments")
2029 2058 return _phase(repo, subset, phases.draft, phases.secret)
2030 2059
2031 2060
2032 2061 # for internal use
2033 2062 @predicate(b'_phaseandancestors(phasename, set)', safe=True)
2034 2063 def _phaseandancestors(repo, subset, x):
2035 2064 # equivalent to (phasename() & ancestors(set)) but more efficient
2036 2065 # phasename could be one of 'draft', 'secret', or '_notpublic'
2037 2066 args = getargs(x, 2, 2, b"_phaseandancestors requires two arguments")
2038 2067 phasename = getsymbol(args[0])
2039 2068 s = getset(repo, fullreposet(repo), args[1])
2040 2069
2041 2070 draft = phases.draft
2042 2071 secret = phases.secret
2043 2072 phasenamemap = {
2044 2073 b'_notpublic': draft,
2045 2074 b'draft': draft, # follow secret's ancestors
2046 2075 b'secret': secret,
2047 2076 }
2048 2077 if phasename not in phasenamemap:
2049 2078 raise error.ParseError(b'%r is not a valid phasename' % phasename)
2050 2079
2051 2080 minimalphase = phasenamemap[phasename]
2052 2081 getphase = repo._phasecache.phase
2053 2082
2054 2083 def cutfunc(rev):
2055 2084 return getphase(repo, rev) < minimalphase
2056 2085
2057 2086 revs = dagop.revancestors(repo, s, cutfunc=cutfunc)
2058 2087
2059 2088 if phasename == b'draft': # need to remove secret changesets
2060 2089 revs = revs.filter(lambda r: getphase(repo, r) == draft)
2061 2090 return subset & revs
2062 2091
2063 2092
2064 2093 @predicate(b'public()', safe=True)
2065 2094 def public(repo, subset, x):
2066 2095 """Changeset in public phase."""
2067 2096 # i18n: "public" is a keyword
2068 2097 getargs(x, 0, 0, _(b"public takes no arguments"))
2069 2098 return _phase(repo, subset, phases.public)
2070 2099
2071 2100
2072 2101 @predicate(b'remote([id [,path]])', safe=False)
2073 2102 def remote(repo, subset, x):
2074 2103 """Local revision that corresponds to the given identifier in a
2075 2104 remote repository, if present. Here, the '.' identifier is a
2076 2105 synonym for the current local branch.
2077 2106 """
2078 2107
2079 2108 from . import hg # avoid start-up nasties
2080 2109
2081 2110 # i18n: "remote" is a keyword
2082 2111 l = getargs(x, 0, 2, _(b"remote takes zero, one, or two arguments"))
2083 2112
2084 2113 q = b'.'
2085 2114 if len(l) > 0:
2086 2115 # i18n: "remote" is a keyword
2087 2116 q = getstring(l[0], _(b"remote requires a string id"))
2088 2117 if q == b'.':
2089 2118 q = repo[b'.'].branch()
2090 2119
2091 2120 dest = b''
2092 2121 if len(l) > 1:
2093 2122 # i18n: "remote" is a keyword
2094 2123 dest = getstring(l[1], _(b"remote requires a repository path"))
2095 2124 dest = repo.ui.expandpath(dest or b'default')
2096 2125 dest, branches = hg.parseurl(dest)
2097 2126
2098 2127 other = hg.peer(repo, {}, dest)
2099 2128 n = other.lookup(q)
2100 2129 if n in repo:
2101 2130 r = repo[n].rev()
2102 2131 if r in subset:
2103 2132 return baseset([r])
2104 2133 return baseset()
2105 2134
2106 2135
2107 2136 @predicate(b'removes(pattern)', safe=True, weight=30)
2108 2137 def removes(repo, subset, x):
2109 2138 """Changesets which remove files matching pattern.
2110 2139
2111 2140 The pattern without explicit kind like ``glob:`` is expected to be
2112 2141 relative to the current directory and match against a file or a
2113 2142 directory.
2114 2143 """
2115 2144 # i18n: "removes" is a keyword
2116 2145 pat = getstring(x, _(b"removes requires a pattern"))
2117 2146 return checkstatus(repo, subset, pat, 'removed')
2118 2147
2119 2148
2120 2149 @predicate(b'rev(number)', safe=True)
2121 2150 def rev(repo, subset, x):
2122 2151 """Revision with the given numeric identifier."""
2123 2152 try:
2124 2153 return _rev(repo, subset, x)
2125 2154 except error.RepoLookupError:
2126 2155 return baseset()
2127 2156
2128 2157
2129 2158 @predicate(b'_rev(number)', safe=True)
2130 2159 def _rev(repo, subset, x):
2131 2160 # internal version of "rev(x)" that raise error if "x" is invalid
2132 2161 # i18n: "rev" is a keyword
2133 2162 l = getargs(x, 1, 1, _(b"rev requires one argument"))
2134 2163 try:
2135 2164 # i18n: "rev" is a keyword
2136 2165 l = int(getstring(l[0], _(b"rev requires a number")))
2137 2166 except (TypeError, ValueError):
2138 2167 # i18n: "rev" is a keyword
2139 2168 raise error.ParseError(_(b"rev expects a number"))
2140 2169 if l not in _virtualrevs:
2141 2170 try:
2142 2171 repo.changelog.node(l) # check that the rev exists
2143 2172 except IndexError:
2144 2173 raise error.RepoLookupError(_(b"unknown revision '%d'") % l)
2145 2174 return subset & baseset([l])
2146 2175
2147 2176
2148 2177 @predicate(b'revset(set)', safe=True, takeorder=True)
2149 2178 def revsetpredicate(repo, subset, x, order):
2150 2179 """Strictly interpret the content as a revset.
2151 2180
2152 2181 The content of this special predicate will be strictly interpreted as a
2153 2182 revset. For example, ``revset(id(0))`` will be interpreted as "id(0)"
2154 2183 without possible ambiguity with a "id(0)" bookmark or tag.
2155 2184 """
2156 2185 return getset(repo, subset, x, order)
2157 2186
2158 2187
2159 2188 @predicate(b'matching(revision [, field])', safe=True)
2160 2189 def matching(repo, subset, x):
2161 2190 """Changesets in which a given set of fields match the set of fields in the
2162 2191 selected revision or set.
2163 2192
2164 2193 To match more than one field pass the list of fields to match separated
2165 2194 by spaces (e.g. ``author description``).
2166 2195
2167 2196 Valid fields are most regular revision fields and some special fields.
2168 2197
2169 2198 Regular revision fields are ``description``, ``author``, ``branch``,
2170 2199 ``date``, ``files``, ``phase``, ``parents``, ``substate``, ``user``
2171 2200 and ``diff``.
2172 2201 Note that ``author`` and ``user`` are synonyms. ``diff`` refers to the
2173 2202 contents of the revision. Two revisions matching their ``diff`` will
2174 2203 also match their ``files``.
2175 2204
2176 2205 Special fields are ``summary`` and ``metadata``:
2177 2206 ``summary`` matches the first line of the description.
2178 2207 ``metadata`` is equivalent to matching ``description user date``
2179 2208 (i.e. it matches the main metadata fields).
2180 2209
2181 2210 ``metadata`` is the default field which is used when no fields are
2182 2211 specified. You can match more than one field at a time.
2183 2212 """
2184 2213 # i18n: "matching" is a keyword
2185 2214 l = getargs(x, 1, 2, _(b"matching takes 1 or 2 arguments"))
2186 2215
2187 2216 revs = getset(repo, fullreposet(repo), l[0])
2188 2217
2189 2218 fieldlist = [b'metadata']
2190 2219 if len(l) > 1:
2191 2220 fieldlist = getstring(
2192 2221 l[1],
2193 2222 # i18n: "matching" is a keyword
2194 2223 _(b"matching requires a string as its second argument"),
2195 2224 ).split()
2196 2225
2197 2226 # Make sure that there are no repeated fields,
2198 2227 # expand the 'special' 'metadata' field type
2199 2228 # and check the 'files' whenever we check the 'diff'
2200 2229 fields = []
2201 2230 for field in fieldlist:
2202 2231 if field == b'metadata':
2203 2232 fields += [b'user', b'description', b'date']
2204 2233 elif field == b'diff':
2205 2234 # a revision matching the diff must also match the files
2206 2235 # since matching the diff is very costly, make sure to
2207 2236 # also match the files first
2208 2237 fields += [b'files', b'diff']
2209 2238 else:
2210 2239 if field == b'author':
2211 2240 field = b'user'
2212 2241 fields.append(field)
2213 2242 fields = set(fields)
2214 2243 if b'summary' in fields and b'description' in fields:
2215 2244 # If a revision matches its description it also matches its summary
2216 2245 fields.discard(b'summary')
2217 2246
2218 2247 # We may want to match more than one field
2219 2248 # Not all fields take the same amount of time to be matched
2220 2249 # Sort the selected fields in order of increasing matching cost
2221 2250 fieldorder = [
2222 2251 b'phase',
2223 2252 b'parents',
2224 2253 b'user',
2225 2254 b'date',
2226 2255 b'branch',
2227 2256 b'summary',
2228 2257 b'files',
2229 2258 b'description',
2230 2259 b'substate',
2231 2260 b'diff',
2232 2261 ]
2233 2262
2234 2263 def fieldkeyfunc(f):
2235 2264 try:
2236 2265 return fieldorder.index(f)
2237 2266 except ValueError:
2238 2267 # assume an unknown field is very costly
2239 2268 return len(fieldorder)
2240 2269
2241 2270 fields = list(fields)
2242 2271 fields.sort(key=fieldkeyfunc)
2243 2272
2244 2273 # Each field will be matched with its own "getfield" function
2245 2274 # which will be added to the getfieldfuncs array of functions
2246 2275 getfieldfuncs = []
2247 2276 _funcs = {
2248 2277 b'user': lambda r: repo[r].user(),
2249 2278 b'branch': lambda r: repo[r].branch(),
2250 2279 b'date': lambda r: repo[r].date(),
2251 2280 b'description': lambda r: repo[r].description(),
2252 2281 b'files': lambda r: repo[r].files(),
2253 2282 b'parents': lambda r: repo[r].parents(),
2254 2283 b'phase': lambda r: repo[r].phase(),
2255 2284 b'substate': lambda r: repo[r].substate,
2256 2285 b'summary': lambda r: repo[r].description().splitlines()[0],
2257 2286 b'diff': lambda r: list(
2258 2287 repo[r].diff(opts=diffutil.diffallopts(repo.ui, {b'git': True}))
2259 2288 ),
2260 2289 }
2261 2290 for info in fields:
2262 2291 getfield = _funcs.get(info, None)
2263 2292 if getfield is None:
2264 2293 raise error.ParseError(
2265 2294 # i18n: "matching" is a keyword
2266 2295 _(b"unexpected field name passed to matching: %s")
2267 2296 % info
2268 2297 )
2269 2298 getfieldfuncs.append(getfield)
2270 2299 # convert the getfield array of functions into a "getinfo" function
2271 2300 # which returns an array of field values (or a single value if there
2272 2301 # is only one field to match)
2273 2302 getinfo = lambda r: [f(r) for f in getfieldfuncs]
2274 2303
2275 2304 def matches(x):
2276 2305 for rev in revs:
2277 2306 target = getinfo(rev)
2278 2307 match = True
2279 2308 for n, f in enumerate(getfieldfuncs):
2280 2309 if target[n] != f(x):
2281 2310 match = False
2282 2311 if match:
2283 2312 return True
2284 2313 return False
2285 2314
2286 2315 return subset.filter(matches, condrepr=(b'<matching%r %r>', fields, revs))
2287 2316
2288 2317
2289 2318 @predicate(b'reverse(set)', safe=True, takeorder=True, weight=0)
2290 2319 def reverse(repo, subset, x, order):
2291 2320 """Reverse order of set."""
2292 2321 l = getset(repo, subset, x, order)
2293 2322 if order == defineorder:
2294 2323 l.reverse()
2295 2324 return l
2296 2325
2297 2326
2298 2327 @predicate(b'roots(set)', safe=True)
2299 2328 def roots(repo, subset, x):
2300 2329 """Changesets in set with no parent changeset in set."""
2301 2330 s = getset(repo, fullreposet(repo), x)
2302 2331 parents = repo.changelog.parentrevs
2303 2332
2304 2333 def filter(r):
2305 2334 for p in parents(r):
2306 2335 if 0 <= p and p in s:
2307 2336 return False
2308 2337 return True
2309 2338
2310 2339 return subset & s.filter(filter, condrepr=b'<roots>')
2311 2340
2312 2341
2313 2342 _sortkeyfuncs = {
2314 2343 b'rev': scmutil.intrev,
2315 2344 b'branch': lambda c: c.branch(),
2316 2345 b'desc': lambda c: c.description(),
2317 2346 b'user': lambda c: c.user(),
2318 2347 b'author': lambda c: c.user(),
2319 2348 b'date': lambda c: c.date()[0],
2320 2349 b'node': scmutil.binnode,
2321 2350 }
2322 2351
2323 2352
2324 2353 def _getsortargs(x):
2325 2354 """Parse sort options into (set, [(key, reverse)], opts)"""
2326 2355 args = getargsdict(x, b'sort', b'set keys topo.firstbranch')
2327 2356 if b'set' not in args:
2328 2357 # i18n: "sort" is a keyword
2329 2358 raise error.ParseError(_(b'sort requires one or two arguments'))
2330 2359 keys = b"rev"
2331 2360 if b'keys' in args:
2332 2361 # i18n: "sort" is a keyword
2333 2362 keys = getstring(args[b'keys'], _(b"sort spec must be a string"))
2334 2363
2335 2364 keyflags = []
2336 2365 for k in keys.split():
2337 2366 fk = k
2338 2367 reverse = k.startswith(b'-')
2339 2368 if reverse:
2340 2369 k = k[1:]
2341 2370 if k not in _sortkeyfuncs and k != b'topo':
2342 2371 raise error.ParseError(
2343 2372 _(b"unknown sort key %r") % pycompat.bytestr(fk)
2344 2373 )
2345 2374 keyflags.append((k, reverse))
2346 2375
2347 2376 if len(keyflags) > 1 and any(k == b'topo' for k, reverse in keyflags):
2348 2377 # i18n: "topo" is a keyword
2349 2378 raise error.ParseError(
2350 2379 _(b'topo sort order cannot be combined with other sort keys')
2351 2380 )
2352 2381
2353 2382 opts = {}
2354 2383 if b'topo.firstbranch' in args:
2355 2384 if any(k == b'topo' for k, reverse in keyflags):
2356 2385 opts[b'topo.firstbranch'] = args[b'topo.firstbranch']
2357 2386 else:
2358 2387 # i18n: "topo" and "topo.firstbranch" are keywords
2359 2388 raise error.ParseError(
2360 2389 _(
2361 2390 b'topo.firstbranch can only be used '
2362 2391 b'when using the topo sort key'
2363 2392 )
2364 2393 )
2365 2394
2366 2395 return args[b'set'], keyflags, opts
2367 2396
2368 2397
2369 2398 @predicate(
2370 2399 b'sort(set[, [-]key... [, ...]])', safe=True, takeorder=True, weight=10
2371 2400 )
2372 2401 def sort(repo, subset, x, order):
2373 2402 """Sort set by keys. The default sort order is ascending, specify a key
2374 2403 as ``-key`` to sort in descending order.
2375 2404
2376 2405 The keys can be:
2377 2406
2378 2407 - ``rev`` for the revision number,
2379 2408 - ``branch`` for the branch name,
2380 2409 - ``desc`` for the commit message (description),
2381 2410 - ``user`` for user name (``author`` can be used as an alias),
2382 2411 - ``date`` for the commit date
2383 2412 - ``topo`` for a reverse topographical sort
2384 2413 - ``node`` the nodeid of the revision
2385 2414
2386 2415 The ``topo`` sort order cannot be combined with other sort keys. This sort
2387 2416 takes one optional argument, ``topo.firstbranch``, which takes a revset that
2388 2417 specifies what topographical branches to prioritize in the sort.
2389 2418
2390 2419 """
2391 2420 s, keyflags, opts = _getsortargs(x)
2392 2421 revs = getset(repo, subset, s, order)
2393 2422
2394 2423 if not keyflags or order != defineorder:
2395 2424 return revs
2396 2425 if len(keyflags) == 1 and keyflags[0][0] == b"rev":
2397 2426 revs.sort(reverse=keyflags[0][1])
2398 2427 return revs
2399 2428 elif keyflags[0][0] == b"topo":
2400 2429 firstbranch = ()
2401 2430 if b'topo.firstbranch' in opts:
2402 2431 firstbranch = getset(repo, subset, opts[b'topo.firstbranch'])
2403 2432 revs = baseset(
2404 2433 dagop.toposort(revs, repo.changelog.parentrevs, firstbranch),
2405 2434 istopo=True,
2406 2435 )
2407 2436 if keyflags[0][1]:
2408 2437 revs.reverse()
2409 2438 return revs
2410 2439
2411 2440 # sort() is guaranteed to be stable
2412 2441 ctxs = [repo[r] for r in revs]
2413 2442 for k, reverse in reversed(keyflags):
2414 2443 ctxs.sort(key=_sortkeyfuncs[k], reverse=reverse)
2415 2444 return baseset([c.rev() for c in ctxs])
2416 2445
2417 2446
2418 2447 @predicate(b'subrepo([pattern])')
2419 2448 def subrepo(repo, subset, x):
2420 2449 """Changesets that add, modify or remove the given subrepo. If no subrepo
2421 2450 pattern is named, any subrepo changes are returned.
2422 2451 """
2423 2452 # i18n: "subrepo" is a keyword
2424 2453 args = getargs(x, 0, 1, _(b'subrepo takes at most one argument'))
2425 2454 pat = None
2426 2455 if len(args) != 0:
2427 2456 pat = getstring(args[0], _(b"subrepo requires a pattern"))
2428 2457
2429 2458 m = matchmod.exact([b'.hgsubstate'])
2430 2459
2431 2460 def submatches(names):
2432 2461 k, p, m = stringutil.stringmatcher(pat)
2433 2462 for name in names:
2434 2463 if m(name):
2435 2464 yield name
2436 2465
2437 2466 def matches(x):
2438 2467 c = repo[x]
2439 2468 s = repo.status(c.p1().node(), c.node(), match=m)
2440 2469
2441 2470 if pat is None:
2442 2471 return s.added or s.modified or s.removed
2443 2472
2444 2473 if s.added:
2445 2474 return any(submatches(c.substate.keys()))
2446 2475
2447 2476 if s.modified:
2448 2477 subs = set(c.p1().substate.keys())
2449 2478 subs.update(c.substate.keys())
2450 2479
2451 2480 for path in submatches(subs):
2452 2481 if c.p1().substate.get(path) != c.substate.get(path):
2453 2482 return True
2454 2483
2455 2484 if s.removed:
2456 2485 return any(submatches(c.p1().substate.keys()))
2457 2486
2458 2487 return False
2459 2488
2460 2489 return subset.filter(matches, condrepr=(b'<subrepo %r>', pat))
2461 2490
2462 2491
2463 2492 def _mapbynodefunc(repo, s, f):
2464 2493 """(repo, smartset, [node] -> [node]) -> smartset
2465 2494
2466 2495 Helper method to map a smartset to another smartset given a function only
2467 2496 talking about nodes. Handles converting between rev numbers and nodes, and
2468 2497 filtering.
2469 2498 """
2470 2499 cl = repo.unfiltered().changelog
2471 2500 torev = cl.index.get_rev
2472 2501 tonode = cl.node
2473 2502 result = {torev(n) for n in f(tonode(r) for r in s)}
2474 2503 result.discard(None)
2475 2504 return smartset.baseset(result - repo.changelog.filteredrevs)
2476 2505
2477 2506
2478 2507 @predicate(b'successors(set)', safe=True)
2479 2508 def successors(repo, subset, x):
2480 2509 """All successors for set, including the given set themselves.
2481 2510 (EXPERIMENTAL)"""
2482 2511 s = getset(repo, fullreposet(repo), x)
2483 2512 f = lambda nodes: obsutil.allsuccessors(repo.obsstore, nodes)
2484 2513 d = _mapbynodefunc(repo, s, f)
2485 2514 return subset & d
2486 2515
2487 2516
2488 2517 def _substringmatcher(pattern, casesensitive=True):
2489 2518 kind, pattern, matcher = stringutil.stringmatcher(
2490 2519 pattern, casesensitive=casesensitive
2491 2520 )
2492 2521 if kind == b'literal':
2493 2522 if not casesensitive:
2494 2523 pattern = encoding.lower(pattern)
2495 2524 matcher = lambda s: pattern in encoding.lower(s)
2496 2525 else:
2497 2526 matcher = lambda s: pattern in s
2498 2527 return kind, pattern, matcher
2499 2528
2500 2529
2501 2530 @predicate(b'tag([name])', safe=True)
2502 2531 def tag(repo, subset, x):
2503 2532 """The specified tag by name, or all tagged revisions if no name is given.
2504 2533
2505 2534 Pattern matching is supported for `name`. See
2506 2535 :hg:`help revisions.patterns`.
2507 2536 """
2508 2537 # i18n: "tag" is a keyword
2509 2538 args = getargs(x, 0, 1, _(b"tag takes one or no arguments"))
2510 2539 cl = repo.changelog
2511 2540 if args:
2512 2541 pattern = getstring(
2513 2542 args[0],
2514 2543 # i18n: "tag" is a keyword
2515 2544 _(b'the argument to tag must be a string'),
2516 2545 )
2517 2546 kind, pattern, matcher = stringutil.stringmatcher(pattern)
2518 2547 if kind == b'literal':
2519 2548 # avoid resolving all tags
2520 2549 tn = repo._tagscache.tags.get(pattern, None)
2521 2550 if tn is None:
2522 2551 raise error.RepoLookupError(
2523 2552 _(b"tag '%s' does not exist") % pattern
2524 2553 )
2525 2554 s = {repo[tn].rev()}
2526 2555 else:
2527 2556 s = {cl.rev(n) for t, n in repo.tagslist() if matcher(t)}
2528 2557 else:
2529 2558 s = {cl.rev(n) for t, n in repo.tagslist() if t != b'tip'}
2530 2559 return subset & s
2531 2560
2532 2561
2533 2562 @predicate(b'tagged', safe=True)
2534 2563 def tagged(repo, subset, x):
2535 2564 return tag(repo, subset, x)
2536 2565
2537 2566
2538 2567 @predicate(b'orphan()', safe=True)
2539 2568 def orphan(repo, subset, x):
2540 2569 """Non-obsolete changesets with obsolete ancestors. (EXPERIMENTAL)"""
2541 2570 # i18n: "orphan" is a keyword
2542 2571 getargs(x, 0, 0, _(b"orphan takes no arguments"))
2543 2572 orphan = obsmod.getrevs(repo, b'orphan')
2544 2573 return subset & orphan
2545 2574
2546 2575
2547 2576 @predicate(b'unstable()', safe=True)
2548 2577 def unstable(repo, subset, x):
2549 2578 """Changesets with instabilities. (EXPERIMENTAL)"""
2550 2579 # i18n: "unstable" is a keyword
2551 2580 getargs(x, 0, 0, b'unstable takes no arguments')
2552 2581 _unstable = set()
2553 2582 _unstable.update(obsmod.getrevs(repo, b'orphan'))
2554 2583 _unstable.update(obsmod.getrevs(repo, b'phasedivergent'))
2555 2584 _unstable.update(obsmod.getrevs(repo, b'contentdivergent'))
2556 2585 return subset & baseset(_unstable)
2557 2586
2558 2587
2559 2588 @predicate(b'user(string)', safe=True, weight=10)
2560 2589 def user(repo, subset, x):
2561 2590 """User name contains string. The match is case-insensitive.
2562 2591
2563 2592 Pattern matching is supported for `string`. See
2564 2593 :hg:`help revisions.patterns`.
2565 2594 """
2566 2595 return author(repo, subset, x)
2567 2596
2568 2597
2569 2598 @predicate(b'wdir()', safe=True, weight=0)
2570 2599 def wdir(repo, subset, x):
2571 2600 """Working directory. (EXPERIMENTAL)"""
2572 2601 # i18n: "wdir" is a keyword
2573 2602 getargs(x, 0, 0, _(b"wdir takes no arguments"))
2574 2603 if wdirrev in subset or isinstance(subset, fullreposet):
2575 2604 return baseset([wdirrev])
2576 2605 return baseset()
2577 2606
2578 2607
2579 2608 def _orderedlist(repo, subset, x):
2580 2609 s = getstring(x, b"internal error")
2581 2610 if not s:
2582 2611 return baseset()
2583 2612 # remove duplicates here. it's difficult for caller to deduplicate sets
2584 2613 # because different symbols can point to the same rev.
2585 2614 cl = repo.changelog
2586 2615 ls = []
2587 2616 seen = set()
2588 2617 for t in s.split(b'\0'):
2589 2618 try:
2590 2619 # fast path for integer revision
2591 2620 r = int(t)
2592 2621 if (b'%d' % r) != t or r not in cl:
2593 2622 raise ValueError
2594 2623 revs = [r]
2595 2624 except ValueError:
2596 2625 revs = stringset(repo, subset, t, defineorder)
2597 2626
2598 2627 for r in revs:
2599 2628 if r in seen:
2600 2629 continue
2601 2630 if (
2602 2631 r in subset
2603 2632 or r in _virtualrevs
2604 2633 and isinstance(subset, fullreposet)
2605 2634 ):
2606 2635 ls.append(r)
2607 2636 seen.add(r)
2608 2637 return baseset(ls)
2609 2638
2610 2639
2611 2640 # for internal use
2612 2641 @predicate(b'_list', safe=True, takeorder=True)
2613 2642 def _list(repo, subset, x, order):
2614 2643 if order == followorder:
2615 2644 # slow path to take the subset order
2616 2645 return subset & _orderedlist(repo, fullreposet(repo), x)
2617 2646 else:
2618 2647 return _orderedlist(repo, subset, x)
2619 2648
2620 2649
2621 2650 def _orderedintlist(repo, subset, x):
2622 2651 s = getstring(x, b"internal error")
2623 2652 if not s:
2624 2653 return baseset()
2625 2654 ls = [int(r) for r in s.split(b'\0')]
2626 2655 s = subset
2627 2656 return baseset([r for r in ls if r in s])
2628 2657
2629 2658
2630 2659 # for internal use
2631 2660 @predicate(b'_intlist', safe=True, takeorder=True, weight=0)
2632 2661 def _intlist(repo, subset, x, order):
2633 2662 if order == followorder:
2634 2663 # slow path to take the subset order
2635 2664 return subset & _orderedintlist(repo, fullreposet(repo), x)
2636 2665 else:
2637 2666 return _orderedintlist(repo, subset, x)
2638 2667
2639 2668
2640 2669 def _orderedhexlist(repo, subset, x):
2641 2670 s = getstring(x, b"internal error")
2642 2671 if not s:
2643 2672 return baseset()
2644 2673 cl = repo.changelog
2645 2674 ls = [cl.rev(bin(r)) for r in s.split(b'\0')]
2646 2675 s = subset
2647 2676 return baseset([r for r in ls if r in s])
2648 2677
2649 2678
2650 2679 # for internal use
2651 2680 @predicate(b'_hexlist', safe=True, takeorder=True)
2652 2681 def _hexlist(repo, subset, x, order):
2653 2682 if order == followorder:
2654 2683 # slow path to take the subset order
2655 2684 return subset & _orderedhexlist(repo, fullreposet(repo), x)
2656 2685 else:
2657 2686 return _orderedhexlist(repo, subset, x)
2658 2687
2659 2688
2660 2689 methods = {
2661 2690 b"range": rangeset,
2662 2691 b"rangeall": rangeall,
2663 2692 b"rangepre": rangepre,
2664 2693 b"rangepost": rangepost,
2665 2694 b"dagrange": dagrange,
2666 2695 b"string": stringset,
2667 2696 b"symbol": stringset,
2668 2697 b"and": andset,
2669 2698 b"andsmally": andsmallyset,
2670 2699 b"or": orset,
2671 2700 b"not": notset,
2672 2701 b"difference": differenceset,
2673 2702 b"relation": relationset,
2674 2703 b"relsubscript": relsubscriptset,
2675 2704 b"subscript": subscriptset,
2676 2705 b"list": listset,
2677 2706 b"keyvalue": keyvaluepair,
2678 2707 b"func": func,
2679 2708 b"ancestor": ancestorspec,
2680 2709 b"parent": parentspec,
2681 2710 b"parentpost": parentpost,
2682 2711 b"smartset": rawsmartset,
2683 2712 }
2684 2713
2685 2714 relations = {
2686 2715 b"g": generationsrel,
2687 2716 b"generations": generationsrel,
2688 2717 }
2689 2718
2690 2719 subscriptrelations = {
2691 2720 b"g": generationssubrel,
2692 2721 b"generations": generationssubrel,
2693 2722 }
2694 2723
2695 2724
2696 2725 def lookupfn(repo):
2697 2726 def fn(symbol):
2698 2727 try:
2699 2728 return scmutil.isrevsymbol(repo, symbol)
2700 2729 except error.AmbiguousPrefixLookupError:
2701 2730 raise error.InputError(
2702 2731 b'ambiguous revision identifier: %s' % symbol
2703 2732 )
2704 2733
2705 2734 return fn
2706 2735
2707 2736
2708 2737 def match(ui, spec, lookup=None):
2709 2738 """Create a matcher for a single revision spec"""
2710 2739 return matchany(ui, [spec], lookup=lookup)
2711 2740
2712 2741
2713 2742 def matchany(ui, specs, lookup=None, localalias=None):
2714 2743 """Create a matcher that will include any revisions matching one of the
2715 2744 given specs
2716 2745
2717 2746 If lookup function is not None, the parser will first attempt to handle
2718 2747 old-style ranges, which may contain operator characters.
2719 2748
2720 2749 If localalias is not None, it is a dict {name: definitionstring}. It takes
2721 2750 precedence over [revsetalias] config section.
2722 2751 """
2723 2752 if not specs:
2724 2753
2725 2754 def mfunc(repo, subset=None):
2726 2755 return baseset()
2727 2756
2728 2757 return mfunc
2729 2758 if not all(specs):
2730 2759 raise error.ParseError(_(b"empty query"))
2731 2760 if len(specs) == 1:
2732 2761 tree = revsetlang.parse(specs[0], lookup)
2733 2762 else:
2734 2763 tree = (
2735 2764 b'or',
2736 2765 (b'list',) + tuple(revsetlang.parse(s, lookup) for s in specs),
2737 2766 )
2738 2767
2739 2768 aliases = []
2740 2769 warn = None
2741 2770 if ui:
2742 2771 aliases.extend(ui.configitems(b'revsetalias'))
2743 2772 warn = ui.warn
2744 2773 if localalias:
2745 2774 aliases.extend(localalias.items())
2746 2775 if aliases:
2747 2776 tree = revsetlang.expandaliases(tree, aliases, warn=warn)
2748 2777 tree = revsetlang.foldconcat(tree)
2749 2778 tree = revsetlang.analyze(tree)
2750 2779 tree = revsetlang.optimize(tree)
2751 2780 return makematcher(tree)
2752 2781
2753 2782
2754 2783 def makematcher(tree):
2755 2784 """Create a matcher from an evaluatable tree"""
2756 2785
2757 2786 def mfunc(repo, subset=None, order=None):
2758 2787 if order is None:
2759 2788 if subset is None:
2760 2789 order = defineorder # 'x'
2761 2790 else:
2762 2791 order = followorder # 'subset & x'
2763 2792 if subset is None:
2764 2793 subset = fullreposet(repo)
2765 2794 return getset(repo, subset, tree, order)
2766 2795
2767 2796 return mfunc
2768 2797
2769 2798
2770 2799 def loadpredicate(ui, extname, registrarobj):
2771 2800 """Load revset predicates from specified registrarobj"""
2772 2801 for name, func in pycompat.iteritems(registrarobj._table):
2773 2802 symbols[name] = func
2774 2803 if func._safe:
2775 2804 safesymbols.add(name)
2776 2805
2777 2806
2778 2807 # load built-in predicates explicitly to setup safesymbols
2779 2808 loadpredicate(None, None, predicate)
2780 2809
2781 2810 # tell hggettext to extract docstrings from these functions:
2782 2811 i18nfunctions = symbols.values()
@@ -1,185 +1,186 b''
1 1 $ hg init a
2 2
3 3 $ echo a > a/a
4 4 $ hg --cwd a ci -Ama
5 5 adding a
6 6
7 7 $ hg clone a c
8 8 updating to branch default
9 9 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
10 10
11 11 $ hg clone a b
12 12 updating to branch default
13 13 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
14 14
15 15 $ echo b >> b/a
16 16 $ hg --cwd b ci -mb
17 17
18 18 Push should provide a hint when both 'default' and 'default-push' not set:
19 19 $ cd c
20 20 $ hg push --config paths.default=
21 21 config error: default repository not configured!
22 22 (see 'hg help config.paths')
23 23 [30]
24 24
25 25 $ cd ..
26 26
27 27 Push should push to 'default' when 'default-push' not set:
28 28
29 29 $ hg --cwd b push
30 30 pushing to $TESTTMP/a
31 31 searching for changes
32 32 adding changesets
33 33 adding manifests
34 34 adding file changes
35 35 added 1 changesets with 1 changes to 1 files
36 36
37 37 Push should push to 'default-push' when set:
38 38
39 39 $ echo '[paths]' >> b/.hg/hgrc
40 40 $ echo 'default-push = ../c' >> b/.hg/hgrc
41 41 $ hg --cwd b push
42 42 pushing to $TESTTMP/c
43 43 searching for changes
44 44 adding changesets
45 45 adding manifests
46 46 adding file changes
47 47 added 1 changesets with 1 changes to 1 files
48 48
49 49 But push should push to 'default' if explicitly specified (issue5000):
50 50
51 51 $ hg --cwd b push default
52 52 pushing to $TESTTMP/a
53 53 searching for changes
54 54 no changes found
55 55 [1]
56 56
57 57 Push should push to 'default-push' when 'default' is not set
58 58
59 59 $ hg -q clone a push-default-only
60 60 $ cd push-default-only
61 61 $ rm .hg/hgrc
62 62
63 63 $ touch foo
64 64 $ hg -q commit -A -m 'add foo'
65 65 $ hg --config paths.default-push=../a push
66 66 pushing to $TESTTMP/a
67 67 searching for changes
68 68 adding changesets
69 69 adding manifests
70 70 adding file changes
71 71 added 1 changesets with 1 changes to 1 files
72 72
73 73 $ cd ..
74 74
75 75 Pushing to a path that isn't defined should not fall back to default
76 76
77 77 $ hg --cwd b push doesnotexist
78 78 abort: repository doesnotexist does not exist
79 79 [255]
80 80
81 81 :pushurl is used when defined
82 82
83 83 $ hg -q clone a pushurlsource
84 84 $ hg -q clone a pushurldest
85 85 $ cd pushurlsource
86 86
87 87 Windows needs a leading slash to make a URL that passes all of the checks
88 88 $ WD=`pwd`
89 89 #if windows
90 90 $ WD="/$WD"
91 91 #endif
92 92 $ cat > .hg/hgrc << EOF
93 93 > [paths]
94 94 > default = https://example.com/not/relevant
95 95 > default:pushurl = file://$WD/../pushurldest
96 96 > EOF
97 97
98 98 $ touch pushurl
99 99 $ hg -q commit -A -m 'add pushurl'
100 100 $ hg push
101 101 pushing to file:/*/$TESTTMP/pushurlsource/../pushurldest (glob)
102 102 searching for changes
103 103 adding changesets
104 104 adding manifests
105 105 adding file changes
106 106 added 1 changesets with 1 changes to 1 files
107 107
108 108 :pushrev is used when no -r is passed
109 109
110 110 $ cat >> .hg/hgrc << EOF
111 111 > default:pushrev = .
112 112 > EOF
113 113 $ hg -q up -r 0
114 114 $ echo head1 > foo
115 115 $ hg -q commit -A -m head1
116 116 $ hg -q up -r 0
117 117 $ echo head2 > foo
118 118 $ hg -q commit -A -m head2
119 119 $ hg push -f
120 120 pushing to file:/*/$TESTTMP/pushurlsource/../pushurldest (glob)
121 121 searching for changes
122 122 adding changesets
123 123 adding manifests
124 124 adding file changes
125 125 added 1 changesets with 1 changes to 1 files (+1 heads)
126 126
127 127 $ hg --config 'paths.default:pushrev=draft()' push -f
128 128 pushing to file:/*/$TESTTMP/pushurlsource/../pushurldest (glob)
129 129 searching for changes
130 130 adding changesets
131 131 adding manifests
132 132 adding file changes
133 133 added 1 changesets with 1 changes to 1 files (+1 heads)
134 134
135 135 Invalid :pushrev raises appropriately
136 136
137 137 $ hg --config 'paths.default:pushrev=notdefined()' push
138 138 pushing to file:/*/$TESTTMP/pushurlsource/../pushurldest (glob)
139 139 hg: parse error: unknown identifier: notdefined
140 (did you mean nodefromfile?)
140 141 [10]
141 142
142 143 $ hg --config 'paths.default:pushrev=(' push
143 144 pushing to file:/*/$TESTTMP/pushurlsource/../pushurldest (glob)
144 145 hg: parse error at 1: not a prefix: end
145 146 ((
146 147 ^ here)
147 148 [10]
148 149
149 150 default :pushrev is taking in account
150 151
151 152 $ echo babar > foo
152 153 $ hg ci -m 'extra commit'
153 154 $ hg up '.^'
154 155 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
155 156 $ echo celeste > foo
156 157 $ hg ci -m 'extra other commit'
157 158 created new head
158 159 $ cat >> .hg/hgrc << EOF
159 160 > [paths]
160 161 > other = file://$WD/../pushurldest
161 162 > *:pushrev = .
162 163 > EOF
163 164 $ hg push other
164 165 pushing to file:/*/$TESTTMP/pushurlsource/../pushurldest (glob)
165 166 searching for changes
166 167 adding changesets
167 168 adding manifests
168 169 adding file changes
169 170 added 1 changesets with 1 changes to 1 files
170 171 $ hg push file://$WD/../pushurldest
171 172 pushing to file:/*/$TESTTMP/pushurlsource/../pushurldest (glob)
172 173 searching for changes
173 174 no changes found
174 175 [1]
175 176
176 177 for comparison, pushing everything would give different result
177 178
178 179 $ hg push file://$WD/../pushurldest --rev 'all()'
179 180 pushing to file:/*/$TESTTMP/pushurlsource/../pushurldest (glob)
180 181 searching for changes
181 182 abort: push creates new remote head 1616ce7cecc8
182 183 (merge or see 'hg help push' for details about pushing new heads)
183 184 [20]
184 185
185 186 $ cd ..
@@ -1,3110 +1,3125 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[b'r3232'] = r3232
20 20 > EOF
21 21 $ cat >> $HGRCPATH << EOF
22 22 > [extensions]
23 23 > drawdag=$TESTDIR/drawdag.py
24 24 > testrevset=$TESTTMP/testrevset.py
25 25 > EOF
26 26
27 27 $ try() {
28 28 > hg debugrevspec --debug "$@"
29 29 > }
30 30
31 31 $ log() {
32 32 > hg log --template '{rev}\n' -r "$1"
33 33 > }
34 34
35 35 extension to build '_intlist()' and '_hexlist()', which is necessary because
36 36 these predicates use '\0' as a separator:
37 37
38 38 $ cat <<EOF > debugrevlistspec.py
39 39 > from __future__ import absolute_import
40 40 > from mercurial import (
41 41 > node as nodemod,
42 42 > registrar,
43 43 > revset,
44 44 > revsetlang,
45 45 > )
46 46 > from mercurial.utils import stringutil
47 47 > cmdtable = {}
48 48 > command = registrar.command(cmdtable)
49 49 > @command(b'debugrevlistspec',
50 50 > [(b'', b'optimize', None, b'print parsed tree after optimizing'),
51 51 > (b'', b'bin', None, b'unhexlify arguments')])
52 52 > def debugrevlistspec(ui, repo, fmt, *args, **opts):
53 53 > if opts['bin']:
54 54 > args = map(nodemod.bin, args)
55 55 > expr = revsetlang.formatspec(fmt, list(args))
56 56 > if ui.verbose:
57 57 > tree = revsetlang.parse(expr, lookup=revset.lookupfn(repo))
58 58 > ui.note(revsetlang.prettyformat(tree), b"\n")
59 59 > if opts["optimize"]:
60 60 > opttree = revsetlang.optimize(revsetlang.analyze(tree))
61 61 > ui.note(b"* optimized:\n", revsetlang.prettyformat(opttree),
62 62 > b"\n")
63 63 > func = revset.match(ui, expr, lookup=revset.lookupfn(repo))
64 64 > revs = func(repo)
65 65 > if ui.verbose:
66 66 > ui.note(b"* set:\n", stringutil.prettyrepr(revs), b"\n")
67 67 > for c in revs:
68 68 > ui.write(b"%d\n" % c)
69 69 > EOF
70 70 $ cat <<EOF >> $HGRCPATH
71 71 > [extensions]
72 72 > debugrevlistspec = $TESTTMP/debugrevlistspec.py
73 73 > EOF
74 74 $ trylist() {
75 75 > hg debugrevlistspec --debug "$@"
76 76 > }
77 77
78 78 $ hg init repo
79 79 $ cd repo
80 80
81 81 $ echo a > a
82 82 $ hg branch a
83 83 marked working directory as branch a
84 84 (branches are permanent and global, did you want a bookmark?)
85 85 $ hg ci -Aqm0
86 86
87 87 $ echo b > b
88 88 $ hg branch b
89 89 marked working directory as branch b
90 90 $ hg ci -Aqm1
91 91
92 92 $ rm a
93 93 $ hg branch a-b-c-
94 94 marked working directory as branch a-b-c-
95 95 $ hg ci -Aqm2 -u Bob
96 96
97 97 $ hg log -r "extra('branch', 'a-b-c-')" --template '{rev}\n'
98 98 2
99 99 $ hg log -r "extra('branch')" --template '{rev}\n'
100 100 0
101 101 1
102 102 2
103 103 $ hg log -r "extra('branch', 're:a')" --template '{rev} {branch}\n'
104 104 0 a
105 105 2 a-b-c-
106 106
107 107 $ hg co 1
108 108 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
109 109 $ hg branch +a+b+c+
110 110 marked working directory as branch +a+b+c+
111 111 $ hg ci -Aqm3
112 112
113 113 $ hg co 2 # interleave
114 114 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
115 115 $ echo bb > b
116 116 $ hg branch -- -a-b-c-
117 117 marked working directory as branch -a-b-c-
118 118 $ hg ci -Aqm4 -d "May 12 2005"
119 119
120 120 $ hg co 3
121 121 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
122 122 $ hg branch !a/b/c/
123 123 marked working directory as branch !a/b/c/
124 124 $ hg ci -Aqm"5 bug"
125 125
126 126 $ hg merge 4
127 127 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
128 128 (branch merge, don't forget to commit)
129 129 $ hg branch _a_b_c_
130 130 marked working directory as branch _a_b_c_
131 131 $ hg ci -Aqm"6 issue619"
132 132
133 133 $ hg branch .a.b.c.
134 134 marked working directory as branch .a.b.c.
135 135 $ hg ci -Aqm7
136 136
137 137 $ hg branch all
138 138 marked working directory as branch all
139 139
140 140 $ hg co 4
141 141 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
142 142 $ hg branch Γ©
143 143 marked working directory as branch \xc3\xa9 (esc)
144 144 $ hg ci -Aqm9
145 145
146 146 $ hg tag -r6 1.0
147 147 $ hg bookmark -r6 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
148 148
149 149 $ hg clone --quiet -U -r 7 . ../remote1
150 150 $ hg clone --quiet -U -r 8 . ../remote2
151 151 $ echo "[paths]" >> .hg/hgrc
152 152 $ echo "default = ../remote1" >> .hg/hgrc
153 153
154 154 trivial
155 155
156 156 $ try 0:1
157 157 (range
158 158 (symbol '0')
159 159 (symbol '1'))
160 160 * set:
161 161 <spanset+ 0:2>
162 162 0
163 163 1
164 164 $ try --optimize :
165 165 (rangeall
166 166 None)
167 167 * optimized:
168 168 (rangeall
169 169 None)
170 170 * set:
171 171 <spanset+ 0:10>
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:10>
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:4>
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:5>
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 (date(this is a test)
403 403 ^ here)
404 404 [10]
405 405 $ log 'date()'
406 406 hg: parse error: date requires a string
407 407 [10]
408 408 $ log 'date'
409 409 abort: unknown revision 'date'
410 410 [255]
411 411 $ log 'date('
412 412 hg: parse error at 5: not a prefix: end
413 413 (date(
414 414 ^ here)
415 415 [10]
416 416 $ log 'date("\xy")'
417 417 hg: parse error: invalid \x escape* (glob)
418 418 [10]
419 419 $ log 'date(tip)'
420 420 hg: parse error: invalid date: 'tip'
421 421 [10]
422 422 $ log '0:date'
423 423 abort: unknown revision 'date'
424 424 [255]
425 425 $ log '::"date"'
426 426 abort: unknown revision 'date'
427 427 [255]
428 428 $ hg book date -r 4
429 429 $ log '0:date'
430 430 0
431 431 1
432 432 2
433 433 3
434 434 4
435 435 $ log '::date'
436 436 0
437 437 1
438 438 2
439 439 4
440 440 $ log '::"date"'
441 441 0
442 442 1
443 443 2
444 444 4
445 445 $ log 'date(2005) and 1::'
446 446 4
447 447 $ hg book -d date
448 448
449 449 function name should be a symbol
450 450
451 451 $ log '"date"(2005)'
452 452 hg: parse error: not a symbol
453 453 [10]
454 454
455 455 keyword arguments
456 456
457 457 $ log 'extra(branch, value=a)'
458 458 0
459 459
460 460 $ log 'extra(branch, a, b)'
461 461 hg: parse error: extra takes at most 2 positional arguments
462 462 [10]
463 463 $ log 'extra(a, label=b)'
464 464 hg: parse error: extra got multiple values for keyword argument 'label'
465 465 [10]
466 466 $ log 'extra(label=branch, default)'
467 467 hg: parse error: extra got an invalid argument
468 468 [10]
469 469 $ log 'extra(branch, foo+bar=baz)'
470 470 hg: parse error: extra got an invalid argument
471 471 [10]
472 472 $ log 'extra(unknown=branch)'
473 473 hg: parse error: extra got an unexpected keyword argument 'unknown'
474 474 [10]
475 475 $ log 'extra((), x)'
476 476 hg: parse error: first argument to extra must be a string
477 477 [10]
478 478 $ log 'extra(label=x, ())'
479 479 hg: parse error: extra got an invalid argument
480 480 [10]
481 481
482 482 $ try 'foo=bar|baz'
483 483 (keyvalue
484 484 (symbol 'foo')
485 485 (or
486 486 (list
487 487 (symbol 'bar')
488 488 (symbol 'baz'))))
489 489 hg: parse error: can't use a key-value pair in this context
490 490 [10]
491 491
492 492 right-hand side should be optimized recursively
493 493
494 494 $ try --optimize 'foo=(not public())'
495 495 (keyvalue
496 496 (symbol 'foo')
497 497 (group
498 498 (not
499 499 (func
500 500 (symbol 'public')
501 501 None))))
502 502 * optimized:
503 503 (keyvalue
504 504 (symbol 'foo')
505 505 (func
506 506 (symbol '_notpublic')
507 507 None))
508 508 hg: parse error: can't use a key-value pair in this context
509 509 [10]
510 510
511 511 relation-subscript operator has the highest binding strength (as function call):
512 512
513 513 $ hg debugrevspec -p parsed 'tip:tip^#generations[-1]'
514 514 * parsed:
515 515 (range
516 516 (symbol 'tip')
517 517 (relsubscript
518 518 (parentpost
519 519 (symbol 'tip'))
520 520 (symbol 'generations')
521 521 (negate
522 522 (symbol '1'))))
523 523 9
524 524 8
525 525 7
526 526 6
527 527 5
528 528 4
529 529
530 530 $ hg debugrevspec -p parsed --no-show-revs 'not public()#generations[0]'
531 531 * parsed:
532 532 (not
533 533 (relsubscript
534 534 (func
535 535 (symbol 'public')
536 536 None)
537 537 (symbol 'generations')
538 538 (symbol '0')))
539 539
540 540 left-hand side of relation-subscript operator should be optimized recursively:
541 541
542 542 $ hg debugrevspec -p analyzed -p optimized --no-show-revs \
543 543 > '(not public())#generations[0]'
544 544 * analyzed:
545 545 (relsubscript
546 546 (not
547 547 (func
548 548 (symbol 'public')
549 549 None))
550 550 (symbol 'generations')
551 551 (symbol '0'))
552 552 * optimized:
553 553 (relsubscript
554 554 (func
555 555 (symbol '_notpublic')
556 556 None)
557 557 (symbol 'generations')
558 558 (symbol '0'))
559 559
560 560 resolution of subscript and relation-subscript ternary operators:
561 561
562 562 $ hg debugrevspec -p analyzed 'tip[0]'
563 563 * analyzed:
564 564 (subscript
565 565 (symbol 'tip')
566 566 (symbol '0'))
567 567 hg: parse error: can't use a subscript in this context
568 568 [10]
569 569
570 570 $ hg debugrevspec -p analyzed 'tip#rel[0]'
571 571 * analyzed:
572 572 (relsubscript
573 573 (symbol 'tip')
574 574 (symbol 'rel')
575 575 (symbol '0'))
576 576 hg: parse error: unknown identifier: rel
577 577 [10]
578 578
579 579 $ hg debugrevspec -p analyzed '(tip#rel)[0]'
580 580 * analyzed:
581 581 (subscript
582 582 (relation
583 583 (symbol 'tip')
584 584 (symbol 'rel'))
585 585 (symbol '0'))
586 586 hg: parse error: can't use a subscript in this context
587 587 [10]
588 588
589 589 $ hg debugrevspec -p analyzed 'tip#rel[0][1]'
590 590 * analyzed:
591 591 (subscript
592 592 (relsubscript
593 593 (symbol 'tip')
594 594 (symbol 'rel')
595 595 (symbol '0'))
596 596 (symbol '1'))
597 597 hg: parse error: can't use a subscript in this context
598 598 [10]
599 599
600 600 $ hg debugrevspec -p analyzed 'tip#rel0#rel1[1]'
601 601 * analyzed:
602 602 (relsubscript
603 603 (relation
604 604 (symbol 'tip')
605 605 (symbol 'rel0'))
606 606 (symbol 'rel1')
607 607 (symbol '1'))
608 608 hg: parse error: unknown identifier: rel1
609 609 [10]
610 610
611 611 $ hg debugrevspec -p analyzed 'tip#rel0[0]#rel1[1]'
612 612 * analyzed:
613 613 (relsubscript
614 614 (relsubscript
615 615 (symbol 'tip')
616 616 (symbol 'rel0')
617 617 (symbol '0'))
618 618 (symbol 'rel1')
619 619 (symbol '1'))
620 620 hg: parse error: unknown identifier: rel1
621 621 [10]
622 622
623 623 parse errors of relation, subscript and relation-subscript operators:
624 624
625 625 $ hg debugrevspec '[0]'
626 626 hg: parse error at 0: not a prefix: [
627 627 ([0]
628 628 ^ here)
629 629 [10]
630 630 $ hg debugrevspec '.#'
631 631 hg: parse error at 2: not a prefix: end
632 632 (.#
633 633 ^ here)
634 634 [10]
635 635 $ hg debugrevspec '#rel'
636 636 hg: parse error at 0: not a prefix: #
637 637 (#rel
638 638 ^ here)
639 639 [10]
640 640 $ hg debugrevspec '.#rel[0'
641 641 hg: parse error at 7: unexpected token: end
642 642 (.#rel[0
643 643 ^ here)
644 644 [10]
645 645 $ hg debugrevspec '.]'
646 646 hg: parse error at 1: invalid token
647 647 (.]
648 648 ^ here)
649 649 [10]
650 650
651 651 $ hg debugrevspec '.#generations[a]'
652 652 hg: parse error: relation subscript must be an integer or a range
653 653 [10]
654 654 $ hg debugrevspec '.#generations[1-2]'
655 655 hg: parse error: relation subscript must be an integer or a range
656 656 [10]
657 657 $ hg debugrevspec '.#generations[foo:bar]'
658 658 hg: parse error: relation subscript bounds must be integers
659 659 [10]
660 660
661 661 suggested relations
662 662
663 663 $ hg debugrevspec '.#generafions[0]'
664 664 hg: parse error: unknown identifier: generafions
665 665 (did you mean generations?)
666 666 [10]
667 667
668 668 $ hg debugrevspec '.#f[0]'
669 669 hg: parse error: unknown identifier: f
670 670 [10]
671 671
672 672 parsed tree at stages:
673 673
674 674 $ hg debugrevspec -p all '()'
675 675 * parsed:
676 676 (group
677 677 None)
678 678 * expanded:
679 679 (group
680 680 None)
681 681 * concatenated:
682 682 (group
683 683 None)
684 684 * analyzed:
685 685 None
686 686 * optimized:
687 687 None
688 688 hg: parse error: missing argument
689 689 [10]
690 690
691 691 $ hg debugrevspec --no-optimized -p all '()'
692 692 * parsed:
693 693 (group
694 694 None)
695 695 * expanded:
696 696 (group
697 697 None)
698 698 * concatenated:
699 699 (group
700 700 None)
701 701 * analyzed:
702 702 None
703 703 hg: parse error: missing argument
704 704 [10]
705 705
706 706 $ hg debugrevspec -p parsed -p analyzed -p optimized '(0|1)-1'
707 707 * parsed:
708 708 (minus
709 709 (group
710 710 (or
711 711 (list
712 712 (symbol '0')
713 713 (symbol '1'))))
714 714 (symbol '1'))
715 715 * analyzed:
716 716 (and
717 717 (or
718 718 (list
719 719 (symbol '0')
720 720 (symbol '1')))
721 721 (not
722 722 (symbol '1')))
723 723 * optimized:
724 724 (difference
725 725 (func
726 726 (symbol '_list')
727 727 (string '0\x001'))
728 728 (symbol '1'))
729 729 0
730 730
731 731 $ hg debugrevspec -p unknown '0'
732 732 abort: invalid stage name: unknown
733 733 [255]
734 734
735 735 $ hg debugrevspec -p all --optimize '0'
736 736 abort: cannot use --optimize with --show-stage
737 737 [255]
738 738
739 739 verify optimized tree:
740 740
741 741 $ hg debugrevspec --verify '0|1'
742 742
743 743 $ hg debugrevspec --verify -v -p analyzed -p optimized 'r3232() & 2'
744 744 * analyzed:
745 745 (and
746 746 (func
747 747 (symbol 'r3232')
748 748 None)
749 749 (symbol '2'))
750 750 * optimized:
751 751 (andsmally
752 752 (func
753 753 (symbol 'r3232')
754 754 None)
755 755 (symbol '2'))
756 756 * analyzed set:
757 757 <baseset [2]>
758 758 * optimized set:
759 759 <baseset [2, 2]>
760 760 --- analyzed
761 761 +++ optimized
762 762 2
763 763 +2
764 764 [1]
765 765
766 766 $ hg debugrevspec --no-optimized --verify-optimized '0'
767 767 abort: cannot use --verify-optimized with --no-optimized
768 768 [255]
769 769
770 770 Test that symbols only get parsed as functions if there's an opening
771 771 parenthesis.
772 772
773 773 $ hg book only -r 9
774 774 $ log 'only(only)' # Outer "only" is a function, inner "only" is the bookmark
775 775 8
776 776 9
777 777
778 778 ':y' behaves like '0:y', but can't be rewritten as such since the revision '0'
779 779 may be hidden (issue5385)
780 780
781 781 $ try -p parsed -p analyzed ':'
782 782 * parsed:
783 783 (rangeall
784 784 None)
785 785 * analyzed:
786 786 (rangeall
787 787 None)
788 788 * set:
789 789 <spanset+ 0:10>
790 790 0
791 791 1
792 792 2
793 793 3
794 794 4
795 795 5
796 796 6
797 797 7
798 798 8
799 799 9
800 800 $ try -p analyzed ':1'
801 801 * analyzed:
802 802 (rangepre
803 803 (symbol '1'))
804 804 * set:
805 805 <spanset+ 0:2>
806 806 0
807 807 1
808 808 $ try -p analyzed ':(1|2)'
809 809 * analyzed:
810 810 (rangepre
811 811 (or
812 812 (list
813 813 (symbol '1')
814 814 (symbol '2'))))
815 815 * set:
816 816 <spanset+ 0:3>
817 817 0
818 818 1
819 819 2
820 820 $ try -p analyzed ':(1&2)'
821 821 * analyzed:
822 822 (rangepre
823 823 (and
824 824 (symbol '1')
825 825 (symbol '2')))
826 826 * set:
827 827 <baseset []>
828 828
829 829 infix/suffix resolution of ^ operator (issue2884, issue5764):
830 830
831 831 x^:y means (x^):y
832 832
833 833 $ try '1^:2'
834 834 (range
835 835 (parentpost
836 836 (symbol '1'))
837 837 (symbol '2'))
838 838 * set:
839 839 <spanset+ 0:3>
840 840 0
841 841 1
842 842 2
843 843
844 844 $ try '1^::2'
845 845 (dagrange
846 846 (parentpost
847 847 (symbol '1'))
848 848 (symbol '2'))
849 849 * set:
850 850 <baseset+ [0, 1, 2]>
851 851 0
852 852 1
853 853 2
854 854
855 855 $ try '1^..2'
856 856 (dagrange
857 857 (parentpost
858 858 (symbol '1'))
859 859 (symbol '2'))
860 860 * set:
861 861 <baseset+ [0, 1, 2]>
862 862 0
863 863 1
864 864 2
865 865
866 866 $ try '9^:'
867 867 (rangepost
868 868 (parentpost
869 869 (symbol '9')))
870 870 * set:
871 871 <spanset+ 8:10>
872 872 8
873 873 9
874 874
875 875 $ try '9^::'
876 876 (dagrangepost
877 877 (parentpost
878 878 (symbol '9')))
879 879 * set:
880 880 <generatorsetasc+>
881 881 8
882 882 9
883 883
884 884 $ try '9^..'
885 885 (dagrangepost
886 886 (parentpost
887 887 (symbol '9')))
888 888 * set:
889 889 <generatorsetasc+>
890 890 8
891 891 9
892 892
893 893 x^:y should be resolved before omitting group operators
894 894
895 895 $ try '1^(:2)'
896 896 (parent
897 897 (symbol '1')
898 898 (group
899 899 (rangepre
900 900 (symbol '2'))))
901 901 hg: parse error: ^ expects a number 0, 1, or 2
902 902 [10]
903 903
904 904 x^:y should be resolved recursively
905 905
906 906 $ try 'sort(1^:2)'
907 907 (func
908 908 (symbol 'sort')
909 909 (range
910 910 (parentpost
911 911 (symbol '1'))
912 912 (symbol '2')))
913 913 * set:
914 914 <spanset+ 0:3>
915 915 0
916 916 1
917 917 2
918 918
919 919 $ try '(3^:4)^:2'
920 920 (range
921 921 (parentpost
922 922 (group
923 923 (range
924 924 (parentpost
925 925 (symbol '3'))
926 926 (symbol '4'))))
927 927 (symbol '2'))
928 928 * set:
929 929 <spanset+ 0:3>
930 930 0
931 931 1
932 932 2
933 933
934 934 $ try '(3^::4)^::2'
935 935 (dagrange
936 936 (parentpost
937 937 (group
938 938 (dagrange
939 939 (parentpost
940 940 (symbol '3'))
941 941 (symbol '4'))))
942 942 (symbol '2'))
943 943 * set:
944 944 <baseset+ [0, 1, 2]>
945 945 0
946 946 1
947 947 2
948 948
949 949 $ try '(9^:)^:'
950 950 (rangepost
951 951 (parentpost
952 952 (group
953 953 (rangepost
954 954 (parentpost
955 955 (symbol '9'))))))
956 956 * set:
957 957 <spanset+ 4:10>
958 958 4
959 959 5
960 960 6
961 961 7
962 962 8
963 963 9
964 964
965 965 x^ in alias should also be resolved
966 966
967 967 $ try 'A' --config 'revsetalias.A=1^:2'
968 968 (symbol 'A')
969 969 * expanded:
970 970 (range
971 971 (parentpost
972 972 (symbol '1'))
973 973 (symbol '2'))
974 974 * set:
975 975 <spanset+ 0:3>
976 976 0
977 977 1
978 978 2
979 979
980 980 $ try 'A:2' --config 'revsetalias.A=1^'
981 981 (range
982 982 (symbol 'A')
983 983 (symbol '2'))
984 984 * expanded:
985 985 (range
986 986 (parentpost
987 987 (symbol '1'))
988 988 (symbol '2'))
989 989 * set:
990 990 <spanset+ 0:3>
991 991 0
992 992 1
993 993 2
994 994
995 995 but not beyond the boundary of alias expansion, because the resolution should
996 996 be made at the parsing stage
997 997
998 998 $ try '1^A' --config 'revsetalias.A=:2'
999 999 (parent
1000 1000 (symbol '1')
1001 1001 (symbol 'A'))
1002 1002 * expanded:
1003 1003 (parent
1004 1004 (symbol '1')
1005 1005 (rangepre
1006 1006 (symbol '2')))
1007 1007 hg: parse error: ^ expects a number 0, 1, or 2
1008 1008 [10]
1009 1009
1010 1010 '::' itself isn't a valid expression
1011 1011
1012 1012 $ try '::'
1013 1013 (dagrangeall
1014 1014 None)
1015 1015 hg: parse error: can't use '::' in this context
1016 1016 [10]
1017 1017
1018 1018 ancestor can accept 0 or more arguments
1019 1019
1020 1020 $ log 'ancestor()'
1021 1021 $ log 'ancestor(1)'
1022 1022 1
1023 1023 $ log 'ancestor(4,5)'
1024 1024 1
1025 1025 $ log 'ancestor(4,5) and 4'
1026 1026 $ log 'ancestor(0,0,1,3)'
1027 1027 0
1028 1028 $ log 'ancestor(3,1,5,3,5,1)'
1029 1029 1
1030 1030 $ log 'ancestor(0,1,3,5)'
1031 1031 0
1032 1032 $ log 'ancestor(1,2,3,4,5)'
1033 1033 1
1034 1034
1035 1035 test ancestors
1036 1036
1037 1037 $ hg log -G -T '{rev}\n' --config experimental.graphshorten=True
1038 1038 @ 9
1039 1039 o 8
1040 1040 | o 7
1041 1041 | o 6
1042 1042 |/|
1043 1043 | o 5
1044 1044 o | 4
1045 1045 | o 3
1046 1046 o | 2
1047 1047 |/
1048 1048 o 1
1049 1049 o 0
1050 1050
1051 1051 $ log 'ancestors(5)'
1052 1052 0
1053 1053 1
1054 1054 3
1055 1055 5
1056 1056 $ log 'ancestor(ancestors(5))'
1057 1057 0
1058 1058 $ log '::r3232()'
1059 1059 0
1060 1060 1
1061 1061 2
1062 1062 3
1063 1063
1064 1064 test common ancestors
1065 1065
1066 1066 $ hg log -T '{rev}\n' -r 'commonancestors(7 + 9)'
1067 1067 0
1068 1068 1
1069 1069 2
1070 1070 4
1071 1071
1072 1072 $ hg log -T '{rev}\n' -r 'commonancestors(heads(all()))'
1073 1073 0
1074 1074 1
1075 1075 2
1076 1076 4
1077 1077
1078 1078 $ hg log -T '{rev}\n' -r 'commonancestors(9)'
1079 1079 0
1080 1080 1
1081 1081 2
1082 1082 4
1083 1083 8
1084 1084 9
1085 1085
1086 1086 $ hg log -T '{rev}\n' -r 'commonancestors(8 + 9)'
1087 1087 0
1088 1088 1
1089 1089 2
1090 1090 4
1091 1091 8
1092 1092
1093 1093 test the specialized implementation of heads(commonancestors(..))
1094 1094 (2 gcas is tested in test-merge-criss-cross.t)
1095 1095
1096 1096 $ hg log -T '{rev}\n' -r 'heads(commonancestors(7 + 9))'
1097 1097 4
1098 1098 $ hg log -T '{rev}\n' -r 'heads(commonancestors(heads(all())))'
1099 1099 4
1100 1100 $ hg log -T '{rev}\n' -r 'heads(commonancestors(9))'
1101 1101 9
1102 1102 $ hg log -T '{rev}\n' -r 'heads(commonancestors(8 + 9))'
1103 1103 8
1104 1104
1105 1105 test ancestor variants of empty revision
1106 1106
1107 1107 $ log 'ancestor(none())'
1108 1108 $ log 'ancestors(none())'
1109 1109 $ log 'commonancestors(none())'
1110 1110 $ log 'heads(commonancestors(none()))'
1111 1111
1112 1112 test ancestors with depth limit
1113 1113
1114 1114 (depth=0 selects the node itself)
1115 1115
1116 1116 $ log 'reverse(ancestors(9, depth=0))'
1117 1117 9
1118 1118
1119 1119 (interleaved: '4' would be missing if heap queue were higher depth first)
1120 1120
1121 1121 $ log 'reverse(ancestors(8:9, depth=1))'
1122 1122 9
1123 1123 8
1124 1124 4
1125 1125
1126 1126 (interleaved: '2' would be missing if heap queue were higher depth first)
1127 1127
1128 1128 $ log 'reverse(ancestors(7+8, depth=2))'
1129 1129 8
1130 1130 7
1131 1131 6
1132 1132 5
1133 1133 4
1134 1134 2
1135 1135
1136 1136 (walk example above by separate queries)
1137 1137
1138 1138 $ log 'reverse(ancestors(8, depth=2)) + reverse(ancestors(7, depth=2))'
1139 1139 8
1140 1140 4
1141 1141 2
1142 1142 7
1143 1143 6
1144 1144 5
1145 1145
1146 1146 (walk 2nd and 3rd ancestors)
1147 1147
1148 1148 $ log 'reverse(ancestors(7, depth=3, startdepth=2))'
1149 1149 5
1150 1150 4
1151 1151 3
1152 1152 2
1153 1153
1154 1154 (interleaved: '4' would be missing if higher-depth ancestors weren't scanned)
1155 1155
1156 1156 $ log 'reverse(ancestors(7+8, depth=2, startdepth=2))'
1157 1157 5
1158 1158 4
1159 1159 2
1160 1160
1161 1161 (note that 'ancestors(x, depth=y, startdepth=z)' does not identical to
1162 1162 'ancestors(x, depth=y) - ancestors(x, depth=z-1)' because a node may have
1163 1163 multiple depths)
1164 1164
1165 1165 $ log 'reverse(ancestors(7+8, depth=2) - ancestors(7+8, depth=1))'
1166 1166 5
1167 1167 2
1168 1168
1169 1169 test bad arguments passed to ancestors()
1170 1170
1171 1171 $ log 'ancestors(., depth=-1)'
1172 1172 hg: parse error: negative depth
1173 1173 [10]
1174 1174 $ log 'ancestors(., depth=foo)'
1175 1175 hg: parse error: ancestors expects an integer depth
1176 1176 [10]
1177 1177
1178 1178 test descendants
1179 1179
1180 1180 $ hg log -G -T '{rev}\n' --config experimental.graphshorten=True
1181 1181 @ 9
1182 1182 o 8
1183 1183 | o 7
1184 1184 | o 6
1185 1185 |/|
1186 1186 | o 5
1187 1187 o | 4
1188 1188 | o 3
1189 1189 o | 2
1190 1190 |/
1191 1191 o 1
1192 1192 o 0
1193 1193
1194 1194 (null is ultimate root and has optimized path)
1195 1195
1196 1196 $ log 'null:4 & descendants(null)'
1197 1197 -1
1198 1198 0
1199 1199 1
1200 1200 2
1201 1201 3
1202 1202 4
1203 1203
1204 1204 (including merge)
1205 1205
1206 1206 $ log ':8 & descendants(2)'
1207 1207 2
1208 1208 4
1209 1209 6
1210 1210 7
1211 1211 8
1212 1212
1213 1213 (multiple roots)
1214 1214
1215 1215 $ log ':8 & descendants(2+5)'
1216 1216 2
1217 1217 4
1218 1218 5
1219 1219 6
1220 1220 7
1221 1221 8
1222 1222
1223 1223 test descendants with depth limit
1224 1224
1225 1225 (depth=0 selects the node itself)
1226 1226
1227 1227 $ log 'descendants(0, depth=0)'
1228 1228 0
1229 1229 $ log 'null: & descendants(null, depth=0)'
1230 1230 -1
1231 1231
1232 1232 (p2 = null should be ignored)
1233 1233
1234 1234 $ log 'null: & descendants(null, depth=2)'
1235 1235 -1
1236 1236 0
1237 1237 1
1238 1238
1239 1239 (multiple paths: depth(6) = (2, 3))
1240 1240
1241 1241 $ log 'descendants(1+3, depth=2)'
1242 1242 1
1243 1243 2
1244 1244 3
1245 1245 4
1246 1246 5
1247 1247 6
1248 1248
1249 1249 (multiple paths: depth(5) = (1, 2), depth(6) = (2, 3))
1250 1250
1251 1251 $ log 'descendants(3+1, depth=2, startdepth=2)'
1252 1252 4
1253 1253 5
1254 1254 6
1255 1255
1256 1256 (multiple depths: depth(6) = (0, 2, 4), search for depth=2)
1257 1257
1258 1258 $ log 'descendants(0+3+6, depth=3, startdepth=1)'
1259 1259 1
1260 1260 2
1261 1261 3
1262 1262 4
1263 1263 5
1264 1264 6
1265 1265 7
1266 1266
1267 1267 (multiple depths: depth(6) = (0, 4), no match)
1268 1268
1269 1269 $ log 'descendants(0+6, depth=3, startdepth=1)'
1270 1270 1
1271 1271 2
1272 1272 3
1273 1273 4
1274 1274 5
1275 1275 7
1276 1276
1277 1277 test ancestors/descendants relation:
1278 1278
1279 1279 $ log 'tip#generations'
1280 1280 0
1281 1281 1
1282 1282 2
1283 1283 4
1284 1284 8
1285 1285 9
1286 1286
1287 1287 $ log '3#g'
1288 1288 0
1289 1289 1
1290 1290 3
1291 1291 5
1292 1292 6
1293 1293 7
1294 1294
1295 1295 $ hg debugrevspec -p parsed 'tip#g'
1296 1296 * parsed:
1297 1297 (relation
1298 1298 (symbol 'tip')
1299 1299 (symbol 'g'))
1300 1300 0
1301 1301 1
1302 1302 2
1303 1303 4
1304 1304 8
1305 1305 9
1306 1306
1307 1307 test ancestors/descendants relation subscript:
1308 1308
1309 1309 $ log 'tip#generations[0]'
1310 1310 9
1311 1311 $ log '.#generations[-1]'
1312 1312 8
1313 1313 $ log '.#g[(-1)]'
1314 1314 8
1315 1315
1316 1316 $ log '6#generations[0:1]'
1317 1317 6
1318 1318 7
1319 1319 $ log '6#generations[-1:1]'
1320 1320 4
1321 1321 5
1322 1322 6
1323 1323 7
1324 1324 $ log '6#generations[0:]'
1325 1325 6
1326 1326 7
1327 1327 $ log '5#generations[:0]'
1328 1328 0
1329 1329 1
1330 1330 3
1331 1331 5
1332 1332 $ log '3#generations[:]'
1333 1333 0
1334 1334 1
1335 1335 3
1336 1336 5
1337 1337 6
1338 1338 7
1339 1339 $ log 'tip#generations[1:-1]'
1340 1340
1341 1341 $ hg debugrevspec -p parsed 'roots(:)#g[2]'
1342 1342 * parsed:
1343 1343 (relsubscript
1344 1344 (func
1345 1345 (symbol 'roots')
1346 1346 (rangeall
1347 1347 None))
1348 1348 (symbol 'g')
1349 1349 (symbol '2'))
1350 1350 2
1351 1351 3
1352 1352
1353 1353 test author
1354 1354
1355 1355 $ log 'author(bob)'
1356 1356 2
1357 1357 $ log 'author("re:bob|test")'
1358 1358 0
1359 1359 1
1360 1360 2
1361 1361 3
1362 1362 4
1363 1363 5
1364 1364 6
1365 1365 7
1366 1366 8
1367 1367 9
1368 1368 $ log 'author(r"re:\S")'
1369 1369 0
1370 1370 1
1371 1371 2
1372 1372 3
1373 1373 4
1374 1374 5
1375 1375 6
1376 1376 7
1377 1377 8
1378 1378 9
1379 1379 $ log 'branch(Γ©)'
1380 1380 8
1381 1381 9
1382 1382 $ log 'branch(a)'
1383 1383 0
1384 1384 $ hg log -r 'branch("re:a")' --template '{rev} {branch}\n'
1385 1385 0 a
1386 1386 2 a-b-c-
1387 1387 3 +a+b+c+
1388 1388 4 -a-b-c-
1389 1389 5 !a/b/c/
1390 1390 6 _a_b_c_
1391 1391 7 .a.b.c.
1392 1392 $ log 'children(ancestor(4,5))'
1393 1393 2
1394 1394 3
1395 1395
1396 1396 $ log 'children(4)'
1397 1397 6
1398 1398 8
1399 1399 $ log 'children(null)'
1400 1400 0
1401 1401
1402 1402 $ log 'closed()'
1403 1403 $ log 'contains(a)'
1404 1404 0
1405 1405 1
1406 1406 3
1407 1407 5
1408 1408 $ log 'contains("../repo/a")'
1409 1409 0
1410 1410 1
1411 1411 3
1412 1412 5
1413 1413 $ log 'desc(B)'
1414 1414 5
1415 1415 $ hg log -r 'desc(r"re:S?u")' --template "{rev} {desc|firstline}\n"
1416 1416 5 5 bug
1417 1417 6 6 issue619
1418 1418 $ log 'descendants(2 or 3)'
1419 1419 2
1420 1420 3
1421 1421 4
1422 1422 5
1423 1423 6
1424 1424 7
1425 1425 8
1426 1426 9
1427 1427 $ log 'file("b*")'
1428 1428 1
1429 1429 4
1430 1430 $ log 'filelog("b")'
1431 1431 1
1432 1432 4
1433 1433 $ log 'filelog("../repo/b")'
1434 1434 1
1435 1435 4
1436 1436 $ log 'follow()'
1437 1437 0
1438 1438 1
1439 1439 2
1440 1440 4
1441 1441 8
1442 1442 9
1443 1443 $ log 'grep("issue\d+")'
1444 1444 6
1445 1445 $ try 'grep("(")' # invalid regular expression
1446 1446 (func
1447 1447 (symbol 'grep')
1448 1448 (string '('))
1449 1449 hg: parse error: invalid match pattern: (unbalanced parenthesis|missing \),.*) (re)
1450 1450 [10]
1451 1451 $ log 'desc("re:(")'
1452 1452 hg: parse error: invalid regular expression: (unbalanced parenthesis|missing \),.*) (re)
1453 1453 [10]
1454 1454 $ try 'grep("\bissue\d+")'
1455 1455 (func
1456 1456 (symbol 'grep')
1457 1457 (string '\x08issue\\d+'))
1458 1458 * set:
1459 1459 <filteredset
1460 1460 <fullreposet+ 0:10>,
1461 1461 <grep '\x08issue\\d+'>>
1462 1462 $ try 'grep(r"\bissue\d+")'
1463 1463 (func
1464 1464 (symbol 'grep')
1465 1465 (string '\\bissue\\d+'))
1466 1466 * set:
1467 1467 <filteredset
1468 1468 <fullreposet+ 0:10>,
1469 1469 <grep '\\bissue\\d+'>>
1470 1470 6
1471 1471 $ try 'grep(r"\")'
1472 1472 hg: parse error at 7: unterminated string
1473 1473 (grep(r"\")
1474 1474 ^ here)
1475 1475 [10]
1476 1476 $ log 'head()'
1477 1477 0
1478 1478 1
1479 1479 2
1480 1480 3
1481 1481 4
1482 1482 5
1483 1483 6
1484 1484 7
1485 1485 9
1486 1486
1487 1487 Test heads
1488 1488
1489 1489 $ log 'heads(6::)'
1490 1490 7
1491 1491
1492 1492 heads() can be computed in subset '9:'
1493 1493
1494 1494 $ hg debugrevspec -s '9: & heads(all())'
1495 1495 * set:
1496 1496 <filteredset
1497 1497 <baseset [9]>,
1498 1498 <baseset+ [7, 9]>>
1499 1499 9
1500 1500
1501 1501 but should follow the order of the subset
1502 1502
1503 1503 $ log 'heads(all())'
1504 1504 7
1505 1505 9
1506 1506 $ log 'heads(tip:0)'
1507 1507 7
1508 1508 9
1509 1509 $ log 'tip:0 & heads(all())'
1510 1510 9
1511 1511 7
1512 1512 $ log 'tip:0 & heads(0:tip)'
1513 1513 9
1514 1514 7
1515 1515
1516 1516 $ log 'keyword(issue)'
1517 1517 6
1518 1518 $ log 'keyword("test a")'
1519 1519
1520 1520 Test first (=limit) and last
1521 1521
1522 1522 $ log 'limit(head(), 1)'
1523 1523 0
1524 1524 $ log 'limit(author("re:bob|test"), 3, 5)'
1525 1525 5
1526 1526 6
1527 1527 7
1528 1528 $ log 'limit(author("re:bob|test"), offset=6)'
1529 1529 6
1530 1530 $ log 'limit(author("re:bob|test"), offset=10)'
1531 1531 $ log 'limit(all(), 1, -1)'
1532 1532 hg: parse error: negative offset
1533 1533 [10]
1534 1534 $ log 'limit(all(), -1)'
1535 1535 hg: parse error: negative number to select
1536 1536 [10]
1537 1537 $ log 'limit(all(), 0)'
1538 1538
1539 1539 $ log 'last(all(), -1)'
1540 1540 hg: parse error: negative number to select
1541 1541 [10]
1542 1542 $ log 'last(all(), 0)'
1543 1543 $ log 'last(all(), 1)'
1544 1544 9
1545 1545 $ log 'last(all(), 2)'
1546 1546 8
1547 1547 9
1548 1548
1549 1549 Test smartset.slice() by first/last()
1550 1550
1551 1551 (using unoptimized set, filteredset as example)
1552 1552
1553 1553 $ hg debugrevspec --no-show-revs -s '0:7 & branch("re:")'
1554 1554 * set:
1555 1555 <filteredset
1556 1556 <spanset+ 0:8>,
1557 1557 <branch 're:'>>
1558 1558 $ log 'limit(0:7 & branch("re:"), 3, 4)'
1559 1559 4
1560 1560 5
1561 1561 6
1562 1562 $ log 'limit(7:0 & branch("re:"), 3, 4)'
1563 1563 3
1564 1564 2
1565 1565 1
1566 1566 $ log 'last(0:7 & branch("re:"), 2)'
1567 1567 6
1568 1568 7
1569 1569
1570 1570 (using baseset)
1571 1571
1572 1572 $ hg debugrevspec --no-show-revs -s 0+1+2+3+4+5+6+7
1573 1573 * set:
1574 1574 <baseset [0, 1, 2, 3, 4, 5, 6, 7]>
1575 1575 $ hg debugrevspec --no-show-revs -s 0::7
1576 1576 * set:
1577 1577 <baseset+ [0, 1, 2, 3, 4, 5, 6, 7]>
1578 1578 $ log 'limit(0+1+2+3+4+5+6+7, 3, 4)'
1579 1579 4
1580 1580 5
1581 1581 6
1582 1582 $ log 'limit(sort(0::7, rev), 3, 4)'
1583 1583 4
1584 1584 5
1585 1585 6
1586 1586 $ log 'limit(sort(0::7, -rev), 3, 4)'
1587 1587 3
1588 1588 2
1589 1589 1
1590 1590 $ log 'last(sort(0::7, rev), 2)'
1591 1591 6
1592 1592 7
1593 1593 $ hg debugrevspec -s 'limit(sort(0::7, rev), 3, 6)'
1594 1594 * set:
1595 1595 <baseset+ [6, 7]>
1596 1596 6
1597 1597 7
1598 1598 $ hg debugrevspec -s 'limit(sort(0::7, rev), 3, 9)'
1599 1599 * set:
1600 1600 <baseset+ []>
1601 1601 $ hg debugrevspec -s 'limit(sort(0::7, -rev), 3, 6)'
1602 1602 * set:
1603 1603 <baseset- [0, 1]>
1604 1604 1
1605 1605 0
1606 1606 $ hg debugrevspec -s 'limit(sort(0::7, -rev), 3, 9)'
1607 1607 * set:
1608 1608 <baseset- []>
1609 1609 $ hg debugrevspec -s 'limit(0::7, 0)'
1610 1610 * set:
1611 1611 <baseset+ []>
1612 1612
1613 1613 (using spanset)
1614 1614
1615 1615 $ hg debugrevspec --no-show-revs -s 0:7
1616 1616 * set:
1617 1617 <spanset+ 0:8>
1618 1618 $ log 'limit(0:7, 3, 4)'
1619 1619 4
1620 1620 5
1621 1621 6
1622 1622 $ log 'limit(7:0, 3, 4)'
1623 1623 3
1624 1624 2
1625 1625 1
1626 1626 $ log 'limit(0:7, 3, 6)'
1627 1627 6
1628 1628 7
1629 1629 $ log 'limit(7:0, 3, 6)'
1630 1630 1
1631 1631 0
1632 1632 $ log 'last(0:7, 2)'
1633 1633 6
1634 1634 7
1635 1635 $ hg debugrevspec -s 'limit(0:7, 3, 6)'
1636 1636 * set:
1637 1637 <spanset+ 6:8>
1638 1638 6
1639 1639 7
1640 1640 $ hg debugrevspec -s 'limit(0:7, 3, 9)'
1641 1641 * set:
1642 1642 <spanset+ 8:8>
1643 1643 $ hg debugrevspec -s 'limit(7:0, 3, 6)'
1644 1644 * set:
1645 1645 <spanset- 0:2>
1646 1646 1
1647 1647 0
1648 1648 $ hg debugrevspec -s 'limit(7:0, 3, 9)'
1649 1649 * set:
1650 1650 <spanset- 0:0>
1651 1651 $ hg debugrevspec -s 'limit(0:7, 0)'
1652 1652 * set:
1653 1653 <spanset+ 0:0>
1654 1654
1655 1655 Test order of first/last revisions
1656 1656
1657 1657 $ hg debugrevspec -s 'first(4:0, 3) & 3:'
1658 1658 * set:
1659 1659 <filteredset
1660 1660 <spanset- 2:5>,
1661 1661 <spanset+ 3:10>>
1662 1662 4
1663 1663 3
1664 1664
1665 1665 $ hg debugrevspec -s '3: & first(4:0, 3)'
1666 1666 * set:
1667 1667 <filteredset
1668 1668 <spanset+ 3:10>,
1669 1669 <spanset- 2:5>>
1670 1670 3
1671 1671 4
1672 1672
1673 1673 $ hg debugrevspec -s 'last(4:0, 3) & :1'
1674 1674 * set:
1675 1675 <filteredset
1676 1676 <spanset- 0:3>,
1677 1677 <spanset+ 0:2>>
1678 1678 1
1679 1679 0
1680 1680
1681 1681 $ hg debugrevspec -s ':1 & last(4:0, 3)'
1682 1682 * set:
1683 1683 <filteredset
1684 1684 <spanset+ 0:2>,
1685 1685 <spanset+ 0:3>>
1686 1686 0
1687 1687 1
1688 1688
1689 1689 Test scmutil.revsingle() should return the last revision
1690 1690
1691 1691 $ hg debugrevspec -s 'last(0::)'
1692 1692 * set:
1693 1693 <baseset slice=0:1
1694 1694 <generatorsetasc->>
1695 1695 9
1696 1696 $ hg identify -r '0::' --num
1697 1697 9
1698 1698
1699 1699 Test matching
1700 1700
1701 1701 $ log 'matching(6)'
1702 1702 6
1703 1703 $ log 'matching(6:7, "phase parents user date branch summary files description substate")'
1704 1704 6
1705 1705 7
1706 1706
1707 1707 Testing min and max
1708 1708
1709 1709 max: simple
1710 1710
1711 1711 $ log 'max(contains(a))'
1712 1712 5
1713 1713
1714 1714 max: simple on unordered set)
1715 1715
1716 1716 $ log 'max((4+0+2+5+7) and contains(a))'
1717 1717 5
1718 1718
1719 1719 max: no result
1720 1720
1721 1721 $ log 'max(contains(stringthatdoesnotappearanywhere))'
1722 1722
1723 1723 max: no result on unordered set
1724 1724
1725 1725 $ log 'max((4+0+2+5+7) and contains(stringthatdoesnotappearanywhere))'
1726 1726
1727 1727 min: simple
1728 1728
1729 1729 $ log 'min(contains(a))'
1730 1730 0
1731 1731
1732 1732 min: simple on unordered set
1733 1733
1734 1734 $ log 'min((4+0+2+5+7) and contains(a))'
1735 1735 0
1736 1736
1737 1737 min: empty
1738 1738
1739 1739 $ log 'min(contains(stringthatdoesnotappearanywhere))'
1740 1740
1741 1741 min: empty on unordered set
1742 1742
1743 1743 $ log 'min((4+0+2+5+7) and contains(stringthatdoesnotappearanywhere))'
1744 1744
1745 1745
1746 1746 $ log 'merge()'
1747 1747 6
1748 1748 $ log 'branchpoint()'
1749 1749 1
1750 1750 4
1751 1751 $ log 'modifies(b)'
1752 1752 4
1753 1753 $ log 'modifies("path:b")'
1754 1754 4
1755 1755 $ log 'modifies("*")'
1756 1756 4
1757 1757 $ log 'modifies("set:modified()")'
1758 1758 4
1759 1759 $ log 'id(5)'
1760 1760 $ log 'only(9)'
1761 1761 8
1762 1762 9
1763 1763 $ log 'only(8)'
1764 1764 8
1765 1765 $ log 'only(9, 5)'
1766 1766 2
1767 1767 4
1768 1768 8
1769 1769 9
1770 1770 $ log 'only(7 + 9, 5 + 2)'
1771 1771 4
1772 1772 6
1773 1773 7
1774 1774 8
1775 1775 9
1776 1776
1777 1777 Test empty set input
1778 1778 $ log 'only(p2())'
1779 1779 $ log 'only(p1(), p2())'
1780 1780 0
1781 1781 1
1782 1782 2
1783 1783 4
1784 1784 8
1785 1785 9
1786 1786
1787 1787 Test '%' operator
1788 1788
1789 1789 $ log '9%'
1790 1790 8
1791 1791 9
1792 1792 $ log '9%5'
1793 1793 2
1794 1794 4
1795 1795 8
1796 1796 9
1797 1797 $ log '(7 + 9)%(5 + 2)'
1798 1798 4
1799 1799 6
1800 1800 7
1801 1801 8
1802 1802 9
1803 1803
1804 1804 Test operand of '%' is optimized recursively (issue4670)
1805 1805
1806 1806 $ try --optimize '8:9-8%'
1807 1807 (onlypost
1808 1808 (minus
1809 1809 (range
1810 1810 (symbol '8')
1811 1811 (symbol '9'))
1812 1812 (symbol '8')))
1813 1813 * optimized:
1814 1814 (func
1815 1815 (symbol 'only')
1816 1816 (difference
1817 1817 (range
1818 1818 (symbol '8')
1819 1819 (symbol '9'))
1820 1820 (symbol '8')))
1821 1821 * set:
1822 1822 <baseset+ [8, 9]>
1823 1823 8
1824 1824 9
1825 1825 $ try --optimize '(9)%(5)'
1826 1826 (only
1827 1827 (group
1828 1828 (symbol '9'))
1829 1829 (group
1830 1830 (symbol '5')))
1831 1831 * optimized:
1832 1832 (func
1833 1833 (symbol 'only')
1834 1834 (list
1835 1835 (symbol '9')
1836 1836 (symbol '5')))
1837 1837 * set:
1838 1838 <baseset+ [2, 4, 8, 9]>
1839 1839 2
1840 1840 4
1841 1841 8
1842 1842 9
1843 1843
1844 1844 Test the order of operations
1845 1845
1846 1846 $ log '7 + 9%5 + 2'
1847 1847 7
1848 1848 2
1849 1849 4
1850 1850 8
1851 1851 9
1852 1852
1853 1853 Test explicit numeric revision
1854 1854 $ log 'rev(-2)'
1855 1855 $ log 'rev(-1)'
1856 1856 -1
1857 1857 $ log 'rev(0)'
1858 1858 0
1859 1859 $ log 'rev(9)'
1860 1860 9
1861 1861 $ log 'rev(10)'
1862 1862 $ log 'rev(tip)'
1863 1863 hg: parse error: rev expects a number
1864 1864 [10]
1865 1865
1866 1866 Test hexadecimal revision
1867 1867 $ log 'id(2)'
1868 1868 $ log 'id(8)'
1869 1869 3
1870 1870 $ hg log --template '{rev}\n' -r 'id(x8)'
1871 1871 3
1872 1872 $ hg log --template '{rev}\n' -r 'x8'
1873 1873 3
1874 1874 $ hg log --template '{rev}\n' -r 'id(x)'
1875 1875 $ hg log --template '{rev}\n' -r 'x'
1876 1876 abort: ambiguous revision identifier: x
1877 1877 [10]
1878 1878 $ log 'id(23268)'
1879 1879 4
1880 1880 $ log 'id(2785f51eece)'
1881 1881 0
1882 1882 $ log 'id(d5d0dcbdc4d9ff5dbb2d336f32f0bb561c1a532c)'
1883 1883 8
1884 1884 $ log 'id(d5d0dcbdc4a)'
1885 1885 $ log 'id(d5d0dcbdc4w)'
1886 1886 $ log 'id(d5d0dcbdc4d9ff5dbb2d336f32f0bb561c1a532d)'
1887 1887 $ log 'id(d5d0dcbdc4d9ff5dbb2d336f32f0bb561c1a532q)'
1888 1888 $ log 'id(1.0)'
1889 1889 $ log 'id(xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)'
1890 1890
1891 1891 Test null revision
1892 1892 $ log '(null)'
1893 1893 -1
1894 1894 $ log '(null:0)'
1895 1895 -1
1896 1896 0
1897 1897 $ log '(0:null)'
1898 1898 0
1899 1899 -1
1900 1900 $ log 'null::0'
1901 1901 -1
1902 1902 0
1903 1903 $ log 'null:tip - 0:'
1904 1904 -1
1905 1905 $ log 'null: and null::' | head -1
1906 1906 -1
1907 1907 $ log 'null: or 0:' | head -2
1908 1908 -1
1909 1909 0
1910 1910 $ log 'ancestors(null)'
1911 1911 -1
1912 1912 $ log 'reverse(null:)' | tail -2
1913 1913 0
1914 1914 -1
1915 1915 $ log 'first(null:)'
1916 1916 -1
1917 1917 $ log 'min(null:)'
1918 1918 BROKEN: should be '-1'
1919 1919 $ log 'tip:null and all()' | tail -2
1920 1920 1
1921 1921 0
1922 1922
1923 1923 Test working-directory revision
1924 1924 $ hg debugrevspec 'wdir()'
1925 1925 2147483647
1926 1926 $ hg debugrevspec 'wdir()^'
1927 1927 9
1928 1928 $ hg up 7
1929 1929 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
1930 1930 $ hg debugrevspec 'wdir()^'
1931 1931 7
1932 1932 $ hg debugrevspec 'wdir()^0'
1933 1933 2147483647
1934 1934 $ hg debugrevspec 'wdir()~3'
1935 1935 5
1936 1936 $ hg debugrevspec 'ancestors(wdir())'
1937 1937 0
1938 1938 1
1939 1939 2
1940 1940 3
1941 1941 4
1942 1942 5
1943 1943 6
1944 1944 7
1945 1945 2147483647
1946 1946 $ hg debugrevspec '0:wdir() & ancestor(wdir())'
1947 1947 2147483647
1948 1948 $ hg debugrevspec '0:wdir() & ancestor(.:wdir())'
1949 1949 4
1950 1950 $ hg debugrevspec '0:wdir() & ancestor(wdir(), wdir())'
1951 1951 2147483647
1952 1952 $ hg debugrevspec '0:wdir() & ancestor(wdir(), tip)'
1953 1953 4
1954 1954 $ hg debugrevspec 'null:wdir() & ancestor(wdir(), null)'
1955 1955 -1
1956 1956 $ hg debugrevspec 'wdir()~0'
1957 1957 2147483647
1958 1958 $ hg debugrevspec 'p1(wdir())'
1959 1959 7
1960 1960 $ hg debugrevspec 'p2(wdir())'
1961 1961 $ hg debugrevspec 'parents(wdir())'
1962 1962 7
1963 1963 $ hg debugrevspec 'wdir()^1'
1964 1964 7
1965 1965 $ hg debugrevspec 'wdir()^2'
1966 1966 $ hg debugrevspec 'wdir()^3'
1967 1967 hg: parse error: ^ expects a number 0, 1, or 2
1968 1968 [10]
1969 1969 For tests consistency
1970 1970 $ hg up 9
1971 1971 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
1972 1972 $ hg debugrevspec 'tip or wdir()'
1973 1973 9
1974 1974 2147483647
1975 1975 $ hg debugrevspec '0:tip and wdir()'
1976 1976 $ log '0:wdir()' | tail -3
1977 1977 8
1978 1978 9
1979 1979 2147483647
1980 1980 $ log 'wdir():0' | head -3
1981 1981 2147483647
1982 1982 9
1983 1983 8
1984 1984 $ log 'wdir():wdir()'
1985 1985 2147483647
1986 1986 $ log '(all() + wdir()) & min(. + wdir())'
1987 1987 9
1988 1988 $ log '(all() + wdir()) & max(. + wdir())'
1989 1989 2147483647
1990 1990 $ log 'first(wdir() + .)'
1991 1991 2147483647
1992 1992 $ log 'last(. + wdir())'
1993 1993 2147483647
1994 1994
1995 1995 Test working-directory integer revision and node id
1996 1996
1997 1997 $ hg debugrevspec '2147483647'
1998 1998 2147483647
1999 1999 $ hg debugrevspec 'rev(2147483647)'
2000 2000 2147483647
2001 2001 $ hg debugrevspec 'ffffffffffffffffffffffffffffffffffffffff'
2002 2002 2147483647
2003 2003 $ hg debugrevspec 'ffffffffffff'
2004 2004 2147483647
2005 2005 $ hg debugrevspec 'id(ffffffffffffffffffffffffffffffffffffffff)'
2006 2006 2147483647
2007 2007 $ hg debugrevspec 'id(ffffffffffff)'
2008 2008 2147483647
2009 2009 $ hg debugrevspec 'ffffffffffff+000000000000'
2010 2010 2147483647
2011 2011 -1
2012 2012
2013 2013 $ cd ..
2014 2014
2015 2015 Test short 'ff...' hash collision
2016 2016
2017 2017 $ hg init wdir-hashcollision
2018 2018 $ cd wdir-hashcollision
2019 2019 $ cat <<EOF >> .hg/hgrc
2020 2020 > [experimental]
2021 2021 > evolution.createmarkers=True
2022 2022 > EOF
2023 2023 $ echo 0 > a
2024 2024 $ hg ci -qAm 0
2025 2025 $ for i in 2463 2961 6726 78127; do
2026 2026 > hg up -q 0
2027 2027 > echo $i > a
2028 2028 > hg ci -qm $i
2029 2029 > done
2030 2030 $ hg up -q null
2031 2031 $ hg log -r '0:wdir()' -T '{rev}:{node} {shortest(node, 3)}\n'
2032 2032 0:b4e73ffab476aa0ee32ed81ca51e07169844bc6a b4e
2033 2033 1:fffbae3886c8fbb2114296380d276fd37715d571 fffba
2034 2034 2:fffb6093b00943f91034b9bdad069402c834e572 fffb6
2035 2035 3:fff48a9b9de34a4d64120c29548214c67980ade3 fff4
2036 2036 4:ffff85cff0ff78504fcdc3c0bc10de0c65379249 ffff8
2037 2037 2147483647:ffffffffffffffffffffffffffffffffffffffff fffff
2038 2038 $ hg debugobsolete fffbae3886c8fbb2114296380d276fd37715d571
2039 2039 1 new obsolescence markers
2040 2040 obsoleted 1 changesets
2041 2041
2042 2042 $ hg debugrevspec 'fff'
2043 2043 abort: ambiguous revision identifier: fff
2044 2044 [10]
2045 2045 $ hg debugrevspec 'ffff'
2046 2046 abort: ambiguous revision identifier: ffff
2047 2047 [10]
2048 2048 $ hg debugrevspec 'fffb'
2049 2049 abort: ambiguous revision identifier: fffb
2050 2050 [10]
2051 2051 BROKEN should be '2' (node lookup uses unfiltered repo)
2052 2052 $ hg debugrevspec 'id(fffb)'
2053 2053 BROKEN should be '2' (node lookup uses unfiltered repo)
2054 2054 $ hg debugrevspec 'ffff8'
2055 2055 4
2056 2056 $ hg debugrevspec 'fffff'
2057 2057 2147483647
2058 2058
2059 2059 $ cd ..
2060 2060
2061 2061 Test branch() with wdir()
2062 2062
2063 2063 $ cd repo
2064 2064
2065 2065 $ log '0:wdir() & branch("literal:Γ©")'
2066 2066 8
2067 2067 9
2068 2068 2147483647
2069 2069 $ log '0:wdir() & branch("re:Γ©")'
2070 2070 8
2071 2071 9
2072 2072 2147483647
2073 2073 $ log '0:wdir() & branch("re:^a")'
2074 2074 0
2075 2075 2
2076 2076 $ log '0:wdir() & branch(8)'
2077 2077 8
2078 2078 9
2079 2079 2147483647
2080 2080
2081 2081 branch(wdir()) returns all revisions belonging to the working branch. The wdir
2082 2082 itself isn't returned unless it is explicitly populated.
2083 2083
2084 2084 $ log 'branch(wdir())'
2085 2085 8
2086 2086 9
2087 2087 $ log '0:wdir() & branch(wdir())'
2088 2088 8
2089 2089 9
2090 2090 2147483647
2091 2091
2092 2092 $ log 'outgoing()'
2093 2093 8
2094 2094 9
2095 2095 $ log 'outgoing("../remote1")'
2096 2096 8
2097 2097 9
2098 2098 $ log 'outgoing("../remote2")'
2099 2099 3
2100 2100 5
2101 2101 6
2102 2102 7
2103 2103 9
2104 2104 $ log 'p1(merge())'
2105 2105 5
2106 2106 $ log 'p2(merge())'
2107 2107 4
2108 2108 $ log 'parents(merge())'
2109 2109 4
2110 2110 5
2111 2111
2112 2112 $ hg merge 7
2113 2113 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
2114 2114 (branch merge, don't forget to commit)
2115 2115 $ log '0:wdir() & merge()'
2116 2116 6
2117 2117 2147483647
2118 2118 $ hg update -qC .
2119 2119 $ log '0:wdir() & merge()'
2120 2120 6
2121 2121
2122 2122 $ log 'p1(branchpoint())'
2123 2123 0
2124 2124 2
2125 2125 $ log 'p2(branchpoint())'
2126 2126 $ log 'parents(branchpoint())'
2127 2127 0
2128 2128 2
2129 2129 $ log 'removes(a)'
2130 2130 2
2131 2131 $ log 'roots(all())'
2132 2132 0
2133 2133 $ log 'reverse(2 or 3 or 4 or 5)'
2134 2134 5
2135 2135 4
2136 2136 3
2137 2137 2
2138 2138 $ log 'reverse(all())'
2139 2139 9
2140 2140 8
2141 2141 7
2142 2142 6
2143 2143 5
2144 2144 4
2145 2145 3
2146 2146 2
2147 2147 1
2148 2148 0
2149 2149 $ log 'reverse(all()) & filelog(b)'
2150 2150 4
2151 2151 1
2152 2152 $ log 'rev(5)'
2153 2153 5
2154 2154 $ log 'sort(limit(reverse(all()), 3))'
2155 2155 7
2156 2156 8
2157 2157 9
2158 2158 $ log 'sort(2 or 3 or 4 or 5, date)'
2159 2159 2
2160 2160 3
2161 2161 5
2162 2162 4
2163 2163 $ log 'tagged()'
2164 2164 6
2165 2165 $ log 'tag()'
2166 2166 6
2167 2167 $ log 'tag(1.0)'
2168 2168 6
2169 2169 $ log 'tag(tip)'
2170 2170 9
2171 2171
2172 2172 Test order of revisions in compound expression
2173 2173 ----------------------------------------------
2174 2174
2175 2175 The general rule is that only the outermost (= leftmost) predicate can
2176 2176 enforce its ordering requirement. The other predicates should take the
2177 2177 ordering defined by it.
2178 2178
2179 2179 'A & B' should follow the order of 'A':
2180 2180
2181 2181 $ log '2:0 & 0::2'
2182 2182 2
2183 2183 1
2184 2184 0
2185 2185
2186 2186 'head()' combines sets in right order:
2187 2187
2188 2188 $ log '2:0 & head()'
2189 2189 2
2190 2190 1
2191 2191 0
2192 2192
2193 2193 'x:y' takes ordering parameter into account:
2194 2194
2195 2195 $ try -p optimized '3:0 & 0:3 & not 2:1'
2196 2196 * optimized:
2197 2197 (difference
2198 2198 (and
2199 2199 (range
2200 2200 (symbol '3')
2201 2201 (symbol '0'))
2202 2202 (range
2203 2203 (symbol '0')
2204 2204 (symbol '3')))
2205 2205 (range
2206 2206 (symbol '2')
2207 2207 (symbol '1')))
2208 2208 * set:
2209 2209 <filteredset
2210 2210 <filteredset
2211 2211 <spanset- 0:4>,
2212 2212 <spanset+ 0:4>>,
2213 2213 <not
2214 2214 <spanset+ 1:3>>>
2215 2215 3
2216 2216 0
2217 2217
2218 2218 'a + b', which is optimized to '_list(a b)', should take the ordering of
2219 2219 the left expression:
2220 2220
2221 2221 $ try --optimize '2:0 & (0 + 1 + 2)'
2222 2222 (and
2223 2223 (range
2224 2224 (symbol '2')
2225 2225 (symbol '0'))
2226 2226 (group
2227 2227 (or
2228 2228 (list
2229 2229 (symbol '0')
2230 2230 (symbol '1')
2231 2231 (symbol '2')))))
2232 2232 * optimized:
2233 2233 (and
2234 2234 (range
2235 2235 (symbol '2')
2236 2236 (symbol '0'))
2237 2237 (func
2238 2238 (symbol '_list')
2239 2239 (string '0\x001\x002')))
2240 2240 * set:
2241 2241 <filteredset
2242 2242 <spanset- 0:3>,
2243 2243 <baseset [0, 1, 2]>>
2244 2244 2
2245 2245 1
2246 2246 0
2247 2247
2248 2248 'A + B' should take the ordering of the left expression:
2249 2249
2250 2250 $ try --optimize '2:0 & (0:1 + 2)'
2251 2251 (and
2252 2252 (range
2253 2253 (symbol '2')
2254 2254 (symbol '0'))
2255 2255 (group
2256 2256 (or
2257 2257 (list
2258 2258 (range
2259 2259 (symbol '0')
2260 2260 (symbol '1'))
2261 2261 (symbol '2')))))
2262 2262 * optimized:
2263 2263 (and
2264 2264 (range
2265 2265 (symbol '2')
2266 2266 (symbol '0'))
2267 2267 (or
2268 2268 (list
2269 2269 (range
2270 2270 (symbol '0')
2271 2271 (symbol '1'))
2272 2272 (symbol '2'))))
2273 2273 * set:
2274 2274 <filteredset
2275 2275 <spanset- 0:3>,
2276 2276 <addset
2277 2277 <spanset+ 0:2>,
2278 2278 <baseset [2]>>>
2279 2279 2
2280 2280 1
2281 2281 0
2282 2282
2283 2283 '_intlist(a b)' should behave like 'a + b':
2284 2284
2285 2285 $ trylist --optimize '2:0 & %ld' 0 1 2
2286 2286 (and
2287 2287 (range
2288 2288 (symbol '2')
2289 2289 (symbol '0'))
2290 2290 (func
2291 2291 (symbol '_intlist')
2292 2292 (string '0\x001\x002')))
2293 2293 * optimized:
2294 2294 (andsmally
2295 2295 (range
2296 2296 (symbol '2')
2297 2297 (symbol '0'))
2298 2298 (func
2299 2299 (symbol '_intlist')
2300 2300 (string '0\x001\x002')))
2301 2301 * set:
2302 2302 <filteredset
2303 2303 <spanset- 0:3>,
2304 2304 <baseset+ [0, 1, 2]>>
2305 2305 2
2306 2306 1
2307 2307 0
2308 2308
2309 2309 $ trylist --optimize '%ld & 2:0' 0 2 1
2310 2310 (and
2311 2311 (func
2312 2312 (symbol '_intlist')
2313 2313 (string '0\x002\x001'))
2314 2314 (range
2315 2315 (symbol '2')
2316 2316 (symbol '0')))
2317 2317 * optimized:
2318 2318 (and
2319 2319 (func
2320 2320 (symbol '_intlist')
2321 2321 (string '0\x002\x001'))
2322 2322 (range
2323 2323 (symbol '2')
2324 2324 (symbol '0')))
2325 2325 * set:
2326 2326 <filteredset
2327 2327 <baseset [0, 2, 1]>,
2328 2328 <spanset- 0:3>>
2329 2329 0
2330 2330 2
2331 2331 1
2332 2332
2333 2333 '_hexlist(a b)' should behave like 'a + b':
2334 2334
2335 2335 $ trylist --optimize --bin '2:0 & %ln' `hg log -T '{node} ' -r0:2`
2336 2336 (and
2337 2337 (range
2338 2338 (symbol '2')
2339 2339 (symbol '0'))
2340 2340 (func
2341 2341 (symbol '_hexlist')
2342 2342 (string '*'))) (glob)
2343 2343 * optimized:
2344 2344 (and
2345 2345 (range
2346 2346 (symbol '2')
2347 2347 (symbol '0'))
2348 2348 (func
2349 2349 (symbol '_hexlist')
2350 2350 (string '*'))) (glob)
2351 2351 * set:
2352 2352 <filteredset
2353 2353 <spanset- 0:3>,
2354 2354 <baseset [0, 1, 2]>>
2355 2355 2
2356 2356 1
2357 2357 0
2358 2358
2359 2359 $ trylist --optimize --bin '%ln & 2:0' `hg log -T '{node} ' -r0+2+1`
2360 2360 (and
2361 2361 (func
2362 2362 (symbol '_hexlist')
2363 2363 (string '*')) (glob)
2364 2364 (range
2365 2365 (symbol '2')
2366 2366 (symbol '0')))
2367 2367 * optimized:
2368 2368 (andsmally
2369 2369 (func
2370 2370 (symbol '_hexlist')
2371 2371 (string '*')) (glob)
2372 2372 (range
2373 2373 (symbol '2')
2374 2374 (symbol '0')))
2375 2375 * set:
2376 2376 <baseset [0, 2, 1]>
2377 2377 0
2378 2378 2
2379 2379 1
2380 2380
2381 2381 '_list' should not go through the slow follow-order path if order doesn't
2382 2382 matter:
2383 2383
2384 2384 $ try -p optimized '2:0 & not (0 + 1)'
2385 2385 * optimized:
2386 2386 (difference
2387 2387 (range
2388 2388 (symbol '2')
2389 2389 (symbol '0'))
2390 2390 (func
2391 2391 (symbol '_list')
2392 2392 (string '0\x001')))
2393 2393 * set:
2394 2394 <filteredset
2395 2395 <spanset- 0:3>,
2396 2396 <not
2397 2397 <baseset [0, 1]>>>
2398 2398 2
2399 2399
2400 2400 $ try -p optimized '2:0 & not (0:2 & (0 + 1))'
2401 2401 * optimized:
2402 2402 (difference
2403 2403 (range
2404 2404 (symbol '2')
2405 2405 (symbol '0'))
2406 2406 (and
2407 2407 (range
2408 2408 (symbol '0')
2409 2409 (symbol '2'))
2410 2410 (func
2411 2411 (symbol '_list')
2412 2412 (string '0\x001'))))
2413 2413 * set:
2414 2414 <filteredset
2415 2415 <spanset- 0:3>,
2416 2416 <not
2417 2417 <baseset [0, 1]>>>
2418 2418 2
2419 2419
2420 2420 because 'present()' does nothing other than suppressing an error, the
2421 2421 ordering requirement should be forwarded to the nested expression
2422 2422
2423 2423 $ try -p optimized 'present(2 + 0 + 1)'
2424 2424 * optimized:
2425 2425 (func
2426 2426 (symbol 'present')
2427 2427 (func
2428 2428 (symbol '_list')
2429 2429 (string '2\x000\x001')))
2430 2430 * set:
2431 2431 <baseset [2, 0, 1]>
2432 2432 2
2433 2433 0
2434 2434 1
2435 2435
2436 2436 $ try --optimize '2:0 & present(0 + 1 + 2)'
2437 2437 (and
2438 2438 (range
2439 2439 (symbol '2')
2440 2440 (symbol '0'))
2441 2441 (func
2442 2442 (symbol 'present')
2443 2443 (or
2444 2444 (list
2445 2445 (symbol '0')
2446 2446 (symbol '1')
2447 2447 (symbol '2')))))
2448 2448 * optimized:
2449 2449 (and
2450 2450 (range
2451 2451 (symbol '2')
2452 2452 (symbol '0'))
2453 2453 (func
2454 2454 (symbol 'present')
2455 2455 (func
2456 2456 (symbol '_list')
2457 2457 (string '0\x001\x002'))))
2458 2458 * set:
2459 2459 <filteredset
2460 2460 <spanset- 0:3>,
2461 2461 <baseset [0, 1, 2]>>
2462 2462 2
2463 2463 1
2464 2464 0
2465 2465
2466 2466 'reverse()' should take effect only if it is the outermost expression:
2467 2467
2468 2468 $ try --optimize '0:2 & reverse(all())'
2469 2469 (and
2470 2470 (range
2471 2471 (symbol '0')
2472 2472 (symbol '2'))
2473 2473 (func
2474 2474 (symbol 'reverse')
2475 2475 (func
2476 2476 (symbol 'all')
2477 2477 None)))
2478 2478 * optimized:
2479 2479 (and
2480 2480 (range
2481 2481 (symbol '0')
2482 2482 (symbol '2'))
2483 2483 (func
2484 2484 (symbol 'reverse')
2485 2485 (func
2486 2486 (symbol 'all')
2487 2487 None)))
2488 2488 * set:
2489 2489 <filteredset
2490 2490 <spanset+ 0:3>,
2491 2491 <spanset+ 0:10>>
2492 2492 0
2493 2493 1
2494 2494 2
2495 2495
2496 2496 'sort()' should take effect only if it is the outermost expression:
2497 2497
2498 2498 $ try --optimize '0:2 & sort(all(), -rev)'
2499 2499 (and
2500 2500 (range
2501 2501 (symbol '0')
2502 2502 (symbol '2'))
2503 2503 (func
2504 2504 (symbol 'sort')
2505 2505 (list
2506 2506 (func
2507 2507 (symbol 'all')
2508 2508 None)
2509 2509 (negate
2510 2510 (symbol 'rev')))))
2511 2511 * optimized:
2512 2512 (and
2513 2513 (range
2514 2514 (symbol '0')
2515 2515 (symbol '2'))
2516 2516 (func
2517 2517 (symbol 'sort')
2518 2518 (list
2519 2519 (func
2520 2520 (symbol 'all')
2521 2521 None)
2522 2522 (string '-rev'))))
2523 2523 * set:
2524 2524 <filteredset
2525 2525 <spanset+ 0:3>,
2526 2526 <spanset+ 0:10>>
2527 2527 0
2528 2528 1
2529 2529 2
2530 2530
2531 2531 invalid argument passed to noop sort():
2532 2532
2533 2533 $ log '0:2 & sort()'
2534 2534 hg: parse error: sort requires one or two arguments
2535 2535 [10]
2536 2536 $ log '0:2 & sort(all(), -invalid)'
2537 2537 hg: parse error: unknown sort key '-invalid'
2538 2538 [10]
2539 2539
2540 2540 for 'A & f(B)', 'B' should not be affected by the order of 'A':
2541 2541
2542 2542 $ try --optimize '2:0 & first(1 + 0 + 2)'
2543 2543 (and
2544 2544 (range
2545 2545 (symbol '2')
2546 2546 (symbol '0'))
2547 2547 (func
2548 2548 (symbol 'first')
2549 2549 (or
2550 2550 (list
2551 2551 (symbol '1')
2552 2552 (symbol '0')
2553 2553 (symbol '2')))))
2554 2554 * optimized:
2555 2555 (and
2556 2556 (range
2557 2557 (symbol '2')
2558 2558 (symbol '0'))
2559 2559 (func
2560 2560 (symbol 'first')
2561 2561 (func
2562 2562 (symbol '_list')
2563 2563 (string '1\x000\x002'))))
2564 2564 * set:
2565 2565 <filteredset
2566 2566 <baseset [1]>,
2567 2567 <spanset- 0:3>>
2568 2568 1
2569 2569
2570 2570 $ try --optimize '2:0 & not last(0 + 2 + 1)'
2571 2571 (and
2572 2572 (range
2573 2573 (symbol '2')
2574 2574 (symbol '0'))
2575 2575 (not
2576 2576 (func
2577 2577 (symbol 'last')
2578 2578 (or
2579 2579 (list
2580 2580 (symbol '0')
2581 2581 (symbol '2')
2582 2582 (symbol '1'))))))
2583 2583 * optimized:
2584 2584 (difference
2585 2585 (range
2586 2586 (symbol '2')
2587 2587 (symbol '0'))
2588 2588 (func
2589 2589 (symbol 'last')
2590 2590 (func
2591 2591 (symbol '_list')
2592 2592 (string '0\x002\x001'))))
2593 2593 * set:
2594 2594 <filteredset
2595 2595 <spanset- 0:3>,
2596 2596 <not
2597 2597 <baseset [1]>>>
2598 2598 2
2599 2599 0
2600 2600
2601 2601 for 'A & (op)(B)', 'B' should not be affected by the order of 'A':
2602 2602
2603 2603 $ try --optimize '2:0 & (1 + 0 + 2):(0 + 2 + 1)'
2604 2604 (and
2605 2605 (range
2606 2606 (symbol '2')
2607 2607 (symbol '0'))
2608 2608 (range
2609 2609 (group
2610 2610 (or
2611 2611 (list
2612 2612 (symbol '1')
2613 2613 (symbol '0')
2614 2614 (symbol '2'))))
2615 2615 (group
2616 2616 (or
2617 2617 (list
2618 2618 (symbol '0')
2619 2619 (symbol '2')
2620 2620 (symbol '1'))))))
2621 2621 * optimized:
2622 2622 (and
2623 2623 (range
2624 2624 (symbol '2')
2625 2625 (symbol '0'))
2626 2626 (range
2627 2627 (func
2628 2628 (symbol '_list')
2629 2629 (string '1\x000\x002'))
2630 2630 (func
2631 2631 (symbol '_list')
2632 2632 (string '0\x002\x001'))))
2633 2633 * set:
2634 2634 <filteredset
2635 2635 <spanset- 0:3>,
2636 2636 <baseset [1]>>
2637 2637 1
2638 2638
2639 2639 'A & B' can be rewritten as 'flipand(B, A)' by weight.
2640 2640
2641 2641 $ try --optimize 'contains("glob:*") & (2 + 0 + 1)'
2642 2642 (and
2643 2643 (func
2644 2644 (symbol 'contains')
2645 2645 (string 'glob:*'))
2646 2646 (group
2647 2647 (or
2648 2648 (list
2649 2649 (symbol '2')
2650 2650 (symbol '0')
2651 2651 (symbol '1')))))
2652 2652 * optimized:
2653 2653 (andsmally
2654 2654 (func
2655 2655 (symbol 'contains')
2656 2656 (string 'glob:*'))
2657 2657 (func
2658 2658 (symbol '_list')
2659 2659 (string '2\x000\x001')))
2660 2660 * set:
2661 2661 <filteredset
2662 2662 <baseset+ [0, 1, 2]>,
2663 2663 <contains 'glob:*'>>
2664 2664 0
2665 2665 1
2666 2666 2
2667 2667
2668 2668 and in this example, 'A & B' is rewritten as 'B & A', but 'A' overrides
2669 2669 the order appropriately:
2670 2670
2671 2671 $ try --optimize 'reverse(contains("glob:*")) & (0 + 2 + 1)'
2672 2672 (and
2673 2673 (func
2674 2674 (symbol 'reverse')
2675 2675 (func
2676 2676 (symbol 'contains')
2677 2677 (string 'glob:*')))
2678 2678 (group
2679 2679 (or
2680 2680 (list
2681 2681 (symbol '0')
2682 2682 (symbol '2')
2683 2683 (symbol '1')))))
2684 2684 * optimized:
2685 2685 (andsmally
2686 2686 (func
2687 2687 (symbol 'reverse')
2688 2688 (func
2689 2689 (symbol 'contains')
2690 2690 (string 'glob:*')))
2691 2691 (func
2692 2692 (symbol '_list')
2693 2693 (string '0\x002\x001')))
2694 2694 * set:
2695 2695 <filteredset
2696 2696 <baseset- [0, 1, 2]>,
2697 2697 <contains 'glob:*'>>
2698 2698 2
2699 2699 1
2700 2700 0
2701 2701
2702 2702 test sort revset
2703 2703 --------------------------------------------
2704 2704
2705 2705 test when adding two unordered revsets
2706 2706
2707 2707 $ log 'sort(keyword(issue) or modifies(b))'
2708 2708 4
2709 2709 6
2710 2710
2711 2711 test when sorting a reversed collection in the same way it is
2712 2712
2713 2713 $ log 'sort(reverse(all()), -rev)'
2714 2714 9
2715 2715 8
2716 2716 7
2717 2717 6
2718 2718 5
2719 2719 4
2720 2720 3
2721 2721 2
2722 2722 1
2723 2723 0
2724 2724
2725 2725 test when sorting a reversed collection
2726 2726
2727 2727 $ log 'sort(reverse(all()), rev)'
2728 2728 0
2729 2729 1
2730 2730 2
2731 2731 3
2732 2732 4
2733 2733 5
2734 2734 6
2735 2735 7
2736 2736 8
2737 2737 9
2738 2738
2739 2739
2740 2740 test sorting two sorted collections in different orders
2741 2741
2742 2742 $ log 'sort(outgoing() or reverse(removes(a)), rev)'
2743 2743 2
2744 2744 8
2745 2745 9
2746 2746
2747 2747 test sorting two sorted collections in different orders backwards
2748 2748
2749 2749 $ log 'sort(outgoing() or reverse(removes(a)), -rev)'
2750 2750 9
2751 2751 8
2752 2752 2
2753 2753
2754 2754 test empty sort key which is noop
2755 2755
2756 2756 $ log 'sort(0 + 2 + 1, "")'
2757 2757 0
2758 2758 2
2759 2759 1
2760 2760
2761 2761 test invalid sort keys
2762 2762
2763 2763 $ log 'sort(all(), -invalid)'
2764 2764 hg: parse error: unknown sort key '-invalid'
2765 2765 [10]
2766 2766
2767 2767 $ cd ..
2768 2768
2769 2769 test sorting by multiple keys including variable-length strings
2770 2770
2771 2771 $ hg init sorting
2772 2772 $ cd sorting
2773 2773 $ cat <<EOF >> .hg/hgrc
2774 2774 > [ui]
2775 2775 > logtemplate = '{rev} {branch|p5}{desc|p5}{author|p5}{date|hgdate}\n'
2776 2776 > [templatealias]
2777 2777 > p5(s) = pad(s, 5)
2778 2778 > EOF
2779 2779 $ hg branch -qf b12
2780 2780 $ hg ci -m m111 -u u112 -d '111 10800'
2781 2781 $ hg branch -qf b11
2782 2782 $ hg ci -m m12 -u u111 -d '112 7200'
2783 2783 $ hg branch -qf b111
2784 2784 $ hg ci -m m11 -u u12 -d '111 3600'
2785 2785 $ hg branch -qf b112
2786 2786 $ hg ci -m m111 -u u11 -d '120 0'
2787 2787 $ hg branch -qf b111
2788 2788 $ hg ci -m m112 -u u111 -d '110 14400'
2789 2789 created new head
2790 2790
2791 2791 compare revisions (has fast path):
2792 2792
2793 2793 $ hg log -r 'sort(all(), rev)'
2794 2794 0 b12 m111 u112 111 10800
2795 2795 1 b11 m12 u111 112 7200
2796 2796 2 b111 m11 u12 111 3600
2797 2797 3 b112 m111 u11 120 0
2798 2798 4 b111 m112 u111 110 14400
2799 2799
2800 2800 $ hg log -r 'sort(all(), -rev)'
2801 2801 4 b111 m112 u111 110 14400
2802 2802 3 b112 m111 u11 120 0
2803 2803 2 b111 m11 u12 111 3600
2804 2804 1 b11 m12 u111 112 7200
2805 2805 0 b12 m111 u112 111 10800
2806 2806
2807 2807 compare variable-length strings (issue5218):
2808 2808
2809 2809 $ hg log -r 'sort(all(), branch)'
2810 2810 1 b11 m12 u111 112 7200
2811 2811 2 b111 m11 u12 111 3600
2812 2812 4 b111 m112 u111 110 14400
2813 2813 3 b112 m111 u11 120 0
2814 2814 0 b12 m111 u112 111 10800
2815 2815
2816 2816 $ hg log -r 'sort(all(), -branch)'
2817 2817 0 b12 m111 u112 111 10800
2818 2818 3 b112 m111 u11 120 0
2819 2819 2 b111 m11 u12 111 3600
2820 2820 4 b111 m112 u111 110 14400
2821 2821 1 b11 m12 u111 112 7200
2822 2822
2823 2823 $ hg log -r 'sort(all(), desc)'
2824 2824 2 b111 m11 u12 111 3600
2825 2825 0 b12 m111 u112 111 10800
2826 2826 3 b112 m111 u11 120 0
2827 2827 4 b111 m112 u111 110 14400
2828 2828 1 b11 m12 u111 112 7200
2829 2829
2830 2830 $ hg log -r 'sort(all(), -desc)'
2831 2831 1 b11 m12 u111 112 7200
2832 2832 4 b111 m112 u111 110 14400
2833 2833 0 b12 m111 u112 111 10800
2834 2834 3 b112 m111 u11 120 0
2835 2835 2 b111 m11 u12 111 3600
2836 2836
2837 2837 $ hg log -r 'sort(all(), user)'
2838 2838 3 b112 m111 u11 120 0
2839 2839 1 b11 m12 u111 112 7200
2840 2840 4 b111 m112 u111 110 14400
2841 2841 0 b12 m111 u112 111 10800
2842 2842 2 b111 m11 u12 111 3600
2843 2843
2844 2844 $ hg log -r 'sort(all(), -user)'
2845 2845 2 b111 m11 u12 111 3600
2846 2846 0 b12 m111 u112 111 10800
2847 2847 1 b11 m12 u111 112 7200
2848 2848 4 b111 m112 u111 110 14400
2849 2849 3 b112 m111 u11 120 0
2850 2850
2851 2851 compare dates (tz offset should have no effect):
2852 2852
2853 2853 $ hg log -r 'sort(all(), date)'
2854 2854 4 b111 m112 u111 110 14400
2855 2855 0 b12 m111 u112 111 10800
2856 2856 2 b111 m11 u12 111 3600
2857 2857 1 b11 m12 u111 112 7200
2858 2858 3 b112 m111 u11 120 0
2859 2859
2860 2860 $ hg log -r 'sort(all(), -date)'
2861 2861 3 b112 m111 u11 120 0
2862 2862 1 b11 m12 u111 112 7200
2863 2863 0 b12 m111 u112 111 10800
2864 2864 2 b111 m11 u12 111 3600
2865 2865 4 b111 m112 u111 110 14400
2866 2866
2867 2867 be aware that 'sort(x, -k)' is not exactly the same as 'reverse(sort(x, k))'
2868 2868 because '-k' reverses the comparison, not the list itself:
2869 2869
2870 2870 $ hg log -r 'sort(0 + 2, date)'
2871 2871 0 b12 m111 u112 111 10800
2872 2872 2 b111 m11 u12 111 3600
2873 2873
2874 2874 $ hg log -r 'sort(0 + 2, -date)'
2875 2875 0 b12 m111 u112 111 10800
2876 2876 2 b111 m11 u12 111 3600
2877 2877
2878 2878 $ hg log -r 'reverse(sort(0 + 2, date))'
2879 2879 2 b111 m11 u12 111 3600
2880 2880 0 b12 m111 u112 111 10800
2881 2881
2882 2882 sort by multiple keys:
2883 2883
2884 2884 $ hg log -r 'sort(all(), "branch -rev")'
2885 2885 1 b11 m12 u111 112 7200
2886 2886 4 b111 m112 u111 110 14400
2887 2887 2 b111 m11 u12 111 3600
2888 2888 3 b112 m111 u11 120 0
2889 2889 0 b12 m111 u112 111 10800
2890 2890
2891 2891 $ hg log -r 'sort(all(), "-desc -node")'
2892 2892 1 b11 m12 u111 112 7200
2893 2893 4 b111 m112 u111 110 14400
2894 2894 3 b112 m111 u11 120 0
2895 2895 0 b12 m111 u112 111 10800
2896 2896 2 b111 m11 u12 111 3600
2897 2897
2898 2898 $ hg log -r 'sort(all(), "user -branch date rev")'
2899 2899 3 b112 m111 u11 120 0
2900 2900 4 b111 m112 u111 110 14400
2901 2901 1 b11 m12 u111 112 7200
2902 2902 0 b12 m111 u112 111 10800
2903 2903 2 b111 m11 u12 111 3600
2904 2904
2905 2905 sort including wdir (rev/-rev has fast path):
2906 2906
2907 2907 $ hg log -r 'sort(. + wdir(), rev)' -T '{rev}\n'
2908 2908 4
2909 2909 2147483647
2910 2910 $ hg log -r 'sort(. + wdir(), -rev)' -T '{rev}\n'
2911 2911 2147483647
2912 2912 4
2913 2913
2914 2914 $ hg log -r 'sort(. + wdir(), "branch rev")' -T '{rev}\n'
2915 2915 4
2916 2916 2147483647
2917 2917 $ hg log -r 'sort(. + wdir(), "branch -rev")' -T '{rev}\n'
2918 2918 2147483647
2919 2919 4
2920 2920
2921 2921 $ hg log -r 'sort(. + wdir(), node)' -T '{node}\n'
2922 2922 ec7c1c90b589ade8603d5fb619dc6c25173a723f
2923 2923 ffffffffffffffffffffffffffffffffffffffff
2924 2924 $ hg log -r 'sort(. + wdir(), -node)' -T '{node}\n'
2925 2925 ffffffffffffffffffffffffffffffffffffffff
2926 2926 ec7c1c90b589ade8603d5fb619dc6c25173a723f
2927 2927
2928 2928 toposort prioritises graph branches
2929 2929
2930 2930 $ hg up 2
2931 2931 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
2932 2932 $ touch a
2933 2933 $ hg addremove
2934 2934 adding a
2935 2935 $ hg ci -m 't1' -u 'tu' -d '130 0'
2936 2936 created new head
2937 2937 $ echo 'a' >> a
2938 2938 $ hg ci -m 't2' -u 'tu' -d '130 0'
2939 2939 $ hg book book1
2940 2940 $ hg up 4
2941 2941 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
2942 2942 (leaving bookmark book1)
2943 2943 $ touch a
2944 2944 $ hg addremove
2945 2945 adding a
2946 2946 $ hg ci -m 't3' -u 'tu' -d '130 0'
2947 2947
2948 2948 $ hg log -r 'sort(all(), topo)'
2949 2949 7 b111 t3 tu 130 0
2950 2950 4 b111 m112 u111 110 14400
2951 2951 3 b112 m111 u11 120 0
2952 2952 6 b111 t2 tu 130 0
2953 2953 5 b111 t1 tu 130 0
2954 2954 2 b111 m11 u12 111 3600
2955 2955 1 b11 m12 u111 112 7200
2956 2956 0 b12 m111 u112 111 10800
2957 2957
2958 2958 $ hg log -r 'sort(all(), -topo)'
2959 2959 0 b12 m111 u112 111 10800
2960 2960 1 b11 m12 u111 112 7200
2961 2961 2 b111 m11 u12 111 3600
2962 2962 5 b111 t1 tu 130 0
2963 2963 6 b111 t2 tu 130 0
2964 2964 3 b112 m111 u11 120 0
2965 2965 4 b111 m112 u111 110 14400
2966 2966 7 b111 t3 tu 130 0
2967 2967
2968 2968 $ hg log -r 'sort(all(), topo, topo.firstbranch=book1)'
2969 2969 6 b111 t2 tu 130 0
2970 2970 5 b111 t1 tu 130 0
2971 2971 7 b111 t3 tu 130 0
2972 2972 4 b111 m112 u111 110 14400
2973 2973 3 b112 m111 u11 120 0
2974 2974 2 b111 m11 u12 111 3600
2975 2975 1 b11 m12 u111 112 7200
2976 2976 0 b12 m111 u112 111 10800
2977 2977
2978 2978 topographical sorting can't be combined with other sort keys, and you can't
2979 2979 use the topo.firstbranch option when topo sort is not active:
2980 2980
2981 2981 $ hg log -r 'sort(all(), "topo user")'
2982 2982 hg: parse error: topo sort order cannot be combined with other sort keys
2983 2983 [10]
2984 2984
2985 2985 $ hg log -r 'sort(all(), user, topo.firstbranch=book1)'
2986 2986 hg: parse error: topo.firstbranch can only be used when using the topo sort key
2987 2987 [10]
2988 2988
2989 2989 topo.firstbranch should accept any kind of expressions:
2990 2990
2991 2991 $ hg log -r 'sort(0, topo, topo.firstbranch=(book1))'
2992 2992 0 b12 m111 u112 111 10800
2993 2993
2994 2994 $ cd ..
2995 2995 $ cd repo
2996 2996
2997 2997 test multiline revset with errors
2998 2998
2999 2999 $ echo > multiline-revset
3000 3000 $ echo '. +' >> multiline-revset
3001 3001 $ echo '.^ +' >> multiline-revset
3002 3002 $ hg log -r "`cat multiline-revset`"
3003 3003 hg: parse error at 9: not a prefix: end
3004 3004 ( . + .^ +
3005 3005 ^ here)
3006 3006 [10]
3007 3007 $ hg debugrevspec -v 'revset(first(rev(0)))' -p all
3008 3008 * parsed:
3009 3009 (func
3010 3010 (symbol 'revset')
3011 3011 (func
3012 3012 (symbol 'first')
3013 3013 (func
3014 3014 (symbol 'rev')
3015 3015 (symbol '0'))))
3016 3016 * expanded:
3017 3017 (func
3018 3018 (symbol 'revset')
3019 3019 (func
3020 3020 (symbol 'first')
3021 3021 (func
3022 3022 (symbol 'rev')
3023 3023 (symbol '0'))))
3024 3024 * concatenated:
3025 3025 (func
3026 3026 (symbol 'revset')
3027 3027 (func
3028 3028 (symbol 'first')
3029 3029 (func
3030 3030 (symbol 'rev')
3031 3031 (symbol '0'))))
3032 3032 * analyzed:
3033 3033 (func
3034 3034 (symbol 'revset')
3035 3035 (func
3036 3036 (symbol 'first')
3037 3037 (func
3038 3038 (symbol 'rev')
3039 3039 (symbol '0'))))
3040 3040 * optimized:
3041 3041 (func
3042 3042 (symbol 'revset')
3043 3043 (func
3044 3044 (symbol 'first')
3045 3045 (func
3046 3046 (symbol 'rev')
3047 3047 (symbol '0'))))
3048 3048 * set:
3049 3049 <baseset+ [0]>
3050 3050 0
3051 3051
3052 3052 abort if the revset doesn't expect given size
3053 3053 $ log 'expectsize()'
3054 3054 hg: parse error: invalid set of arguments
3055 3055 [10]
3056 3056 $ log 'expectsize(0:2, a)'
3057 3057 hg: parse error: expectsize requires a size range or a positive integer
3058 3058 [10]
3059 3059 $ log 'expectsize(0:2, 3)'
3060 3060 0
3061 3061 1
3062 3062 2
3063 3063
3064 3064 $ log 'expectsize(2:0, 3)'
3065 3065 2
3066 3066 1
3067 3067 0
3068 3068 $ log 'expectsize(0:1, 1)'
3069 3069 abort: revset size mismatch. expected 1, got 2
3070 3070 [255]
3071 3071 $ log 'expectsize(0:4, -1)'
3072 3072 hg: parse error: negative size
3073 3073 [10]
3074 3074 $ log 'expectsize(0:2, 2:4)'
3075 3075 0
3076 3076 1
3077 3077 2
3078 3078 $ log 'expectsize(0:1, 3:5)'
3079 3079 abort: revset size mismatch. expected between 3 and 5, got 2
3080 3080 [255]
3081 3081 $ log 'expectsize(0:1, -1:2)'
3082 3082 hg: parse error: negative size
3083 3083 [10]
3084 3084 $ log 'expectsize(0:1, 1:-2)'
3085 3085 hg: parse error: negative size
3086 3086 [10]
3087 3087 $ log 'expectsize(0:2, a:4)'
3088 3088 hg: parse error: size range bounds must be integers
3089 3089 [10]
3090 3090 $ log 'expectsize(0:2, 2:b)'
3091 3091 hg: parse error: size range bounds must be integers
3092 3092 [10]
3093 3093 $ log 'expectsize(0:2, 2:)'
3094 3094 0
3095 3095 1
3096 3096 2
3097 3097 $ log 'expectsize(0:2, :5)'
3098 3098 0
3099 3099 1
3100 3100 2
3101 3101 $ log 'expectsize(0:2, :)'
3102 3102 0
3103 3103 1
3104 3104 2
3105 3105 $ log 'expectsize(0:2, 4:)'
3106 3106 abort: revset size mismatch. expected between 4 and 11, got 3
3107 3107 [255]
3108 3108 $ log 'expectsize(0:2, :2)'
3109 3109 abort: revset size mismatch. expected between 0 and 2, got 3
3110 3110 [255]
3111
3112 Test getting list of node from file
3113
3114 $ hg log -r '0:2' -T '{node}\n' > some.nodes
3115 $ hg log -r 'nodefromfile("some.nodes")' -T '{rev}\n'
3116 0
3117 1
3118 2
3119 $ hg log -r 'nodefromfile("missing-file")' -T '{rev}\n'
3120 abort: cannot open nodes file "missing-file": $ENOENT$
3121 [255]
3122 $ echo bad-node > bad.nodes
3123 $ hg log -r 'nodefromfile("bad.nodes")' -T '{rev}\n'
3124 $ echo abcdefabcdefabcdeabcdeabcdeabcdeabcdeabc > missing.nodes
3125
General Comments 0
You need to be logged in to leave comments. Login now