Rev 6463: (jelmer) Support forward slashes in colocated branch names. (Jelmer Vernooij) in file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/2.5/

Patch Queue Manager pqm at pqm.ubuntu.com
Fri Jan 27 20:46:28 UTC 2012


At file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/2.5/

------------------------------------------------------------
revno: 6463 [merge]
revision-id: pqm at pqm.ubuntu.com-20120127204627-l1k18d3chedgs3bu
parent: pqm at pqm.ubuntu.com-20120127145606-1t08tdt2ozzv4re5
parent: jelmer at samba.org-20120127154712-mjxgfhgv6bnsptbj
committer: Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: 2.5
timestamp: Fri 2012-01-27 20:46:27 +0000
message:
  (jelmer) Support forward slashes in colocated branch names. (Jelmer Vernooij)
modified:
  bzrlib/bzrdir.py               bzrdir.py-20060131065624-156dfea39c4387cb
  bzrlib/errors.py               errors.py-20050309040759-20512168c4e14fbd
  bzrlib/tests/per_controldir_colo/test_supported.py test_supported.py-20100411192232-kawv9qu1t42gv89k-3
  bzrlib/tests/test_bzrdir.py    test_bzrdir.py-20060131065654-deba40eef51cf220
  doc/en/release-notes/bzr-2.5.txt bzr2.5.txt-20110708125756-587p0hpw7oke4h05-1
=== modified file 'bzrlib/bzrdir.py'
--- a/bzrlib/bzrdir.py	2012-01-20 21:33:24 +0000
+++ b/bzrlib/bzrdir.py	2012-01-27 20:46:27 +0000
@@ -1105,25 +1105,30 @@
         except NotImplementedError:
             raise errors.IncompatibleFormat(branch_format, self._format)
         if name != "":
-            try:
-                self.transport.mkdir('branches', mode=self._get_mkdir_mode())
-            except errors.FileExists:
-                pass
             branches = self._read_branch_list()
             utf8_name = name.encode("utf-8")
             if not utf8_name in branches:
                 self.control_files.lock_write()
                 try:
                     branches = self._read_branch_list()
+                    dirname = urlutils.dirname(utf8_name)
+                    if dirname != "" and dirname in branches:
+                        raise errors.ParentBranchExists(name)
+                    child_branches = [
+                        b.startswith(utf8_name+"/") for b in branches]
+                    if any(child_branches):
+                        raise errors.AlreadyBranchError(name)
                     branches.append(utf8_name)
                     self._write_branch_list(branches)
                 finally:
                     self.control_files.unlock()
+        branch_transport = self.transport.clone(path)
+        branch_transport.create_prefix()
         try:
-            self.transport.mkdir(path, mode=self._get_mkdir_mode())
+            self.transport.mkdir('.', mode=self._get_mkdir_mode())
         except errors.FileExists:
             pass
-        return self.transport.clone(path)
+        return branch_transport
 
 
 class BzrFormat(object):

=== modified file 'bzrlib/errors.py'
--- a/bzrlib/errors.py	2012-01-20 13:21:01 +0000
+++ b/bzrlib/errors.py	2012-01-27 15:47:12 +0000
@@ -710,6 +710,11 @@
     _fmt = 'Already a branch: "%(path)s".'
 
 
+class ParentBranchExists(AlreadyBranchError):
+
+    _fmt = 'Parent branch already exists: "%(path)s".'
+
+
 class BranchExistsWithoutWorkingTree(PathError):
 
     _fmt = 'Directory contains a branch, but no working tree \

=== modified file 'bzrlib/tests/per_controldir_colo/test_supported.py'
--- a/bzrlib/tests/per_controldir_colo/test_supported.py	2012-01-18 17:37:38 +0000
+++ b/bzrlib/tests/per_controldir_colo/test_supported.py	2012-01-23 19:09:00 +0000
@@ -135,6 +135,13 @@
         self.assertEqual(target_branch.base,
                          repo.bzrdir.get_branches()['foo'].base)
 
+    def test_branch_name_with_slash(self):
+        repo = self.make_repository('branch-1')
+        target_branch = repo.bzrdir.create_branch(name='foo/bar')
+        self.assertEqual(['foo/bar'], repo.bzrdir.get_branches().keys())
+        self.assertEqual(
+            target_branch.base, repo.bzrdir.open_branch(name='foo/bar').base)
+
     def test_branch_reference(self):
         referenced = self.make_branch('referenced')
         repo = self.make_repository('repo')

=== modified file 'bzrlib/tests/test_bzrdir.py'
--- a/bzrlib/tests/test_bzrdir.py	2012-01-02 10:24:02 +0000
+++ b/bzrlib/tests/test_bzrdir.py	2012-01-27 15:47:12 +0000
@@ -1450,6 +1450,22 @@
         self.assertRaises(errors.BzrError, converter.convert, tree.bzrdir,
             None)
 
+    def test_nested(self):
+        tree = self.make_branch_and_tree('.', format='development-colo')
+        tree.bzrdir.create_branch(name='foo')
+        tree.bzrdir.create_branch(name='fool/bla')
+        self.assertRaises(
+            errors.ParentBranchExists, tree.bzrdir.create_branch,
+            name='foo/bar')
+
+    def test_parent(self):
+        tree = self.make_branch_and_tree('.', format='development-colo')
+        tree.bzrdir.create_branch(name='fool/bla')
+        tree.bzrdir.create_branch(name='foo/bar')
+        self.assertRaises(
+            errors.AlreadyBranchError, tree.bzrdir.create_branch,
+            name='foo')
+
 
 class SampleBzrFormat(bzrdir.BzrFormat):
 

=== modified file 'doc/en/release-notes/bzr-2.5.txt'
--- a/doc/en/release-notes/bzr-2.5.txt	2012-01-27 14:56:06 +0000
+++ b/doc/en/release-notes/bzr-2.5.txt	2012-01-27 20:46:27 +0000
@@ -36,6 +36,9 @@
   a control directory (but no branch or working tree).
   (Jelmer Vernooij, #913980)
 
+* Colocated branches can now have names including forward slashes, to
+  allow for namespaces. (Jelmer Vernooij, #907980)
+
 * New HPSS call for ``BzrDir.get_branches``. (Jelmer Vernooij, #894460)
 
 * Checkouts of colocated branches are now always lightweight.




More information about the bazaar-commits mailing list