Rev 3527: (mbp, for robertc) simple annotation on stacked knits in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Mon Jul 7 09:35:01 BST 2008


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 3527
revision-id:pqm at pqm.ubuntu.com-20080707083451-33s2p0jaawgzkyfk
parent: pqm at pqm.ubuntu.com-20080704171330-ieh195xj7su2k2xq
parent: mbp at sourcefrog.net-20080707073357-yzlhyhy3vjmi6qpp
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Mon 2008-07-07 09:34:51 +0100
message:
  (mbp, for robertc) simple annotation on stacked knits
modified:
  bzrlib/graph.py                graph_walker.py-20070525030359-y852guab65d4wtn0-1
  bzrlib/knit.py                 knit.py-20051212171256-f056ac8f0fbe1bd9
  bzrlib/tests/test_knit.py      test_knit.py-20051212171302-95d4c00dd5f11f2b
    ------------------------------------------------------------
    revno: 3517.4.2
    revision-id:mbp at sourcefrog.net-20080707073357-yzlhyhy3vjmi6qpp
    parent: mbp at sourcefrog.net-20080704043212-jmwl1vrqhtao5gy3
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: annotate
    timestamp: Mon 2008-07-07 17:33:57 +1000
    message:
      Make simple-annotation and graph code more tolerant of knits with no graph
    modified:
      bzrlib/graph.py                graph_walker.py-20070525030359-y852guab65d4wtn0-1
      bzrlib/knit.py                 knit.py-20051212171256-f056ac8f0fbe1bd9
    ------------------------------------------------------------
    revno: 3517.4.1
    revision-id:mbp at sourcefrog.net-20080704043212-jmwl1vrqhtao5gy3
    parent: pqm at pqm.ubuntu.com-20080702195105-5gqthymygmtjrwaf
    parent: robertc at robertcollins.net-20080625070414-lhy6t5b0gwuotsrf
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: annotate
    timestamp: Fri 2008-07-04 14:32:12 +1000
    message:
      Merge unoptimized annotate code for stacking, and only use it when needed
    modified:
      bzrlib/knit.py                 knit.py-20051212171256-f056ac8f0fbe1bd9
      bzrlib/tests/test_knit.py      test_knit.py-20051212171302-95d4c00dd5f11f2b
    ------------------------------------------------------------
    revno: 3350.3.19.1.1.1.1.1.6.1.12.1.1
    revision-id:robertc at robertcollins.net-20080625070414-lhy6t5b0gwuotsrf
    parent: robertc at robertcollins.net-20080625012948-aclmfg49kaf8zdv8
    committer: Robert Collins <robertc at robertcollins.net>
    branch nick: stacking-annotate
    timestamp: Wed 2008-06-25 17:04:14 +1000
    message:
      Redo annotate more simply, using just the public interfaces for VersionedFiles.
    modified:
      bzrlib/knit.py                 knit.py-20051212171256-f056ac8f0fbe1bd9
      bzrlib/tests/test_knit.py      test_knit.py-20051212171302-95d4c00dd5f11f2b
=== modified file 'bzrlib/graph.py'
--- a/bzrlib/graph.py	2008-05-29 20:17:37 +0000
+++ b/bzrlib/graph.py	2008-07-07 07:33:57 +0000
@@ -1228,6 +1228,8 @@
         parent_map = self._parents_provider.get_parent_map(revisions)
         found_revisions.update(parent_map)
         for rev_id, parents in parent_map.iteritems():
+            if parents is None:
+                continue
             new_found_parents = [p for p in parents if p not in self.seen]
             if new_found_parents:
                 # Calling set.update() with an empty generator is actually

=== modified file 'bzrlib/knit.py'
--- a/bzrlib/knit.py	2008-07-03 08:16:47 +0000
+++ b/bzrlib/knit.py	2008-07-07 08:34:51 +0000
@@ -2680,12 +2680,52 @@
 
         :param key: The key to annotate.
         """
+        if True or len(self._knit._fallback_vfs) > 0:
+            # stacked knits can't use the fast path at present.
+            return self._simple_annotate(key)
         records = self._get_build_graph(key)
         if key in self._ghosts:
             raise errors.RevisionNotPresent(key, self._knit)
         self._annotate_records(records)
         return self._annotated_lines[key]
 
+    def _simple_annotate(self, key):
+        """Return annotated fulltext, rediffing from the full texts.
+
+        This is slow but makes no assumptions about the repository
+        being able to produce line deltas.
+        """
+        # TODO: this code generates a parent maps of present ancestors; it
+        # could be split out into a separate method, and probably should use
+        # iter_ancestry instead. -- mbp and robertc 20080704
+        graph = Graph(self._knit)
+        head_cache = _mod_graph.FrozenHeadsCache(graph)
+        search = graph._make_breadth_first_searcher([key])
+        keys = set()
+        while True:
+            try:
+                present, ghosts = search.next_with_ghosts()
+            except StopIteration:
+                break
+            keys.update(present)
+        parent_map = self._knit.get_parent_map(keys)
+        parent_cache = {}
+        reannotate = annotate.reannotate
+        for record in self._knit.get_record_stream(keys, 'topological', True):
+            key = record.key
+            fulltext = split_lines(record.get_bytes_as('fulltext'))
+            parents = parent_map[key]
+            if parents is not None:
+                parent_lines = [parent_cache[parent] for parent in parent_map[key]]
+            else:
+                parent_lines = []
+            parent_cache[key] = list(
+                reannotate(parent_lines, fulltext, key, None, head_cache))
+        try:
+            return parent_cache[key]
+        except KeyError, e:
+            raise errors.RevisionNotPresent(key, self._knit)
+
 
 try:
     from bzrlib._knit_load_data_c import _load_data_c as _load_data

=== modified file 'bzrlib/tests/test_knit.py'
--- a/bzrlib/tests/test_knit.py	2008-07-01 03:49:54 +0000
+++ b/bzrlib/tests/test_knit.py	2008-07-04 04:32:12 +0000
@@ -1431,11 +1431,15 @@
         # directly.
         basis.add_lines(key_basis, (), ['foo\n', 'bar\n'])
         basis.calls = []
-        self.assertRaises(RevisionNotPresent, test.annotate, key_basis)
-        raise KnownFailure("Annotation on stacked knits currently fails.")
         details = test.annotate(key_basis)
         self.assertEqual([(key_basis, 'foo\n'), (key_basis, 'bar\n')], details)
-        self.assertEqual([("annotate", key_basis)], basis.calls)
+        # Not optimised to date:
+        # self.assertEqual([("annotate", key_basis)], basis.calls)
+        self.assertEqual([('get_parent_map', set([key_basis])),
+            ('get_parent_map', set([key_basis])),
+            ('get_parent_map', set([key_basis])),
+            ('get_record_stream', [key_basis], 'unordered', True)],
+            basis.calls)
 
     def test_check(self):
         # check() must not check the fallback files, it's none of its business.




More information about the bazaar-commits mailing list