Rev 2640: Implement KnitGraphIndex.get_options. in http://people.ubuntu.com/~robertc/baz2.0/repository

Robert Collins robertc at robertcollins.net
Fri Jul 13 21:19:29 BST 2007


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

------------------------------------------------------------
revno: 2640
revision-id: robertc at robertcollins.net-20070713201927-5809g0zvjv17s5qf
parent: robertc at robertcollins.net-20070713200634-hvhse33adl211oa7
committer: Robert Collins <robertc at robertcollins.net>
branch nick: repository
timestamp: Sat 2007-07-14 06:19:27 +1000
message:
  Implement KnitGraphIndex.get_options.
modified:
  bzrlib/knit.py                 knit.py-20051212171256-f056ac8f0fbe1bd9
  bzrlib/tests/test_knit.py      test_knit.py-20051212171302-95d4c00dd5f11f2b
=== modified file 'bzrlib/knit.py'
--- a/bzrlib/knit.py	2007-07-13 20:06:34 +0000
+++ b/bzrlib/knit.py	2007-07-13 20:19:27 +0000
@@ -1294,6 +1294,10 @@
             return 'line-delta'
 
     def get_options(self, version_id):
+        """Return a string represention options.
+
+        e.g. foo,bar
+        """
         return self._cache[version_id][1]
 
     def get_parents(self, version_id):
@@ -1401,7 +1405,11 @@
         """Return compression method of specified version."""
         if not self._deltas:
             return 'fulltext'
-        if len(self._get_node(version_id)[1][1]):
+        return self._parent_compression(self._get_node(version_id)[1][1])
+
+    def _parent_compression(self, reference_list):
+        # use the second reference list to decide if this is delta'd or not.
+        if len(reference_list):
             return 'line-delta'
         else:
             return 'fulltext'
@@ -1409,6 +1417,19 @@
     def _get_node(self, version_id):
         return list(self._graph_index.iter_entries([version_id]))[0]
 
+    def get_options(self, version_id):
+        """Return a string represention options.
+
+        e.g. foo,bar
+        """
+        node = self._get_node(version_id)
+        if not self._deltas:
+            options = ['fulltext']
+        else:
+            options = [self._parent_compression(node[1][1])]
+        if node[2][0] == 'N':
+            options.append('no-eol')
+        return ','.join(options)
 
 
 class _KnitData(_KnitComponentFile):

=== modified file 'bzrlib/tests/test_knit.py'
--- a/bzrlib/tests/test_knit.py	2007-07-13 20:06:34 +0000
+++ b/bzrlib/tests/test_knit.py	2007-07-13 20:19:27 +0000
@@ -1528,14 +1528,14 @@
         # build a complex graph across several indices.
         if deltas:
             index1 = self.make_g_index('1', 2, [
-                ('tip', (['parent'], [], ), ' 0 100'),
+                ('tip', (['parent'], [], ), 'N0 100'),
                 ('tail', ([], []), '')])
             index2 = self.make_g_index('2', 2, [
                 ('parent', (['tail', 'ghost'], ['tail']), ' 100 78'),
                 ('separate', ([], []), '')])
         else:
             index1 = self.make_g_index('1', 1, [
-                ('tip', (['parent'], ), ' 0 100'),
+                ('tip', (['parent'], ), 'N0 100'),
                 ('tail', ([], ), '')])
             index2 = self.make_g_index('2', 1, [
                 ('parent', (['tail', 'ghost'], ), ' 100 78'),
@@ -1642,6 +1642,18 @@
         self.assertEqual('fulltext', index.get_method('tip'))
         self.assertEqual('fulltext', index.get_method('parent'))
 
+    def test_get_options_deltas(self):
+        index = self.two_graph_index(deltas=True)
+        self.assertEqual('fulltext,no-eol', index.get_options('tip'))
+        self.assertEqual('line-delta', index.get_options('parent'))
+
+    def test_get_options_no_deltas(self):
+        # check that the parent-history lookup is ignored with deltas=False.
+        index = self.two_graph_index(deltas=False)
+        self.assertEqual('fulltext,no-eol', index.get_options('tip'))
+        self.assertEqual('fulltext', index.get_options('parent'))
+
+
 ## --- mutating tests for later ---
 #
 #  def test_add_version




More information about the bazaar-commits mailing list