Rev 3379: stacked get_parent_map. in http://people.ubuntu.com/~robertc/baz2.0/shallow-branch

Robert Collins robertc at robertcollins.net
Thu Jun 19 07:43:37 BST 2008


At http://people.ubuntu.com/~robertc/baz2.0/shallow-branch

------------------------------------------------------------
revno: 3379
revision-id: robertc at robertcollins.net-20080619064333-apziisq1g280m70v
parent: robertc at robertcollins.net-20080619045351-wjknb9el37ravhjj
committer: Robert Collins <robertc at robertcollins.net>
branch nick: stacking-knits
timestamp: Thu 2008-06-19 16:43:33 +1000
message:
  stacked get_parent_map.
modified:
  bzrlib/knit.py                 knit.py-20051212171256-f056ac8f0fbe1bd9
  bzrlib/tests/test_knit.py      test_knit.py-20051212171302-95d4c00dd5f11f2b
  bzrlib/versionedfile.py        versionedfile.py-20060222045106-5039c71ee3b65490
=== modified file 'bzrlib/knit.py'
--- a/bzrlib/knit.py	2008-06-19 04:53:51 +0000
+++ b/bzrlib/knit.py	2008-06-19 06:43:33 +0000
@@ -1025,7 +1025,16 @@
         :return: A mapping from keys to parents. Absent keys are absent from
             the mapping.
         """
-        return self._index.get_parent_map(keys)
+        result = {}
+        sources = [self._index] + self._fallback_vfs
+        missing = set(keys)
+        for source in sources:
+            if not missing:
+                break
+            new_result = source.get_parent_map(missing)
+            result.update(new_result)
+            missing.difference_update(set(new_result))
+        return result
 
     def _get_record_map(self, keys):
         """Produce a dictionary of knit records.

=== modified file 'bzrlib/tests/test_knit.py'
--- a/bzrlib/tests/test_knit.py	2008-06-19 04:53:51 +0000
+++ b/bzrlib/tests/test_knit.py	2008-06-19 06:43:33 +0000
@@ -58,7 +58,10 @@
 from bzrlib.transport import get_transport
 from bzrlib.transport.memory import MemoryTransport
 from bzrlib.tuned_gzip import GzipFile
-from bzrlib.versionedfile import ConstantMapper
+from bzrlib.versionedfile import (
+    ConstantMapper,
+    RecordingVersionedFilesDecorator,
+    )
 
 
 class _CompiledKnitFeature(Feature):
@@ -1377,6 +1380,7 @@
 
     def get_basis_and_test_knit(self):
         basis = self.make_test_knit(name='basis')
+        basis = RecordingVersionedFilesDecorator(basis)
         test = self.make_test_knit(name='test')
         test.add_fallback_versioned_files(basis)
         return basis, test
@@ -1401,7 +1405,23 @@
         test.check()
 
     def test_get_parent_map(self):
-        pass
+        # parents in the test knit are answered without asking the basis
+        basis, test = self.get_basis_and_test_knit()
+        key = ('foo',)
+        key_basis = ('bar',)
+        key_missing = ('missing',)
+        test.add_lines(key, (), [])
+        parent_map = test.get_parent_map([key])
+        self.assertEqual({key: ()}, parent_map)
+        self.assertEqual([], basis.calls)
+        # But parents that are not in the test knit are looked for in the basis
+        basis.add_lines(key_basis, (), [])
+        basis.calls = []
+        parent_map = test.get_parent_map([key, key_basis, key_missing])
+        self.assertEqual({key: (),
+            key_basis: ()}, parent_map)
+        self.assertEqual([("get_parent_map", set([key_basis, key_missing]))],
+            basis.calls)
 
     def test_get_record_stream(self):
         pass

=== modified file 'bzrlib/versionedfile.py'
--- a/bzrlib/versionedfile.py	2008-06-12 03:25:25 +0000
+++ b/bzrlib/versionedfile.py	2008-06-19 06:43:33 +0000
@@ -19,6 +19,7 @@
 
 """Versioned text file storage api."""
 
+from copy import copy
 from cStringIO import StringIO
 import os
 import urllib
@@ -534,6 +535,18 @@
         self._backing_vf = backing_vf
         self.calls = []
 
+    def add_lines(self, key, parents, lines, parent_texts=None,
+        left_matching_blocks=None, nostore_sha=None, random_id=False,
+        check_content=True):
+        self.calls.append(("add_lines", key, parents, lines, parent_texts,
+            left_matching_blocks, nostore_sha, random_id, check_content))
+        return self._backing_vf.add_lines(key, parents, lines, parent_texts,
+            left_matching_blocks, nostore_sha, random_id, check_content)
+
+    def get_parent_map(self, keys):
+        self.calls.append(("get_parent_map", copy(keys)))
+        return self._backing_vf.get_parent_map(keys)
+
     def get_record_stream(self, keys, sort_order, include_delta_closure):
         self.calls.append(("get_record_stream", keys, sort_order,
             include_delta_closure))




More information about the bazaar-commits mailing list