~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/knit.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-06-16 19:32:32 UTC
  • mfrom: (4371.3.48 1.16-better_heads)
  • Revision ID: pqm@pqm.ubuntu.com-20090616193232-rorncr6v3z633n9u
(jam) graph.KnownGraph implementation,
        used for optimized heads() lookups during annotate.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3552
3552
        """Create a heads provider for resolving ancestry issues."""
3553
3553
        if self._heads_provider is not None:
3554
3554
            return self._heads_provider
3555
 
        parent_provider = _mod_graph.DictParentsProvider(
3556
 
            self._revision_id_graph)
3557
 
        graph_obj = _mod_graph.Graph(parent_provider)
3558
 
        head_cache = _mod_graph.FrozenHeadsCache(graph_obj)
3559
 
        self._heads_provider = head_cache
3560
 
        return head_cache
 
3555
        self._heads_provider = _mod_graph.KnownGraph(self._revision_id_graph)
 
3556
        return self._heads_provider
3561
3557
 
3562
3558
    def annotate(self, key):
3563
3559
        """Return the annotated fulltext at the given key.
3586
3582
        being able to produce line deltas.
3587
3583
        """
3588
3584
        # TODO: this code generates a parent maps of present ancestors; it
3589
 
        # could be split out into a separate method, and probably should use
3590
 
        # iter_ancestry instead. -- mbp and robertc 20080704
 
3585
        #       could be split out into a separate method
 
3586
        #       -- mbp and robertc 20080704
3591
3587
        graph = _mod_graph.Graph(self._knit)
3592
 
        head_cache = _mod_graph.FrozenHeadsCache(graph)
3593
 
        search = graph._make_breadth_first_searcher([key])
3594
 
        keys = set()
3595
 
        while True:
3596
 
            try:
3597
 
                present, ghosts = search.next_with_ghosts()
3598
 
            except StopIteration:
3599
 
                break
3600
 
            keys.update(present)
3601
 
        parent_map = self._knit.get_parent_map(keys)
 
3588
        parent_map = dict((k, v) for k, v in graph.iter_ancestry([key])
 
3589
                          if v is not None)
 
3590
        if not parent_map:
 
3591
            raise errors.RevisionNotPresent(key, self)
 
3592
        keys = parent_map.keys()
 
3593
        heads_provider = _mod_graph.KnownGraph(parent_map)
3602
3594
        parent_cache = {}
3603
3595
        reannotate = annotate.reannotate
3604
3596
        for record in self._knit.get_record_stream(keys, 'topological', True):
3610
3602
            else:
3611
3603
                parent_lines = []
3612
3604
            parent_cache[key] = list(
3613
 
                reannotate(parent_lines, fulltext, key, None, head_cache))
 
3605
                reannotate(parent_lines, fulltext, key, None, heads_provider))
3614
3606
        try:
3615
3607
            return parent_cache[key]
3616
3608
        except KeyError, e: