/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/graph.py

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2020-02-14 03:16:54 UTC
  • mfrom: (7479.2.3 no-more-python2)
  • Revision ID: breezy.the.bot@gmail.com-20200214031654-bp1xtv2jr9nmhto3
Drop python2 support.

Merged from https://code.launchpad.net/~jelmer/brz/no-more-python2/+merge/378694

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
    revision,
26
26
    trace,
27
27
    )
28
 
from .sixish import (
29
 
    viewitems,
30
 
    viewvalues,
31
 
    )
32
28
 
33
29
STEP_UNIQUE_SEARCHER_EVERY = 5
34
30
 
343
339
        """
344
340
        parent_map = self._parents_provider.get_parent_map(keys)
345
341
        parent_child = {}
346
 
        for child, parents in sorted(viewitems(parent_map)):
 
342
        for child, parents in sorted(parent_map.items()):
347
343
            for parent in parents:
348
344
                parent_child.setdefault(parent, []).append(child)
349
345
        return parent_child
654
650
        # TODO: it might be possible to collapse searchers faster when they
655
651
        #       only have *some* search tips in common.
656
652
        next_unique_searchers = []
657
 
        for searchers in viewvalues(unique_search_tips):
 
653
        for searchers in unique_search_tips.values():
658
654
            if len(searchers) == 1:
659
655
                # Searching unique tips, go for it
660
656
                next_unique_searchers.append(searchers[0])
843
839
                         for c in candidate_heads)
844
840
        active_searchers = dict(searchers)
845
841
        # skip over the actual candidate for each searcher
846
 
        for searcher in viewvalues(active_searchers):
 
842
        for searcher in active_searchers.values():
847
843
            next(searcher)
848
844
        # The common walker finds nodes that are common to two or more of the
849
845
        # input keys, so that we don't access all history when a currently
886
882
                    # some searcher has encountered our known common nodes:
887
883
                    # just stop it
888
884
                    ancestor_set = {ancestor}
889
 
                    for searcher in viewvalues(searchers):
 
885
                    for searcher in searchers.values():
890
886
                        searcher.stop_searching_any(ancestor_set)
891
887
                else:
892
888
                    # or it may have been just reached by all the searchers:
893
 
                    for searcher in viewvalues(searchers):
 
889
                    for searcher in searchers.values():
894
890
                        if ancestor not in searcher.seen:
895
891
                            break
896
892
                    else:
898
894
                        # making it be known as a descendant of all candidates,
899
895
                        # so we can stop searching it, and any seen ancestors
900
896
                        new_common.add(ancestor)
901
 
                        for searcher in viewvalues(searchers):
 
897
                        for searcher in searchers.values():
902
898
                            seen_ancestors =\
903
899
                                searcher.find_seen_ancestors([ancestor])
904
900
                            searcher.stop_searching_any(seen_ancestors)
1021
1017
            processed.update(pending)
1022
1018
            next_map = self.get_parent_map(pending)
1023
1019
            next_pending = set()
1024
 
            for item in viewitems(next_map):
 
1020
            for item in next_map.items():
1025
1021
                yield item
1026
1022
                next_pending.update(p for p in item[1] if p not in processed)
1027
1023
            ghosts = pending.difference(next_map)
1259
1255
        # for revision in revisions.intersection(descendants):
1260
1256
        # simple_ancestors.difference_update(descendants[revision])
1261
1257
        # return simple_ancestors
1262
 
        for revision, parent_ids in viewitems(parent_map):
 
1258
        for revision, parent_ids in parent_map.items():
1263
1259
            if parent_ids is None:
1264
1260
                continue
1265
1261
            for parent_id in parent_ids:
1466
1462
        seen.update(revisions)
1467
1463
        parent_map = self._parents_provider.get_parent_map(revisions)
1468
1464
        found_revisions.update(parent_map)
1469
 
        for rev_id, parents in viewitems(parent_map):
 
1465
        for rev_id, parents in parent_map.items():
1470
1466
            if parents is None:
1471
1467
                continue
1472
1468
            new_found_parents = [p for p in parents if p not in seen]
1509
1505
            all_parents = []
1510
1506
            # We don't care if it is a ghost, since it can't be seen if it is
1511
1507
            # a ghost
1512
 
            for parent_ids in viewvalues(parent_map):
 
1508
            for parent_ids in parent_map.values():
1513
1509
                all_parents.extend(parent_ids)
1514
1510
            next_pending = all_seen.intersection(
1515
1511
                all_parents).difference(seen_ancestors)
1555
1551
                    stop_rev_references[parent_id] += 1
1556
1552
            # if only the stopped revisions reference it, the ref count will be
1557
1553
            # 0 after this loop
1558
 
            for parents in viewvalues(self._current_parents):
 
1554
            for parents in self._current_parents.values():
1559
1555
                for parent_id in parents:
1560
1556
                    try:
1561
1557
                        stop_rev_references[parent_id] -= 1
1562
1558
                    except KeyError:
1563
1559
                        pass
1564
1560
            stop_parents = set()
1565
 
            for rev_id, refs in viewitems(stop_rev_references):
 
1561
            for rev_id, refs in stop_rev_references.items():
1566
1562
                if refs == 0:
1567
1563
                    stop_parents.add(rev_id)
1568
1564
            self._next_query.difference_update(stop_parents)
1598
1594
def invert_parent_map(parent_map):
1599
1595
    """Given a map from child => parents, create a map of parent=>children"""
1600
1596
    child_map = {}
1601
 
    for child, parents in viewitems(parent_map):
 
1597
    for child, parents in parent_map.items():
1602
1598
        for p in parents:
1603
1599
            # Any given parent is likely to have only a small handful
1604
1600
            # of children, many will have only one. So we avoid mem overhead of
1650
1646
    # Will not have any nodes removed, even though you do have an
1651
1647
    # 'uninteresting' linear D->B and E->C
1652
1648
    children = {}
1653
 
    for child, parents in viewitems(parent_map):
 
1649
    for child, parents in parent_map.items():
1654
1650
        children.setdefault(child, [])
1655
1651
        for p in parents:
1656
1652
            children.setdefault(p, []).append(child)