Rev 4404: Switch the api from VF.add_text to VF._add_text and trim some extra 'features'. in lp:///~jameinel/bzr/1.16-commit-fulltext

John Arbash Meinel john at arbash-meinel.com
Thu Jun 4 22:10:09 BST 2009


At lp:///~jameinel/bzr/1.16-commit-fulltext

------------------------------------------------------------
revno: 4404
revision-id: john at arbash-meinel.com-20090604210951-5mxlt1h8p4xdh6pl
parent: john at arbash-meinel.com-20090602203242-fc65n34rxr7169dh
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 1.16-commit-fulltext
timestamp: Thu 2009-06-04 16:09:51 -0500
message:
  Switch the api from VF.add_text to VF._add_text and trim some extra 'features'.
  
  Commit won't be using parent_texts or left_matching_blocks or check_content.
  And for something like fast-import, it will be tuned for GC repositories anyway,
  and there we don't need parent_texts anyway.
-------------- next part --------------
=== modified file 'bzrlib/groupcompress.py'
--- a/bzrlib/groupcompress.py	2009-06-02 20:08:16 +0000
+++ b/bzrlib/groupcompress.py	2009-06-04 21:09:51 +0000
@@ -992,9 +992,7 @@
                                                nostore_sha=nostore_sha))[0]
         return sha1, length, None
 
-    def add_text(self, key, parents, text, parent_texts=None,
-        nostore_sha=None, random_id=False,
-        check_content=True):
+    def _add_text(self, key, parents, text, nostore_sha=None, random_id=False):
         """See VersionedFiles.add_text()."""
         self._index._check_write_ok()
         self._check_add(key, None, random_id, check_content=False)

=== modified file 'bzrlib/knit.py'
--- a/bzrlib/knit.py	2009-06-02 20:32:42 +0000
+++ b/bzrlib/knit.py	2009-06-04 21:09:51 +0000
@@ -914,9 +914,7 @@
             parent_texts, left_matching_blocks, nostore_sha, random_id,
             line_bytes=line_bytes)
 
-    def add_text(self, key, parents, text, parent_texts=None,
-        nostore_sha=None, random_id=False,
-        check_content=True):
+    def _add_text(self, key, parents, text, nostore_sha=None, random_id=False):
         """See VersionedFiles.add_text()."""
         self._index._check_write_ok()
         self._check_add(key, None, random_id, check_content=False)
@@ -928,7 +926,7 @@
             # an empty tuple instead.
             parents = ()
         return self._add(key, None, parents,
-            parent_texts, None, nostore_sha, random_id,
+            None, None, nostore_sha, random_id,
             line_bytes=text)
 
     def _add(self, key, lines, parents, parent_texts,

=== modified file 'bzrlib/repository.py'
--- a/bzrlib/repository.py	2009-06-02 20:32:42 +0000
+++ b/bzrlib/repository.py	2009-06-04 21:09:51 +0000
@@ -816,16 +816,10 @@
         self.basis_delta_revision = basis_revision_id
 
     def _add_text_to_weave(self, file_id, new_text, parents, nostore_sha):
-        # Note: as we read the content directly from the tree, we know its not
-        # been turned into unicode or badly split - but a broken tree
-        # implementation could give us bad output from readlines() so this is
-        # not a guarantee of safety. What would be better is always checking
-        # the content during test suite execution. RBC 20070912
-        parent_keys = tuple((file_id, parent) for parent in parents)
-        return self.repository.texts.add_text(
+        parent_keys = tuple([(file_id, parent) for parent in parents])
+        return self.repository.texts._add_text(
             (file_id, self._new_revision_id), parent_keys, new_text,
-            nostore_sha=nostore_sha, random_id=self.random_revid,
-            check_content=False)[0:2]
+            nostore_sha=nostore_sha, random_id=self.random_revid)[0:2]
 
 
 class RootCommitBuilder(CommitBuilder):

=== modified file 'bzrlib/tests/test_versionedfile.py'
--- a/bzrlib/tests/test_versionedfile.py	2009-06-02 20:08:16 +0000
+++ b/bzrlib/tests/test_versionedfile.py	2009-06-04 21:09:51 +0000
@@ -1497,7 +1497,7 @@
         records.sort()
         self.assertEqual([(key0, 'a\nb\n'), (key1, 'b\nc\n')], records)
 
-    def test_add_text(self):
+    def test__add_text(self):
         f = self.get_versionedfiles()
         if self.key_length == 1:
             key0 = ('r0',)
@@ -1509,11 +1509,11 @@
             key1 = ('fid', 'r1')
             key2 = ('fid', 'r2')
             keyf = ('fid', 'foo')
-        f.add_text(key0, [], 'a\nb\n')
+        f._add_text(key0, [], 'a\nb\n')
         if self.graph:
-            f.add_text(key1, [key0], 'b\nc\n')
+            f._add_text(key1, [key0], 'b\nc\n')
         else:
-            f.add_text(key1, [], 'b\nc\n')
+            f._add_text(key1, [], 'b\nc\n')
         keys = f.keys()
         self.assertTrue(key0 in keys)
         self.assertTrue(key1 in keys)
@@ -1584,8 +1584,8 @@
                 sha, _, _ = vf.add_lines(self.get_simple_key(version), [],
                                          lines)
             else:
-                sha, _, _ = vf.add_text(self.get_simple_key(version), [],
-                                        ''.join(lines))
+                sha, _, _ = vf._add_text(self.get_simple_key(version), [],
+                                         ''.join(lines))
             shas.append(sha)
         # we now have a copy of all the lines in the vf.
         for sha, (version, lines) in zip(
@@ -1595,7 +1595,7 @@
                 vf.add_lines, new_key, [], lines,
                 nostore_sha=sha)
             self.assertRaises(errors.ExistingContent,
-                vf.add_text, new_key, [], ''.join(lines),
+                vf._add_text, new_key, [], ''.join(lines),
                 nostore_sha=sha)
             # and no new version should have been added.
             record = vf.get_record_stream([new_key], 'unordered', True).next()
@@ -1604,7 +1604,7 @@
     def test_add_lines_nostoresha(self):
         self._add_content_nostoresha(add_lines=True)
 
-    def test_add_text_nostoresha(self):
+    def test__add_text_nostoresha(self):
         self._add_content_nostoresha(add_lines=False)
 
     def test_add_lines_return(self):

=== modified file 'bzrlib/versionedfile.py'
--- a/bzrlib/versionedfile.py	2009-06-02 18:59:18 +0000
+++ b/bzrlib/versionedfile.py	2009-06-04 21:09:51 +0000
@@ -829,13 +829,35 @@
         """
         raise NotImplementedError(self.add_lines)
 
-    def add_text(self, key, parents, text, parent_texts=None,
-                 nostore_sha=None, random_id=False, check_content=True):
+    def _add_text(self, key, parents, text, nostore_sha=None, random_id=False):
+        """Add a text to the store.
+
+        This is a private function for use by CommitBuilder.
+
+        :param key: The key tuple of the text to add. If the last element is
+            None, a CHK string will be generated during the addition.
+        :param parents: The parents key tuples of the text to add.
+        :param text: A string containing the text to be committed.
+        :param nostore_sha: Raise ExistingContent and do not add the lines to
+            the versioned file if the digest of the lines matches this.
+        :param random_id: If True a random id has been selected rather than
+            an id determined by some deterministic process such as a converter
+            from a foreign VCS. When True the backend may choose not to check
+            for uniqueness of the resulting key within the versioned file, so
+            this should only be done when the result is expected to be unique
+            anyway.
+        :param check_content: If True, the lines supplied are verified to be
+            bytestrings that are correctly formed lines.
+        :return: The text sha1, the number of bytes in the text, and an opaque
+                 representation of the inserted version which can be provided
+                 back to future _add_text calls in the parent_texts dictionary.
+        """
+        # The default implementation just thunks over to .add_lines(),
+        # inefficient, but it works.
         return self.add_lines(key, parents, osutils.split_lines(text),
-                              parent_texts=parent_texts,
                               nostore_sha=nostore_sha,
                               random_id=random_id,
-                              check_content=check_content)
+                              check_content=True)
 
     def add_mpdiffs(self, records):
         """Add mpdiffs to this VersionedFile.



More information about the bazaar-commits mailing list