21
21
lazy_import(globals(), """
23
23
from bzrlib import (
27
config as _mod_config,
36
revision as _mod_revision,
28
config as _mod_config,
37
revision as _mod_revision,
43
44
from bzrlib.i18n import gettext, ngettext
107
108
for existing_fallback_repo in self.repository._fallback_repositories:
108
109
if existing_fallback_repo.user_url == url:
109
110
# This fallback is already configured. This probably only
110
# happens because BzrDir.sprout is a horrible mess. To avoid
111
# happens because ControlDir.sprout is a horrible mess. To avoid
111
112
# confusing _unstack we don't add this a second time.
112
113
mutter('duplicate activation of fallback %r on %r', url, self)
171
172
For instance, if the branch is at URL/.bzr/branch,
172
173
Branch.open(URL) -> a Branch instance.
174
control = bzrdir.BzrDir.open(base, _unsupported,
175
control = controldir.ControlDir.open(base, _unsupported,
175
176
possible_transports=possible_transports)
176
177
return control.open_branch(unsupported=_unsupported)
179
180
def open_from_transport(transport, name=None, _unsupported=False):
180
181
"""Open the branch rooted at transport"""
181
control = bzrdir.BzrDir.open_from_transport(transport, _unsupported)
182
control = controldir.ControlDir.open_from_transport(transport, _unsupported)
182
183
return control.open_branch(name=name, unsupported=_unsupported)
193
194
format, UnknownFormatError or UnsupportedFormatError are raised.
194
195
If there is one, it is returned, along with the unused portion of url.
196
control, relpath = bzrdir.BzrDir.open_containing(url,
197
control, relpath = controldir.ControlDir.open_containing(url,
197
198
possible_transports)
198
199
return control.open_branch(), relpath
881
882
# stream from one of them to the other. This does mean doing
882
883
# separate SSH connection setup, but unstacking is not a
883
884
# common operation so it's tolerable.
884
new_bzrdir = bzrdir.BzrDir.open(self.bzrdir.root_transport.base)
885
new_bzrdir = controldir.ControlDir.open(
886
self.bzrdir.root_transport.base)
885
887
new_repository = new_bzrdir.find_repository()
886
888
if new_repository._fallback_repositories:
887
889
raise AssertionError("didn't expect %r to have "
1451
1453
from_branch = BranchReferenceFormat().initialize(checkout,
1452
1454
target_branch=self)
1454
checkout_branch = bzrdir.BzrDir.create_branch_convenience(
1456
checkout_branch = controldir.ControlDir.create_branch_convenience(
1455
1457
to_location, force_new_tree=False, format=format)
1456
1458
checkout = checkout_branch.bzrdir
1457
1459
checkout_branch.bind(self)
1595
1597
return not (self == other)
1598
def find_format(klass, a_bzrdir, name=None):
1599
"""Return the format for the branch object in a_bzrdir."""
1600
def find_format(klass, controldir, name=None):
1601
"""Return the format for the branch object in controldir."""
1601
transport = a_bzrdir.get_branch_transport(None, name=name)
1603
transport = controldir.get_branch_transport(None, name=name)
1602
1604
format_string = transport.get_bytes("format")
1603
1605
return format_registry.get(format_string)
1604
1606
except errors.NoSuchFile:
1605
raise errors.NotBranchError(path=transport.base, bzrdir=a_bzrdir)
1607
raise errors.NotBranchError(path=transport.base, bzrdir=controldir)
1606
1608
except KeyError:
1607
1609
raise errors.UnknownFormatError(format=format_string, kind='branch')
1623
1625
return format_registry._get_all()
1625
def get_reference(self, a_bzrdir, name=None):
1626
"""Get the target reference of the branch in a_bzrdir.
1627
def get_reference(self, controldir, name=None):
1628
"""Get the target reference of the branch in controldir.
1628
1630
format probing must have been completed before calling
1629
1631
this method - it is assumed that the format of the branch
1630
in a_bzrdir is correct.
1632
in controldir is correct.
1632
:param a_bzrdir: The bzrdir to get the branch data from.
1634
:param controldir: The controldir to get the branch data from.
1633
1635
:param name: Name of the colocated branch to fetch
1634
1636
:return: None if the branch is not a reference branch.
1639
def set_reference(self, a_bzrdir, name, to_branch):
1640
"""Set the target reference of the branch in a_bzrdir.
1641
def set_reference(self, controldir, name, to_branch):
1642
"""Set the target reference of the branch in controldir.
1642
1644
format probing must have been completed before calling
1643
1645
this method - it is assumed that the format of the branch
1644
in a_bzrdir is correct.
1646
in controldir is correct.
1646
:param a_bzrdir: The bzrdir to set the branch reference for.
1648
:param controldir: The controldir to set the branch reference for.
1647
1649
:param name: Name of colocated branch to set, None for default
1648
1650
:param to_branch: branch that the checkout is to reference
1657
1659
"""Return the short format description for this format."""
1658
1660
raise NotImplementedError(self.get_format_description)
1660
def _run_post_branch_init_hooks(self, a_bzrdir, name, branch):
1662
def _run_post_branch_init_hooks(self, controldir, name, branch):
1661
1663
hooks = Branch.hooks['post_branch_init']
1664
params = BranchInitHookParams(self, a_bzrdir, name, branch)
1666
params = BranchInitHookParams(self, controldir, name, branch)
1665
1667
for hook in hooks:
1668
def initialize(self, a_bzrdir, name=None, repository=None,
1670
def initialize(self, controldir, name=None, repository=None,
1669
1671
append_revisions_only=None):
1670
"""Create a branch of this format in a_bzrdir.
1672
"""Create a branch of this format in controldir.
1672
1674
:param name: Name of the colocated branch to create.
1674
1676
raise NotImplementedError(self.initialize)
1707
1709
raise NotImplementedError(self.network_name)
1709
def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False,
1711
def open(self, controldir, name=None, _found=False, ignore_fallbacks=False,
1710
1712
found_repository=None):
1711
"""Return the branch object for a_bzrdir
1713
"""Return the branch object for controldir.
1713
:param a_bzrdir: A BzrDir that contains a branch.
1715
:param controldir: A ControlDir that contains a branch.
1714
1716
:param name: Name of colocated branch to open
1715
1717
:param _found: a private parameter, do not use it. It is used to
1716
1718
indicate if format probing has already be done.
1936
1938
There are 4 fields that hooks may wish to access:
1938
1940
:ivar format: the branch format
1939
:ivar bzrdir: the BzrDir where the branch will be/has been initialized
1941
:ivar bzrdir: the ControlDir where the branch will be/has been initialized
1940
1942
:ivar name: name of colocated branch, if any (or None)
1941
1943
:ivar branch: the branch created
1945
1947
branch, which refer to the original branch.
1948
def __init__(self, format, a_bzrdir, name, branch):
1950
def __init__(self, format, controldir, name, branch):
1949
1951
"""Create a group of BranchInitHook parameters.
1951
1953
:param format: the branch format
1952
:param a_bzrdir: the BzrDir where the branch will be/has been
1954
:param controldir: the ControlDir where the branch will be/has been
1954
1956
:param name: name of colocated branch, if any (or None)
1955
1957
:param branch: the branch created
1976
1978
There are 4 fields that hooks may wish to access:
1978
:ivar control_dir: BzrDir of the checkout to change
1980
:ivar control_dir: ControlDir of the checkout to change
1979
1981
:ivar to_branch: branch that the checkout is to reference
1980
1982
:ivar force: skip the check for local commits in a heavy checkout
1981
1983
:ivar revision_id: revision ID to switch to (or None)
1984
1986
def __init__(self, control_dir, to_branch, force, revision_id):
1985
1987
"""Create a group of SwitchHook parameters.
1987
:param control_dir: BzrDir of the checkout to change
1989
:param control_dir: ControlDir of the checkout to change
1988
1990
:param to_branch: branch that the checkout is to reference
1989
1991
:param force: skip the check for local commits in a heavy checkout
1990
1992
:param revision_id: revision ID to switch to (or None)
2336
2338
(format, self))
2337
2339
if location is None:
2338
2340
location = self.get_reference(a_bzrdir, name)
2339
real_bzrdir = bzrdir.BzrDir.open(
2341
real_bzrdir = controldir.ControlDir.open(
2340
2342
location, possible_transports=possible_transports)
2341
2343
result = real_bzrdir.open_branch(name=name,
2342
2344
ignore_fallbacks=ignore_fallbacks)