comparison mercurial/scmutil.py @ 34353:2dbd6d259cd2 stable

cleanupnodes: rename "mapping" to "replacements" The next patch will pass in overrides for bookmark moves, which is a mapping itself, so let's rename "mapping" to "replacements" to distinguish them better. Differential Revision: https://phab.mercurial-scm.org/D749
author Martin von Zweigbergk <martinvonz@google.com>
date Wed, 20 Sep 2017 09:32:26 -0700
parents 033a5befbaf7
children 2f427b57bf90
comparison
equal deleted inserted replaced
34352:033a5befbaf7 34353:2dbd6d259cd2
574 self._revcontains = revcontainer.__contains__ 574 self._revcontains = revcontainer.__contains__
575 575
576 def __contains__(self, node): 576 def __contains__(self, node):
577 return self._revcontains(self._torev(node)) 577 return self._revcontains(self._torev(node))
578 578
579 def cleanupnodes(repo, mapping, operation): 579 def cleanupnodes(repo, replacements, operation):
580 """do common cleanups when old nodes are replaced by new nodes 580 """do common cleanups when old nodes are replaced by new nodes
581 581
582 That includes writing obsmarkers or stripping nodes, and moving bookmarks. 582 That includes writing obsmarkers or stripping nodes, and moving bookmarks.
583 (we might also want to move working directory parent in the future) 583 (we might also want to move working directory parent in the future)
584 584
585 mapping is {oldnode: [newnode]} or a iterable of nodes if they do not have 585 replacements is {oldnode: [newnode]} or a iterable of nodes if they do not
586 replacements. operation is a string, like "rebase". 586 have replacements. operation is a string, like "rebase".
587 """ 587 """
588 if not util.safehasattr(mapping, 'items'): 588 if not util.safehasattr(replacements, 'items'):
589 mapping = {n: () for n in mapping} 589 replacements = {n: () for n in replacements}
590 590
591 # Calculate bookmark movements 591 # Calculate bookmark movements
592 moves = {} 592 moves = {}
593 # Unfiltered repo is needed since nodes in mapping might be hidden. 593 # Unfiltered repo is needed since nodes in replacements might be hidden.
594 unfi = repo.unfiltered() 594 unfi = repo.unfiltered()
595 for oldnode, newnodes in mapping.items(): 595 for oldnode, newnodes in replacements.items():
596 if len(newnodes) > 1: 596 if len(newnodes) > 1:
597 # usually a split, take the one with biggest rev number 597 # usually a split, take the one with biggest rev number
598 newnode = next(unfi.set('max(%ln)', newnodes)).node() 598 newnode = next(unfi.set('max(%ln)', newnodes)).node()
599 elif len(newnodes) == 0: 599 elif len(newnodes) == 0:
600 # move bookmark backwards 600 # move bookmark backwards
601 roots = list(unfi.set('max((::%n) - %ln)', oldnode, 601 roots = list(unfi.set('max((::%n) - %ln)', oldnode,
602 list(mapping))) 602 list(replacements)))
603 if roots: 603 if roots:
604 newnode = roots[0].node() 604 newnode = roots[0].node()
605 else: 605 else:
606 newnode = nullid 606 newnode = nullid
607 else: 607 else:
610 610
611 with repo.transaction('cleanup') as tr: 611 with repo.transaction('cleanup') as tr:
612 # Move bookmarks 612 # Move bookmarks
613 bmarks = repo._bookmarks 613 bmarks = repo._bookmarks
614 bmarkchanges = [] 614 bmarkchanges = []
615 allnewnodes = [n for ns in mapping.values() for n in ns] 615 allnewnodes = [n for ns in replacements.values() for n in ns]
616 for oldnode, newnode in moves.items(): 616 for oldnode, newnode in moves.items():
617 oldbmarks = repo.nodebookmarks(oldnode) 617 oldbmarks = repo.nodebookmarks(oldnode)
618 if not oldbmarks: 618 if not oldbmarks:
619 continue 619 continue
620 from . import bookmarks # avoid import cycle 620 from . import bookmarks # avoid import cycle
642 # NOTE: the filtering and sorting might belong to createmarkers. 642 # NOTE: the filtering and sorting might belong to createmarkers.
643 isobs = unfi.obsstore.successors.__contains__ 643 isobs = unfi.obsstore.successors.__contains__
644 torev = unfi.changelog.rev 644 torev = unfi.changelog.rev
645 sortfunc = lambda ns: torev(ns[0]) 645 sortfunc = lambda ns: torev(ns[0])
646 rels = [(unfi[n], tuple(unfi[m] for m in s)) 646 rels = [(unfi[n], tuple(unfi[m] for m in s))
647 for n, s in sorted(mapping.items(), key=sortfunc) 647 for n, s in sorted(replacements.items(), key=sortfunc)
648 if s or not isobs(n)] 648 if s or not isobs(n)]
649 obsolete.createmarkers(repo, rels, operation=operation) 649 obsolete.createmarkers(repo, rels, operation=operation)
650 else: 650 else:
651 from . import repair # avoid import cycle 651 from . import repair # avoid import cycle
652 repair.delayedstrip(repo.ui, repo, list(mapping), operation) 652 repair.delayedstrip(repo.ui, repo, list(replacements), operation)
653 653
654 def addremove(repo, matcher, prefix, opts=None, dry_run=None, similarity=None): 654 def addremove(repo, matcher, prefix, opts=None, dry_run=None, similarity=None):
655 if opts is None: 655 if opts is None:
656 opts = {} 656 opts = {}
657 m = matcher 657 m = matcher