Rev 3905: Change the XMLSerializer.read_inventory_from_string api. in http://bzr.arbash-meinel.com/branches/bzr/1.11/xml_cache

John Arbash Meinel john at arbash-meinel.com
Sat Dec 13 03:19:48 GMT 2008


At http://bzr.arbash-meinel.com/branches/bzr/1.11/xml_cache

------------------------------------------------------------
revno: 3905
revision-id: john at arbash-meinel.com-20081213031940-goymz22b10o9zu32
parent: john at arbash-meinel.com-20081212200628-xmm9i33jq3d6tsh3
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: xml_cache
timestamp: Fri 2008-12-12 21:19:40 -0600
message:
  Change the XMLSerializer.read_inventory_from_string api.
  
  This allows us to pass in the entry cache, rather than using a global.
  This gives a lifetime to the cache, and eliminates some of the
  concerns about expecting a different IE from different serializers, etc.
  
  The cache is also cleared when the repo is unlocked.
-------------- next part --------------
=== modified file 'bzrlib/repository.py'
--- a/bzrlib/repository.py	2008-12-11 21:36:10 +0000
+++ b/bzrlib/repository.py	2008-12-13 03:19:40 +0000
@@ -25,6 +25,7 @@
     check,
     debug,
     errors,
+    fifo_cache,
     generate_ids,
     gpg,
     graph,
@@ -842,6 +843,8 @@
         # Should fetch trigger a reconcile after the fetch? Only needed for
         # some repository formats that can suffer internal inconsistencies.
         self._fetch_reconcile = False
+        # An InventoryEntry cache, used during deserialization
+        self._inventory_entry_cache = fifo_cache.FIFOCache(10*1024)
 
     def __repr__(self):
         return '%s(%r)' % (self.__class__.__name__,
@@ -1145,6 +1148,8 @@
                 raise errors.BzrError(
                     'Must end write groups before releasing write locks.')
         self.control_files.unlock()
+        if self.control_files._lock_count == 0:
+            self._inventory_entry_cache.clear()
         for repo in self._fallback_repositories:
             repo.unlock()
 
@@ -1696,7 +1701,8 @@
         :param revision_id: The expected revision id of the inventory.
         :param xml: A serialised inventory.
         """
-        result = self._serializer.read_inventory_from_string(xml, revision_id)
+        result = self._serializer.read_inventory_from_string(xml, revision_id,
+                    entry_cache=self._inventory_entry_cache)
         if result.revision_id != revision_id:
             raise AssertionError('revision id mismatch %s != %s' % (
                 result.revision_id, revision_id))

=== modified file 'bzrlib/xml5.py'
--- a/bzrlib/xml5.py	2008-12-12 20:06:28 +0000
+++ b/bzrlib/xml5.py	2008-12-13 03:19:40 +0000
@@ -51,8 +51,6 @@
         #   avoiding attributes     2.46s
         #   adding assertions       2.50s
         #   last_parent cache       2.52s (worse, removed)
-        if entry_cache is None:
-            entry_cache = xml8._entry_cache
         unpack_entry = self._unpack_entry
         byid = inv._byid
         for e in elt:

=== modified file 'bzrlib/xml8.py'
--- a/bzrlib/xml8.py	2008-12-12 20:06:28 +0000
+++ b/bzrlib/xml8.py	2008-12-13 03:19:40 +0000
@@ -20,7 +20,6 @@
 from bzrlib import (
     cache_utf8,
     errors,
-    fifo_cache,
     inventory,
     revision as _mod_revision,
     trace,
@@ -40,7 +39,6 @@
     "<":"&lt;",
     ">":"&gt;",
     }
-_entry_cache = fifo_cache.FIFOCache(10*1024)
 
 
 def _ensure_utf8_re():
@@ -376,8 +374,6 @@
         if format != self.format_num:
             raise errors.UnexpectedInventoryFormat('Invalid format version %r'
                                                    % format)
-        if entry_cache is None:
-            entry_cache = _entry_cache
         revision_id = elt.get('revision_id')
         if revision_id is not None:
             revision_id = cache_utf8.encode(revision_id)

=== modified file 'bzrlib/xml_serializer.py'
--- a/bzrlib/xml_serializer.py	2008-06-12 15:51:15 +0000
+++ b/bzrlib/xml_serializer.py	2008-12-13 03:19:40 +0000
@@ -59,7 +59,8 @@
     def write_inventory_to_string(self, inv):
         raise NotImplementedError(self.write_inventory_to_string)
 
-    def read_inventory_from_string(self, xml_string, revision_id=None):
+    def read_inventory_from_string(self, xml_string, revision_id=None,
+                                   entry_cache=None):
         """Read xml_string into an inventory object.
 
         :param xml_string: The xml to read.
@@ -70,9 +71,13 @@
             serialised without a revision identifier can be given the right
             revision id (but not for working tree inventories where users can
             edit the data without triggering checksum errors or anything).
+        :param entry_cache: An optional cache of InventoryEntry objects. If
+            supplied we will look up entries via (file_id, revision_id) which
+            should map to a valid InventoryEntry (File/Directory/etc) object.
         """
         try:
-            return self._unpack_inventory(fromstring(xml_string), revision_id)
+            return self._unpack_inventory(fromstring(xml_string), revision_id,
+                                          entry_cache=entry_cache)
         except ParseError, e:
             raise errors.UnexpectedInventoryFormat(e)
 



More information about the bazaar-commits mailing list