Rev 3805: Quick hack to allow chk inventory pages to refer to whatever possible page they came from. in http://bzr.arbash-meinel.com/branches/bzr/brisbane/knit_parent_hack

John Arbash Meinel john at arbash-meinel.com
Wed Dec 3 01:32:39 GMT 2008


At http://bzr.arbash-meinel.com/branches/bzr/brisbane/knit_parent_hack

------------------------------------------------------------
revno: 3805
revision-id: john at arbash-meinel.com-20081203013227-rou9cbbpgd6bh9fh
parent: john at arbash-meinel.com-20081202235625-h5fo44xy2hxeopo2
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: knit_parent_hack
timestamp: Tue 2008-12-02 19:32:27 -0600
message:
  Quick hack to allow chk inventory pages to refer to whatever possible page they came from.
  Causes a lot of collisions in the Knit layer, and fails to convert bzrtools compeletely.
-------------- next part --------------
=== modified file 'bzrlib/chk_map.py'
--- a/bzrlib/chk_map.py	2008-12-02 23:56:25 +0000
+++ b/bzrlib/chk_map.py	2008-12-03 01:32:27 +0000
@@ -40,7 +40,7 @@
 import heapq
 from bzrlib import lazy_import
 lazy_import.lazy_import(globals(), """
-from bzrlib import versionedfile
+from bzrlib import errors, trace, versionedfile
 """)
 
 
@@ -383,6 +383,7 @@
         :param key_width: The width of keys for this node.
         """
         self._key = None
+        self._orig_key = None
         # Current number of elements
         self._len = 0
         self._maximum_size = 0
@@ -460,6 +461,7 @@
         result._len = length
         result._maximum_size = maximum_size
         result._key = key
+        result._orig_key = key
         result._key_width = width
         result._size = len(bytes)
         return result
@@ -537,6 +539,7 @@
                     node = LeafNode()
                     node.set_maximum_size(self._maximum_size)
                     node._key_width = self._key_width
+                    node._orig_key = self._orig_key
                     result[prefix] = node
                 else:
                     node = result[prefix]
@@ -557,8 +560,20 @@
         lines.append("%d\n" % self._len)
         for key, value in sorted(self._items.items()):
             lines.append("%s\x00%s\n" % ('\x00'.join(key), value))
-        sha1, _, _ = store.add_lines((None,), (), lines)
-        self._key = ("sha1:" + sha1,)
+        if self._orig_key is None:
+            parents = ()
+        else:
+            parents = (self._orig_key,)
+        try:
+            sha1, _, _ = store.add_lines((None,), parents, lines)
+        except errors.DuplicateKeyKnitCorrupt, e:
+            trace.warning('It seems this text already exists somewhere with'
+                          ' different details: %s',
+                          e)
+            self._key = e.key
+        else:
+            self._key = ("sha1:" + sha1,)
+        self._orig_key = self._key
         return [self._key]
 
     def _serialised_key(self, key):
@@ -666,6 +681,7 @@
         result._len = length
         result._maximum_size = maximum_size
         result._key = key
+        result._orig_key = key
         result._key_width = width
         result._size = len(bytes)
         result._node_width = len(prefix)
@@ -814,8 +830,20 @@
             else:
                 key = node._key[0]
             lines.append("%s\x00%s\n" % (prefix, key))
-        sha1, _, _ = store.add_lines((None,), (), lines)
-        self._key = ("sha1:" + sha1,)
+        if self._orig_key is None:
+            parents = ()
+        else:
+            parents = (self._orig_key,)
+        try:
+            sha1, _, _ = store.add_lines((None,), parents, lines)
+        except errors.DuplicateKeyKnitCorrupt, e:
+            trace.warning('It seems this text already exists somewhere with'
+                          ' different details: %s',
+                          e)
+            self._key = e.key
+        else:
+            self._key = ("sha1:" + sha1,)
+        self._orig_key = self._key
         yield self._key
 
     def _serialised_key(self, key):

=== modified file 'bzrlib/errors.py'
--- a/bzrlib/errors.py	2008-11-03 21:52:46 +0000
+++ b/bzrlib/errors.py	2008-12-03 01:32:27 +0000
@@ -1442,6 +1442,13 @@
         self.content = content
 
 
+class DuplicateKeyKnitCorrupt(KnitCorrupt):
+
+    def __init__(self, filename, how, key):
+        KnitCorrupt.__init__(self, filename, how)
+        self.key = key
+
+
 class KnitDataStreamIncompatible(KnitError):
     # Not raised anymore, as we can convert data streams.  In future we may
     # need it again for more exotic cases, so we're keeping it around for now.

=== modified file 'bzrlib/knit.py'
--- a/bzrlib/knit.py	2008-11-11 04:36:29 +0000
+++ b/bzrlib/knit.py	2008-12-03 01:32:27 +0000
@@ -2134,8 +2134,10 @@
             for (index, key, value, node_refs) in present_nodes:
                 if (value[0] != keys[key][0][0] or
                     node_refs != keys[key][1]):
-                    raise KnitCorrupt(self, "inconsistent details in add_records"
-                        ": %s %s" % ((value, node_refs), keys[key]))
+                    raise errors.DuplicateKeyKnitCorrupt(self,
+                        "inconsistent details in add_records"
+                        ":\n%s\n%s" % ((value, node_refs), keys[key]),
+                        key)
                 del keys[key]
         result = []
         if self._parents:

=== modified file 'bzrlib/repofmt/pack_repo.py'
--- a/bzrlib/repofmt/pack_repo.py	2008-11-20 19:41:26 +0000
+++ b/bzrlib/repofmt/pack_repo.py	2008-12-03 01:32:27 +0000
@@ -258,7 +258,7 @@
         # The relative locations of the packs are constrained, but all are
         # passed in because the caller has them, so as to avoid object churn.
         if use_chk_index:
-            chk_index = index_builder_class(reference_lists=0)
+            chk_index = index_builder_class(reference_lists=2)
         else:
             chk_index = None
         Pack.__init__(self,
@@ -1910,9 +1910,9 @@
             self.chk_bytes = KnitVersionedFiles(
                 _KnitGraphIndex(self._pack_collection.chk_index.combined_index,
                     add_callback=self._pack_collection.chk_index.add_callback,
-                    deltas=False, parents=False, is_locked=self.is_locked),
+                    deltas=True, parents=True, is_locked=self.is_locked),
                 data_access=self._pack_collection.chk_index.data_access,
-                max_delta_chain=0)
+                max_delta_chain=200)
         else:
             self.chk_bytes = None
         # True when the repository object is 'write locked' (as opposed to the



More information about the bazaar-commits mailing list