Rev 2842: * Commit no longer checks for new text keys during insertion when the in http://people.ubuntu.com/~robertc/baz2.0/knits

Robert Collins robertc at robertcollins.net
Fri Sep 21 02:49:58 BST 2007


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

------------------------------------------------------------
revno: 2842
revision-id: robertc at robertcollins.net-20070921014929-1t3csvep14m111q8
parent: pqm at pqm.ubuntu.com-20070921005024-anlkzk5nrdtujta4
committer: Robert Collins <robertc at robertcollins.net>
branch nick: knits
timestamp: Fri 2007-09-21 11:49:29 +1000
message:
  * Commit no longer checks for new text keys during insertion when the
    revision id was deterministically unique. (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-20 22:44:15 +0000
+++ b/NEWS	2007-09-21 01:49:29 +0000
@@ -32,6 +32,9 @@
    * Commit in quiet mode is now slightly faster as the information to
      output is no longer calculated. (Ian Clatworthy)
 
+   * Commit no longer checks for new text keys during insertion when the
+     revision id was deterministically unique. (Robert Collins)
+
    * Inventory serialisation no longer double-sha's the content.
      (Robert Collins)
 

=== modified file 'bzrlib/knit.py'
--- a/bzrlib/knit.py	2007-09-21 00:50:24 +0000
+++ b/bzrlib/knit.py	2007-09-21 01:49:29 +0000
@@ -820,7 +820,7 @@
         """See VersionedFile.add_lines_with_ghosts()."""
         self._check_add(version_id, lines, random_id, check_content)
         return self._add(version_id, lines, parents, self.delta,
-            parent_texts, None, nostore_sha)
+            parent_texts, None, nostore_sha, random_id)
 
     def _add_lines(self, version_id, parents, lines, parent_texts,
         left_matching_blocks, nostore_sha, random_id, check_content):
@@ -828,7 +828,7 @@
         self._check_add(version_id, lines, random_id, check_content)
         self._check_versions_present(parents)
         return self._add(version_id, lines[:], parents, self.delta,
-            parent_texts, left_matching_blocks, nostore_sha)
+            parent_texts, left_matching_blocks, nostore_sha, random_id)
 
     def _check_add(self, version_id, lines, random_id, check_content):
         """check that version_id and lines are safe to add."""
@@ -846,7 +846,7 @@
             self._check_lines_are_lines(lines)
 
     def _add(self, version_id, lines, parents, delta, parent_texts,
-             left_matching_blocks, nostore_sha):
+        left_matching_blocks, nostore_sha, random_id):
         """Add a set of lines on top of version specified by parents.
 
         If delta is true, compress the text as a line-delta against
@@ -1369,11 +1369,13 @@
         """Add a version record to the index."""
         self.add_versions(((version_id, options, index_memo, parents),))
 
-    def add_versions(self, versions):
+    def add_versions(self, versions, random_id=False):
         """Add multiple versions to the index.
         
         :param versions: a list of tuples:
                          (version_id, options, pos, size, parents).
+        :param random_id: If True the ids being added were randomly generated
+            and no check for existence will be performed.
         """
         lines = []
         orig_history = self._history[:]
@@ -1709,7 +1711,7 @@
         """Add a version record to the index."""
         return self.add_versions(((version_id, options, access_memo, parents),))
 
-    def add_versions(self, versions):
+    def add_versions(self, versions, random_id=False):
         """Add multiple versions to the index.
         
         This function does not insert data into the Immutable GraphIndex
@@ -1719,6 +1721,8 @@
 
         :param versions: a list of tuples:
                          (version_id, options, pos, size, parents).
+        :param random_id: If True the ids being added were randomly generated
+            and no check for existence will be performed.
         """
         if not self._add_callback:
             raise errors.ReadOnlyError(self)
@@ -1753,12 +1757,13 @@
                         "in parentless index.")
                 node_refs = ()
             keys[key] = (value, node_refs)
-        present_nodes = self._get_entries(keys)
-        for (index, key, value, node_refs) in present_nodes:
-            if (value, node_refs) != keys[key]:
-                raise KnitCorrupt(self, "inconsistent details in add_versions"
-                    ": %s %s" % ((value, node_refs), keys[key]))
-            del keys[key]
+        if not random_id:
+            present_nodes = self._get_entries(keys)
+            for (index, key, value, node_refs) in present_nodes:
+                if (value, node_refs) != keys[key]:
+                    raise KnitCorrupt(self, "inconsistent details in add_versions"
+                        ": %s %s" % ((value, node_refs), keys[key]))
+                del keys[key]
         result = []
         if self._parents:
             for key, (value, node_refs) in keys.iteritems():

=== modified file 'bzrlib/tests/test_knit.py'
--- a/bzrlib/tests/test_knit.py	2007-09-05 22:25:01 +0000
+++ b/bzrlib/tests/test_knit.py	2007-09-21 01:49:29 +0000
@@ -816,6 +816,18 @@
         self.assertEqual(["c"], index.get_parents_with_ghosts("a"))
         self.assertEqual(["a"], index.get_parents_with_ghosts("b"))
 
+    def test_add_versions_random_id_is_accepted(self):
+        transport = MockTransport([
+            _KnitIndex.HEADER
+            ])
+        index = self.get_knit_index(transport, "filename", "r")
+
+        index.add_versions([
+            ("a", ["option"], (None, 0, 1), ["b"]),
+            ("a", ["opt"], (None, 1, 2), ["c"]),
+            ("b", ["option"], (None, 2, 3), ["a"])
+            ], random_id=True)
+
     def test_delay_create_and_add_versions(self):
         transport = MockTransport()
 
@@ -2307,6 +2319,10 @@
             [('new', 'no-eol,line-delta', (None, 0, 100), ['parent'])])
         self.assertEqual([], self.caught_entries)
 
+    def test_add_versions_random_id_accepted(self):
+        index = self.two_graph_index(catch_adds=True)
+        index.add_versions([], random_id=True)
+
     def test_add_versions_same_dup(self):
         index = self.two_graph_index(catch_adds=True)
         # options can be spelt two different ways
@@ -2570,6 +2586,10 @@
             [('new', 'no-eol,fulltext', (None, 0, 100), ['parent'])])
         self.assertEqual([], self.caught_entries)
 
+    def test_add_versions_random_id_accepted(self):
+        index = self.two_graph_index(catch_adds=True)
+        index.add_versions([], random_id=True)
+
     def test_add_versions_same_dup(self):
         index = self.two_graph_index(catch_adds=True)
         # options can be spelt two different ways



More information about the bazaar-commits mailing list