Rev 3354: List the available conversions from a given delta encoding in http://people.ubuntu.com/~robertc/baz2.0/versioned_files

Robert Collins robertc at robertcollins.net
Wed Apr 16 23:02:58 BST 2008


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

------------------------------------------------------------
revno: 3354
revision-id: robertc at robertcollins.net-20080416220251-74w8b8wcgzfkkjfl
parent: robertc at robertcollins.net-20080416040740-g3cjhoaez95b7gsr
committer: Robert Collins <robertc at robertcollins.net>
branch nick: data_stream_revamp
timestamp: Thu 2008-04-17 08:02:51 +1000
message:
  List the available conversions from a given delta encoding
modified:
  bzrlib/knit.py                 knit.py-20051212171256-f056ac8f0fbe1bd9
  bzrlib/tests/test_versionedfile.py test_versionedfile.py-20060222045249-db45c9ed14a1c2e5
  bzrlib/versionedfile.py        versionedfile.py-20060222045106-5039c71ee3b65490
  bzrlib/weave.py                knit.py-20050627021749-759c29984154256b
=== modified file 'bzrlib/knit.py'
--- a/bzrlib/knit.py	2008-04-16 04:07:40 +0000
+++ b/bzrlib/knit.py	2008-04-16 22:02:51 +0000
@@ -172,10 +172,18 @@
             annotated_kind = 'annotated-'
         else:
             annotated_kind = ''
-        self.storage_kind = 'knit-%s%s-gz' % (annotated_kind, kind)
+        native_uncompressed = 'knit-%s%s' % (annotated_kind, kind)
+        self.storage_kind = native_uncompressed + '-gz'
         self._raw_record = raw_record
         self._build_details = build_details
         self._knit = knit
+        # we can trivially hand back the storage kind, and unzip it
+        self.available_conversions = [self.storage_kind]
+        self.available_conversions.append(native_uncompressed)
+        if annotated:
+            self.available_conversions.append('knit-%s' % kind)
+        if kind == 'ft':
+            self.available_conversions.append('fulltext')
 
     def get_bytes_as(self, storage_kind):
         if storage_kind == self.storage_kind:

=== modified file 'bzrlib/tests/test_versionedfile.py'
--- a/bzrlib/tests/test_versionedfile.py	2008-04-16 04:07:40 +0000
+++ b/bzrlib/tests/test_versionedfile.py	2008-04-16 22:02:51 +0000
@@ -113,9 +113,9 @@
             ['base\n', 'left\n', 'right\n', 'merged\n'])
         return f, parents
 
-    def assertValidStorageKind(self, storage_kind):
-        """Assert that storage_kind is a valid storage_kind."""
-        self.assertSubset([storage_kind],
+    def assertValidStorageKind(self, storage_kinds):
+        """Assert that storage_kinds are valid storage_kinds."""
+        self.assertSubset(storage_kinds,
             ['mpdiff', 'knit-annotated-ft', 'knit-annotated-delta',
              'knit-ft', 'knit-delta', 'fulltext', 'knit-annotated-ft-gz',
              'knit-annotated-delta-gz', 'knit-ft-gz', 'knit-delta-gz'])
@@ -124,11 +124,15 @@
         """Capture a stream for testing."""
         for factory in entries:
             on_seen(factory.key)
-            self.assertValidStorageKind(factory.storage_kind)
+            self.assertValidStorageKind([factory.storage_kind])
             self.assertEqual(f.get_sha1s([factory.key[0]])[0], factory.sha1)
             self.assertEqual(parents[factory.key[0]], factory.parents)
             self.assertIsInstance(factory.get_bytes_as(factory.storage_kind),
                 str)
+            self.assertIsInstance(factory.available_conversions, list)
+            self.assertValidStorageKind(factory.available_conversions)
+            self.assertSubset([factory.storage_kind],
+                factory.available_conversions)
 
     def test_get_record_stream_interface(self):
         """each item in a stream has to provide a regular interface."""
@@ -161,7 +165,7 @@
         seen = []
         for factory in entries:
             seen.append(factory.key)
-            self.assertValidStorageKind(factory.storage_kind)
+            self.assertValidStorageKind([factory.storage_kind])
             self.assertEqual(f.get_sha1s([factory.key[0]])[0], factory.sha1)
             self.assertEqual(parents[factory.key[0]], factory.parents)
             self.assertEqual(f.get_text(factory.key[0]),
@@ -184,7 +188,7 @@
         seen = set()
         for factory in entries:
             seen.add(factory.key)
-            self.assertValidStorageKind(factory.storage_kind)
+            self.assertValidStorageKind([factory.storage_kind])
             self.assertEqual(f.get_sha1s([factory.key[0]])[0], factory.sha1)
             self.assertEqual(parents[factory.key[0]], factory.parents)
             # currently no stream emits mpdiff

=== modified file 'bzrlib/versionedfile.py'
--- a/bzrlib/versionedfile.py	2008-04-16 04:07:40 +0000
+++ b/bzrlib/versionedfile.py	2008-04-16 22:02:51 +0000
@@ -54,7 +54,9 @@
     :ivar parents: A tuple of parent keys for self.key. If the object has
         no parent information, None (as opposed to () for an empty list of
         parents).
-        """
+    :ivar available_conversions: A list of the storage kinds this key can be
+        converted into, in order of cost of conversion.
+    """
 
     def __init__(self):
         """Create a ContentFactory."""
@@ -62,6 +64,7 @@
         self.storage_kind = None
         self.key = None
         self.parents = None
+        self.available_conversions = None
 
 
 class VersionedFile(object):

=== modified file 'bzrlib/weave.py'
--- a/bzrlib/weave.py	2008-04-16 04:07:40 +0000
+++ b/bzrlib/weave.py	2008-04-16 22:02:51 +0000
@@ -113,6 +113,7 @@
         self.parents = tuple((parent,) for parent in parents)
         self.storage_kind = 'fulltext'
         self._weave = weave
+        self.available_conversions = ['fulltext']
 
     def get_bytes_as(self, storage_kind):
         if storage_kind == 'fulltext':




More information about the bazaar-commits mailing list