/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): Martin
  • Date: 2017-06-05 21:50:19 UTC
  • mfrom: (6656.1.3 dict_viewing)
  • Revision ID: breezy.the.bot@gmail.com-20170605215019-uw7s07tx11p194kh
Apply 2to3 dict fixer and clean up with sixish view methods

Merged from https://code.launchpad.net/~gz/brz/dict_viewing/+merge/325108

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
    )
28
32
 
29
33
STEP_UNIQUE_SEARCHER_EVERY = 5
30
34
 
335
339
        """
336
340
        parent_map = self._parents_provider.get_parent_map(keys)
337
341
        parent_child = {}
338
 
        for child, parents in sorted(parent_map.items()):
 
342
        for child, parents in sorted(viewitems(parent_map)):
339
343
            for parent in parents:
340
344
                parent_child.setdefault(parent, []).append(child)
341
345
        return parent_child
358
362
        NULL_REVISION = revision.NULL_REVISION
359
363
        known_revnos[NULL_REVISION] = 0
360
364
 
361
 
        searching_known_tips = list(known_revnos.keys())
 
365
        searching_known_tips = list(known_revnos)
362
366
 
363
367
        unknown_searched = {}
364
368
 
645
649
        # TODO: it might be possible to collapse searchers faster when they
646
650
        #       only have *some* search tips in common.
647
651
        next_unique_searchers = []
648
 
        for searchers in unique_search_tips.itervalues():
 
652
        for searchers in viewvalues(unique_search_tips):
649
653
            if len(searchers) == 1:
650
654
                # Searching unique tips, go for it
651
655
                next_unique_searchers.append(searchers[0])
835
839
                          for c in candidate_heads)
836
840
        active_searchers = dict(searchers)
837
841
        # skip over the actual candidate for each searcher
838
 
        for searcher in active_searchers.itervalues():
 
842
        for searcher in viewvalues(active_searchers):
839
843
            next(searcher)
840
844
        # The common walker finds nodes that are common to two or more of the
841
845
        # input keys, so that we don't access all history when a currently
852
856
            except StopIteration:
853
857
                # No common points being searched at this time.
854
858
                pass
855
 
            for candidate in active_searchers.keys():
 
859
            for candidate in list(active_searchers):
856
860
                try:
857
861
                    searcher = active_searchers[candidate]
858
862
                except KeyError:
878
882
                    # some searcher has encountered our known common nodes:
879
883
                    # just stop it
880
884
                    ancestor_set = {ancestor}
881
 
                    for searcher in searchers.itervalues():
 
885
                    for searcher in viewvalues(searchers):
882
886
                        searcher.stop_searching_any(ancestor_set)
883
887
                else:
884
888
                    # or it may have been just reached by all the searchers:
885
 
                    for searcher in searchers.itervalues():
 
889
                    for searcher in viewvalues(searchers):
886
890
                        if ancestor not in searcher.seen:
887
891
                            break
888
892
                    else:
890
894
                        # making it be known as a descendant of all candidates,
891
895
                        # so we can stop searching it, and any seen ancestors
892
896
                        new_common.add(ancestor)
893
 
                        for searcher in searchers.itervalues():
 
897
                        for searcher in viewvalues(searchers):
894
898
                            seen_ancestors =\
895
899
                                searcher.find_seen_ancestors([ancestor])
896
900
                            searcher.stop_searching_any(seen_ancestors)
1013
1017
            processed.update(pending)
1014
1018
            next_map = self.get_parent_map(pending)
1015
1019
            next_pending = set()
1016
 
            for item in next_map.iteritems():
 
1020
            for item in viewitems(next_map):
1017
1021
                yield item
1018
1022
                next_pending.update(p for p in item[1] if p not in processed)
1019
1023
            ghosts = pending.difference(next_map)
1249
1253
        ## for revision in revisions.intersection(descendants):
1250
1254
        ##   simple_ancestors.difference_update(descendants[revision])
1251
1255
        ## return simple_ancestors
1252
 
        for revision, parent_ids in parent_map.iteritems():
 
1256
        for revision, parent_ids in viewitems(parent_map):
1253
1257
            if parent_ids is None:
1254
1258
                continue
1255
1259
            for parent_id in parent_ids:
1468
1472
        seen.update(revisions)
1469
1473
        parent_map = self._parents_provider.get_parent_map(revisions)
1470
1474
        found_revisions.update(parent_map)
1471
 
        for rev_id, parents in parent_map.iteritems():
 
1475
        for rev_id, parents in viewitems(parent_map):
1472
1476
            if parents is None:
1473
1477
                continue
1474
1478
            new_found_parents = [p for p in parents if p not in seen]
1511
1515
            all_parents = []
1512
1516
            # We don't care if it is a ghost, since it can't be seen if it is
1513
1517
            # a ghost
1514
 
            for parent_ids in parent_map.itervalues():
 
1518
            for parent_ids in viewvalues(parent_map):
1515
1519
                all_parents.extend(parent_ids)
1516
1520
            next_pending = all_seen.intersection(all_parents).difference(seen_ancestors)
1517
1521
            seen_ancestors.update(next_pending)
1556
1560
                    stop_rev_references[parent_id] += 1
1557
1561
            # if only the stopped revisions reference it, the ref count will be
1558
1562
            # 0 after this loop
1559
 
            for parents in self._current_parents.itervalues():
 
1563
            for parents in viewvalues(self._current_parents):
1560
1564
                for parent_id in parents:
1561
1565
                    try:
1562
1566
                        stop_rev_references[parent_id] -= 1
1563
1567
                    except KeyError:
1564
1568
                        pass
1565
1569
            stop_parents = set()
1566
 
            for rev_id, refs in stop_rev_references.iteritems():
 
1570
            for rev_id, refs in viewitems(stop_rev_references):
1567
1571
                if refs == 0:
1568
1572
                    stop_parents.add(rev_id)
1569
1573
            self._next_query.difference_update(stop_parents)
1599
1603
def invert_parent_map(parent_map):
1600
1604
    """Given a map from child => parents, create a map of parent=>children"""
1601
1605
    child_map = {}
1602
 
    for child, parents in parent_map.iteritems():
 
1606
    for child, parents in viewitems(parent_map):
1603
1607
        for p in parents:
1604
1608
            # Any given parent is likely to have only a small handful
1605
1609
            # of children, many will have only one. So we avoid mem overhead of
1651
1655
    # Will not have any nodes removed, even though you do have an
1652
1656
    # 'uninteresting' linear D->B and E->C
1653
1657
    children = {}
1654
 
    for child, parents in parent_map.iteritems():
 
1658
    for child, parents in viewitems(parent_map):
1655
1659
        children.setdefault(child, [])
1656
1660
        for p in parents:
1657
1661
            children.setdefault(p, []).append(child)