PATCH: cache basis inventory in .bzr

Martin Pool mbp at sourcefrog.net
Fri Nov 25 07:51:48 GMT 2005


Here's another updated version, but it still causes some test failures.   

Some of the branch tests want to set the revision history to point to
revisions which are not stored.  That's probably not such a reasonable
thing to do anymore, and probably the tests should be changed.

-- 
Martin
-------------- next part --------------
=== modified file 'bzrlib/branch.py'
--- bzrlib/branch.py	
+++ bzrlib/branch.py	
@@ -844,8 +844,17 @@
 
     @needs_write_lock
     def set_revision_history(self, rev_history):
-        """See Branch.set_revision_history."""
+        """Set the revision history to a sequence of revision ids.
+
+        These identify the revisions considered on the mainline of this branch.
+        """
+        old_revision = self.last_revision()
+        if len(rev_history):
+            new_revision = rev_history[-1]
+        else:
+            new_revision = None
         self.put_controlfile('revision-history', '\n'.join(rev_history))
+        self.working_tree().set_last_revision(new_revision, old_revision)
 
     def has_revision(self, revision_id):
         """See Branch.has_revision."""
@@ -992,6 +1001,16 @@
             inv = self.get_revision_inventory(revision_id)
             return RevisionTree(self.weave_store, inv, revision_id)
 
+    def basis_tree(self):
+        """See Branch.basis_tree."""
+        try:
+            revision_id = self.last_revision()
+            xml = self.working_tree().read_basis_inventory(revision_id)
+            inv = bzrlib.xml5.serializer_v5.read_inventory_from_string(xml)
+            return RevisionTree(self.weave_store, inv, revision_id)
+        except NoSuchFile, e:
+            return self.revision_tree(self.last_revision())
+
     def working_tree(self):
         """See Branch.working_tree."""
         from bzrlib.workingtree import WorkingTree

=== modified file 'bzrlib/clone.py'
--- bzrlib/clone.py	
+++ bzrlib/clone.py	
@@ -88,10 +88,10 @@
         branch_to = Branch.initialize(to_location)
         mutter("copy branch from %s to %s", branch_from, branch_to)
         branch_to.working_tree().set_root_id(branch_from.get_root_id())
-        branch_to.set_revision_history(history)
         _copy_control_weaves(branch_from, branch_to)
         _copy_text_weaves(branch_from, branch_to)
         _copy_revision_store(branch_from, branch_to)
+        branch_to.set_revision_history(history)
         build_working_dir(to_location)
         branch_to.set_parent(branch_from.base)
         mutter("copied")

=== modified file 'bzrlib/workingtree.py'
--- bzrlib/workingtree.py	
+++ bzrlib/workingtree.py	
@@ -68,6 +68,7 @@
                             realpath,
                             relpath,
                             rename)
+import bzrlib.transport
 import bzrlib.tree
 from bzrlib.trace import mutter
 import bzrlib.xml5
@@ -777,6 +778,35 @@
         """See Branch.lock_write, and WorkingTree.unlock."""
         return self.branch.lock_write()
 
+    def _basis_inventory_name(self, revision_id):
+        return 'basis-inventory.%s' % revision_id
+
+    def set_last_revision(self, new_revision, old_revision):
+        """Set the basis revision of the working tree.
+        
+        new_revision is the new basis revision_id.
+        old_revision was the previous basis revision_id.
+
+        Either may be None if going from or to an empty branch.
+        """
+        # TODO: working tree should probably remember the old revision itself
+        if old_revision:
+            path = self._basis_inventory_name(old_revision)
+            path = self.branch._rel_controlfilename(path)
+            try:
+                self.branch._transport.delete(path)
+            except (bzrlib.transport.TransportError, IOError), e:
+                mutter("ignored %s while deleting %s", e, path)
+        if new_revision is not None:
+            xml = self.branch.get_inventory_xml(new_revision)
+            path = self._basis_inventory_name(new_revision)
+            self.branch.put_controlfile(path, xml)
+
+    def read_basis_inventory(self, revision_id):
+        """Read the cached basis inventory."""
+        path = self._basis_inventory_name(revision_id)
+        return self.branch.controlfile(path, 'r').read()
+        
     @needs_read_lock
     def read_working_inventory(self):
         """Read the working inventory."""

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20051125/9c52ca6b/attachment.pgp 


More information about the bazaar mailing list