/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: Jelmer Vernooij
  • Date: 2018-11-11 04:08:32 UTC
  • mto: (7143.16.20 even-more-cleanups)
  • mto: This revision was merged to the branch mainline in revision 7175.
  • Revision ID: jelmer@jelmer.uk-20181111040832-nsljjynzzwmznf3h
Run autopep8.

Show diffs side-by-side

added added

removed removed

Lines of Context:
141
141
 
142
142
    The cache is enabled by default, but may be disabled and re-enabled.
143
143
    """
 
144
 
144
145
    def __init__(self, parent_provider=None, get_parent_map=None):
145
146
        """Constructor.
146
147
 
376
377
            to_search.update(searching_known_tips)
377
378
            parent_map = self.get_parent_map(to_search)
378
379
            parents = parent_map.get(cur_tip, None)
379
 
            if not parents: # An empty list or None is a ghost
 
380
            if not parents:  # An empty list or None is a ghost
380
381
                raise errors.GhostRevisionsHaveNoRevno(target_revision_id,
381
382
                                                       cur_tip)
382
383
            cur_tip = parents[0]
466
467
 
467
468
        (all_unique_searcher,
468
469
         unique_tip_searchers) = self._make_unique_searchers(unique_nodes,
469
 
                                    unique_searcher, common_searcher)
 
470
                                                             unique_searcher, common_searcher)
470
471
 
471
472
        self._refine_unique_nodes(unique_searcher, all_unique_searcher,
472
473
                                  unique_tip_searchers, common_searcher)
504
505
                next_common_nodes.intersection(unique_searcher.seen))
505
506
            if unique_are_common_nodes:
506
507
                ancestors = unique_searcher.find_seen_ancestors(
507
 
                                unique_are_common_nodes)
 
508
                    unique_are_common_nodes)
508
509
                # TODO: This is a bit overboard, we only really care about
509
510
                #       the ancestors of the tips because the rest we
510
511
                #       already know. This is *correct* but causes us to
511
512
                #       search too much ancestry.
512
 
                ancestors.update(common_searcher.find_seen_ancestors(ancestors))
 
513
                ancestors.update(
 
514
                    common_searcher.find_seen_ancestors(ancestors))
513
515
                unique_searcher.stop_searching_any(ancestors)
514
516
                common_searcher.start_searching(ancestors)
515
517
 
525
527
        :return: (all_unique_searcher, unique_tip_searchers)
526
528
        """
527
529
        unique_tips = self._remove_simple_descendants(unique_nodes,
528
 
                        self.get_parent_map(unique_nodes))
 
530
                                                      self.get_parent_map(unique_nodes))
529
531
 
530
532
        if len(unique_tips) == 1:
531
533
            unique_tip_searchers = []
532
 
            ancestor_all_unique = unique_searcher.find_seen_ancestors(unique_tips)
 
534
            ancestor_all_unique = unique_searcher.find_seen_ancestors(
 
535
                unique_tips)
533
536
        else:
534
537
            unique_tip_searchers = []
535
538
            for tip in unique_tips:
548
551
                    ancestor_all_unique = set(searcher.seen)
549
552
                else:
550
553
                    ancestor_all_unique = ancestor_all_unique.intersection(
551
 
                                                searcher.seen)
 
554
                        searcher.seen)
552
555
        # Collapse all the common nodes into a single searcher
553
556
        all_unique_searcher = self._make_breadth_first_searcher(
554
 
                                ancestor_all_unique)
 
557
            ancestor_all_unique)
555
558
        if ancestor_all_unique:
556
559
            # We've seen these nodes in all the searchers, so we'll just go to
557
560
            # the next
605
608
        for searcher in unique_tip_searchers:
606
609
            common_to_all_unique_nodes.intersection_update(searcher.seen)
607
610
        common_to_all_unique_nodes.intersection_update(
608
 
                                    all_unique_searcher.seen)
 
611
            all_unique_searcher.seen)
609
612
        # Step all-unique less frequently than the other searchers.
610
613
        # In the common case, we don't need to spider out far here, so
611
614
        # avoid doing extra work.
692
695
            # These nodes are common ancestors of all unique nodes
693
696
            common_to_all_unique_nodes = self._find_nodes_common_to_all_unique(
694
697
                unique_tip_searchers, all_unique_searcher, newly_seen_unique,
695
 
                step_all_unique_counter==0)
 
698
                step_all_unique_counter == 0)
696
699
            step_all_unique_counter = ((step_all_unique_counter + 1)
697
700
                                       % STEP_UNIQUE_SEARCHER_EVERY)
698
701
 
839
842
        if len(candidate_heads) < 2:
840
843
            return candidate_heads
841
844
        searchers = dict((c, self._make_breadth_first_searcher([c]))
842
 
                          for c in candidate_heads)
 
845
                         for c in candidate_heads)
843
846
        active_searchers = dict(searchers)
844
847
        # skip over the actual candidate for each searcher
845
848
        for searcher in viewvalues(active_searchers):
935
938
                    break
936
939
                continue
937
940
            parent_ids = self.get_parent_map([next]).get(next, None)
938
 
            if not parent_ids: # Ghost, nothing to search here
 
941
            if not parent_ids:  # Ghost, nothing to search here
939
942
                continue
940
943
            for parent_id in reversed(parent_ids):
941
944
                # TODO: (performance) We see the parent at this point, but we
1032
1035
        if stop_keys is None:
1033
1036
            stop_keys = ()
1034
1037
        next_key = start_key
 
1038
 
1035
1039
        def get_parents(key):
1036
1040
            try:
1037
1041
                return self._parents_provider.get_parent_map([key])[key]
1076
1080
        """
1077
1081
        return ((upper_bound_revid is None or
1078
1082
                    self.is_ancestor(revid, upper_bound_revid)) and
1079
 
               (lower_bound_revid is None or
1080
 
                    self.is_ancestor(lower_bound_revid, revid)))
 
1083
                (lower_bound_revid is None or
 
1084
                     self.is_ancestor(lower_bound_revid, revid)))
1081
1085
 
1082
1086
    def _search_for_extra_common(self, common, searchers):
1083
1087
        """Make sure that unique nodes are genuinely unique.
1116
1120
        left_searcher = searchers[0]
1117
1121
        right_searcher = searchers[1]
1118
1122
        unique = left_searcher.seen.symmetric_difference(right_searcher.seen)
1119
 
        if not unique: # No unique nodes, nothing to do
 
1123
        if not unique:  # No unique nodes, nothing to do
1120
1124
            return
1121
1125
        total_unique = len(unique)
1122
1126
        unique = self._remove_simple_descendants(unique,
1123
 
                    self.get_parent_map(unique))
 
1127
                                                 self.get_parent_map(unique))
1124
1128
        simple_unique = len(unique)
1125
1129
 
1126
1130
        unique_searchers = []
1130
1134
            else:
1131
1135
                parent_searcher = right_searcher
1132
1136
            revs_to_search = parent_searcher.find_seen_ancestors([revision_id])
1133
 
            if not revs_to_search: # XXX: This shouldn't be possible
 
1137
            if not revs_to_search:  # XXX: This shouldn't be possible
1134
1138
                revs_to_search = [revision_id]
1135
1139
            searcher = self._make_breadth_first_searcher(revs_to_search)
1136
1140
            # We don't care about the starting nodes.
1147
1151
                ancestor_all_unique = set(searcher.seen)
1148
1152
            else:
1149
1153
                ancestor_all_unique = ancestor_all_unique.intersection(
1150
 
                                            searcher.seen)
 
1154
                    searcher.seen)
1151
1155
 
1152
1156
        trace.mutter('Started %d unique searchers for %d unique revisions',
1153
1157
                     simple_unique, total_unique)
1154
1158
 
1155
 
        while True: # If we have no more nodes we have nothing to do
 
1159
        while True:  # If we have no more nodes we have nothing to do
1156
1160
            newly_seen_common = set()
1157
1161
            for searcher in common_searchers:
1158
1162
                newly_seen_common.update(searcher.step())
1185
1189
                # If a 'common' node is an ancestor of all unique searchers, we
1186
1190
                # can stop searching it.
1187
1191
                stop_searching_common = ancestor_all_unique.intersection(
1188
 
                                            newly_seen_common)
 
1192
                    newly_seen_common)
1189
1193
                if stop_searching_common:
1190
1194
                    for searcher in common_searchers:
1191
1195
                        searcher.stop_searching_any(stop_searching_common)
1244
1248
 
1245
1249
        # This is the same as the following loop. I don't know that it is any
1246
1250
        # faster.
1247
 
        ## simple_ancestors.difference_update(r for r, p_ids in parent_map.iteritems()
1248
 
        ##     if p_ids is not None and revisions.intersection(p_ids))
1249
 
        ## return simple_ancestors
 
1251
        # simple_ancestors.difference_update(r for r, p_ids in parent_map.iteritems()
 
1252
        # if p_ids is not None and revisions.intersection(p_ids))
 
1253
        # return simple_ancestors
1250
1254
 
1251
1255
        # Yet Another Way, invert the parent map (which can be cached)
1252
1256
        ## descendants = {}
1253
 
        ## for revision_id, parent_ids in parent_map.iteritems():
1254
 
        ##   for p_id in parent_ids:
 
1257
        # for revision_id, parent_ids in parent_map.iteritems():
 
1258
        # for p_id in parent_ids:
1255
1259
        ##       descendants.setdefault(p_id, []).append(revision_id)
1256
 
        ## for revision in revisions.intersection(descendants):
1257
 
        ##   simple_ancestors.difference_update(descendants[revision])
1258
 
        ## return simple_ancestors
 
1260
        # for revision in revisions.intersection(descendants):
 
1261
        # simple_ancestors.difference_update(descendants[revision])
 
1262
        # return simple_ancestors
1259
1263
        for revision, parent_ids in viewitems(parent_map):
1260
1264
            if parent_ids is None:
1261
1265
                continue
1508
1512
            # a ghost
1509
1513
            for parent_ids in viewvalues(parent_map):
1510
1514
                all_parents.extend(parent_ids)
1511
 
            next_pending = all_seen.intersection(all_parents).difference(seen_ancestors)
 
1515
            next_pending = all_seen.intersection(
 
1516
                all_parents).difference(seen_ancestors)
1512
1517
            seen_ancestors.update(next_pending)
1513
1518
            next_pending.difference_update(not_searched_yet)
1514
1519
            pending = next_pending