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
19
18
from cStringIO import StringIO
22
21
lazy_import(globals(), """
24
23
from bzrlib import (
29
config as _mod_config,
38
revision as _mod_revision,
27
config as _mod_config,
36
revision as _mod_revision,
45
43
from bzrlib.i18n import gettext, ngettext
109
107
for existing_fallback_repo in self.repository._fallback_repositories:
110
108
if existing_fallback_repo.user_url == url:
111
109
# This fallback is already configured. This probably only
112
# happens because ControlDir.sprout is a horrible mess. To avoid
110
# happens because BzrDir.sprout is a horrible mess. To avoid
113
111
# confusing _unstack we don't add this a second time.
114
112
mutter('duplicate activation of fallback %r on %r', url, self)
173
171
For instance, if the branch is at URL/.bzr/branch,
174
172
Branch.open(URL) -> a Branch instance.
176
control = controldir.ControlDir.open(base, _unsupported,
174
control = bzrdir.BzrDir.open(base, _unsupported,
177
175
possible_transports=possible_transports)
178
176
return control.open_branch(unsupported=_unsupported)
181
179
def open_from_transport(transport, name=None, _unsupported=False):
182
180
"""Open the branch rooted at transport"""
183
control = controldir.ControlDir.open_from_transport(transport, _unsupported)
181
control = bzrdir.BzrDir.open_from_transport(transport, _unsupported)
184
182
return control.open_branch(name=name, unsupported=_unsupported)
195
193
format, UnknownFormatError or UnsupportedFormatError are raised.
196
194
If there is one, it is returned, along with the unused portion of url.
198
control, relpath = controldir.ControlDir.open_containing(url,
196
control, relpath = bzrdir.BzrDir.open_containing(url,
199
197
possible_transports)
200
198
return control.open_branch(), relpath
883
881
# stream from one of them to the other. This does mean doing
884
882
# separate SSH connection setup, but unstacking is not a
885
883
# common operation so it's tolerable.
886
new_bzrdir = controldir.ControlDir.open(
887
self.bzrdir.root_transport.base)
884
new_bzrdir = bzrdir.BzrDir.open(self.bzrdir.root_transport.base)
888
885
new_repository = new_bzrdir.find_repository()
889
886
if new_repository._fallback_repositories:
890
887
raise AssertionError("didn't expect %r to have "
1008
1005
raise NotImplementedError(self._gen_revision_history)
1010
@deprecated_method(deprecated_in((2, 5, 0)))
1011
1007
@needs_read_lock
1012
1008
def revision_history(self):
1013
1009
"""Return sequence of revision ids on this branch.
1015
1011
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):
1021
1014
if 'evil' in debug.debug_flags:
1022
1015
mutter_callsite(3, "revision_history scales with history.")
1023
1016
if self._revision_history_cache is not None:
1093
1086
"""Given a revision id, return its revno"""
1094
1087
if _mod_revision.is_null(revision_id):
1096
history = self._revision_history()
1089
history = self.revision_history()
1098
1091
return history.index(revision_id) + 1
1099
1092
except ValueError:
1396
1389
# TODO: We should probably also check that self.revision_history
1397
1390
# matches the repository for older branch formats.
1398
1391
# If looking for the code that cross-checks repository parents against
1399
# the Graph.iter_lefthand_ancestry output, that is now a repository
1392
# the iter_reverse_revision_history output, that is now a repository
1400
1393
# specific check.
1458
1451
from_branch = BranchReferenceFormat().initialize(checkout,
1459
1452
target_branch=self)
1461
checkout_branch = controldir.ControlDir.create_branch_convenience(
1454
checkout_branch = bzrdir.BzrDir.create_branch_convenience(
1462
1455
to_location, force_new_tree=False, format=format)
1463
1456
checkout = checkout_branch.bzrdir
1464
1457
checkout_branch.bind(self)
1602
1595
return not (self == other)
1605
def find_format(klass, controldir, name=None):
1606
"""Return the format for the branch object in controldir."""
1598
def find_format(klass, a_bzrdir, name=None):
1599
"""Return the format for the branch object in a_bzrdir."""
1608
transport = controldir.get_branch_transport(None, name=name)
1601
transport = a_bzrdir.get_branch_transport(None, name=name)
1609
1602
format_string = transport.get_bytes("format")
1610
1603
return format_registry.get(format_string)
1611
1604
except errors.NoSuchFile:
1612
raise errors.NotBranchError(path=transport.base, bzrdir=controldir)
1605
raise errors.NotBranchError(path=transport.base, bzrdir=a_bzrdir)
1613
1606
except KeyError:
1614
1607
raise errors.UnknownFormatError(format=format_string, kind='branch')
1630
1623
return format_registry._get_all()
1632
def get_reference(self, controldir, name=None):
1633
"""Get the target reference of the branch in controldir.
1625
def get_reference(self, a_bzrdir, name=None):
1626
"""Get the target reference of the branch in a_bzrdir.
1635
1628
format probing must have been completed before calling
1636
1629
this method - it is assumed that the format of the branch
1637
in controldir is correct.
1630
in a_bzrdir is correct.
1639
:param controldir: The controldir to get the branch data from.
1632
:param a_bzrdir: The bzrdir to get the branch data from.
1640
1633
:param name: Name of the colocated branch to fetch
1641
1634
:return: None if the branch is not a reference branch.
1646
def set_reference(self, controldir, name, to_branch):
1647
"""Set the target reference of the branch in controldir.
1639
def set_reference(self, a_bzrdir, name, to_branch):
1640
"""Set the target reference of the branch in a_bzrdir.
1649
1642
format probing must have been completed before calling
1650
1643
this method - it is assumed that the format of the branch
1651
in controldir is correct.
1644
in a_bzrdir is correct.
1653
:param controldir: The controldir to set the branch reference for.
1646
:param a_bzrdir: The bzrdir to set the branch reference for.
1654
1647
:param name: Name of colocated branch to set, None for default
1655
1648
:param to_branch: branch that the checkout is to reference
1664
1657
"""Return the short format description for this format."""
1665
1658
raise NotImplementedError(self.get_format_description)
1667
def _run_post_branch_init_hooks(self, controldir, name, branch):
1660
def _run_post_branch_init_hooks(self, a_bzrdir, name, branch):
1668
1661
hooks = Branch.hooks['post_branch_init']
1671
params = BranchInitHookParams(self, controldir, name, branch)
1664
params = BranchInitHookParams(self, a_bzrdir, name, branch)
1672
1665
for hook in hooks:
1675
def initialize(self, controldir, name=None, repository=None,
1668
def initialize(self, a_bzrdir, name=None, repository=None,
1676
1669
append_revisions_only=None):
1677
"""Create a branch of this format in controldir.
1670
"""Create a branch of this format in a_bzrdir.
1679
1672
:param name: Name of the colocated branch to create.
1681
1674
raise NotImplementedError(self.initialize)
1714
1707
raise NotImplementedError(self.network_name)
1716
def open(self, controldir, name=None, _found=False, ignore_fallbacks=False,
1709
def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False,
1717
1710
found_repository=None):
1718
"""Return the branch object for controldir.
1711
"""Return the branch object for a_bzrdir
1720
:param controldir: A ControlDir that contains a branch.
1713
:param a_bzrdir: A BzrDir that contains a branch.
1721
1714
:param name: Name of colocated branch to open
1722
1715
:param _found: a private parameter, do not use it. It is used to
1723
1716
indicate if format probing has already be done.
1943
1936
There are 4 fields that hooks may wish to access:
1945
1938
:ivar format: the branch format
1946
:ivar bzrdir: the ControlDir where the branch will be/has been initialized
1939
:ivar bzrdir: the BzrDir where the branch will be/has been initialized
1947
1940
:ivar name: name of colocated branch, if any (or None)
1948
1941
:ivar branch: the branch created
1952
1945
branch, which refer to the original branch.
1955
def __init__(self, format, controldir, name, branch):
1948
def __init__(self, format, a_bzrdir, name, branch):
1956
1949
"""Create a group of BranchInitHook parameters.
1958
1951
:param format: the branch format
1959
:param controldir: the ControlDir where the branch will be/has been
1952
:param a_bzrdir: the BzrDir where the branch will be/has been
1961
1954
:param name: name of colocated branch, if any (or None)
1962
1955
:param branch: the branch created
1983
1976
There are 4 fields that hooks may wish to access:
1985
:ivar control_dir: ControlDir of the checkout to change
1978
:ivar control_dir: BzrDir of the checkout to change
1986
1979
:ivar to_branch: branch that the checkout is to reference
1987
1980
:ivar force: skip the check for local commits in a heavy checkout
1988
1981
:ivar revision_id: revision ID to switch to (or None)
1991
1984
def __init__(self, control_dir, to_branch, force, revision_id):
1992
1985
"""Create a group of SwitchHook parameters.
1994
:param control_dir: ControlDir of the checkout to change
1987
:param control_dir: BzrDir of the checkout to change
1995
1988
:param to_branch: branch that the checkout is to reference
1996
1989
:param force: skip the check for local commits in a heavy checkout
1997
1990
:param revision_id: revision ID to switch to (or None)
2084
2077
except errors.NoSuchFile:
2085
2078
raise errors.NotBranchError(path=transport.base, bzrdir=a_bzrdir)
2088
def _matchingbzrdir(self):
2089
ret = bzrdir.BzrDirMetaFormat1()
2090
ret.set_branch_format(self)
2081
super(BranchFormatMetadir, self).__init__()
2082
self._matchingbzrdir = bzrdir.BzrDirMetaFormat1()
2083
self._matchingbzrdir.set_branch_format(self)
2093
2085
def supports_tags(self):
2256
2248
supports_reference_locations = False
2259
class BranchReferenceFormat(BranchFormatMetadir):
2251
class BranchReferenceFormat(BranchFormat):
2260
2252
"""Bzr branch reference format.
2262
2254
Branch references are used in implementing checkouts, they
2305
2297
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)
2308
2305
def _make_reference_clone_function(format, a_branch):
2309
2306
"""Create a clone() routine for a branch dynamically."""
2310
2307
def clone(to_bzrdir, revision_id=None,
2339
2336
(format, self))
2340
2337
if location is None:
2341
2338
location = self.get_reference(a_bzrdir, name)
2342
real_bzrdir = controldir.ControlDir.open(
2339
real_bzrdir = bzrdir.BzrDir.open(
2343
2340
location, possible_transports=possible_transports)
2344
2341
result = real_bzrdir.open_branch(name=name,
2345
2342
ignore_fallbacks=ignore_fallbacks)
2778
2775
if revision_id == _mod_revision.NULL_REVISION:
2779
2776
new_history = []
2781
new_history = self._revision_history()
2778
new_history = self.revision_history()
2782
2779
if revision_id is not None and new_history != []:
2784
2781
new_history = new_history[:new_history.index(revision_id) + 1]