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