14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
19
from cStringIO import StringIO
21
22
lazy_import(globals(), """
23
24
from bzrlib import (
27
config as _mod_config,
36
revision as _mod_revision,
29
config as _mod_config,
38
revision as _mod_revision,
43
45
from bzrlib.i18n import gettext, ngettext
107
109
for existing_fallback_repo in self.repository._fallback_repositories:
108
110
if existing_fallback_repo.user_url == url:
109
111
# This fallback is already configured. This probably only
110
# happens because BzrDir.sprout is a horrible mess. To avoid
112
# happens because ControlDir.sprout is a horrible mess. To avoid
111
113
# confusing _unstack we don't add this a second time.
112
114
mutter('duplicate activation of fallback %r on %r', url, self)
171
173
For instance, if the branch is at URL/.bzr/branch,
172
174
Branch.open(URL) -> a Branch instance.
174
control = bzrdir.BzrDir.open(base, _unsupported,
176
control = controldir.ControlDir.open(base, _unsupported,
175
177
possible_transports=possible_transports)
176
178
return control.open_branch(unsupported=_unsupported)
179
181
def open_from_transport(transport, name=None, _unsupported=False):
180
182
"""Open the branch rooted at transport"""
181
control = bzrdir.BzrDir.open_from_transport(transport, _unsupported)
183
control = controldir.ControlDir.open_from_transport(transport, _unsupported)
182
184
return control.open_branch(name=name, unsupported=_unsupported)
193
195
format, UnknownFormatError or UnsupportedFormatError are raised.
194
196
If there is one, it is returned, along with the unused portion of url.
196
control, relpath = bzrdir.BzrDir.open_containing(url,
198
control, relpath = controldir.ControlDir.open_containing(url,
197
199
possible_transports)
198
200
return control.open_branch(), relpath
881
883
# stream from one of them to the other. This does mean doing
882
884
# separate SSH connection setup, but unstacking is not a
883
885
# common operation so it's tolerable.
884
new_bzrdir = bzrdir.BzrDir.open(self.bzrdir.root_transport.base)
886
new_bzrdir = controldir.ControlDir.open(
887
self.bzrdir.root_transport.base)
885
888
new_repository = new_bzrdir.find_repository()
886
889
if new_repository._fallback_repositories:
887
890
raise AssertionError("didn't expect %r to have "
1455
1458
from_branch = BranchReferenceFormat().initialize(checkout,
1456
1459
target_branch=self)
1458
checkout_branch = bzrdir.BzrDir.create_branch_convenience(
1461
checkout_branch = controldir.ControlDir.create_branch_convenience(
1459
1462
to_location, force_new_tree=False, format=format)
1460
1463
checkout = checkout_branch.bzrdir
1461
1464
checkout_branch.bind(self)
1599
1602
return not (self == other)
1602
def find_format(klass, a_bzrdir, name=None):
1603
"""Return the format for the branch object in a_bzrdir."""
1605
def find_format(klass, controldir, name=None):
1606
"""Return the format for the branch object in controldir."""
1605
transport = a_bzrdir.get_branch_transport(None, name=name)
1608
transport = controldir.get_branch_transport(None, name=name)
1606
1609
format_string = transport.get_bytes("format")
1607
1610
return format_registry.get(format_string)
1608
1611
except errors.NoSuchFile:
1609
raise errors.NotBranchError(path=transport.base, bzrdir=a_bzrdir)
1612
raise errors.NotBranchError(path=transport.base, bzrdir=controldir)
1610
1613
except KeyError:
1611
1614
raise errors.UnknownFormatError(format=format_string, kind='branch')
1627
1630
return format_registry._get_all()
1629
def get_reference(self, a_bzrdir, name=None):
1630
"""Get the target reference of the branch in a_bzrdir.
1632
def get_reference(self, controldir, name=None):
1633
"""Get the target reference of the branch in controldir.
1632
1635
format probing must have been completed before calling
1633
1636
this method - it is assumed that the format of the branch
1634
in a_bzrdir is correct.
1637
in controldir is correct.
1636
:param a_bzrdir: The bzrdir to get the branch data from.
1639
:param controldir: The controldir to get the branch data from.
1637
1640
:param name: Name of the colocated branch to fetch
1638
1641
:return: None if the branch is not a reference branch.
1643
def set_reference(self, a_bzrdir, name, to_branch):
1644
"""Set the target reference of the branch in a_bzrdir.
1646
def set_reference(self, controldir, name, to_branch):
1647
"""Set the target reference of the branch in controldir.
1646
1649
format probing must have been completed before calling
1647
1650
this method - it is assumed that the format of the branch
1648
in a_bzrdir is correct.
1651
in controldir is correct.
1650
:param a_bzrdir: The bzrdir to set the branch reference for.
1653
:param controldir: The controldir to set the branch reference for.
1651
1654
:param name: Name of colocated branch to set, None for default
1652
1655
:param to_branch: branch that the checkout is to reference
1661
1664
"""Return the short format description for this format."""
1662
1665
raise NotImplementedError(self.get_format_description)
1664
def _run_post_branch_init_hooks(self, a_bzrdir, name, branch):
1667
def _run_post_branch_init_hooks(self, controldir, name, branch):
1665
1668
hooks = Branch.hooks['post_branch_init']
1668
params = BranchInitHookParams(self, a_bzrdir, name, branch)
1671
params = BranchInitHookParams(self, controldir, name, branch)
1669
1672
for hook in hooks:
1672
def initialize(self, a_bzrdir, name=None, repository=None,
1675
def initialize(self, controldir, name=None, repository=None,
1673
1676
append_revisions_only=None):
1674
"""Create a branch of this format in a_bzrdir.
1677
"""Create a branch of this format in controldir.
1676
1679
:param name: Name of the colocated branch to create.
1678
1681
raise NotImplementedError(self.initialize)
1711
1714
raise NotImplementedError(self.network_name)
1713
def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False,
1716
def open(self, controldir, name=None, _found=False, ignore_fallbacks=False,
1714
1717
found_repository=None):
1715
"""Return the branch object for a_bzrdir
1718
"""Return the branch object for controldir.
1717
:param a_bzrdir: A BzrDir that contains a branch.
1720
:param controldir: A ControlDir that contains a branch.
1718
1721
:param name: Name of colocated branch to open
1719
1722
:param _found: a private parameter, do not use it. It is used to
1720
1723
indicate if format probing has already be done.
1940
1943
There are 4 fields that hooks may wish to access:
1942
1945
:ivar format: the branch format
1943
:ivar bzrdir: the BzrDir where the branch will be/has been initialized
1946
:ivar bzrdir: the ControlDir where the branch will be/has been initialized
1944
1947
:ivar name: name of colocated branch, if any (or None)
1945
1948
:ivar branch: the branch created
1949
1952
branch, which refer to the original branch.
1952
def __init__(self, format, a_bzrdir, name, branch):
1955
def __init__(self, format, controldir, name, branch):
1953
1956
"""Create a group of BranchInitHook parameters.
1955
1958
:param format: the branch format
1956
:param a_bzrdir: the BzrDir where the branch will be/has been
1959
:param controldir: the ControlDir where the branch will be/has been
1958
1961
:param name: name of colocated branch, if any (or None)
1959
1962
:param branch: the branch created
1980
1983
There are 4 fields that hooks may wish to access:
1982
:ivar control_dir: BzrDir of the checkout to change
1985
:ivar control_dir: ControlDir of the checkout to change
1983
1986
:ivar to_branch: branch that the checkout is to reference
1984
1987
:ivar force: skip the check for local commits in a heavy checkout
1985
1988
:ivar revision_id: revision ID to switch to (or None)
1988
1991
def __init__(self, control_dir, to_branch, force, revision_id):
1989
1992
"""Create a group of SwitchHook parameters.
1991
:param control_dir: BzrDir of the checkout to change
1994
:param control_dir: ControlDir of the checkout to change
1992
1995
:param to_branch: branch that the checkout is to reference
1993
1996
:param force: skip the check for local commits in a heavy checkout
1994
1997
:param revision_id: revision ID to switch to (or None)
2081
2084
except errors.NoSuchFile:
2082
2085
raise errors.NotBranchError(path=transport.base, bzrdir=a_bzrdir)
2085
super(BranchFormatMetadir, self).__init__()
2086
self._matchingbzrdir = bzrdir.BzrDirMetaFormat1()
2087
self._matchingbzrdir.set_branch_format(self)
2088
def _matchingbzrdir(self):
2089
ret = bzrdir.BzrDirMetaFormat1()
2090
ret.set_branch_format(self)
2089
2093
def supports_tags(self):
2252
2256
supports_reference_locations = False
2255
class BranchReferenceFormat(BranchFormat):
2259
class BranchReferenceFormat(BranchFormatMetadir):
2256
2260
"""Bzr branch reference format.
2258
2262
Branch references are used in implementing checkouts, they
2301
2305
self._run_post_branch_init_hooks(a_bzrdir, name, branch)
2305
super(BranchReferenceFormat, self).__init__()
2306
self._matchingbzrdir = bzrdir.BzrDirMetaFormat1()
2307
self._matchingbzrdir.set_branch_format(self)
2309
2308
def _make_reference_clone_function(format, a_branch):
2310
2309
"""Create a clone() routine for a branch dynamically."""
2311
2310
def clone(to_bzrdir, revision_id=None,
2340
2339
(format, self))
2341
2340
if location is None:
2342
2341
location = self.get_reference(a_bzrdir, name)
2343
real_bzrdir = bzrdir.BzrDir.open(
2342
real_bzrdir = controldir.ControlDir.open(
2344
2343
location, possible_transports=possible_transports)
2345
2344
result = real_bzrdir.open_branch(name=name,
2346
2345
ignore_fallbacks=ignore_fallbacks)