/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 bzrlib/graph.py

  • Committer: John Arbash Meinel
  • Date: 2007-12-04 18:11:51 UTC
  • mfrom: (3074 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3075.
  • Revision ID: john@arbash-meinel.com-20071204181151-br85qwsgshso16q5
[merge] bzr.dev 3074

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
from bzrlib import (
18
18
    errors,
 
19
    revision,
19
20
    tsort,
20
21
    )
21
22
from bzrlib.deprecated_graph import (node_distances, select_farthest)
22
 
from bzrlib.revision import NULL_REVISION
23
23
 
24
24
# DIAGRAM of terminology
25
25
#       A
242
242
            order if they need it.
243
243
        """
244
244
        candidate_heads = set(keys)
 
245
        if revision.NULL_REVISION in candidate_heads:
 
246
            # NULL_REVISION is only a head if it is the only entry
 
247
            candidate_heads.remove(revision.NULL_REVISION)
 
248
            if not candidate_heads:
 
249
                return set([revision.NULL_REVISION])
245
250
        if len(candidate_heads) < 2:
246
251
            return candidate_heads
247
252
        searchers = dict((c, self._make_breadth_first_searcher([c]))
310
315
            common_walker.start_searching(new_common)
311
316
        return candidate_heads
312
317
 
313
 
    def find_unique_lca(self, left_revision, right_revision):
 
318
    def find_unique_lca(self, left_revision, right_revision,
 
319
                        count_steps=False):
314
320
        """Find a unique LCA.
315
321
 
316
322
        Find lowest common ancestors.  If there is no unique  common
321
327
 
322
328
        Note that None is not an acceptable substitute for NULL_REVISION.
323
329
        in the input for this method.
 
330
 
 
331
        :param count_steps: If True, the return value will be a tuple of
 
332
            (unique_lca, steps) where steps is the number of times that
 
333
            find_lca was run.  If False, only unique_lca is returned.
324
334
        """
325
335
        revisions = [left_revision, right_revision]
 
336
        steps = 0
326
337
        while True:
 
338
            steps += 1
327
339
            lca = self.find_lca(*revisions)
328
340
            if len(lca) == 1:
329
 
                return lca.pop()
 
341
                result = lca.pop()
 
342
                if count_steps:
 
343
                    return result, steps
 
344
                else:
 
345
                    return result
330
346
            if len(lca) == 0:
331
347
                raise errors.NoCommonAncestor(left_revision, right_revision)
332
348
            revisions = lca