[patch, #43064] create working bzr directories when pushing new old-format branches

Martin Pool mbp at sourcefrog.net
Fri May 5 10:14:35 BST 2006


There's always one...

This patch fixes this scenario:

  Using bzr 0.8 you push an old all-in-one branch to a new remote
  location.  This doesn't update the working tree, which is expected,
  but it also leaves the working tree in such a state that you can't
  revert it, which is bad.

What it does is create the two working tree control files in an empty
state.  (Reviews appreciated; I'm not absolutely sure it's in
the right place.)

Robert, if you think this is OK would you merge it for 0.8 please?

-- 
Martin
-------------- next part --------------
=== modified file 'bzrlib/bzrdir.py'
--- bzrlib/bzrdir.py	
+++ bzrlib/bzrdir.py	
@@ -588,7 +588,8 @@
         result = self._format._initialize_for_clone(url)
         basis_repo, basis_branch, basis_tree = self._get_basis_components(basis)
         self.open_repository().clone(result, revision_id=revision_id, basis=basis_repo)
-        self.open_branch().clone(result, revision_id=revision_id)
+        from_branch = self.open_branch()
+        from_branch.clone(result, revision_id=revision_id)
         try:
             self.open_workingtree().clone(result, basis=basis_tree)
         except errors.NotLocalUrl:
@@ -596,8 +597,9 @@
             try:
                 WorkingTreeFormat2().initialize(result)
             except errors.NotLocalUrl:
-                # but we canot do it for remote trees.
-                pass
+                # but we cannot do it for remote trees.
+                to_branch = result.open_branch()
+                WorkingTreeFormat2().stub_initialize_remote(to_branch.control_files)
         return result
 
     def create_branch(self):

=== modified file 'bzrlib/workingtree.py'
--- bzrlib/workingtree.py	
+++ bzrlib/workingtree.py	
@@ -1500,6 +1500,22 @@
         """See WorkingTreeFormat.get_format_description()."""
         return "Working tree format 2"
 
+    def stub_initialize_remote(self, control_files):
+        """As a special workaround create critical control files for a remote working tree
+        
+        This ensures that it can later be updated and dealt with locally,
+        since BzrDirFormat6 and BzrDirFormat5 cannot represent dirs with 
+        no working tree.  (See bug #43064).
+        """
+        sio = StringIO()
+        inv = Inventory()
+        bzrlib.xml5.serializer_v5.write_inventory(inv, sio)
+        sio.seek(0)
+        control_files.put('inventory', sio)
+
+        control_files.put_utf8('pending-merges', '')
+        
+
     def initialize(self, a_bzrdir, revision_id=None):
         """See WorkingTreeFormat.initialize()."""
         if not isinstance(a_bzrdir.transport, LocalTransport):



More information about the bazaar mailing list