/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2490.2.5 by Aaron Bentley
Use GraphWalker.unique_ancestor to determine merge base
1
# Copyright (C) 2007 Canonical Ltd
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
2490.2.28 by Aaron Bentley
Fix handling of null revision
17
from bzrlib import errors
2490.2.21 by Aaron Bentley
Rename graph to deprecated_graph
18
from bzrlib.deprecated_graph import (node_distances, select_farthest)
2490.2.1 by Aaron Bentley
Start work on GraphWalker
19
from bzrlib.revision import NULL_REVISION
20
2490.2.25 by Aaron Bentley
Update from review
21
# DIAGRAM of terminology
22
#       A
23
#       /\
24
#      B  C
25
#      |  |\
26
#      D  E F
27
#      |\/| |
28
#      |/\|/
29
#      G  H
30
#
31
# In this diagram, relative to G and H:
32
# A, B, C, D, E are common ancestors.
33
# C, D and E are border ancestors, because each has a non-common descendant.
34
# D and E are least common ancestors because none of their descendants are
35
# common ancestors.
36
# C is not a least common ancestor because its descendant, E, is a common
37
# ancestor.
38
#
39
# The find_unique_lca algorithm will pick A in two steps:
40
# 1. find_lca('G', 'H') => ['D', 'E']
41
# 2. Since len(['D', 'E']) > 1, find_lca('D', 'E') => ['A']
42
43
2490.2.5 by Aaron Bentley
Use GraphWalker.unique_ancestor to determine merge base
44
2490.2.13 by Aaron Bentley
Update distinct -> lowest, refactor, add ParentsProvider concept
45
class _StackedParentsProvider(object):
46
47
    def __init__(self, parent_providers):
48
        self._parent_providers = parent_providers
49
2490.2.28 by Aaron Bentley
Fix handling of null revision
50
    def __repr__(self):
51
        return "_StackedParentsProvider(%r)" % self._parent_providers
52
2490.2.13 by Aaron Bentley
Update distinct -> lowest, refactor, add ParentsProvider concept
53
    def get_parents(self, revision_ids):
2490.2.25 by Aaron Bentley
Update from review
54
        """Find revision ids of the parents of a list of revisions
2490.2.13 by Aaron Bentley
Update distinct -> lowest, refactor, add ParentsProvider concept
55
56
        A list is returned of the same length as the input.  Each entry
57
        is a list of parent ids for the corresponding input revision.
58
59
        [NULL_REVISION] is used as the parent of the first user-committed
60
        revision.  Its parent list is empty.
61
62
        If the revision is not present (i.e. a ghost), None is used in place
63
        of the list of parents.
64
        """
65
        found = {}
66
        for parents_provider in self._parent_providers:
2490.2.25 by Aaron Bentley
Update from review
67
            pending_revisions = [r for r in revision_ids if r not in found]
68
            parent_list = parents_provider.get_parents(pending_revisions)
69
            new_found = dict((k, v) for k, v in zip(pending_revisions,
70
                             parent_list) if v is not None)
2490.2.13 by Aaron Bentley
Update distinct -> lowest, refactor, add ParentsProvider concept
71
            found.update(new_found)
72
            if len(found) == len(revision_ids):
73
                break
2490.2.25 by Aaron Bentley
Update from review
74
        return [found.get(r, None) for r in revision_ids]
2490.2.13 by Aaron Bentley
Update distinct -> lowest, refactor, add ParentsProvider concept
75
76
2490.2.22 by Aaron Bentley
Rename GraphWalker -> Graph, _AncestryWalker -> _BreadthFirstSearcher
77
class Graph(object):
2490.2.10 by Aaron Bentley
Clarify text, remove unused _get_ancestry method
78
    """Provide incremental access to revision graphs.
79
80
    This is the generic implementation; it is intended to be subclassed to
81
    specialize it for other repository types.
82
    """
2490.2.1 by Aaron Bentley
Start work on GraphWalker
83
2490.2.13 by Aaron Bentley
Update distinct -> lowest, refactor, add ParentsProvider concept
84
    def __init__(self, parents_provider):
2490.2.22 by Aaron Bentley
Rename GraphWalker -> Graph, _AncestryWalker -> _BreadthFirstSearcher
85
        """Construct a Graph that uses several graphs as its input
2490.2.10 by Aaron Bentley
Clarify text, remove unused _get_ancestry method
86
87
        This should not normally be invoked directly, because there may be
88
        specialized implementations for particular repository types.  See
2490.2.21 by Aaron Bentley
Rename graph to deprecated_graph
89
        Repository.get_graph()
2490.2.10 by Aaron Bentley
Clarify text, remove unused _get_ancestry method
90
2490.2.22 by Aaron Bentley
Rename GraphWalker -> Graph, _AncestryWalker -> _BreadthFirstSearcher
91
        :param parents_func: an object providing a get_parents call
92
            conforming to the behavior of StackedParentsProvider.get_parents
2490.2.13 by Aaron Bentley
Update distinct -> lowest, refactor, add ParentsProvider concept
93
        """
94
        self.get_parents = parents_provider.get_parents
2490.2.29 by Aaron Bentley
Make parents provider private
95
        self._parents_provider = parents_provider
2490.2.28 by Aaron Bentley
Fix handling of null revision
96
97
    def __repr__(self):
2490.2.29 by Aaron Bentley
Make parents provider private
98
        return 'Graph(%r)' % self._parents_provider
2490.2.13 by Aaron Bentley
Update distinct -> lowest, refactor, add ParentsProvider concept
99
100
    def find_lca(self, *revisions):
101
        """Determine the lowest common ancestors of the provided revisions
102
103
        A lowest common ancestor is a common ancestor none of whose
104
        descendants are common ancestors.  In graphs, unlike trees, there may
105
        be multiple lowest common ancestors.
2490.2.12 by Aaron Bentley
Improve documentation
106
107
        This algorithm has two phases.  Phase 1 identifies border ancestors,
2490.2.13 by Aaron Bentley
Update distinct -> lowest, refactor, add ParentsProvider concept
108
        and phase 2 filters border ancestors to determine lowest common
109
        ancestors.
2490.2.12 by Aaron Bentley
Improve documentation
110
111
        In phase 1, border ancestors are identified, using a breadth-first
112
        search starting at the bottom of the graph.  Searches are stopped
113
        whenever a node or one of its descendants is determined to be common
114
2490.2.13 by Aaron Bentley
Update distinct -> lowest, refactor, add ParentsProvider concept
115
        In phase 2, the border ancestors are filtered to find the least
2490.2.12 by Aaron Bentley
Improve documentation
116
        common ancestors.  This is done by searching the ancestries of each
117
        border ancestor.
118
2490.2.13 by Aaron Bentley
Update distinct -> lowest, refactor, add ParentsProvider concept
119
        Phase 2 is perfomed on the principle that a border ancestor that is
120
        not an ancestor of any other border ancestor is a least common
121
        ancestor.
2490.2.12 by Aaron Bentley
Improve documentation
122
123
        Searches are stopped when they find a node that is determined to be a
124
        common ancestor of all border ancestors, because this shows that it
125
        cannot be a descendant of any border ancestor.
126
127
        The scaling of this operation should be proportional to
128
        1. The number of uncommon ancestors
129
        2. The number of border ancestors
130
        3. The length of the shortest path between a border ancestor and an
131
           ancestor of all border ancestors.
2490.2.3 by Aaron Bentley
Implement new merge base picker
132
        """
2490.2.23 by Aaron Bentley
Adapt find_borders to produce a graph difference
133
        border_common, common, sides = self._find_border_ancestors(revisions)
2490.2.13 by Aaron Bentley
Update distinct -> lowest, refactor, add ParentsProvider concept
134
        return self._filter_candidate_lca(border_common)
2490.2.9 by Aaron Bentley
Fix minimal common ancestor algorithm for non-minimal perhipheral ancestors
135
2490.2.23 by Aaron Bentley
Adapt find_borders to produce a graph difference
136
    def find_difference(self, left_revision, right_revision):
2490.2.25 by Aaron Bentley
Update from review
137
        """Determine the graph difference between two revisions"""
2490.2.23 by Aaron Bentley
Adapt find_borders to produce a graph difference
138
        border, common, (left, right) = self._find_border_ancestors(
139
            [left_revision, right_revision])
140
        return (left.difference(right).difference(common),
141
                right.difference(left).difference(common))
142
2490.2.22 by Aaron Bentley
Rename GraphWalker -> Graph, _AncestryWalker -> _BreadthFirstSearcher
143
    def _make_breadth_first_searcher(self, revisions):
144
        return _BreadthFirstSearcher(revisions, self)
145
2490.2.10 by Aaron Bentley
Clarify text, remove unused _get_ancestry method
146
    def _find_border_ancestors(self, revisions):
2490.2.12 by Aaron Bentley
Improve documentation
147
        """Find common ancestors with at least one uncommon descendant.
148
149
        Border ancestors are identified using a breadth-first
150
        search starting at the bottom of the graph.  Searches are stopped
151
        whenever a node or one of its descendants is determined to be common.
152
153
        This will scale with the number of uncommon ancestors.
2490.2.25 by Aaron Bentley
Update from review
154
155
        As well as the border ancestors, a set of seen common ancestors and a
156
        list of sets of seen ancestors for each input revision is returned.
157
        This allows calculation of graph difference from the results of this
158
        operation.
2490.2.12 by Aaron Bentley
Improve documentation
159
        """
2490.2.28 by Aaron Bentley
Fix handling of null revision
160
        if None in revisions:
161
            raise errors.InvalidRevisionId(None, self)
2490.2.22 by Aaron Bentley
Rename GraphWalker -> Graph, _AncestryWalker -> _BreadthFirstSearcher
162
        common_searcher = self._make_breadth_first_searcher([])
2490.2.19 by Aaron Bentley
Implement common-ancestor-based culling
163
        common_ancestors = set()
2490.2.22 by Aaron Bentley
Rename GraphWalker -> Graph, _AncestryWalker -> _BreadthFirstSearcher
164
        searchers = [self._make_breadth_first_searcher([r])
165
                     for r in revisions]
166
        active_searchers = searchers[:]
2490.2.13 by Aaron Bentley
Update distinct -> lowest, refactor, add ParentsProvider concept
167
        border_ancestors = set()
2490.2.22 by Aaron Bentley
Rename GraphWalker -> Graph, _AncestryWalker -> _BreadthFirstSearcher
168
        def update_common(searcher, revisions):
169
            w_seen_ancestors = searcher.find_seen_ancestors(
2490.2.19 by Aaron Bentley
Implement common-ancestor-based culling
170
                revision)
2490.2.22 by Aaron Bentley
Rename GraphWalker -> Graph, _AncestryWalker -> _BreadthFirstSearcher
171
            stopped = searcher.stop_searching_any(w_seen_ancestors)
2490.2.19 by Aaron Bentley
Implement common-ancestor-based culling
172
            common_ancestors.update(w_seen_ancestors)
2490.2.22 by Aaron Bentley
Rename GraphWalker -> Graph, _AncestryWalker -> _BreadthFirstSearcher
173
            common_searcher.start_searching(stopped)
2490.2.19 by Aaron Bentley
Implement common-ancestor-based culling
174
2490.2.7 by Aaron Bentley
Start implementing mca that scales with number of uncommon ancestors
175
        while True:
2490.2.22 by Aaron Bentley
Rename GraphWalker -> Graph, _AncestryWalker -> _BreadthFirstSearcher
176
            if len(active_searchers) == 0:
2490.2.23 by Aaron Bentley
Adapt find_borders to produce a graph difference
177
                return border_ancestors, common_ancestors, [s.seen for s in
178
                                                            searchers]
2490.2.19 by Aaron Bentley
Implement common-ancestor-based culling
179
            try:
2490.2.22 by Aaron Bentley
Rename GraphWalker -> Graph, _AncestryWalker -> _BreadthFirstSearcher
180
                new_common = common_searcher.next()
2490.2.19 by Aaron Bentley
Implement common-ancestor-based culling
181
                common_ancestors.update(new_common)
182
            except StopIteration:
183
                pass
184
            else:
2490.2.22 by Aaron Bentley
Rename GraphWalker -> Graph, _AncestryWalker -> _BreadthFirstSearcher
185
                for searcher in active_searchers:
186
                    for revision in new_common.intersection(searcher.seen):
187
                        update_common(searcher, revision)
2490.2.19 by Aaron Bentley
Implement common-ancestor-based culling
188
2490.2.7 by Aaron Bentley
Start implementing mca that scales with number of uncommon ancestors
189
            newly_seen = set()
2490.2.22 by Aaron Bentley
Rename GraphWalker -> Graph, _AncestryWalker -> _BreadthFirstSearcher
190
            new_active_searchers = []
191
            for searcher in active_searchers:
2490.2.7 by Aaron Bentley
Start implementing mca that scales with number of uncommon ancestors
192
                try:
2490.2.22 by Aaron Bentley
Rename GraphWalker -> Graph, _AncestryWalker -> _BreadthFirstSearcher
193
                    newly_seen.update(searcher.next())
2490.2.7 by Aaron Bentley
Start implementing mca that scales with number of uncommon ancestors
194
                except StopIteration:
195
                    pass
196
                else:
2490.2.22 by Aaron Bentley
Rename GraphWalker -> Graph, _AncestryWalker -> _BreadthFirstSearcher
197
                    new_active_searchers.append(searcher)
198
            active_searchers = new_active_searchers
2490.2.7 by Aaron Bentley
Start implementing mca that scales with number of uncommon ancestors
199
            for revision in newly_seen:
2490.2.19 by Aaron Bentley
Implement common-ancestor-based culling
200
                if revision in common_ancestors:
2490.2.22 by Aaron Bentley
Rename GraphWalker -> Graph, _AncestryWalker -> _BreadthFirstSearcher
201
                    for searcher in searchers:
202
                        update_common(searcher, revision)
2490.2.19 by Aaron Bentley
Implement common-ancestor-based culling
203
                    continue
2490.2.22 by Aaron Bentley
Rename GraphWalker -> Graph, _AncestryWalker -> _BreadthFirstSearcher
204
                for searcher in searchers:
205
                    if revision not in searcher.seen:
2490.2.7 by Aaron Bentley
Start implementing mca that scales with number of uncommon ancestors
206
                        break
207
                else:
2490.2.13 by Aaron Bentley
Update distinct -> lowest, refactor, add ParentsProvider concept
208
                    border_ancestors.add(revision)
2490.2.22 by Aaron Bentley
Rename GraphWalker -> Graph, _AncestryWalker -> _BreadthFirstSearcher
209
                    for searcher in searchers:
210
                        update_common(searcher, revision)
2490.2.9 by Aaron Bentley
Fix minimal common ancestor algorithm for non-minimal perhipheral ancestors
211
2490.2.13 by Aaron Bentley
Update distinct -> lowest, refactor, add ParentsProvider concept
212
    def _filter_candidate_lca(self, candidate_lca):
2490.2.12 by Aaron Bentley
Improve documentation
213
        """Remove candidates which are ancestors of other candidates.
214
215
        This is done by searching the ancestries of each border ancestor.  It
216
        is perfomed on the principle that a border ancestor that is not an
2490.2.13 by Aaron Bentley
Update distinct -> lowest, refactor, add ParentsProvider concept
217
        ancestor of any other border ancestor is a lowest common ancestor.
2490.2.12 by Aaron Bentley
Improve documentation
218
219
        Searches are stopped when they find a node that is determined to be a
220
        common ancestor of all border ancestors, because this shows that it
221
        cannot be a descendant of any border ancestor.
222
223
        This will scale with the number of candidate ancestors and the length
224
        of the shortest path from a candidate to an ancestor common to all
225
        candidates.
226
        """
2490.2.22 by Aaron Bentley
Rename GraphWalker -> Graph, _AncestryWalker -> _BreadthFirstSearcher
227
        searchers = dict((c, self._make_breadth_first_searcher([c]))
228
                          for c in candidate_lca)
229
        active_searchers = dict(searchers)
230
        # skip over the actual candidate for each searcher
231
        for searcher in active_searchers.itervalues():
232
            searcher.next()
233
        while len(active_searchers) > 0:
234
            for candidate, searcher in list(active_searchers.iteritems()):
2490.2.9 by Aaron Bentley
Fix minimal common ancestor algorithm for non-minimal perhipheral ancestors
235
                try:
2490.2.22 by Aaron Bentley
Rename GraphWalker -> Graph, _AncestryWalker -> _BreadthFirstSearcher
236
                    ancestors = searcher.next()
2490.2.9 by Aaron Bentley
Fix minimal common ancestor algorithm for non-minimal perhipheral ancestors
237
                except StopIteration:
2490.2.22 by Aaron Bentley
Rename GraphWalker -> Graph, _AncestryWalker -> _BreadthFirstSearcher
238
                    del active_searchers[candidate]
2490.2.9 by Aaron Bentley
Fix minimal common ancestor algorithm for non-minimal perhipheral ancestors
239
                    continue
240
                for ancestor in ancestors:
2490.2.13 by Aaron Bentley
Update distinct -> lowest, refactor, add ParentsProvider concept
241
                    if ancestor in candidate_lca:
242
                        candidate_lca.remove(ancestor)
2490.2.22 by Aaron Bentley
Rename GraphWalker -> Graph, _AncestryWalker -> _BreadthFirstSearcher
243
                        del searchers[ancestor]
244
                        if ancestor in active_searchers:
245
                            del active_searchers[ancestor]
246
                    for searcher in searchers.itervalues():
247
                        if ancestor not in searcher.seen:
2490.2.9 by Aaron Bentley
Fix minimal common ancestor algorithm for non-minimal perhipheral ancestors
248
                            break
249
                    else:
2490.2.22 by Aaron Bentley
Rename GraphWalker -> Graph, _AncestryWalker -> _BreadthFirstSearcher
250
                        # if this revision was seen by all searchers, then it
2490.2.9 by Aaron Bentley
Fix minimal common ancestor algorithm for non-minimal perhipheral ancestors
251
                        # is a descendant of all candidates, so we can stop
2490.2.10 by Aaron Bentley
Clarify text, remove unused _get_ancestry method
252
                        # searching it, and any seen ancestors
2490.2.22 by Aaron Bentley
Rename GraphWalker -> Graph, _AncestryWalker -> _BreadthFirstSearcher
253
                        for searcher in searchers.itervalues():
2490.2.9 by Aaron Bentley
Fix minimal common ancestor algorithm for non-minimal perhipheral ancestors
254
                            seen_ancestors =\
2490.2.22 by Aaron Bentley
Rename GraphWalker -> Graph, _AncestryWalker -> _BreadthFirstSearcher
255
                                searcher.find_seen_ancestors(ancestor)
256
                            searcher.stop_searching_any(seen_ancestors)
2490.2.13 by Aaron Bentley
Update distinct -> lowest, refactor, add ParentsProvider concept
257
        return candidate_lca
258
259
    def find_unique_lca(self, left_revision, right_revision):
260
        """Find a unique LCA.
261
262
        Find lowest common ancestors.  If there is no unique  common
263
        ancestor, find the lowest common ancestors of those ancestors.
264
265
        Iteration stops when a unique lowest common ancestor is found.
266
        The graph origin is necessarily a unique lowest common ancestor.
2490.2.5 by Aaron Bentley
Use GraphWalker.unique_ancestor to determine merge base
267
268
        Note that None is not an acceptable substitute for NULL_REVISION.
2490.2.13 by Aaron Bentley
Update distinct -> lowest, refactor, add ParentsProvider concept
269
        in the input for this method.
2490.2.3 by Aaron Bentley
Implement new merge base picker
270
        """
271
        revisions = [left_revision, right_revision]
272
        while True:
2490.2.13 by Aaron Bentley
Update distinct -> lowest, refactor, add ParentsProvider concept
273
            lca = self.find_lca(*revisions)
274
            if len(lca) == 1:
275
                return lca.pop()
276
            revisions = lca
2490.2.7 by Aaron Bentley
Start implementing mca that scales with number of uncommon ancestors
277
278
2490.2.22 by Aaron Bentley
Rename GraphWalker -> Graph, _AncestryWalker -> _BreadthFirstSearcher
279
class _BreadthFirstSearcher(object):
280
    """Parallel search the breadth-first the ancestry of revisions.
2490.2.10 by Aaron Bentley
Clarify text, remove unused _get_ancestry method
281
282
    This class implements the iterator protocol, but additionally
283
    1. provides a set of seen ancestors, and
284
    2. allows some ancestries to be unsearched, via stop_searching_any
285
    """
2490.2.7 by Aaron Bentley
Start implementing mca that scales with number of uncommon ancestors
286
2490.2.22 by Aaron Bentley
Rename GraphWalker -> Graph, _AncestryWalker -> _BreadthFirstSearcher
287
    def __init__(self, revisions, parents_provider):
2490.2.18 by Aaron Bentley
Change AncestryWalker to take a set of ancestors
288
        self._start = set(revisions)
2490.2.10 by Aaron Bentley
Clarify text, remove unused _get_ancestry method
289
        self._search_revisions = None
2490.2.18 by Aaron Bentley
Change AncestryWalker to take a set of ancestors
290
        self.seen = set(revisions)
2490.2.22 by Aaron Bentley
Rename GraphWalker -> Graph, _AncestryWalker -> _BreadthFirstSearcher
291
        self._parents_provider = parents_provider 
2490.2.7 by Aaron Bentley
Start implementing mca that scales with number of uncommon ancestors
292
293
    def __repr__(self):
2490.2.25 by Aaron Bentley
Update from review
294
        return ('_BreadthFirstSearcher(self._search_revisions=%r,'
295
                ' self.seen=%r)' % (self._search_revisions, self.seen))
2490.2.7 by Aaron Bentley
Start implementing mca that scales with number of uncommon ancestors
296
297
    def next(self):
2490.2.10 by Aaron Bentley
Clarify text, remove unused _get_ancestry method
298
        """Return the next ancestors of this revision.
299
2490.2.12 by Aaron Bentley
Improve documentation
300
        Ancestors are returned in the order they are seen in a breadth-first
301
        traversal.  No ancestor will be returned more than once.
2490.2.10 by Aaron Bentley
Clarify text, remove unused _get_ancestry method
302
        """
303
        if self._search_revisions is None:
304
            self._search_revisions = self._start
2490.2.7 by Aaron Bentley
Start implementing mca that scales with number of uncommon ancestors
305
        else:
2490.2.10 by Aaron Bentley
Clarify text, remove unused _get_ancestry method
306
            new_search_revisions = set()
2490.2.22 by Aaron Bentley
Rename GraphWalker -> Graph, _AncestryWalker -> _BreadthFirstSearcher
307
            for parents in self._parents_provider.get_parents(
2490.2.13 by Aaron Bentley
Update distinct -> lowest, refactor, add ParentsProvider concept
308
                self._search_revisions):
309
                if parents is None:
310
                    continue
311
                new_search_revisions.update(p for p in parents if
312
                                            p not in self.seen)
2490.2.10 by Aaron Bentley
Clarify text, remove unused _get_ancestry method
313
            self._search_revisions = new_search_revisions
314
        if len(self._search_revisions) == 0:
2490.2.7 by Aaron Bentley
Start implementing mca that scales with number of uncommon ancestors
315
            raise StopIteration()
2490.2.10 by Aaron Bentley
Clarify text, remove unused _get_ancestry method
316
        self.seen.update(self._search_revisions)
317
        return self._search_revisions
2490.2.7 by Aaron Bentley
Start implementing mca that scales with number of uncommon ancestors
318
2490.2.8 by Aaron Bentley
fix iteration stuff
319
    def __iter__(self):
320
        return self
2490.2.7 by Aaron Bentley
Start implementing mca that scales with number of uncommon ancestors
321
322
    def find_seen_ancestors(self, revision):
2490.2.25 by Aaron Bentley
Update from review
323
        """Find ancestors of this revision that have already been seen."""
2490.2.22 by Aaron Bentley
Rename GraphWalker -> Graph, _AncestryWalker -> _BreadthFirstSearcher
324
        searcher = _BreadthFirstSearcher([revision], self._parents_provider)
2490.2.7 by Aaron Bentley
Start implementing mca that scales with number of uncommon ancestors
325
        seen_ancestors = set()
2490.2.22 by Aaron Bentley
Rename GraphWalker -> Graph, _AncestryWalker -> _BreadthFirstSearcher
326
        for ancestors in searcher:
2490.2.7 by Aaron Bentley
Start implementing mca that scales with number of uncommon ancestors
327
            for ancestor in ancestors:
328
                if ancestor not in self.seen:
2490.2.22 by Aaron Bentley
Rename GraphWalker -> Graph, _AncestryWalker -> _BreadthFirstSearcher
329
                    searcher.stop_searching_any([ancestor])
2490.2.7 by Aaron Bentley
Start implementing mca that scales with number of uncommon ancestors
330
                else:
331
                    seen_ancestors.add(ancestor)
332
        return seen_ancestors
333
2490.2.10 by Aaron Bentley
Clarify text, remove unused _get_ancestry method
334
    def stop_searching_any(self, revisions):
335
        """
336
        Remove any of the specified revisions from the search list.
337
338
        None of the specified revisions are required to be present in the
2490.2.12 by Aaron Bentley
Improve documentation
339
        search list.  In this case, the call is a no-op.
2490.2.10 by Aaron Bentley
Clarify text, remove unused _get_ancestry method
340
        """
2490.2.25 by Aaron Bentley
Update from review
341
        stopped = self._search_revisions.intersection(revisions)
342
        self._search_revisions = self._search_revisions.difference(revisions)
343
        return stopped
2490.2.17 by Aaron Bentley
Add start_searching, tweak stop_searching_any
344
345
    def start_searching(self, revisions):
346
        if self._search_revisions is None:
2490.2.19 by Aaron Bentley
Implement common-ancestor-based culling
347
            self._start = set(revisions)
2490.2.17 by Aaron Bentley
Add start_searching, tweak stop_searching_any
348
        else:
2490.2.25 by Aaron Bentley
Update from review
349
            self._search_revisions.update(revisions.difference(self.seen))
2490.2.19 by Aaron Bentley
Implement common-ancestor-based culling
350
        self.seen.update(revisions)