Rev 3678: Clean up push, allowing default stacking policies (abentley) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Tue Sep 2 16:28:54 BST 2008


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 3678
revision-id: pqm at pqm.ubuntu.com-20080902152844-dext0kmx4m0u5szy
parent: pqm at pqm.ubuntu.com-20080902062416-dxdxccqki90bcynl
parent: aaron at aaronbentley.com-20080829183550-8ia9bn0nsfr4ykl2
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Tue 2008-09-02 16:28:44 +0100
message:
  Clean up push, allowing default stacking policies (abentley)
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
  bzrlib/bzrdir.py               bzrdir.py-20060131065624-156dfea39c4387cb
  bzrlib/push.py                 push.py-20080606021927-5fe39050e8xne9un-1
  bzrlib/tests/bzrdir_implementations/test_bzrdir.py test_bzrdir.py-20060131065642-0ebeca5e30e30866
  bzrlib/tests/test_bzrdir.py    test_bzrdir.py-20060131065654-deba40eef51cf220
  bzrlib/workingtree.py          workingtree.py-20050511021032-29b6ec0a681e02e3
    ------------------------------------------------------------
    revno: 3650.5.9
    revision-id: aaron at aaronbentley.com-20080829183550-8ia9bn0nsfr4ykl2
    parent: aaron at aaronbentley.com-20080829182605-nfow1sxbop7kpetd
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: push
    timestamp: Fri 2008-08-29 14:35:50 -0400
    message:
      Update NEWS
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
    ------------------------------------------------------------
    revno: 3650.5.8
    revision-id: aaron at aaronbentley.com-20080829182605-nfow1sxbop7kpetd
    parent: aaron at aaronbentley.com-20080829161528-rtlmesic8d6bdsqy
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: push
    timestamp: Fri 2008-08-29 14:26:05 -0400
    message:
      Remove unused WorkingTreeFormat2 instances
    modified:
      bzrlib/bzrdir.py               bzrdir.py-20060131065624-156dfea39c4387cb
    ------------------------------------------------------------
    revno: 3650.5.7
    revision-id: aaron at aaronbentley.com-20080829161528-rtlmesic8d6bdsqy
    parent: aaron at aaronbentley.com-20080829141616-ztfe16tnr0aq0tar
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: push
    timestamp: Fri 2008-08-29 12:15:28 -0400
    message:
      Fix working tree initialization
    modified:
      bzrlib/bzrdir.py               bzrdir.py-20060131065624-156dfea39c4387cb
      bzrlib/workingtree.py          workingtree.py-20050511021032-29b6ec0a681e02e3
    ------------------------------------------------------------
    revno: 3650.5.6
    revision-id: aaron at aaronbentley.com-20080829141616-ztfe16tnr0aq0tar
    parent: aaron at aaronbentley.com-20080828215850-eaqm6p4pbpp262c2
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: push
    timestamp: Fri 2008-08-29 10:16:16 -0400
    message:
      Fix cloning problems by creating missing working tree files
    modified:
      bzrlib/bzrdir.py               bzrdir.py-20060131065624-156dfea39c4387cb
      bzrlib/workingtree.py          workingtree.py-20050511021032-29b6ec0a681e02e3
    ------------------------------------------------------------
    revno: 3650.5.5
    revision-id: aaron at aaronbentley.com-20080828215850-eaqm6p4pbpp262c2
    parent: aaron at aaronbentley.com-20080828213630-l1qa8cwpu7yym0sh
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: push
    timestamp: Thu 2008-08-28 17:58:50 -0400
    message:
      Make WorkingTree.clone use bzrdir's format
    modified:
      bzrlib/bzrdir.py               bzrdir.py-20060131065624-156dfea39c4387cb
      bzrlib/workingtree.py          workingtree.py-20050511021032-29b6ec0a681e02e3
    ------------------------------------------------------------
    revno: 3650.5.4
    revision-id: aaron at aaronbentley.com-20080828213630-l1qa8cwpu7yym0sh
    parent: aaron at aaronbentley.com-20080828205127-v4u2emf8p4ex1x1z
    parent: aaron at aaronbentley.com-20080828213220-m0cmqwofh9g9cmv7
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: push
    timestamp: Thu 2008-08-28 17:36:30 -0400
    message:
      Merge from sprout
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/bzrdir.py               bzrdir.py-20060131065624-156dfea39c4387cb
      bzrlib/remote.py               remote.py-20060720103555-yeeg2x51vn0rbtdp-1
      bzrlib/tests/test_bzrdir.py    test_bzrdir.py-20060131065654-deba40eef51cf220
    ------------------------------------------------------------
    revno: 3650.5.3
    revision-id: aaron at aaronbentley.com-20080828205127-v4u2emf8p4ex1x1z
    parent: aaron at aaronbentley.com-20080828193529-xk69k2ehmi3j2w05
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: push
    timestamp: Thu 2008-08-28 16:51:27 -0400
    message:
      Add failing test of BzrDir.clone
    modified:
      bzrlib/tests/bzrdir_implementations/test_bzrdir.py test_bzrdir.py-20060131065642-0ebeca5e30e30866
    ------------------------------------------------------------
    revno: 3650.5.2
    revision-id: aaron at aaronbentley.com-20080828193529-xk69k2ehmi3j2w05
    parent: aaron at aaronbentley.com-20080828185759-fbc45dxmvt02c3a1
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: push
    timestamp: Thu 2008-08-28 15:35:29 -0400
    message:
      Always show stacked message if stacking done.
    modified:
      bzrlib/push.py                 push.py-20080606021927-5fe39050e8xne9un-1
    ------------------------------------------------------------
    revno: 3650.5.1
    revision-id: aaron at aaronbentley.com-20080828185759-fbc45dxmvt02c3a1
    parent: aaron at aaronbentley.com-20080828163339-3zdi0ewhixwpwoqn
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: push
    timestamp: Thu 2008-08-28 14:57:59 -0400
    message:
      Fix push to use clone all the time.
    modified:
      bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
      bzrlib/bzrdir.py               bzrdir.py-20060131065624-156dfea39c4387cb
      bzrlib/push.py                 push.py-20080606021927-5fe39050e8xne9un-1
      bzrlib/tests/test_bzrdir.py    test_bzrdir.py-20060131065654-deba40eef51cf220
=== modified file 'NEWS'
--- a/NEWS	2008-09-02 05:28:37 +0000
+++ b/NEWS	2008-09-02 15:28:44 +0000
@@ -23,8 +23,8 @@
 
   IMPROVEMENTS:
 
-    * ``bzr branch`` uses the default stacking policy if the branch format
-      supports it. (Aaron Bentley)
+    * ``bzr branch`` and ``bzr push`` use the default stacking policy if the
+      branch format supports it. (Aaron Bentley)
 
     * ``bzr init`` and ``bzr init-repo`` will now print out the same as
       ``bzr info`` if it completed successfully.
@@ -85,6 +85,9 @@
     * The deprecated ``Branch.abspath`` and unimplemented 
       ``Branch.rename_one`` and ``Branch.move`` were removed. (Jelmer Vernooij)
 
+    * BzrDir.clone_on_transport implementations must now accept a stacked_on
+      parameter.  (Aaron Bentley)
+
     * BzrDir.cloning_metadir implementations must now take a require_stacking
       parameter.  (Aaron Bentley)
 

=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py	2008-08-27 18:24:50 +0000
+++ b/bzrlib/branch.py	2008-08-28 18:57:59 +0000
@@ -672,7 +672,7 @@
         revision_id: if not None, the revision history in the new branch will
                      be truncated to end with revision_id.
         """
-        result = self._format.initialize(to_bzrdir)
+        result = to_bzrdir.create_branch()
         self.copy_content_into(result, revision_id=revision_id)
         return  result
 

=== modified file 'bzrlib/bzrdir.py'
--- a/bzrlib/bzrdir.py	2008-09-02 03:17:08 +0000
+++ b/bzrlib/bzrdir.py	2008-09-02 15:28:44 +0000
@@ -177,7 +177,8 @@
                                        preserve_stacking=preserve_stacking)
 
     def clone_on_transport(self, transport, revision_id=None,
-                           force_new_repo=False, preserve_stacking=False):
+                           force_new_repo=False, preserve_stacking=False,
+                           stacked_on=None):
         """Clone this bzrdir and its contents to transport verbatim.
 
         :param transport: The transport for the location to produce the clone
@@ -191,9 +192,10 @@
             new branch on top of the other branch's stacked-on branch.
         """
         transport.ensure_base()
-        result = self.cloning_metadir().initialize_on_transport(transport)
+        require_stacking = (stacked_on is not None)
+        metadir = self.cloning_metadir(require_stacking)
+        result = metadir.initialize_on_transport(transport)
         repository_policy = None
-        stack_on = None
         try:
             local_repo = self.find_repository()
         except errors.NoRepositoryPresent:
@@ -208,7 +210,7 @@
                 local_repo = local_branch.repository
             if preserve_stacking:
                 try:
-                    stack_on = local_branch.get_stacked_on_url()
+                    stacked_on = local_branch.get_stacked_on_url()
                 except (errors.UnstackableBranchFormat,
                         errors.UnstackableRepositoryFormat,
                         errors.NotStacked):
@@ -217,7 +219,8 @@
         if local_repo:
             # may need to copy content in
             repository_policy = result.determine_repository_policy(
-                force_new_repo, stack_on, self.root_transport.base)
+                force_new_repo, stacked_on, self.root_transport.base,
+                require_stacking=require_stacking)
             make_working_trees = local_repo.make_working_trees()
             result_repo = repository_policy.acquire_repository(
                 make_working_trees, local_repo.is_shared())
@@ -1198,22 +1201,18 @@
         preserve_stacking has no effect, since no source branch using this
         family of formats can be stacked, so there is no stacking to preserve.
         """
-        from bzrlib.workingtree import WorkingTreeFormat2
         self._make_tail(url)
         result = self._format._initialize_for_clone(url)
         self.open_repository().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)
+            tree = self.open_workingtree()
         except errors.NotLocalUrl:
             # make a new one, this format always has to have one.
-            try:
-                WorkingTreeFormat2().initialize(result)
-            except errors.NotLocalUrl:
-                # but we cannot do it for remote trees.
-                to_branch = result.open_branch()
-                WorkingTreeFormat2()._stub_initialize_remote(to_branch)
+            result._init_workingtree()
+        else:
+            tree.clone(result)
         return result
 
     def create_branch(self):
@@ -1237,6 +1236,9 @@
     def create_workingtree(self, revision_id=None, from_branch=None,
                            accelerator_tree=None, hardlink=False):
         """See BzrDir.create_workingtree."""
+        # The workingtree is sometimes created when the bzrdir is created,
+        # but not when cloning.
+
         # this looks buggy but is not -really-
         # because this format creates the workingtree when the bzrdir is
         # created
@@ -1246,7 +1248,10 @@
         # that can do wonky stuff here, and that only
         # happens for creating checkouts, which cannot be 
         # done on this format anyway. So - acceptable wart.
-        result = self.open_workingtree(recommend_upgrade=False)
+        try:
+            result = self.open_workingtree(recommend_upgrade=False)
+        except errors.NoSuchFile:
+            result = self._init_workingtree()
         if revision_id is not None:
             if revision_id == _mod_revision.NULL_REVISION:
                 result.set_parent_ids([])
@@ -1254,6 +1259,16 @@
                 result.set_parent_ids([revision_id])
         return result
 
+    def _init_workingtree(self):
+        from bzrlib.workingtree import WorkingTreeFormat2
+        try:
+            return WorkingTreeFormat2().initialize(self)
+        except errors.NotLocalUrl:
+            # Even though we can't access the working tree, we need to
+            # create its control files.
+            return WorkingTreeFormat2()._stub_initialize_on_transport(
+                self.transport, self._control_files._file_mode)
+
     def destroy_workingtree(self):
         """See BzrDir.destroy_workingtree."""
         raise errors.UnsupportedOperation(self.destroy_workingtree, self)
@@ -1889,17 +1904,11 @@
         """
         from bzrlib.branch import BzrBranchFormat4
         from bzrlib.repofmt.weaverepo import RepositoryFormat5
-        from bzrlib.workingtree import WorkingTreeFormat2
         result = (super(BzrDirFormat5, self).initialize_on_transport(transport))
         RepositoryFormat5().initialize(result, _internal=True)
         if not _cloning:
             branch = BzrBranchFormat4().initialize(result)
-            try:
-                WorkingTreeFormat2().initialize(result)
-            except errors.NotLocalUrl:
-                # Even though we can't access the working tree, we need to
-                # create its control files.
-                WorkingTreeFormat2()._stub_initialize_remote(branch)
+            result._init_workingtree()
         return result
 
     def _open(self, transport):
@@ -1952,17 +1961,11 @@
         """
         from bzrlib.branch import BzrBranchFormat4
         from bzrlib.repofmt.weaverepo import RepositoryFormat6
-        from bzrlib.workingtree import WorkingTreeFormat2
         result = super(BzrDirFormat6, self).initialize_on_transport(transport)
         RepositoryFormat6().initialize(result, _internal=True)
         if not _cloning:
             branch = BzrBranchFormat4().initialize(result)
-            try:
-                WorkingTreeFormat2().initialize(result)
-            except errors.NotLocalUrl:
-                # Even though we can't access the working tree, we need to
-                # create its control files.
-                WorkingTreeFormat2()._stub_initialize_remote(branch)
+            result._init_workingtree()
         return result
 
     def _open(self, transport):

=== modified file 'bzrlib/push.py'
--- a/bzrlib/push.py	2008-07-17 05:51:29 +0000
+++ b/bzrlib/push.py	2008-08-28 19:35:29 +0000
@@ -101,29 +101,19 @@
         # Now the target directory exists, but doesn't have a .bzr
         # directory. So we need to create it, along with any work to create
         # all of the dependent branches, etc.
-        if stacked_on is not None:
-            # This should be buried in the clone method itself. TODO.
-            try:
-                # if the from format is stackable, this will either work or
-                # trigger NotStacked. If it's not, an error will be given to
-                # the user.
-                br_from.get_stacked_on_url()
-            except errors.NotStacked:
-                pass
-            # now we need to sprout the repository,
-            dir_to = br_from.bzrdir._format.initialize_on_transport(to_transport)
-            br_from.repository._format.initialize(dir_to)
-            br_to = br_from._format.initialize(dir_to)
-            br_to.set_stacked_on_url(stacked_on)
-            # and copy the data up.
-            br_from.push(br_to)
-        else:
-            dir_to = br_from.bzrdir.clone_on_transport(to_transport,
-                revision_id=revision_id)
+        dir_to = br_from.bzrdir.clone_on_transport(to_transport,
+            revision_id=revision_id, stacked_on=stacked_on)
         br_to = dir_to.open_branch()
         # TODO: Some more useful message about what was copied
-        if stacked_on is not None:
-            note('Created new stacked branch referring to %s.' % stacked_on)
+        try:
+            finally_stacked_on = br_to.get_stacked_on_url()
+        except (errors.UnstackableBranchFormat,
+                errors.UnstackableRepositoryFormat,
+                errors.NotStacked):
+            finally_stacked_on = None
+        if finally_stacked_on is not None:
+            note('Created new stacked branch referring to %s.' %
+                 finally_stacked_on)
         else:
             note('Created new branch.')
         # We successfully created the target, remember it

=== modified file 'bzrlib/tests/bzrdir_implementations/test_bzrdir.py'
--- a/bzrlib/tests/bzrdir_implementations/test_bzrdir.py	2008-07-22 00:12:33 +0000
+++ b/bzrlib/tests/bzrdir_implementations/test_bzrdir.py	2008-08-28 20:51:27 +0000
@@ -646,6 +646,13 @@
         a_dir.open_branch()
         self.assertRaises(errors.NoWorkingTree, a_dir.open_workingtree)
 
+    def test_clone_respects_stacked(self):
+        branch = self.make_branch('parent')
+        child_transport = branch.bzrdir.root_transport.clone('../child')
+        child = branch.bzrdir.clone_on_transport(child_transport,
+                                                 stacked_on=branch.base)
+        self.assertEqual(child.open_branch().get_stacked_on_url(), branch.base)
+
     def test_get_branch_reference_on_reference(self):
         """get_branch_reference should return the right url."""
         referenced_branch = self.make_branch('referenced')

=== modified file 'bzrlib/tests/test_bzrdir.py'
--- a/bzrlib/tests/test_bzrdir.py	2008-08-29 21:08:16 +0000
+++ b/bzrlib/tests/test_bzrdir.py	2008-09-02 15:28:44 +0000
@@ -486,6 +486,17 @@
         self.assertTrue(repo._format.supports_external_lookups)
         self.assertFalse(repo.supports_rich_root())
 
+    def test_clone_on_transport_upgrades_format_if_stacked_on_specified(self):
+        child_branch, new_child_transport = self.prepare_default_stacking(
+            child_format='pack-0.92')
+        new_child = child_branch.bzrdir.clone_on_transport(new_child_transport,
+            stacked_on=child_branch.bzrdir.root_transport.base)
+        self.assertEqual(child_branch.bzrdir.root_transport.base,
+                         new_child.open_branch().get_stacked_on_url())
+        repo = new_child.open_repository()
+        self.assertTrue(repo._format.supports_external_lookups)
+        self.assertFalse(repo.supports_rich_root())
+
     def test_sprout_upgrades_to_rich_root_format_if_needed(self):
         child_branch, new_child_transport = self.prepare_default_stacking(
             child_format='rich-root-pack')

=== modified file 'bzrlib/workingtree.py'
--- a/bzrlib/workingtree.py	2008-08-26 16:44:12 +0000
+++ b/bzrlib/workingtree.py	2008-09-02 15:28:44 +0000
@@ -520,7 +520,7 @@
             and this one merged in.
         """
         # assumes the target bzr dir format is compatible.
-        result = self._format.initialize(to_bzrdir)
+        result = to_bzrdir.create_workingtree()
         self.copy_content_into(result, revision_id)
         return result
 
@@ -2714,22 +2714,19 @@
         """See WorkingTreeFormat.get_format_description()."""
         return "Working tree format 2"
 
-    def _stub_initialize_remote(self, branch):
-        """As a special workaround create critical control files for a remote working tree.
-        
+    def _stub_initialize_on_transport(self, transport, file_mode):
+        """Workaround: create 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 
+        since BzrDirFormat6 and BzrDirFormat5 cannot represent dirs with
         no working tree.  (See bug #43064).
         """
         sio = StringIO()
         inv = Inventory()
         xml5.serializer_v5.write_inventory(inv, sio, working=True)
         sio.seek(0)
-        branch._transport.put_file('inventory', sio,
-            mode=branch.control_files._file_mode)
-        branch._transport.put_bytes('pending-merges', '',
-            mode=branch.control_files._file_mode)
-        
+        transport.put_file('inventory', sio, file_mode)
+        transport.put_bytes('pending-merges', '', file_mode)
 
     def initialize(self, a_bzrdir, revision_id=None, from_branch=None,
                    accelerator_tree=None, hardlink=False):




More information about the bazaar-commits mailing list