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

Robert Collins robertc at robertcollins.net
Fri Jul 13 19:54:50 BST 2007


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

------------------------------------------------------------
revno: 2636
revision-id: robertc at robertcollins.net-20070713185447-8edq39gs1yj548m1
parent: robertc at robertcollins.net-20070713183236-iyluu19jnoef43qc
committer: Robert Collins <robertc at robertcollins.net>
branch nick: repository
timestamp: Sat 2007-07-14 04:54:47 +1000
message:
  Implement KnitGraphIndex.get_position.
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 18:32:36 +0000
+++ b/bzrlib/knit.py	2007-07-13 18:54:47 +0000
@@ -1390,6 +1390,12 @@
         """True if the version is in the index."""
         return len(list(self._graph_index.iter_entries([version_id]))) == 1
 
+    def get_position(self, version_id):
+        """Return data position and size of specified version."""
+        node = list(self._graph_index.iter_entries([version_id]))[0]
+        bits = node[2][1:].split(' ')
+        return int(bits[0]), int(bits[1])
+
 
 class _KnitData(_KnitComponentFile):
     """Contents of the knit data file"""

=== modified file 'bzrlib/tests/test_knit.py'
--- a/bzrlib/tests/test_knit.py	2007-07-13 18:32:36 +0000
+++ b/bzrlib/tests/test_knit.py	2007-07-13 18:54:47 +0000
@@ -1522,10 +1522,10 @@
     def two_graph_index(self):
         # build a complex graph across several indices.
         index1 = self.make_g_index('1', 1, [
-            ('tip', (['parent'], ), ''),
+            ('tip', (['parent'], ), ' 0 100'),
             ('tail', ([], ), '')])
         index2 = self.make_g_index('2', 1, [
-            ('parent', (['tail', 'ghost'], ), ''),
+            ('parent', (['tail', 'ghost'], ), ' 100 78'),
             ('separate', ([], ), '')])
         combined_index = CombinedGraphIndex([index1, index2])
         return KnitGraphIndex(combined_index)
@@ -1613,6 +1613,11 @@
         self.assertTrue(index.has_version('tail'))
         self.assertFalse(index.has_version('ghost'))
 
+    def test_get_position(self):
+        index = self.two_graph_index()
+        self.assertEqual((0, 100), index.get_position('tip'))
+        self.assertEqual((100, 78), index.get_position('parent'))
+
 ## --- mutating tests for later ---
 #
 #  def test_add_version




More information about the bazaar-commits mailing list