Rev 6274: (jelmer) Make sure that a branch user URL uniquely identifies that branch, in file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/

Patch Queue Manager pqm at pqm.ubuntu.com
Thu Nov 17 18:06:47 UTC 2011


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

------------------------------------------------------------
revno: 6274 [merge]
revision-id: pqm at pqm.ubuntu.com-20111117180646-k4mtsuzgseulh81c
parent: pqm at pqm.ubuntu.com-20111117174145-2nb7jko9c5t7llcb
parent: jelmer at samba.org-20111117172457-csm7061se0d46b2u
committer: Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2011-11-17 18:06:46 +0000
message:
  (jelmer) Make sure that a branch user URL uniquely identifies that branch,
   and can be used to open it. (Jelmer Vernooij)
modified:
  bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
  bzrlib/bzrdir.py               bzrdir.py-20060131065624-156dfea39c4387cb
  bzrlib/tests/blackbox/test_branch.py test_branch.py-20060524161337-noms9gmcwqqrfi8y-1
  bzrlib/tests/blackbox/test_init.py test_init.py-20060309032856-a292116204d86eb7
  bzrlib/tests/per_controldir_colo/test_supported.py test_supported.py-20100411192232-kawv9qu1t42gv89k-3
  bzrlib/tests/per_transport.py  test_transport_implementations.py-20051227111451-f97c5c7d5c49fce7
  bzrlib/tests/test_foreign.py   test_foreign.py-20081125004048-ywb901edgp9lluxo-1
  bzrlib/transport/__init__.py   transport.py-20050711165921-4978aa7ce1285ad5
  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 00:12:43 +0000
+++ b/bzrlib/branch.py	2011-11-17 18:06:46 +0000
@@ -2438,11 +2438,12 @@
             raise ValueError('a_bzrdir must be supplied')
         else:
             self.bzrdir = a_bzrdir
-        self._base = self.bzrdir.transport.clone('..').base
+        self._user_transport = self.bzrdir.transport.clone('..')
+        if name is not None:
+            self._user_transport.set_segment_parameter(
+                "branch", urlutils.escape(name))
+        self._base = self._user_transport.base
         self.name = name
-        # XXX: We should be able to just do
-        #   self.base = self.bzrdir.root_transport.base
-        # but this does not quite work yet -- mbp 20080522
         self._format = _format
         if _control_files is None:
             raise ValueError('BzrBranch _control_files is None')
@@ -2452,11 +2453,7 @@
         Branch.__init__(self)
 
     def __str__(self):
-        if self.name is None:
-            return '%s(%s)' % (self.__class__.__name__, self.user_url)
-        else:
-            return '%s(%s,%s)' % (self.__class__.__name__, self.user_url,
-                self.name)
+        return '%s(%s)' % (self.__class__.__name__, self.user_url)
 
     __repr__ = __str__
 
@@ -2466,6 +2463,10 @@
 
     base = property(_get_base, doc="The URL for the root of this branch.")
 
+    @property
+    def user_transport(self):
+        return self._user_transport
+
     def _get_config(self):
         return _mod_config.TransportConfig(self._transport, 'branch.conf')
 

=== modified file 'bzrlib/bzrdir.py'
--- a/bzrlib/bzrdir.py	2011-11-04 16:10:43 +0000
+++ b/bzrlib/bzrdir.py	2011-11-16 02:44:11 +0000
@@ -771,6 +771,9 @@
         return controldir.ControlDir.create(base, format=format,
                 possible_transports=possible_transports)
 
+    def __repr__(self):
+        return "<%s at %r>" % (self.__class__.__name__, self.user_url)
+
 
 class BzrDirMeta1(BzrDir):
     """A .bzr meta version 1 control object.
@@ -788,6 +791,8 @@
     def create_branch(self, name=None, repository=None,
             append_revisions_only=None):
         """See BzrDir.create_branch."""
+        if name is None:
+            name = self._get_selected_branch()
         return self._format.get_branch_format().initialize(self, name=name,
                 repository=repository,
                 append_revisions_only=append_revisions_only)
@@ -938,6 +943,8 @@
     def open_branch(self, name=None, unsupported=False,
                     ignore_fallbacks=False):
         """See BzrDir.open_branch."""
+        if name is None:
+            name = self._get_selected_branch()
         format = self.find_branch_format(name=name)
         format.check_support_status(unsupported)
         return format.open(self, name=name,
@@ -983,13 +990,11 @@
         it uses the default branch.
 
         :param name: Optional branch name to use
-        :return: Relative path to branch, branch name
+        :return: Relative path to branch
         """
         if name is None:
-            name = self._get_selected_branch()
-        if name is None:
-            return 'branch', None
-        return urlutils.join('branches', name), name
+            return 'branch'
+        return urlutils.join('branches', name.encode("utf-8"))
 
     def _read_branch_list(self):
         """Read the branch list.
@@ -1019,16 +1024,18 @@
 
     def destroy_branch(self, name=None):
         """See BzrDir.create_branch."""
-        path, name = self._get_branch_path(name)
+        if name is None:
+            name = self._get_selected_branch()
+        path = self._get_branch_path(name)
         if name is not None:
             self.control_files.lock_write()
             try:
                 branches = self._read_branch_list()
                 try:
-                    branches.remove(name)
+                    branches.remove(name.encode("utf-8"))
                 except ValueError:
                     raise errors.NotBranchError(name)
-                self._write_branch_list(name)
+                self._write_branch_list(branches)
             finally:
                 self.control_files.unlock()
         self.transport.delete_tree(path)
@@ -1043,14 +1050,14 @@
             pass
 
         # colocated branches
-        ret.extend([self.open_branch(name) for name in
+        ret.extend([self.open_branch(name.decode("utf-8")) for name in
                     self._read_branch_list()])
 
         return ret
 
     def get_branch_transport(self, branch_format, name=None):
         """See BzrDir.get_branch_transport()."""
-        path, name = self._get_branch_path(name)
+        path = self._get_branch_path(name)
         # XXX: this shouldn't implicitly create the directory if it's just
         # promising to get a transport -- mbp 20090727
         if branch_format is None:
@@ -1065,11 +1072,12 @@
             except errors.FileExists:
                 pass
             branches = self._read_branch_list()
-            if not name in branches:
+            utf8_name = name.encode("utf-8")
+            if not utf8_name in branches:
                 self.control_files.lock_write()
                 try:
                     branches = self._read_branch_list()
-                    branches.append(name)
+                    branches.append(utf8_name)
                     self._write_branch_list(branches)
                 finally:
                     self.control_files.unlock()

=== modified file 'bzrlib/tests/blackbox/test_branch.py'
--- a/bzrlib/tests/blackbox/test_branch.py	2011-11-17 00:12:43 +0000
+++ b/bzrlib/tests/blackbox/test_branch.py	2011-11-17 18:06:46 +0000
@@ -69,7 +69,7 @@
         out, err = self.run_bzr(
             'init --format=development-colo file:b,branch=orig')
         self.assertEqual(
-            """Created a standalone tree (format: development-colo)\n""",
+            """Created a lightweight checkout (format: development-colo)\n""",
             out)
         self.assertEqual('', err)
         out, err = self.run_bzr(

=== modified file 'bzrlib/tests/blackbox/test_init.py'
--- a/bzrlib/tests/blackbox/test_init.py	2011-10-05 14:12:34 +0000
+++ b/bzrlib/tests/blackbox/test_init.py	2011-11-17 17:24:57 +0000
@@ -57,7 +57,7 @@
     def test_init_colocated(self):
         """Smoke test for constructing a colocated branch."""
         out, err = self.run_bzr('init --format=development-colo file:,branch=abranch')
-        self.assertEqual("""Created a standalone tree (format: development-colo)\n""",
+        self.assertEqual("""Created a lightweight checkout (format: development-colo)\n""",
             out)
         self.assertEqual('', err)
         out, err = self.run_bzr('branches')

=== modified file 'bzrlib/tests/per_controldir_colo/test_supported.py'
--- a/bzrlib/tests/per_controldir_colo/test_supported.py	2011-05-13 12:51:05 +0000
+++ b/bzrlib/tests/per_controldir_colo/test_supported.py	2011-11-16 18:01:29 +0000
@@ -16,15 +16,17 @@
 
 """Tests for bzr directories that support colocated branches."""
 
-import bzrlib.branch
+from bzrlib.branch import Branch
 from bzrlib import (
     errors,
     tests,
-    transport,
     )
 from bzrlib.tests import (
     per_controldir,
     )
+from bzrlib.tests.features import (
+    UnicodeFilenameFeature,
+    )
 
 
 class TestColocatedBranchSupport(per_controldir.TestCaseWithControlDir):
@@ -53,7 +55,54 @@
         except errors.UninitializableFormat:
             raise tests.TestNotApplicable(
                 'Control dir does not support creating new branches.')
-        made_repo = made_control.create_repository()
+        made_control.create_repository()
         made_branch = made_control.create_branch("colo")
-        self.assertIsInstance(made_branch, bzrlib.branch.Branch)
-        self.assertEqual(made_control, made_branch.bzrdir)
+        self.assertIsInstance(made_branch, Branch)
+        self.assertEquals("colo", made_branch.name)
+        self.assertEqual(made_control, made_branch.bzrdir)
+
+    def test_open_by_url(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')
+        t = self.get_transport()
+        try:
+            made_control = self.bzrdir_format.initialize(t.base)
+        except errors.UninitializableFormat:
+            raise tests.TestNotApplicable(
+                'Control dir does not support creating new branches.')
+        made_control.create_repository()
+        made_branch = made_control.create_branch(name="colo")
+        other_branch = made_control.create_branch(name="othercolo")
+        self.assertIsInstance(made_branch, Branch)
+        self.assertEqual(made_control, made_branch.bzrdir)
+        self.assertNotEqual(made_branch.user_url, other_branch.user_url)
+        self.assertNotEqual(made_branch.control_url, other_branch.control_url)
+        re_made_branch = Branch.open(made_branch.user_url)
+        self.assertEquals(re_made_branch.name, "colo")
+        self.assertEqual(made_branch.control_url, re_made_branch.control_url)
+        self.assertEqual(made_branch.user_url, re_made_branch.user_url)
+
+    def test_unicode(self):
+        self.requireFeature(UnicodeFilenameFeature)
+        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')
+        t = self.get_transport()
+        try:
+            made_control = self.bzrdir_format.initialize(t.base)
+        except errors.UninitializableFormat:
+            raise tests.TestNotApplicable(
+                'Control dir does not support creating new branches.')
+        made_control.create_repository()
+        made_branch = made_control.create_branch(name=u"col\xe9")
+        self.assertTrue(
+            u"col\xe9" in [b.name for b in made_control.list_branches()])
+        made_branch = Branch.open(made_branch.user_url)
+        self.assertEquals(u"col\xe9", made_branch.name)
+        made_control.destroy_branch(u"col\xe9")

=== modified file 'bzrlib/tests/per_transport.py'
--- a/bzrlib/tests/per_transport.py	2011-11-16 12:17:27 +0000
+++ b/bzrlib/tests/per_transport.py	2011-11-17 18:06:46 +0000
@@ -1791,6 +1791,18 @@
         transport = _mod_transport.get_transport_from_url(url)
         self.assertEquals(parameters, transport.get_segment_parameters())
 
+    def test_set_segment_parameters(self):
+        """Segment parameters can be set and show up in base."""
+        transport = self.get_transport("foo")
+        orig_base = transport.base
+        transport.set_segment_parameter("arm", "board")
+        self.assertEquals("%s,arm=board" % orig_base, transport.base)
+        self.assertEquals({"arm": "board"}, transport.get_segment_parameters())
+        transport.set_segment_parameter("arm", None)
+        transport.set_segment_parameter("nonexistant", None)
+        self.assertEquals({}, transport.get_segment_parameters())
+        self.assertEquals(orig_base, transport.base)
+
     def test_stat_symlink(self):
         # if a transport points directly to a symlink (and supports symlinks
         # at all) you can tell this.  helps with bug 32669.

=== modified file 'bzrlib/tests/test_foreign.py'
--- a/bzrlib/tests/test_foreign.py	2011-10-14 15:45:10 +0000
+++ b/bzrlib/tests/test_foreign.py	2011-11-17 17:24:57 +0000
@@ -91,6 +91,10 @@
 class DummyForeignVcsBranch(branch.BzrBranch6,foreign.ForeignBranch):
     """A Dummy VCS Branch."""
 
+    @property
+    def user_transport(self):
+        return self.bzrdir.user_transport
+
     def __init__(self, _format, _control_files, a_bzrdir, *args, **kwargs):
         self._format = _format
         self._base = a_bzrdir.transport.base

=== modified file 'bzrlib/transport/__init__.py'
--- a/bzrlib/transport/__init__.py	2011-09-04 23:25:09 +0000
+++ b/bzrlib/transport/__init__.py	2011-11-16 18:10:36 +0000
@@ -310,7 +310,8 @@
     def __init__(self, base):
         super(Transport, self).__init__()
         self.base = base
-        self._segment_parameters = urlutils.split_segment_parameters(base)[1]
+        (self._raw_base, self._segment_parameters) = (
+            urlutils.split_segment_parameters(base))
 
     def _translate_error(self, e, path, raise_generic=True):
         """Translate an IOError or OSError into an appropriate bzr error.
@@ -415,6 +416,22 @@
         """
         return self._segment_parameters
 
+    def set_segment_parameter(self, name, value):
+        """Set a segment parameter.
+
+        :param name: Segment parameter name (urlencoded string)
+        :param value: Segment parameter value (urlencoded string)
+        """
+        if value is None:
+            try:
+                del self._segment_parameters[name]
+            except KeyError:
+                pass
+        else:
+            self._segment_parameters[name] = value
+        self.base = urlutils.join_segment_parameters(
+            self._raw_base, self._segment_parameters)
+
     def _pump(self, from_file, to_file):
         """Most children will need to copy from one file-like
         object or string to another one.

=== modified file 'doc/en/release-notes/bzr-2.5.txt'
--- a/doc/en/release-notes/bzr-2.5.txt	2011-11-17 17:16:09 +0000
+++ b/doc/en/release-notes/bzr-2.5.txt	2011-11-17 18:06:46 +0000
@@ -192,6 +192,8 @@
   being referenced from e.g. a branch history at the same time.
   (Jelmer Vernooij)
 
+* New method ``Transport.set_segment_parameter``.  (Jelmer Vernooij)
+
 * ``UIFactory.choose`` has been added: prompt the user for a list of
   choices. (Benoît Pierre)
 




More information about the bazaar-commits mailing list