Rev 3386: define behaviour for add_lines with stacked storage. in http://people.ubuntu.com/~robertc/baz2.0/shallow-branch

Robert Collins robertc at robertcollins.net
Mon Jun 23 05:45:04 BST 2008


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

------------------------------------------------------------
revno: 3386
revision-id: robertc at robertcollins.net-20080623044500-szw4ohqv0lxy44yk
parent: robertc at robertcollins.net-20080623023518-1zae3rsj8h0npnt1
committer: Robert Collins <robertc at robertcollins.net>
branch nick: stacking-knits
timestamp: Mon 2008-06-23 14:45:00 +1000
message:
  define behaviour for add_lines with stacked storage.
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	2008-06-23 01:13:20 +0000
+++ b/bzrlib/knit.py	2008-06-23 04:45:00 +0000
@@ -895,7 +895,11 @@
         fulltext_size = None
         for count in xrange(self._max_delta_chain):
             # XXX: Collapse these two queries:
-            method = self._index.get_method(parent)
+            try:
+                method = self._index.get_method(parent)
+            except RevisionNotPresent:
+                # Some basis is not locally present: always delta
+                return False
             index, pos, size = self._index.get_position(parent)
             if method == 'fulltext':
                 fulltext_size = size
@@ -1832,7 +1836,10 @@
         """
         prefix, suffix = self._split_key(key)
         self._load_prefixes([prefix])
-        return self._kndx_cache[prefix][0][suffix][1]
+        try:
+            return self._kndx_cache[prefix][0][suffix][1]
+        except KeyError:
+            raise RevisionNotPresent(key, self)
 
     def get_parent_map(self, keys):
         """Get a map of the parents of keys.

=== modified file 'bzrlib/tests/test_knit.py'
--- a/bzrlib/tests/test_knit.py	2008-06-23 02:35:18 +0000
+++ b/bzrlib/tests/test_knit.py	2008-06-23 04:45:00 +0000
@@ -1395,7 +1395,26 @@
         test.add_fallback_versioned_files(basis)
 
     def test_add_lines(self):
-        pass
+        # lines added to the test are not added to the basis
+        basis, test = self.get_basis_and_test_knit()
+        key = ('foo',)
+        key_basis = ('bar',)
+        key_cross_border = ('quux',)
+        key_delta = ('zaphod',)
+        test.add_lines(key, (), ['foo\n'])
+        self.assertEqual({}, basis.get_parent_map([key]))
+        # lines added to the test that reference across the stack do a
+        # fulltext.
+        basis.add_lines(key_basis, (), ['foo\n'])
+        basis.calls = []
+        test.add_lines(key_cross_border, (key_basis,), ['foo\n'])
+        self.assertEqual('fulltext', test._index.get_method(key_cross_border))
+        self.assertEqual([("get_parent_map", set([key_basis]))], basis.calls)
+        basis.calls = []
+        # Subsequent adds do delta.
+        test.add_lines(key_delta, (key_cross_border,), ['foo\n'])
+        self.assertEqual('line-delta', test._index.get_method(key_delta))
+        self.assertEqual([], basis.calls)
 
     def test_annotate(self):
         # annotations from the test knit are answered without asking the basis




More information about the bazaar-commits mailing list