comparison hgext/evolve.py @ 1388:c96e4ab4e5cc

merge with stable
author Pierre-Yves David <pierre-yves.david@fb.com>
date Thu, 18 Jun 2015 17:57:11 -0700
parents 3d2d3333fb0b b5eaec8a53d0
children 35518d26b549
comparison
equal deleted inserted replaced
1373:3d2d3333fb0b 1388:c96e4ab4e5cc
255 return symbol 255 return symbol
256 return dec 256 return dec
257 257
258 258
259 def templatekw(self, keywordname): 259 def templatekw(self, keywordname):
260 """Decorated function is a revset keyword 260 """Decorated function is a template keyword
261 261
262 The name of the keyword must be given as the decorator argument. 262 The name of the keyword must be given as the decorator argument.
263 The symbol is added during `extsetup`. 263 The symbol is added during `extsetup`.
264 264
265 example:: 265 example::
442 revset.getargs(x, 0, 0, 'troubled takes no arguments') 442 revset.getargs(x, 0, 0, 'troubled takes no arguments')
443 troubled = set() 443 troubled = set()
444 troubled.update(getrevs(repo, 'unstable')) 444 troubled.update(getrevs(repo, 'unstable'))
445 troubled.update(getrevs(repo, 'bumped')) 445 troubled.update(getrevs(repo, 'bumped'))
446 troubled.update(getrevs(repo, 'divergent')) 446 troubled.update(getrevs(repo, 'divergent'))
447 return subset & revset.baseset(troubled) 447 troubled = revset.baseset(troubled)
448 troubled.sort() # set is non-ordered, enforce order
449 return subset & troubled
448 450
449 ### Obsolescence graph 451 ### Obsolescence graph
450 452
451 # XXX SOME MAJOR CLEAN UP TO DO HERE XXX 453 # XXX SOME MAJOR CLEAN UP TO DO HERE XXX
452 454
453 def _precursors(repo, s): 455 def _precursors(repo, s):
454 """Precursor of a changeset""" 456 """Precursor of a changeset"""
455 cs = set() 457 cs = set()
456 nm = repo.changelog.nodemap 458 nm = repo.changelog.nodemap
457 markerbysubj = repo.obsstore.precursors 459 markerbysubj = repo.obsstore.precursors
460 node = repo.changelog.node
458 for r in s: 461 for r in s:
459 for p in markerbysubj.get(repo[r].node(), ()): 462 for p in markerbysubj.get(node(r), ()):
460 pr = nm.get(p[0]) 463 pr = nm.get(p[0])
461 if pr is not None: 464 if pr is not None:
462 cs.add(pr) 465 cs.add(pr)
466 cs -= repo.changelog.filteredrevs # nodemap has no filtering
463 return cs 467 return cs
464 468
465 def _allprecursors(repo, s): # XXX we need a better naming 469 def _allprecursors(repo, s): # XXX we need a better naming
466 """transitive precursors of a subset""" 470 """transitive precursors of a subset"""
467 toproceed = [repo[r].node() for r in s] 471 node = repo.changelog.node
472 toproceed = [node(r) for r in s]
468 seen = set() 473 seen = set()
469 allsubjects = repo.obsstore.precursors 474 allsubjects = repo.obsstore.precursors
470 while toproceed: 475 while toproceed:
471 nc = toproceed.pop() 476 nc = toproceed.pop()
472 for mark in allsubjects.get(nc, ()): 477 for mark in allsubjects.get(nc, ()):
478 cs = set() 483 cs = set()
479 for p in seen: 484 for p in seen:
480 pr = nm.get(p) 485 pr = nm.get(p)
481 if pr is not None: 486 if pr is not None:
482 cs.add(pr) 487 cs.add(pr)
488 cs -= repo.changelog.filteredrevs # nodemap has no filtering
483 return cs 489 return cs
484 490
485 def _successors(repo, s): 491 def _successors(repo, s):
486 """Successors of a changeset""" 492 """Successors of a changeset"""
487 cs = set() 493 cs = set()
494 node = repo.changelog.node
488 nm = repo.changelog.nodemap 495 nm = repo.changelog.nodemap
489 markerbyobj = repo.obsstore.successors 496 markerbyobj = repo.obsstore.successors
490 for r in s: 497 for r in s:
491 for p in markerbyobj.get(repo[r].node(), ()): 498 for p in markerbyobj.get(node(r), ()):
492 for sub in p[1]: 499 for sub in p[1]:
493 sr = nm.get(sub) 500 sr = nm.get(sub)
494 if sr is not None: 501 if sr is not None:
495 cs.add(sr) 502 cs.add(sr)
503 cs -= repo.changelog.filteredrevs # nodemap has no filtering
496 return cs 504 return cs
497 505
498 def _allsuccessors(repo, s, haltonflags=0): # XXX we need a better naming 506 def _allsuccessors(repo, s, haltonflags=0): # XXX we need a better naming
499 """transitive successors of a subset 507 """transitive successors of a subset
500 508
501 haltonflags allows to provide flags which prevent the evaluation of a 509 haltonflags allows to provide flags which prevent the evaluation of a
502 marker. """ 510 marker. """
503 toproceed = [repo[r].node() for r in s] 511 node = repo.changelog.node
512 toproceed = [node(r) for r in s]
504 seen = set() 513 seen = set()
505 allobjects = repo.obsstore.successors 514 allobjects = repo.obsstore.successors
506 while toproceed: 515 while toproceed:
507 nc = toproceed.pop() 516 nc = toproceed.pop()
508 for mark in allobjects.get(nc, ()): 517 for mark in allobjects.get(nc, ()):
518 cs = set() 527 cs = set()
519 for s in seen: 528 for s in seen:
520 sr = nm.get(s) 529 sr = nm.get(s)
521 if sr is not None: 530 if sr is not None:
522 cs.add(sr) 531 cs.add(sr)
532 cs -= repo.changelog.filteredrevs # nodemap has no filtering
523 return cs 533 return cs
524 534
525 535
526 536
527 537
538 def revsetsuspended(repo, subset, x): 548 def revsetsuspended(repo, subset, x):
539 """``suspended()`` 549 """``suspended()``
540 Obsolete changesets with non-obsolete descendants. 550 Obsolete changesets with non-obsolete descendants.
541 """ 551 """
542 revset.getargs(x, 0, 0, 'suspended takes no arguments') 552 revset.getargs(x, 0, 0, 'suspended takes no arguments')
543 suspended = getrevs(repo, 'suspended') 553 suspended = revset.baseset(getrevs(repo, 'suspended'))
544 return [r for r in subset if r in suspended] 554 suspended.sort()
555 return subset & suspended
545 556
546 557
547 @eh.revset('precursors') 558 @eh.revset('precursors')
548 def revsetprecursors(repo, subset, x): 559 def revsetprecursors(repo, subset, x):
549 """``precursors(set)`` 560 """``precursors(set)``
550 Immediate precursors of changesets in set. 561 Immediate precursors of changesets in set.
551 """ 562 """
552 s = revset.getset(repo, revset.fullreposet(repo), x) 563 s = revset.getset(repo, revset.fullreposet(repo), x)
553 cs = _precursors(repo, s) 564 s = revset.baseset(_precursors(repo, s))
554 return [r for r in subset if r in cs] 565 s.sort()
566 return subset & s
555 567
556 568
557 @eh.revset('allprecursors') 569 @eh.revset('allprecursors')
558 def revsetallprecursors(repo, subset, x): 570 def revsetallprecursors(repo, subset, x):
559 """``allprecursors(set)`` 571 """``allprecursors(set)``
560 Transitive precursors of changesets in set. 572 Transitive precursors of changesets in set.
561 """ 573 """
562 s = revset.getset(repo, revset.fullreposet(repo), x) 574 s = revset.getset(repo, revset.fullreposet(repo), x)
563 cs = _allprecursors(repo, s) 575 s = revset.baseset(_allprecursors(repo, s))
564 return [r for r in subset if r in cs] 576 s.sort()
577 return subset & s
565 578
566 579
567 @eh.revset('successors') 580 @eh.revset('successors')
568 def revsetsuccessors(repo, subset, x): 581 def revsetsuccessors(repo, subset, x):
569 """``successors(set)`` 582 """``successors(set)``
570 Immediate successors of changesets in set. 583 Immediate successors of changesets in set.
571 """ 584 """
572 s = revset.getset(repo, revset.fullreposet(repo), x) 585 s = revset.getset(repo, revset.fullreposet(repo), x)
573 cs = _successors(repo, s) 586 s = revset.baseset(_successors(repo, s))
574 return [r for r in subset if r in cs] 587 s.sort()
588 return subset & s
575 589
576 @eh.revset('allsuccessors') 590 @eh.revset('allsuccessors')
577 def revsetallsuccessors(repo, subset, x): 591 def revsetallsuccessors(repo, subset, x):
578 """``allsuccessors(set)`` 592 """``allsuccessors(set)``
579 Transitive successors of changesets in set. 593 Transitive successors of changesets in set.
580 """ 594 """
581 s = revset.getset(repo, revset.fullreposet(repo), x) 595 s = revset.getset(repo, revset.fullreposet(repo), x)
582 cs = _allsuccessors(repo, s) 596 s = revset.baseset(_allsuccessors(repo, s))
583 return [r for r in subset if r in cs] 597 s.sort()
598 return subset & s
584 599
585 ### template keywords 600 ### template keywords
586 # XXX it does not handle troubles well :-/ 601 # XXX it does not handle troubles well :-/
587 602
588 @eh.templatekw('obsolete') 603 @eh.templatekw('obsolete')
1738 1753
1739 This only return the first one. 1754 This only return the first one.
1740 1755
1741 XXX this woobly function won't survive XXX 1756 XXX this woobly function won't survive XXX
1742 """ 1757 """
1743 repo = ctx.repo.unfitered() 1758 repo = ctx._repo.unfiltered()
1744 for base in repo.set('reverse(precursors(%d))', ctx): 1759 for base in repo.set('reverse(allprecursors(%d))', ctx):
1745 newer = obsolete.successorssets(ctx._repo, base.node()) 1760 newer = obsolete.successorssets(ctx._repo, base.node())
1746 # drop filter and solution including the original ctx 1761 # drop filter and solution including the original ctx
1747 newer = [n for n in newer if n and ctx.node() not in n] 1762 newer = [n for n in newer if n and ctx.node() not in n]
1748 if newer: 1763 if newer:
1749 return base, tuple(ctx._repo[o] for o in newer[0]) 1764 return base, tuple(ctx._repo[o] for o in newer[0])