Rev 2851: * ``KnitVersionedFile.add*`` will no longer cache added records even when in http://people.ubuntu.com/~robertc/baz2.0/knits

Robert Collins robertc at robertcollins.net
Mon Sep 24 03:30:17 BST 2007


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

------------------------------------------------------------
revno: 2851
revision-id: robertc at robertcollins.net-20070924022944-lv2e2glumuo3ne8q
parent: pqm at pqm.ubuntu.com-20070923210826-t3ymvo1l68z96in1
committer: Robert Collins <robertc at robertcollins.net>
branch nick: knits
timestamp: Mon 2007-09-24 12:29:44 +1000
message:
  * ``KnitVersionedFile.add*`` will no longer cache added records even when
    enable_cache() has been called - the caching feature is now exclusively for
    reading existing data. (Robert Collins)
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/knit.py                 knit.py-20051212171256-f056ac8f0fbe1bd9
  bzrlib/tests/test_knit.py      test_knit.py-20051212171302-95d4c00dd5f11f2b
=== modified file 'NEWS'
--- a/NEWS	2007-09-22 15:43:48 +0000
+++ b/NEWS	2007-09-24 02:29:44 +0000
@@ -91,6 +91,10 @@
 
   API BREAKS:
 
+   * ``KnitVersionedFile.add*`` will no longer cache added records even when
+     enable_cache() has been called - the caching feature is now exclusively for
+     reading existing data. (Robert Collins)
+
    * The ``VersionedFile`` interface now allows content checks to be bypassed
      by supplying check_content=False.  This saves nearly 30% of the minimum
      cost to store a version of a file. (Robert Collins)

=== modified file 'bzrlib/knit.py'
--- a/bzrlib/knit.py	2007-09-21 06:35:09 +0000
+++ b/bzrlib/knit.py	2007-09-24 02:29:44 +0000
@@ -104,6 +104,7 @@
 from bzrlib.osutils import (
     contains_whitespace,
     contains_linebreaks,
+    sha_string,
     sha_strings,
     )
 from bzrlib.symbol_versioning import DEPRECATED_PARAMETER, deprecated_passed
@@ -854,17 +855,12 @@
 
         Any versions not present will be converted into ghosts.
         """
-        #  461    0   6546.0390     43.9100   bzrlib.knit:489(_add)
-        # +400    0    889.4890    418.9790   +bzrlib.knit:192(lower_fulltext)
-        # +461    0   1364.8070    108.8030   +bzrlib.knit:996(add_record)
-        # +461    0    193.3940     41.5720   +bzrlib.knit:898(add_version)
-        # +461    0    134.0590     18.3810   +bzrlib.osutils:361(sha_strings)
-        # +461    0     36.3420     15.4540   +bzrlib.knit:146(make)
-        # +1383   0      8.0370      8.0370   +<len>
-        # +61     0     13.5770      7.9190   +bzrlib.knit:199(lower_line_delta)
-        # +61     0    963.3470      7.8740   +bzrlib.knit:427(_get_content)
-        # +61     0    973.9950      5.2950   +bzrlib.knit:136(line_delta)
-        # +61     0   1918.1800      5.2640   +bzrlib.knit:359(_merge_annotations)
+        # first thing, if the content is something we don't need to store, find
+        # that out.
+        line_bytes = ''.join(lines)
+        digest = sha_string(line_bytes)
+        if nostore_sha == digest:
+            raise errors.ExistingContent
 
         present_parents = []
         if parent_texts is None:
@@ -879,10 +875,7 @@
              present_parents[0] != parents[0])):
             delta = False
 
-        digest = sha_strings(lines)
-        if nostore_sha == digest:
-            raise errors.ExistingContent
-        text_length = sum(map(len, lines))
+        text_length = len(line_bytes)
         options = []
         if lines:
             if lines[-1][-1] != '\n':
@@ -908,13 +901,20 @@
         if delta:
             options.append('line-delta')
             store_lines = self.factory.lower_line_delta(delta_hunks)
+            size, bytes = self._data._record_to_data(version_id, digest,
+                store_lines)
         else:
             options.append('fulltext')
+            # get mixed annotation + content and feed it into the
+            # serialiser.
             store_lines = self.factory.lower_fulltext(content)
+            size, bytes = self._data._record_to_data(version_id, digest,
+                store_lines)
 
-        access_memo = self._data.add_record(version_id, digest, store_lines)
+        access_memo = self._data.add_raw_records([size], bytes)[0]
         self._index.add_versions(
-            ((version_id, options, access_memo, parents),), random_id=random_id)
+            ((version_id, options, access_memo, parents),),
+            random_id=random_id)
         return digest, text_length, content
 
     def check(self, progress_bar=None):
@@ -2005,17 +2005,6 @@
         """
         return self._access.add_raw_records(sizes, raw_data)
         
-    def add_record(self, version_id, digest, lines):
-        """Write new text record to disk. 
-        
-        Returns index data for retrieving it later, as per add_raw_records.
-        """
-        size, bytes = self._record_to_data(version_id, digest, lines)
-        result = self.add_raw_records([size], bytes)
-        if self._do_cache:
-            self._cache[version_id] = bytes
-        return result[0]
-
     def _parse_record_header(self, version_id, raw_data):
         """Parse a record header for consistency.
 

=== modified file 'bzrlib/tests/test_knit.py'
--- a/bzrlib/tests/test_knit.py	2007-09-21 06:35:09 +0000
+++ b/bzrlib/tests/test_knit.py	2007-09-24 02:29:44 +0000
@@ -1907,11 +1907,8 @@
 
 class TestKnitCaching(KnitTests):
     
-    def create_knit(self, cache_add=False):
+    def create_knit(self):
         k = self.make_test_knit(True)
-        if cache_add:
-            k.enable_cache()
-
         k.add_lines('text-1', [], split_lines(TEXT_1))
         k.add_lines('text-2', [], split_lines(TEXT_2))
         return k
@@ -1921,14 +1918,6 @@
         # Nothing should be cached without setting 'enable_cache'
         self.assertEqual({}, k._data._cache)
 
-    def test_cache_add_and_clear(self):
-        k = self.create_knit(True)
-
-        self.assertEqual(['text-1', 'text-2'], sorted(k._data._cache.keys()))
-
-        k.clear_cache()
-        self.assertEqual({}, k._data._cache)
-
     def test_cache_data_read_raw(self):
         k = self.create_knit()
 



More information about the bazaar-commits mailing list