~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/graph.py

  • Committer: Robert Collins
  • Date: 2007-10-17 22:59:21 UTC
  • mto: (2592.3.218 repository)
  • mto: This revision was merged to the branch mainline in revision 2917.
  • Revision ID: robertc@robertcollins.net-20071017225921-l3ypcpn0p9aawmp5
Factor out the Graph.heads() cache from _RevisionTextVersionCache for reuse, and use it in commit.

Show diffs side-by-side

added added

removed removed

Lines of Context:
371
371
        return False
372
372
 
373
373
 
 
374
class HeadsCache(object):
 
375
    """A cache of results for graph heads calls."""
 
376
 
 
377
    def __init__(self, graph):
 
378
        self.graph = graph
 
379
        self._heads = {}
 
380
 
 
381
    def heads(self, keys):
 
382
        """Return the heads of keys.
 
383
 
 
384
        :see also: Graph.heads.
 
385
        :param keys: The keys to calculate heads for.
 
386
        :return: A set containing the heads, which may be mutated without
 
387
            affecting future lookups.
 
388
        """
 
389
        keys = set(keys)
 
390
        try:
 
391
            return set(self._heads[keys])
 
392
        except KeyError:
 
393
            heads = self.graph.heads(keys)
 
394
            self._heads[keys] = heads
 
395
            return set(heads)
 
396
 
 
397
 
374
398
class _BreadthFirstSearcher(object):
375
399
    """Parallel search the breadth-first the ancestry of revisions.
376
400