Rev 3247: Switch the api, add Repository.get_annotator() rather than just using the VersionedFile for it. in http://bzr.arbash-meinel.com/branches/bzr/1.3-dev/annotate_cleanup

John Arbash Meinel john at arbash-meinel.com
Thu Mar 6 15:07:46 GMT 2008


At http://bzr.arbash-meinel.com/branches/bzr/1.3-dev/annotate_cleanup

------------------------------------------------------------
revno: 3247
revision-id:john at arbash-meinel.com-20080306150444-w60gqq2itn6o4tuz
parent: john at arbash-meinel.com-20080306095333-ne8gnbxgtuc38aew
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: annotate_cleanup
timestamp: Thu 2008-03-06 15:04:44 +0000
message:
  Switch the api, add Repository.get_annotator() rather than just using the VersionedFile for it.
added:
  bzrlib/tests/repository_implementations/test_get_annotator.py test_get_annotator.p-20080306150412-d70sqlw7nqk8uxa7-1
modified:
  bzrlib/knit.py                 knit.py-20051212171256-f056ac8f0fbe1bd9
  bzrlib/remote.py               remote.py-20060720103555-yeeg2x51vn0rbtdp-1
  bzrlib/repository.py           rev_storage.py-20051111201905-119e9401e46257e3
  bzrlib/tests/repository_implementations/__init__.py __init__.py-20060131092037-9564957a7d4a841b
  bzrlib/versionedfile.py        versionedfile.py-20060222045106-5039c71ee3b65490
  bzrlib/workingtree.py          workingtree.py-20050511021032-29b6ec0a681e02e3
-------------- next part --------------
=== modified file 'bzrlib/knit.py'
--- a/bzrlib/knit.py	2008-03-06 09:53:33 +0000
+++ b/bzrlib/knit.py	2008-03-06 15:04:44 +0000
@@ -319,6 +319,14 @@
 
     annotated = True
 
+    def annotate_iter(self, knit, version_id):
+        content = knit._get_content(version_id)
+        return content.annotate_iter()
+
+    def annotate(self, knit, version_id):
+        content = knit._get_content(version_id)
+        return content.annotate()
+
     def make(self, lines, version_id):
         num_lines = len(lines)
         return AnnotatedKnitContent(zip([version_id] * num_lines, lines))
@@ -421,16 +429,19 @@
                        for origin, text in lines)
         return out
 
-    def annotate_iter(self, knit, version_id):
-        content = knit._get_content(version_id)
-        return content.annotate_iter()
-
 
 class KnitPlainFactory(_KnitFactory):
     """Factory for creating plain Content objects."""
 
     annotated = False
 
+    def annotate(self, knit, version_id):
+        annotator = _KnitAnnotator(knit)
+        return annotator.annotate(version_id)
+
+    def annotate_iter(self, knit, version_id):
+        return iter(self.annotate(knit, version_id))
+
     def make(self, lines, version_id):
         return PlainKnitContent(lines, version_id)
 
@@ -483,10 +494,6 @@
             out.extend(lines)
         return out
 
-    def annotate_iter(self, knit, version_id):
-        annotator = _KnitAnnotator(knit)
-        return iter(annotator.get_annotated_lines(version_id))
-
 
 def make_empty_knit(transport, relpath):
     """Construct a empty knit at the specified location."""
@@ -1249,10 +1256,17 @@
 
     __len__ = num_versions
 
+    def annotate(self, version_id):
+        """See VersionedFile.annotate."""
+        return self.factory.annotate(self, version_id)
+
     def annotate_iter(self, version_id):
         """See VersionedFile.annotate_iter."""
         return self.factory.annotate_iter(self, version_id)
 
+    def annotate(self, version_id):
+        return self.factory.annotate(self, version_id)
+
     def get_parents(self, version_id):
         """See VersionedFile.get_parents."""
         # perf notes:
@@ -2843,7 +2857,7 @@
     recommended.
     """
     annotator = _KnitAnnotator(knit)
-    return iter(annotator.get_annotated_lines(revision_id))
+    return iter(annotator.annotate(revision_id))
 
 
 class _KnitAnnotator(object):
@@ -2877,7 +2891,16 @@
         self._heads_provider = None
 
         self._nodes_to_keep_annotations = set()
-        self._generations_until_keep = 100
+        self._generations_until_keep = 10
+
+    def annotate(self, revision_id):
+        """Return the annotated fulltext at the given revision.
+
+        :param revision_id: The revision id for this file
+        """
+        records = self._get_build_graph(revision_id)
+        self._annotate_records(records)
+        return self._annotated_lines[revision_id]
 
     def set_generations_until_keep(self, value):
         """Set the number of generations before caching a node.
@@ -3079,15 +3102,6 @@
         self._heads_provider = head_cache
         return head_cache
 
-    def get_annotated_lines(self, revision_id):
-        """Return the annotated fulltext at the given revision.
-
-        :param revision_id: The revision id for this file
-        """
-        records = self._get_build_graph(revision_id)
-        self._annotate_records(records)
-        return self._annotated_lines[revision_id]
-
 
 try:
     from bzrlib._knit_load_data_c import _load_data_c as _load_data

=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py	2008-02-22 04:46:46 +0000
+++ b/bzrlib/remote.py	2008-03-06 15:04:44 +0000
@@ -360,6 +360,11 @@
         self._ensure_real()
         return self._real_repository._generate_text_key_index()
 
+    def get_annotator(self, file_id):
+        """See Repository.get_annotator()"""
+        self._ensure_real()
+        return self._real_repository.get_annotator(file_id)
+
     def get_revision_graph(self, revision_id=None):
         """See Repository.get_revision_graph()."""
         if revision_id is None:

=== modified file 'bzrlib/repository.py'
--- a/bzrlib/repository.py	2008-02-19 03:58:32 +0000
+++ b/bzrlib/repository.py	2008-03-06 15:04:44 +0000
@@ -808,6 +808,14 @@
                 branches.extend(repository.find_branches())
         return branches
 
+    def get_annotator(self, file_id):
+        """Return an object that supports .annotate() to get annotated lines.
+        """
+        # VersionedFile supports .annotate(), but some repositories might want
+        # to have custom implementations.
+        return self.weave_store.get_weave(file_id,
+                self.get_transaction())
+
     def get_data_stream(self, revision_ids):
         raise NotImplementedError(self.get_data_stream)
 

=== modified file 'bzrlib/tests/repository_implementations/__init__.py'
--- a/bzrlib/tests/repository_implementations/__init__.py	2008-01-11 03:54:51 +0000
+++ b/bzrlib/tests/repository_implementations/__init__.py	2008-03-06 15:04:44 +0000
@@ -866,6 +866,7 @@
         'test_fetch',
         'test_fileid_involved',
         'test_find_text_key_references',
+        'test_get_annotator',
         'test__generate_text_key_index',
         'test_has_same_location',
         'test_has_revisions',

=== added file 'bzrlib/tests/repository_implementations/test_get_annotator.py'
--- a/bzrlib/tests/repository_implementations/test_get_annotator.py	1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/repository_implementations/test_get_annotator.py	2008-03-06 15:04:44 +0000
@@ -0,0 +1,43 @@
+# Copyright (C) 2008 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+
+"""Tests for the get_annotator API."""
+
+
+from bzrlib.tests.repository_implementations import TestCaseWithRepository
+
+
+class TestGetAnnotator(TestCaseWithRepository):
+
+    def test_annotate(self):
+        tree = self.make_branch_and_tree('tree')
+        self.build_tree_contents([('tree/file', 'a\nb\n')])
+        tree.add(['file'], ['file-id'])
+        tree.commit('file', rev_id='rev1')
+        self.build_tree_contents([('tree/file', 'a\nb\nc\n')])
+        tree.commit('file2', rev_id='rev2')
+        repo = tree.branch.repository
+        repo.lock_read()
+        self.addCleanup(repo.unlock)
+        annotator = repo.get_annotator('file-id')
+        self.assertEqual([('rev1', 'a\n'),
+                          ('rev1', 'b\n'),
+                         ], annotator.annotate('rev1'))
+        self.assertEqual([('rev1', 'a\n'),
+                          ('rev1', 'b\n'),
+                          ('rev2', 'c\n'),
+                         ], annotator.annotate('rev2'))

=== modified file 'bzrlib/versionedfile.py'
--- a/bzrlib/versionedfile.py	2008-01-11 05:08:20 +0000
+++ b/bzrlib/versionedfile.py	2008-03-06 15:04:44 +0000
@@ -402,6 +402,9 @@
     def annotate(self, version_id):
         return list(self.annotate_iter(version_id))
 
+    def get_annotated_lines(self, version_id):
+        return list(self.annotate_iter(version_id))
+
     def join(self, other, pb=None, msg=None, version_ids=None,
              ignore_missing=False):
         """Integrate versions from other into this versioned file.

=== modified file 'bzrlib/workingtree.py'
--- a/bzrlib/workingtree.py	2008-02-28 01:33:35 +0000
+++ b/bzrlib/workingtree.py	2008-03-06 15:04:44 +0000
@@ -505,6 +505,8 @@
         incorrectly attributed to CURRENT_REVISION (but after committing, the
         attribution will be correct).
         """
+        from bzrlib import annotate
+
         basis = self.basis_tree()
         basis.lock_read()
         try:
@@ -515,7 +517,6 @@
                 return basis.annotate_iter(file_id)
             if kind[1] is None:
                 return None
-            import annotate
             if kind[0] != 'file':
                 old_lines = []
             else:



More information about the bazaar-commits mailing list