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