Rev 3737: Add the concept of CHK lookups to Repository. in http://people.ubuntu.com/~robertc/baz2.0/repository

Robert Collins robertc at robertcollins.net
Thu Sep 25 07:41:48 BST 2008


At http://people.ubuntu.com/~robertc/baz2.0/repository

------------------------------------------------------------
revno: 3737
revision-id: robertc at robertcollins.net-20080925064142-prla9jiwsdkfypwp
parent: robertc at robertcollins.net-20080925055104-wgdloa74hy8c2l3j
committer: Robert Collins <robertc at robertcollins.net>
branch nick: repository
timestamp: Thu 2008-09-25 16:41:42 +1000
message:
  Add the concept of CHK lookups to Repository.
added:
  bzrlib/tests/per_repository_chk/ per_repository_chk-20080925061730-e4g24t5xstp2n2vp-1
  bzrlib/tests/per_repository_chk/__init__.py __init__.py-20080925061730-e4g24t5xstp2n2vp-2
  bzrlib/tests/per_repository_chk/test_supported.py test_supported.py-20080925063728-k65ry0n2rhta6t34-1
  bzrlib/tests/per_repository_chk/test_unsupported.py test_unsupported.py-20080925063728-k65ry0n2rhta6t34-2
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/remote.py               remote.py-20060720103555-yeeg2x51vn0rbtdp-1
  bzrlib/repofmt/knitrepo.py     knitrepo.py-20070206081537-pyy4a00xdas0j4pf-1
  bzrlib/repofmt/pack_repo.py    pack_repo.py-20070813041115-gjv5ma7ktfqwsjgn-1
  bzrlib/repofmt/weaverepo.py    presplitout.py-20070125045333-wfav3tsh73oxu3zk-1
  bzrlib/repository.py           rev_storage.py-20051111201905-119e9401e46257e3
  bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
=== modified file 'NEWS'
--- a/NEWS	2008-09-25 01:21:44 +0000
+++ b/NEWS	2008-09-25 06:41:42 +0000
@@ -115,6 +115,10 @@
     * New win32utils.get_local_appdata_location() provides access to a local
       directory for storing data.  (Mark Hammond)
 
+    * The Repository model has been extended to allow some formats to
+      expose data via CHK based lookups (Though no formats support this as
+      yet). (Robert Collins)
+
 
 bzr 1.7 2008-09-23
 ------------------

=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py	2008-09-23 02:16:55 +0000
+++ b/bzrlib/remote.py	2008-09-25 06:41:42 +0000
@@ -334,6 +334,16 @@
         self._ensure_real()
         return self._real_repository.abort_write_group()
 
+    @property
+    def chk_bytes(self):
+        """Decorate the real repository for now.
+
+        In the long term a full blown network facility is needed to avoid
+        creating a real repository object locally.
+        """
+        self._ensure_real()
+        return self._real_repository.chk_bytes
+
     def commit_write_group(self):
         """Complete a write group on the decorated repository.
         

=== modified file 'bzrlib/repofmt/knitrepo.py'
--- a/bzrlib/repofmt/knitrepo.py	2008-07-28 06:08:42 +0000
+++ b/bzrlib/repofmt/knitrepo.py	2008-09-25 06:41:42 +0000
@@ -292,6 +292,8 @@
     supports_ghosts = True
     # External lookups are not supported in this format.
     supports_external_lookups = False
+    # No CHK support.
+    supports_chks = False
 
     def _get_inventories(self, repo_transport, repo, name='inventory'):
         mapper = ConstantMapper(name)
@@ -377,6 +379,7 @@
         repo.signatures = self._get_signatures(repo_transport, repo)
         repo.inventories = self._get_inventories(repo_transport, repo)
         repo.texts = self._get_texts(repo_transport, repo)
+        repo.chk_bytes = None
         repo._transport = repo_transport
         return repo
 

=== modified file 'bzrlib/repofmt/pack_repo.py'
--- a/bzrlib/repofmt/pack_repo.py	2008-09-25 05:51:04 +0000
+++ b/bzrlib/repofmt/pack_repo.py	2008-09-25 06:41:42 +0000
@@ -1730,6 +1730,7 @@
                 deltas=True, parents=True, is_locked=self.is_locked),
             data_access=self._pack_collection.text_index.data_access,
             max_delta_chain=200)
+        self.chk_bytes = None
         # True when the repository object is 'write locked' (as opposed to the
         # physical lock only taken out around changes to the pack-names list.) 
         # Another way to represent this would be a decorator around the control
@@ -1927,8 +1928,10 @@
     # Set this attribute in derived clases to control the _serializer that the
     # repository objects will have passed to their constructor.
     _serializer = None
-    # External references are not supported in pack repositories yet.
+    # External references are not supported in most pack repositories.
     supports_external_lookups = False
+    # Most pack formats do not use chk lookups.
+    supports_chks = False
     # What index classes to use
     index_builder_class = None
     index_class = None

=== modified file 'bzrlib/repofmt/weaverepo.py'
--- a/bzrlib/repofmt/weaverepo.py	2008-07-29 15:51:45 +0000
+++ b/bzrlib/repofmt/weaverepo.py	2008-09-25 06:41:42 +0000
@@ -256,6 +256,7 @@
     supports_tree_reference = False
     supports_ghosts = False
     supports_external_lookups = False
+    supports_chks = False
 
     def initialize(self, a_bzrdir, shared=False, _internal=False):
         """Create a weave repository."""
@@ -301,6 +302,7 @@
         result.signatures = self._get_signatures(repo_transport, result)
         result.inventories = self._get_inventories(repo_transport, result)
         result.texts = self._get_texts(repo_transport, result)
+        result.chk_bytes = None
         return result
 
     def check_conversion_target(self, target_format):
@@ -464,6 +466,7 @@
 
     _versionedfile_class = weave.WeaveFile
     supports_ghosts = False
+    supports_chks = False
 
     def get_format_string(self):
         """See RepositoryFormat.get_format_string()."""
@@ -539,6 +542,7 @@
         result.signatures = self._get_signatures(repo_transport, result)
         result.inventories = self._get_inventories(repo_transport, result)
         result.texts = self._get_texts(repo_transport, result)
+        result.chk_bytes = None
         result._transport = repo_transport
         return result
 

=== modified file 'bzrlib/repository.py'
--- a/bzrlib/repository.py	2008-09-25 05:51:04 +0000
+++ b/bzrlib/repository.py	2008-09-25 06:41:42 +0000
@@ -456,16 +456,18 @@
     which views a particular line of development through that history.
 
     The Repository builds on top of some byte storage facilies (the revisions,
-    signatures, inventories and texts attributes) and a Transport, which
-    respectively provide byte storage and a means to access the (possibly
+    signatures, inventories, texts and chk_bytes attributes) and a Transport,
+    which respectively provide byte storage and a means to access the (possibly
     remote) disk.
 
     The byte storage facilities are addressed via tuples, which we refer to
     as 'keys' throughout the code base. Revision_keys, inventory_keys and
     signature_keys are all 1-tuples: (revision_id,). text_keys are two-tuples:
-    (file_id, revision_id). We use this interface because it allows low
-    friction with the underlying code that implements disk indices, network
-    encoding and other parts of bzrlib.
+    (file_id, revision_id). chk_bytes uses CHK keys - a 1-tuple with a single
+    byte string made up of a hash identifier and a hash value. 
+    We use this interface because it allows low friction with the underlying
+    code that implements disk indices, network encoding and other parts of
+    bzrlib.
 
     :ivar revisions: A bzrlib.versionedfile.VersionedFiles instance containing
         the serialised revisions for the repository. This can be used to obtain
@@ -490,6 +492,11 @@
         The result of trying to insert data into the repository via this store
         is undefined: it should be considered read-only except for implementors
         of repositories.
+    :ivar chk_bytes: A bzrlib.versionedfile.VersioedFiles instance containing
+        any data the repository chooses to store or have indexed by its hash.
+        The result of trying to insert data into the repository via this store
+        is undefined: it should be considered read-only except for implementors
+        of repositories.
     :ivar _transport: Transport for file access to repository, typically
         pointing to .bzr/repository.
     """
@@ -2105,6 +2112,9 @@
     # Can this repository be given external locations to lookup additional
     # data. Set to True or False in derived classes.
     supports_external_lookups = None
+    # Does this format support CHK bytestring lookups. Set to True or False in
+    # derived classes.
+    supports_chks = None
 
     def __str__(self):
         return "<%s>" % self.__class__.__name__

=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2008-09-23 16:56:38 +0000
+++ b/bzrlib/tests/__init__.py	2008-09-25 06:41:42 +0000
@@ -2755,6 +2755,8 @@
                    'bzrlib.tests.intertree_implementations',
                    'bzrlib.tests.per_lock',
                    'bzrlib.tests.per_repository',
+                   'bzrlib.tests.per_repository_chk',
+                   'bzrlib.tests.per_repository_reference',
                    'bzrlib.tests.test__dirstate_helpers',
                    'bzrlib.tests.test_ancestry',
                    'bzrlib.tests.test_annotate',
@@ -2839,7 +2841,6 @@
                    'bzrlib.tests.test_registry',
                    'bzrlib.tests.test_remote',
                    'bzrlib.tests.test_repository',
-                   'bzrlib.tests.per_repository_reference',
                    'bzrlib.tests.test_revert',
                    'bzrlib.tests.test_revision',
                    'bzrlib.tests.test_revisionspec',

=== added directory 'bzrlib/tests/per_repository_chk'
=== added file 'bzrlib/tests/per_repository_chk/__init__.py'
--- a/bzrlib/tests/per_repository_chk/__init__.py	1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/per_repository_chk/__init__.py	2008-09-25 06:41:42 +0000
@@ -0,0 +1,72 @@
+# 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
+
+
+"""Repository implementation tests for CHK support.
+
+These tests check the conformance of the chk index some repositories support.
+All repository formats are tested - those that do not suppport chk indices
+have the test_unsupported tests run; the others have the test_supported tests
+run.
+"""
+
+from bzrlib import (
+    repository,
+    remote,
+    )
+from bzrlib.bzrdir import BzrDir
+from bzrlib.tests import (
+                          adapt_modules,
+                          adapt_tests,
+                          TestScenarioApplier,
+                          TestSuite,
+                          )
+from bzrlib.tests.per_repository import (
+    all_repository_format_scenarios,
+    TestCaseWithRepository,
+    )
+
+
+def load_tests(standard_tests, module, loader):
+    supported = []
+    notsupported = []
+    for test_name, scenario_info in all_repository_format_scenarios():
+        # For remote repositories, we need at least one chk
+        # capable format to test it:
+        # if isinstance(format, remote.RemoteRepositoryFormat):
+        #     scenario_info['bzrdir_format'].repository_format = 
+        if scenario_info['repository_format'].supports_chks:
+            supported.append((test_name, scenario_info))
+        else:
+            notsupported.append((test_name, scenario_info))
+    adapter = TestScenarioApplier()
+
+    module_list = [
+        'bzrlib.tests.per_repository_chk.test_supported',
+        ]
+    unsupported_list = [
+        'bzrlib.tests.per_repository_chk.test_unsupported',
+        ]
+    result = TestSuite()
+    # Any tests in this module are unparameterised.
+    result.addTest(standard_tests)
+    # Supported formats get the supported tests
+    adapter.scenarios = supported
+    adapt_modules(module_list, adapter, loader, result)
+    # Unsupported formats get the unsupported tetss
+    adapter.scenarios = notsupported
+    adapt_modules(unsupported_list, adapter, loader, result)
+    return result

=== added file 'bzrlib/tests/per_repository_chk/test_supported.py'
--- a/bzrlib/tests/per_repository_chk/test_supported.py	1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/per_repository_chk/test_supported.py	2008-09-25 06:41:42 +0000
@@ -0,0 +1,27 @@
+# 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 repositories that support CHK indices."""
+
+from bzrlib.versionedfile import VersionedFiles
+from bzrlib.tests.per_repository_chk import TestCaseWithRepository
+
+
+class TestCHKSupport(TestCaseWithRepository):
+
+    def test_chk_bytes_attribute_is_VersionedFiles(self):
+        repo = self.make_repository('.')
+        self.assertIsInstance(repo.chk_bytes, VersionedFiles)

=== added file 'bzrlib/tests/per_repository_chk/test_unsupported.py'
--- a/bzrlib/tests/per_repository_chk/test_unsupported.py	1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/per_repository_chk/test_unsupported.py	2008-09-25 06:41:42 +0000
@@ -0,0 +1,26 @@
+# 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 repositories that do not support CHK indices."""
+
+from bzrlib.tests.per_repository_chk import TestCaseWithRepository
+
+
+class TestNoCHKSupport(TestCaseWithRepository):
+
+    def test_chk_bytes_attribute_is_None(self):
+        repo = self.make_repository('.')
+        self.assertEqual(None, repo.chk_bytes)




More information about the bazaar-commits mailing list