Rev 6276: (jelmer) Support switching to colocated branches in "bzr switch". (Jelmer in file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/

Patch Queue Manager pqm at pqm.ubuntu.com
Thu Nov 17 19:50:39 UTC 2011


At file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 6276 [merge]
revision-id: pqm at pqm.ubuntu.com-20111117195038-1e3ypqmovs2bjhtp
parent: pqm at pqm.ubuntu.com-20111117190047-e2773128biccz770
parent: jelmer at samba.org-20111117185621-f4xnp76w6o8d6v3q
committer: Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2011-11-17 19:50:38 +0000
message:
  (jelmer) Support switching to colocated branches in "bzr switch". (Jelmer
   Vernooij)
modified:
  bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
  bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
  bzrlib/bzrdir.py               bzrdir.py-20060131065624-156dfea39c4387cb
  bzrlib/tests/blackbox/test_branch.py test_branch.py-20060524161337-noms9gmcwqqrfi8y-1
  bzrlib/tests/blackbox/test_switch.py test_switch.py-20071122111948-0c5en6uz92bwl76h-1
  bzrlib/tests/per_controldir_colo/test_supported.py test_supported.py-20100411192232-kawv9qu1t42gv89k-3
  doc/en/release-notes/bzr-2.5.txt bzr2.5.txt-20110708125756-587p0hpw7oke4h05-1
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py	2011-11-17 18:06:46 +0000
+++ b/bzrlib/branch.py	2011-11-17 18:39:26 +0000
@@ -2300,7 +2300,7 @@
             raise errors.IncompatibleFormat(self, a_bzrdir._format)
         branch_transport = a_bzrdir.get_branch_transport(self, name=name)
         branch_transport.put_bytes('location',
-            target_branch.bzrdir.user_url)
+            target_branch.user_url)
         branch_transport.put_bytes('format', self.get_format_string())
         branch = self.open(
             a_bzrdir, name, _found=True,

=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2011-11-17 19:00:47 +0000
+++ b/bzrlib/builtins.py	2011-11-17 19:50:38 +0000
@@ -6070,17 +6070,35 @@
             if '/' not in to_location and '\\' not in to_location:
                 # This path is meant to be relative to the existing branch
                 this_url = self._get_branch_location(control_dir)
-                to_location = urlutils.join(this_url, '..', to_location)
+                # Perhaps the target control dir supports colocated branches?
+                try:
+                    root = controldir.ControlDir.open(this_url,
+                        possible_transports=[control_dir.user_transport])
+                except errors.NotBranchError:
+                    colocated = False
+                else:
+                    colocated = root._format.colocated_branches
+                if colocated:
+                    to_location = urlutils.join_segment_parameters(this_url,
+                        {"branch": urlutils.escape(to_location)})
+                else:
+                    to_location = urlutils.join(
+                        this_url, '..', urlutils.escape(to_location))
             to_branch = branch.bzrdir.sprout(to_location,
                                  possible_transports=[branch.bzrdir.root_transport],
                                  source_branch=branch).open_branch()
         else:
+            # Perhaps it's a colocated branch?
             try:
-                to_branch = Branch.open(to_location)
-            except errors.NotBranchError:
-                this_url = self._get_branch_location(control_dir)
-                to_branch = Branch.open(
-                    urlutils.join(this_url, '..', to_location))
+                to_branch = control_dir.open_branch(to_location)
+            except (errors.NotBranchError, errors.NoColocatedBranchSupport):
+                try:
+                    to_branch = Branch.open(to_location)
+                except errors.NotBranchError:
+                    this_url = self._get_branch_location(control_dir)
+                    to_branch = Branch.open(
+                        urlutils.join(
+                            this_url, '..', urlutils.escape(to_location)))
         if revision is not None:
             revision = revision.as_revision_id(to_branch)
         switch.switch(control_dir, to_branch, force, revision_id=revision)

=== modified file 'bzrlib/bzrdir.py'
--- a/bzrlib/bzrdir.py	2011-11-16 02:44:11 +0000
+++ b/bzrlib/bzrdir.py	2011-11-17 18:56:21 +0000
@@ -375,7 +375,10 @@
         target_transport.ensure_base()
         cloning_format = self.cloning_metadir(stacked)
         # Create/update the result branch
-        result = cloning_format.initialize_on_transport(target_transport)
+        try:
+            result = controldir.ControlDir.open_from_transport(target_transport)
+        except errors.NotBranchError:
+            result = cloning_format.initialize_on_transport(target_transport)
         source_branch, source_repository = self._find_source_repo(
             add_cleanup, source_branch)
         fetch_spec_factory.source_branch = source_branch
@@ -414,7 +417,7 @@
         mutter("created new branch %r" % (result_branch,))
 
         # Create/update the result working tree
-        if (create_tree_if_local and
+        if (create_tree_if_local and not result.has_workingtree() and
             isinstance(target_transport, local.LocalTransport) and
             (result_repo is None or result_repo.make_working_trees())):
             wt = result.create_workingtree(accelerator_tree=accelerator_tree,

=== modified file 'bzrlib/tests/blackbox/test_branch.py'
--- a/bzrlib/tests/blackbox/test_branch.py	2011-11-17 19:00:47 +0000
+++ b/bzrlib/tests/blackbox/test_branch.py	2011-11-17 19:50:38 +0000
@@ -482,7 +482,7 @@
         # being too low. If rpc_count increases, more network roundtrips have
         # become necessary for this use case. Please do not adjust this number
         # upwards without agreement from bzr's network support maintainers.
-        self.assertLength(39, self.hpss_calls)
+        self.assertLength(40, self.hpss_calls)
 
     def test_branch_from_trivial_branch_streaming_acceptance(self):
         self.setup_smart_server_with_call_log()

=== modified file 'bzrlib/tests/blackbox/test_switch.py'
--- a/bzrlib/tests/blackbox/test_switch.py	2011-07-18 13:58:52 +0000
+++ b/bzrlib/tests/blackbox/test_switch.py	2011-11-16 17:52:07 +0000
@@ -20,6 +20,7 @@
 
 import os
 
+from bzrlib.bzrdir import BzrDir
 from bzrlib import (
         osutils,
         urlutils,
@@ -30,6 +31,7 @@
         TestCaseWithTransport,
         script,
         )
+from bzrlib.tests.features import UnicodeFilenameFeature
 from bzrlib.directory_service import directories
 
 
@@ -152,6 +154,21 @@
         self.assertEqual(branchb_id, checkout.last_revision())
         self.assertEqual(tree2.branch.base, checkout.branch.get_bound_location())
 
+    def test_switch_finds_relative_unicode_branch(self):
+        """Switch will find 'foo' relative to the branch the checkout is of."""
+        self.requireFeature(UnicodeFilenameFeature)
+        self.build_tree(['repo/'])
+        tree1 = self.make_branch_and_tree('repo/brancha')
+        tree1.commit('foo')
+        tree2 = self.make_branch_and_tree(u'repo/branch\xe9')
+        tree2.pull(tree1.branch)
+        branchb_id = tree2.commit('bar')
+        checkout =  tree1.branch.create_checkout('checkout', lightweight=True)
+        self.run_bzr(['switch', u'branch\xe9'], working_dir='checkout')
+        self.assertEqual(branchb_id, checkout.last_revision())
+        checkout = checkout.bzrdir.open_workingtree()
+        self.assertEqual(tree2.branch.base, checkout.branch.base)
+
     def test_switch_revision(self):
         tree = self._create_sample_tree()
         checkout = tree.branch.create_checkout('checkout', lightweight=True)
@@ -159,6 +176,65 @@
         self.assertPathExists('checkout/file-1')
         self.assertPathDoesNotExist('checkout/file-2')
 
+    def test_switch_existing_colocated(self):
+        # Create a branch branch-1 that initially is a checkout of 'foo'
+        # Use switch to change it to 'anotherbranch'
+        repo = self.make_repository('branch-1', format='development-colo')
+        target_branch = repo.bzrdir.create_branch(name='foo')
+        branch.BranchReferenceFormat().initialize(
+            repo.bzrdir, target_branch=target_branch)
+        tree = repo.bzrdir.create_workingtree()
+        self.build_tree(['branch-1/file-1', 'branch-1/file-2'])
+        tree.add('file-1')
+        revid1 = tree.commit('rev1')
+        tree.add('file-2')
+        revid2 = tree.commit('rev2')
+        otherbranch = tree.bzrdir.create_branch(name='anotherbranch')
+        otherbranch.generate_revision_history(revid1)
+        self.run_bzr(['switch', 'anotherbranch'], working_dir='branch-1')
+        tree = WorkingTree.open("branch-1")
+        self.assertEquals(tree.last_revision(), revid1)
+        self.assertEquals(tree.branch.control_url, otherbranch.control_url)
+
+    def test_switch_new_colocated(self):
+        # Create a branch branch-1 that initially is a checkout of 'foo'
+        # Use switch to create 'anotherbranch' which derives from that
+        repo = self.make_repository('branch-1', format='development-colo')
+        target_branch = repo.bzrdir.create_branch(name='foo')
+        branch.BranchReferenceFormat().initialize(
+            repo.bzrdir, target_branch=target_branch)
+        tree = repo.bzrdir.create_workingtree()
+        self.build_tree(['branch-1/file-1', 'branch-1/file-2'])
+        tree.add('file-1')
+        revid1 = tree.commit('rev1')
+        self.run_bzr(['switch', '-b', 'anotherbranch'], working_dir='branch-1')
+        bzrdir = BzrDir.open("branch-1")
+        self.assertEquals(
+            set([b.name for b in bzrdir.list_branches()]),
+            set(["foo", "anotherbranch"]))
+        self.assertEquals(bzrdir.open_branch().name, "anotherbranch")
+        self.assertEquals(bzrdir.open_branch().last_revision(), revid1)
+
+    def test_switch_new_colocated_unicode(self):
+        # Create a branch branch-1 that initially is a checkout of 'foo'
+        # Use switch to create 'branch\xe9' which derives from that
+        self.requireFeature(UnicodeFilenameFeature)
+        repo = self.make_repository('branch-1', format='development-colo')
+        target_branch = repo.bzrdir.create_branch(name='foo')
+        branch.BranchReferenceFormat().initialize(
+            repo.bzrdir, target_branch=target_branch)
+        tree = repo.bzrdir.create_workingtree()
+        self.build_tree(['branch-1/file-1', 'branch-1/file-2'])
+        tree.add('file-1')
+        revid1 = tree.commit('rev1')
+        self.run_bzr(['switch', '-b', u'branch\xe9'], working_dir='branch-1')
+        bzrdir = BzrDir.open("branch-1")
+        self.assertEquals(
+            set([b.name for b in bzrdir.list_branches()]),
+            set(["foo", u"branch\xe9"]))
+        self.assertEquals(bzrdir.open_branch().name, u"branch\xe9")
+        self.assertEquals(bzrdir.open_branch().last_revision(), revid1)
+
     def test_switch_only_revision(self):
         tree = self._create_sample_tree()
         checkout = tree.branch.create_checkout('checkout', lightweight=True)

=== modified file 'bzrlib/tests/per_controldir_colo/test_supported.py'
--- a/bzrlib/tests/per_controldir_colo/test_supported.py	2011-11-16 18:01:29 +0000
+++ b/bzrlib/tests/per_controldir_colo/test_supported.py	2011-11-17 18:39:26 +0000
@@ -20,6 +20,7 @@
 from bzrlib import (
     errors,
     tests,
+    urlutils,
     )
 from bzrlib.tests import (
     per_controldir,
@@ -86,6 +87,26 @@
         self.assertEqual(made_branch.control_url, re_made_branch.control_url)
         self.assertEqual(made_branch.user_url, re_made_branch.user_url)
 
+    def test_sprout_into_colocated(self):
+        # a bzrdir can construct a branch and repository for itself.
+        if not self.bzrdir_format.is_supported():
+            # unsupported formats are not loopback testable
+            # because the default open will not open them and
+            # they may not be initializable.
+            raise tests.TestNotApplicable('Control dir format not supported')
+        from_tree = self.make_branch_and_tree('from')
+        revid = from_tree.commit("rev1")
+        try:
+            other_branch = self.make_branch("to")
+        except errors.UninitializableFormat:
+            raise tests.TestNotApplicable(
+                'Control dir does not support creating new branches.')
+        to_dir = from_tree.bzrdir.sprout(
+            urlutils.join_segment_parameters(
+                other_branch.bzrdir.user_url, {"branch": "target"}))
+        to_branch = to_dir.open_branch(name="target")
+        self.assertEquals(revid, to_branch.last_revision())
+
     def test_unicode(self):
         self.requireFeature(UnicodeFilenameFeature)
         if not self.bzrdir_format.is_supported():

=== modified file 'doc/en/release-notes/bzr-2.5.txt'
--- a/doc/en/release-notes/bzr-2.5.txt	2011-11-17 18:06:46 +0000
+++ b/doc/en/release-notes/bzr-2.5.txt	2011-11-17 18:42:24 +0000
@@ -26,6 +26,13 @@
 .. Improvements to existing commands, especially improved performance 
    or memory usage, or better results.
 
+* When using ``bzr switch`` to switch to a sibling of the current
+  branch, the relative branch name should no longer be url-encoded.
+  (Jelmer Vernooij)
+
+* ``bzr switch`` now accepts colocated branch names to switch to.
+  (Jelmer Vernooij, #826814)
+
 Bug Fixes
 *********
 




More information about the bazaar-commits mailing list