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 "
1451
1454
from_branch = BranchReferenceFormat().initialize(checkout,
1452
1455
target_branch=self)
1454
checkout_branch = bzrdir.BzrDir.create_branch_convenience(
1457
checkout_branch = controldir.ControlDir.create_branch_convenience(
1455
1458
to_location, force_new_tree=False, format=format)
1456
1459
checkout = checkout_branch.bzrdir
1457
1460
checkout_branch.bind(self)
1595
1598
return not (self == other)
1598
def find_format(klass, a_bzrdir, name=None):
1599
"""Return the format for the branch object in a_bzrdir."""
1601
def find_format(klass, controldir, name=None):
1602
"""Return the format for the branch object in controldir."""
1601
transport = a_bzrdir.get_branch_transport(None, name=name)
1604
transport = controldir.get_branch_transport(None, name=name)
1602
1605
format_string = transport.get_bytes("format")
1603
1606
return format_registry.get(format_string)
1604
1607
except errors.NoSuchFile:
1605
raise errors.NotBranchError(path=transport.base, bzrdir=a_bzrdir)
1608
raise errors.NotBranchError(path=transport.base, bzrdir=controldir)
1606
1609
except KeyError:
1607
1610
raise errors.UnknownFormatError(format=format_string, kind='branch')
1623
1626
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.
1628
def get_reference(self, controldir, name=None):
1629
"""Get the target reference of the branch in controldir.
1628
1631
format probing must have been completed before calling
1629
1632
this method - it is assumed that the format of the branch
1630
in a_bzrdir is correct.
1633
in controldir is correct.
1632
:param a_bzrdir: The bzrdir to get the branch data from.
1635
:param controldir: The controldir to get the branch data from.
1633
1636
:param name: Name of the colocated branch to fetch
1634
1637
: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.
1642
def set_reference(self, controldir, name, to_branch):
1643
"""Set the target reference of the branch in controldir.
1642
1645
format probing must have been completed before calling
1643
1646
this method - it is assumed that the format of the branch
1644
in a_bzrdir is correct.
1647
in controldir is correct.
1646
:param a_bzrdir: The bzrdir to set the branch reference for.
1649
:param controldir: The controldir to set the branch reference for.
1647
1650
:param name: Name of colocated branch to set, None for default
1648
1651
:param to_branch: branch that the checkout is to reference
1657
1660
"""Return the short format description for this format."""
1658
1661
raise NotImplementedError(self.get_format_description)
1660
def _run_post_branch_init_hooks(self, a_bzrdir, name, branch):
1663
def _run_post_branch_init_hooks(self, controldir, name, branch):
1661
1664
hooks = Branch.hooks['post_branch_init']
1664
params = BranchInitHookParams(self, a_bzrdir, name, branch)
1667
params = BranchInitHookParams(self, controldir, name, branch)
1665
1668
for hook in hooks:
1668
def initialize(self, a_bzrdir, name=None, repository=None,
1671
def initialize(self, controldir, name=None, repository=None,
1669
1672
append_revisions_only=None):
1670
"""Create a branch of this format in a_bzrdir.
1673
"""Create a branch of this format in controldir.
1672
1675
:param name: Name of the colocated branch to create.
1674
1677
raise NotImplementedError(self.initialize)
1707
1710
raise NotImplementedError(self.network_name)
1709
def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False,
1712
def open(self, controldir, name=None, _found=False, ignore_fallbacks=False,
1710
1713
found_repository=None):
1711
"""Return the branch object for a_bzrdir
1714
"""Return the branch object for controldir.
1713
:param a_bzrdir: A BzrDir that contains a branch.
1716
:param controldir: A ControlDir that contains a branch.
1714
1717
:param name: Name of colocated branch to open
1715
1718
:param _found: a private parameter, do not use it. It is used to
1716
1719
indicate if format probing has already be done.
1936
1939
There are 4 fields that hooks may wish to access:
1938
1941
:ivar format: the branch format
1939
:ivar bzrdir: the BzrDir where the branch will be/has been initialized
1942
:ivar bzrdir: the ControlDir where the branch will be/has been initialized
1940
1943
:ivar name: name of colocated branch, if any (or None)
1941
1944
:ivar branch: the branch created
1945
1948
branch, which refer to the original branch.
1948
def __init__(self, format, a_bzrdir, name, branch):
1951
def __init__(self, format, controldir, name, branch):
1949
1952
"""Create a group of BranchInitHook parameters.
1951
1954
:param format: the branch format
1952
:param a_bzrdir: the BzrDir where the branch will be/has been
1955
:param controldir: the ControlDir where the branch will be/has been
1954
1957
:param name: name of colocated branch, if any (or None)
1955
1958
:param branch: the branch created
1976
1979
There are 4 fields that hooks may wish to access:
1978
:ivar control_dir: BzrDir of the checkout to change
1981
:ivar control_dir: ControlDir of the checkout to change
1979
1982
:ivar to_branch: branch that the checkout is to reference
1980
1983
:ivar force: skip the check for local commits in a heavy checkout
1981
1984
:ivar revision_id: revision ID to switch to (or None)
1984
1987
def __init__(self, control_dir, to_branch, force, revision_id):
1985
1988
"""Create a group of SwitchHook parameters.
1987
:param control_dir: BzrDir of the checkout to change
1990
:param control_dir: ControlDir of the checkout to change
1988
1991
:param to_branch: branch that the checkout is to reference
1989
1992
:param force: skip the check for local commits in a heavy checkout
1990
1993
:param revision_id: revision ID to switch to (or None)
2077
2080
except errors.NoSuchFile:
2078
2081
raise errors.NotBranchError(path=transport.base, bzrdir=a_bzrdir)
2081
super(BranchFormatMetadir, self).__init__()
2082
self._matchingbzrdir = bzrdir.BzrDirMetaFormat1()
2083
self._matchingbzrdir.set_branch_format(self)
2084
def _matchingbzrdir(self):
2085
ret = bzrdir.BzrDirMetaFormat1()
2086
ret.set_branch_format(self)
2085
2089
def supports_tags(self):
2248
2252
supports_reference_locations = False
2251
class BranchReferenceFormat(BranchFormat):
2255
class BranchReferenceFormat(BranchFormatMetadir):
2252
2256
"""Bzr branch reference format.
2254
2258
Branch references are used in implementing checkouts, they
2297
2301
self._run_post_branch_init_hooks(a_bzrdir, name, branch)
2301
super(BranchReferenceFormat, self).__init__()
2302
self._matchingbzrdir = bzrdir.BzrDirMetaFormat1()
2303
self._matchingbzrdir.set_branch_format(self)
2305
2304
def _make_reference_clone_function(format, a_branch):
2306
2305
"""Create a clone() routine for a branch dynamically."""
2307
2306
def clone(to_bzrdir, revision_id=None,
2336
2335
(format, self))
2337
2336
if location is None:
2338
2337
location = self.get_reference(a_bzrdir, name)
2339
real_bzrdir = bzrdir.BzrDir.open(
2338
real_bzrdir = controldir.ControlDir.open(
2340
2339
location, possible_transports=possible_transports)
2341
2340
result = real_bzrdir.open_branch(name=name,
2342
2341
ignore_fallbacks=ignore_fallbacks)