Rev 5072: (Jelmer) Add name argument to BzrDir.create_branch(), in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Tue Mar 2 20:45:16 GMT 2010
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 5072 [merge]
revision-id: pqm at pqm.ubuntu.com-20100302204508-4j07g2h9wj49o494
parent: pqm at pqm.ubuntu.com-20100302164538-yx0io3uv54l2o7im
parent: jelmer at samba.org-20100302195018-x2rz29tcs77k4v67
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Tue 2010-03-02 20:45:08 +0000
message:
(Jelmer) Add name argument to BzrDir.create_branch(),
BzrDir.destroy_branch() and BzrDir.open_branch().
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
bzrlib/bzrdir.py bzrdir.py-20060131065624-156dfea39c4387cb
bzrlib/errors.py errors.py-20050309040759-20512168c4e14fbd
bzrlib/remote.py remote.py-20060720103555-yeeg2x51vn0rbtdp-1
bzrlib/tests/per_bzrdir/test_bzrdir.py test_bzrdir.py-20060131065642-0ebeca5e30e30866
bzrlib/tests/test_bzrdir.py test_bzrdir.py-20060131065654-deba40eef51cf220
bzrlib/tests/test_foreign.py test_foreign.py-20081125004048-ywb901edgp9lluxo-1
=== modified file 'NEWS'
--- a/NEWS 2010-03-02 15:56:28 +0000
+++ b/NEWS 2010-03-02 19:50:18 +0000
@@ -118,6 +118,9 @@
to be done separately.
(Martin Pool, #507710)
+* New method ``BzrDir.list_branches()`` that returns a sequence of branches
+ present in a control directory. (Jelmer Vernooij)
+
* Remove unused ``CommandFailed`` exception.
(Martin Pool)
@@ -133,6 +136,10 @@
now use the generic pluggable command lookup infrastructure.
(Robert Collins)
+* The methods ``BzrDir.create_branch()``, ``BzrDir.destroy_branch()`` and
+ ``BzrDir.open_branch()`` now take an optional ``name`` argument.
+ (Jelmer Vernooij)
+
Testing
*******
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py 2010-02-17 17:11:16 +0000
+++ b/bzrlib/branch.py 2010-03-02 19:50:18 +0000
@@ -167,13 +167,13 @@
"""
control = bzrdir.BzrDir.open(base, _unsupported,
possible_transports=possible_transports)
- return control.open_branch(_unsupported)
+ return control.open_branch(unsupported=_unsupported)
@staticmethod
def open_from_transport(transport, _unsupported=False):
"""Open the branch rooted at transport"""
control = bzrdir.BzrDir.open_from_transport(transport, _unsupported)
- return control.open_branch(_unsupported)
+ return control.open_branch(unsupported=_unsupported)
@staticmethod
def open_containing(url, possible_transports=None):
=== modified file 'bzrlib/bzrdir.py'
--- a/bzrlib/bzrdir.py 2010-02-23 07:43:11 +0000
+++ b/bzrlib/bzrdir.py 2010-03-02 19:50:18 +0000
@@ -396,16 +396,23 @@
"""Destroy the repository in this BzrDir"""
raise NotImplementedError(self.destroy_repository)
- def create_branch(self):
+ def create_branch(self, name=None):
"""Create a branch in this BzrDir.
+ :param name: Name of the colocated branch to create, None for
+ the default branch.
+
The bzrdir's format will control what branch format is created.
For more control see BranchFormatXX.create(a_bzrdir).
"""
raise NotImplementedError(self.create_branch)
- def destroy_branch(self):
- """Destroy the branch in this BzrDir"""
+ def destroy_branch(self, name=None):
+ """Destroy a branch in this BzrDir.
+
+ :param name: Name of the branch to destroy, None for the default
+ branch.
+ """
raise NotImplementedError(self.destroy_branch)
@staticmethod
@@ -892,7 +899,8 @@
BzrDir._check_supported(format, _unsupported)
return format.open(transport, _found=True)
- def open_branch(self, unsupported=False, ignore_fallbacks=False):
+ def open_branch(self, name=None, unsupported=False,
+ ignore_fallbacks=False):
"""Open the branch object at this BzrDir if one is present.
If unsupported is True, then no longer supported branch formats can
@@ -1036,7 +1044,7 @@
"""
raise NotImplementedError(self.open_workingtree)
- def has_branch(self):
+ def has_branch(self, name=None):
"""Tell if this bzrdir contains a branch.
Note: if you're going to open the branch, you should just go ahead
@@ -1044,7 +1052,7 @@
branch and discards it, and that's somewhat expensive.)
"""
try:
- self.open_branch()
+ self.open_branch(name)
return True
except errors.NotBranchError:
return False
@@ -1373,11 +1381,13 @@
tree.clone(result)
return result
- def create_branch(self):
+ def create_branch(self, name=None):
"""See BzrDir.create_branch."""
+ if name is not None:
+ raise errors.NoColocatedBranchSupport(self)
return self._format.get_branch_format().initialize(self)
- def destroy_branch(self):
+ def destroy_branch(self, name=None):
"""See BzrDir.destroy_branch."""
raise errors.UnsupportedOperation(self.destroy_branch, self)
@@ -1479,8 +1489,11 @@
format = BzrDirFormat.get_default_format()
return not isinstance(self._format, format.__class__)
- def open_branch(self, unsupported=False, ignore_fallbacks=False):
+ def open_branch(self, name=None, unsupported=False,
+ ignore_fallbacks=False):
"""See BzrDir.open_branch."""
+ if name is not None:
+ raise errors.NoColocatedBranchSupport(self)
from bzrlib.branch import BzrBranchFormat4
format = BzrBranchFormat4()
self._check_supported(format, unsupported)
@@ -1607,12 +1620,16 @@
"""See BzrDir.can_convert_format()."""
return True
- def create_branch(self):
+ def create_branch(self, name=None):
"""See BzrDir.create_branch."""
+ if name is not None:
+ raise errors.NoColocatedBranchSupport(self)
return self._format.get_branch_format().initialize(self)
- def destroy_branch(self):
+ def destroy_branch(self, name=None):
"""See BzrDir.create_branch."""
+ if name is not None:
+ raise errors.NoColocatedBranchSupport(self)
self.transport.delete_tree('branch')
def create_repository(self, shared=False):
@@ -1739,13 +1756,11 @@
return True
except errors.NoRepositoryPresent:
pass
- try:
- if not isinstance(self.open_branch()._format,
+ for branch in self.list_branches():
+ if not isinstance(branch._format,
format.get_branch_format().__class__):
# the branch needs an upgrade.
return True
- except errors.NotBranchError:
- pass
try:
my_wt = self.open_workingtree(recommend_upgrade=False)
if not isinstance(my_wt._format,
@@ -1756,8 +1771,11 @@
pass
return False
- def open_branch(self, unsupported=False, ignore_fallbacks=False):
+ def open_branch(self, name=None, unsupported=False,
+ ignore_fallbacks=False):
"""See BzrDir.open_branch."""
+ if name is not None:
+ raise errors.NoColocatedBranchSupport(self)
format = self.find_branch_format()
self._check_supported(format, unsupported)
return format.open(self, _found=True, ignore_fallbacks=ignore_fallbacks)
@@ -1820,6 +1838,10 @@
_lock_file_name = 'branch-lock'
+ colocated_branches = False
+ """Whether co-located branches are supported for this control dir format.
+ """
+
# _lock_class must be set in subclasses to the lock type, typ.
# TransportLock or LockDir
=== modified file 'bzrlib/errors.py'
--- a/bzrlib/errors.py 2010-02-17 17:11:16 +0000
+++ b/bzrlib/errors.py 2010-03-02 19:50:18 +0000
@@ -3124,3 +3124,12 @@
def __init__(self, path):
self.path = path
+
+
+class NoColocatedBranchSupport(BzrError):
+
+ _fmt = ("%(bzrdir)r does not support co-located branches.")
+
+ def __init__(self, bzrdir):
+ self.bzrdir = bzrdir
+
=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py 2010-02-23 07:43:11 +0000
+++ b/bzrlib/remote.py 2010-03-02 19:50:18 +0000
@@ -242,7 +242,9 @@
self._ensure_real()
self._real_bzrdir.destroy_repository()
- def create_branch(self):
+ def create_branch(self, name=None):
+ if name is not None:
+ raise errors.NoColocatedBranchSupport(self)
# as per meta1 formats - just delegate to the format object which may
# be parameterised.
real_branch = self._format.get_branch_format().initialize(self)
@@ -259,10 +261,10 @@
self._next_open_branch_result = result
return result
- def destroy_branch(self):
+ def destroy_branch(self, name=None):
"""See BzrDir.destroy_branch"""
self._ensure_real()
- self._real_bzrdir.destroy_branch()
+ self._real_bzrdir.destroy_branch(name=name)
self._next_open_branch_result = None
def create_workingtree(self, revision_id=None, from_branch=None):
@@ -318,9 +320,12 @@
"""See BzrDir._get_tree_branch()."""
return None, self.open_branch()
- def open_branch(self, _unsupported=False, ignore_fallbacks=False):
- if _unsupported:
+ def open_branch(self, name=None, unsupported=False,
+ ignore_fallbacks=False):
+ if unsupported:
raise NotImplementedError('unsupported flag support not implemented yet.')
+ if name is not None:
+ raise errors.NoColocatedBranchSupport(self)
if self._next_open_branch_result is not None:
# See create_branch for details.
result = self._next_open_branch_result
=== modified file 'bzrlib/tests/per_bzrdir/test_bzrdir.py'
--- a/bzrlib/tests/per_bzrdir/test_bzrdir.py 2010-02-23 07:43:11 +0000
+++ b/bzrlib/tests/per_bzrdir/test_bzrdir.py 2010-03-02 19:50:18 +0000
@@ -247,11 +247,22 @@
try:
bzrdir.destroy_branch()
except (errors.UnsupportedOperation, errors.TransportNotPossible):
- raise TestNotApplicable('Format does not support destroying tree')
+ raise TestNotApplicable('Format does not support destroying branch')
self.assertRaises(errors.NotBranchError, bzrdir.open_branch)
bzrdir.create_branch()
bzrdir.open_branch()
+ def test_destroy_colocated_branch(self):
+ branch = self.make_branch('branch')
+ bzrdir = branch.bzrdir
+ try:
+ colo_branch = bzrdir.create_branch('colo')
+ except errors.NoColocatedBranchSupport:
+ raise TestNotApplicable('BzrDir does not do colocated branches')
+ bzrdir.destroy_branch("colo")
+ self.assertRaises(errors.NotBranchError, bzrdir.open_branch,
+ "colo")
+
def test_destroy_repository(self):
repo = self.make_repository('repository')
bzrdir = repo.bzrdir
@@ -1410,6 +1421,23 @@
self.failUnless(isinstance(made_branch, bzrlib.branch.Branch))
self.assertEqual(made_control, made_branch.bzrdir)
+ def test_create_colo_branch(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 TestNotApplicable('Control dir format not supported')
+ t = get_transport(self.get_url())
+ made_control = self.bzrdir_format.initialize(t.base)
+ made_repo = made_control.create_repository()
+ try:
+ made_branch = made_control.create_branch("colo")
+ except errors.NoColocatedBranchSupport:
+ raise TestNotApplicable('Colocated branches not supported')
+ self.failUnless(isinstance(made_branch, bzrlib.branch.Branch))
+ self.assertEqual(made_control, made_branch.bzrdir)
+
def test_open_branch(self):
if not self.bzrdir_format.is_supported():
# unsupported formats are not loopback testable
=== modified file 'bzrlib/tests/test_bzrdir.py'
--- a/bzrlib/tests/test_bzrdir.py 2010-02-23 07:43:11 +0000
+++ b/bzrlib/tests/test_bzrdir.py 2010-03-02 19:50:18 +0000
@@ -36,6 +36,7 @@
)
import bzrlib.branch
from bzrlib.errors import (NotBranchError,
+ NoColocatedBranchSupport,
UnknownFormatError,
UnsupportedFormatError,
)
@@ -206,8 +207,10 @@
"""See BzrDir.open_repository."""
return SampleRepository(self)
- def create_branch(self):
+ def create_branch(self, name=None):
"""See BzrDir.create_branch."""
+ if name is not None:
+ raise NoColocatedBranchSupport(self)
return SampleBranch(self)
def create_workingtree(self):
=== modified file 'bzrlib/tests/test_foreign.py'
--- a/bzrlib/tests/test_foreign.py 2010-02-17 17:11:16 +0000
+++ b/bzrlib/tests/test_foreign.py 2010-03-02 19:50:18 +0000
@@ -243,7 +243,9 @@
self._control_files = lockable_files.LockableFiles(self.transport,
"lock", lockable_files.TransportLock)
- def open_branch(self, ignore_fallbacks=True):
+ def open_branch(self, name=None, unsupported=False, ignore_fallbacks=True):
+ if name is not None:
+ raise errors.NoColocatedBranchSupport(self)
return self._format.get_branch_format().open(self, _found=True)
def cloning_metadir(self, stacked=False):
More information about the bazaar-commits
mailing list