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 "
1005
1008
raise NotImplementedError(self._gen_revision_history)
1010
@deprecated_method(deprecated_in((2, 5, 0)))
1007
1011
@needs_read_lock
1008
1012
def revision_history(self):
1009
1013
"""Return sequence of revision ids on this branch.
1011
1015
This method will cache the revision history for as long as it is safe to
1018
return self._revision_history()
1020
def _revision_history(self):
1014
1021
if 'evil' in debug.debug_flags:
1015
1022
mutter_callsite(3, "revision_history scales with history.")
1016
1023
if self._revision_history_cache is not None:
1086
1093
"""Given a revision id, return its revno"""
1087
1094
if _mod_revision.is_null(revision_id):
1089
history = self.revision_history()
1096
history = self._revision_history()
1091
1098
return history.index(revision_id) + 1
1092
1099
except ValueError:
1389
1396
# TODO: We should probably also check that self.revision_history
1390
1397
# matches the repository for older branch formats.
1391
1398
# If looking for the code that cross-checks repository parents against
1392
# the iter_reverse_revision_history output, that is now a repository
1399
# the Graph.iter_lefthand_ancestry output, that is now a repository
1393
1400
# specific check.
1451
1458
from_branch = BranchReferenceFormat().initialize(checkout,
1452
1459
target_branch=self)
1454
checkout_branch = bzrdir.BzrDir.create_branch_convenience(
1461
checkout_branch = controldir.ControlDir.create_branch_convenience(
1455
1462
to_location, force_new_tree=False, format=format)
1456
1463
checkout = checkout_branch.bzrdir
1457
1464
checkout_branch.bind(self)
1595
1602
return not (self == other)
1598
def find_format(klass, a_bzrdir, name=None):
1599
"""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."""
1601
transport = a_bzrdir.get_branch_transport(None, name=name)
1608
transport = controldir.get_branch_transport(None, name=name)
1602
1609
format_string = transport.get_bytes("format")
1603
1610
return format_registry.get(format_string)
1604
1611
except errors.NoSuchFile:
1605
raise errors.NotBranchError(path=transport.base, bzrdir=a_bzrdir)
1612
raise errors.NotBranchError(path=transport.base, bzrdir=controldir)
1606
1613
except KeyError:
1607
1614
raise errors.UnknownFormatError(format=format_string, kind='branch')
1623
1630
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.
1632
def get_reference(self, controldir, name=None):
1633
"""Get the target reference of the branch in controldir.
1628
1635
format probing must have been completed before calling
1629
1636
this method - it is assumed that the format of the branch
1630
in a_bzrdir is correct.
1637
in controldir is correct.
1632
:param a_bzrdir: The bzrdir to get the branch data from.
1639
:param controldir: The controldir to get the branch data from.
1633
1640
:param name: Name of the colocated branch to fetch
1634
1641
: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.
1646
def set_reference(self, controldir, name, to_branch):
1647
"""Set the target reference of the branch in controldir.
1642
1649
format probing must have been completed before calling
1643
1650
this method - it is assumed that the format of the branch
1644
in a_bzrdir is correct.
1651
in controldir is correct.
1646
:param a_bzrdir: The bzrdir to set the branch reference for.
1653
:param controldir: The controldir to set the branch reference for.
1647
1654
:param name: Name of colocated branch to set, None for default
1648
1655
:param to_branch: branch that the checkout is to reference
1657
1664
"""Return the short format description for this format."""
1658
1665
raise NotImplementedError(self.get_format_description)
1660
def _run_post_branch_init_hooks(self, a_bzrdir, name, branch):
1667
def _run_post_branch_init_hooks(self, controldir, name, branch):
1661
1668
hooks = Branch.hooks['post_branch_init']
1664
params = BranchInitHookParams(self, a_bzrdir, name, branch)
1671
params = BranchInitHookParams(self, controldir, name, branch)
1665
1672
for hook in hooks:
1668
def initialize(self, a_bzrdir, name=None, repository=None,
1675
def initialize(self, controldir, name=None, repository=None,
1669
1676
append_revisions_only=None):
1670
"""Create a branch of this format in a_bzrdir.
1677
"""Create a branch of this format in controldir.
1672
1679
:param name: Name of the colocated branch to create.
1674
1681
raise NotImplementedError(self.initialize)
1707
1714
raise NotImplementedError(self.network_name)
1709
def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False,
1716
def open(self, controldir, name=None, _found=False, ignore_fallbacks=False,
1710
1717
found_repository=None):
1711
"""Return the branch object for a_bzrdir
1718
"""Return the branch object for controldir.
1713
:param a_bzrdir: A BzrDir that contains a branch.
1720
:param controldir: A ControlDir that contains a branch.
1714
1721
:param name: Name of colocated branch to open
1715
1722
:param _found: a private parameter, do not use it. It is used to
1716
1723
indicate if format probing has already be done.
1936
1943
There are 4 fields that hooks may wish to access:
1938
1945
:ivar format: the branch format
1939
: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
1940
1947
:ivar name: name of colocated branch, if any (or None)
1941
1948
:ivar branch: the branch created
1945
1952
branch, which refer to the original branch.
1948
def __init__(self, format, a_bzrdir, name, branch):
1955
def __init__(self, format, controldir, name, branch):
1949
1956
"""Create a group of BranchInitHook parameters.
1951
1958
:param format: the branch format
1952
:param a_bzrdir: the BzrDir where the branch will be/has been
1959
:param controldir: the ControlDir where the branch will be/has been
1954
1961
:param name: name of colocated branch, if any (or None)
1955
1962
:param branch: the branch created
1976
1983
There are 4 fields that hooks may wish to access:
1978
:ivar control_dir: BzrDir of the checkout to change
1985
:ivar control_dir: ControlDir of the checkout to change
1979
1986
:ivar to_branch: branch that the checkout is to reference
1980
1987
:ivar force: skip the check for local commits in a heavy checkout
1981
1988
:ivar revision_id: revision ID to switch to (or None)
1984
1991
def __init__(self, control_dir, to_branch, force, revision_id):
1985
1992
"""Create a group of SwitchHook parameters.
1987
:param control_dir: BzrDir of the checkout to change
1994
:param control_dir: ControlDir of the checkout to change
1988
1995
:param to_branch: branch that the checkout is to reference
1989
1996
:param force: skip the check for local commits in a heavy checkout
1990
1997
:param revision_id: revision ID to switch to (or None)
2077
2084
except errors.NoSuchFile:
2078
2085
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)
2088
def _matchingbzrdir(self):
2089
ret = bzrdir.BzrDirMetaFormat1()
2090
ret.set_branch_format(self)
2085
2093
def supports_tags(self):
2248
2256
supports_reference_locations = False
2251
class BranchReferenceFormat(BranchFormat):
2259
class BranchReferenceFormat(BranchFormatMetadir):
2252
2260
"""Bzr branch reference format.
2254
2262
Branch references are used in implementing checkouts, they
2297
2305
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
2308
def _make_reference_clone_function(format, a_branch):
2306
2309
"""Create a clone() routine for a branch dynamically."""
2307
2310
def clone(to_bzrdir, revision_id=None,
2336
2339
(format, self))
2337
2340
if location is None:
2338
2341
location = self.get_reference(a_bzrdir, name)
2339
real_bzrdir = bzrdir.BzrDir.open(
2342
real_bzrdir = controldir.ControlDir.open(
2340
2343
location, possible_transports=possible_transports)
2341
2344
result = real_bzrdir.open_branch(name=name,
2342
2345
ignore_fallbacks=ignore_fallbacks)
2775
2778
if revision_id == _mod_revision.NULL_REVISION:
2776
2779
new_history = []
2778
new_history = self.revision_history()
2781
new_history = self._revision_history()
2779
2782
if revision_id is not None and new_history != []:
2781
2784
new_history = new_history[:new_history.index(revision_id) + 1]