170
170
return control.open_branch(unsupported=_unsupported)
173
def open_from_transport(transport, name=None, _unsupported=False):
173
def open_from_transport(transport, _unsupported=False):
174
174
"""Open the branch rooted at transport"""
175
175
control = bzrdir.BzrDir.open_from_transport(transport, _unsupported)
176
return control.open_branch(name=name, unsupported=_unsupported)
176
return control.open_branch(unsupported=_unsupported)
179
179
def open_containing(url, possible_transports=None):
217
217
def _get_fallback_repository(self, url):
218
218
"""Get the repository we fallback to at url."""
219
219
url = urlutils.join(self.base, url)
220
a_branch = Branch.open(url,
220
a_bzrdir = bzrdir.BzrDir.open(url,
221
221
possible_transports=[self.bzrdir.root_transport])
222
return a_branch.repository
222
return a_bzrdir.open_branch().repository
224
224
def _get_tags_bytes(self):
225
225
"""Get the bytes of a serialised tags dict.
1317
1317
if lightweight:
1318
1318
format = self._get_checkout_format()
1319
1319
checkout = format.initialize_on_transport(t)
1320
from_branch = BranchReferenceFormat().initialize(checkout,
1320
from_branch = BranchReferenceFormat().initialize(checkout, self)
1323
1322
format = self._get_checkout_format()
1324
1323
checkout_branch = bzrdir.BzrDir.create_branch_convenience(
1366
1365
def supports_tags(self):
1367
1366
return self._format.supports_tags()
1369
def automatic_tag_name(self, revision_id):
1370
"""Try to automatically find the tag name for a revision.
1372
:param revision_id: Revision id of the revision.
1373
:return: A tag name or None if no tag name could be determined.
1375
for hook in Branch.hooks['automatic_tag_name']:
1376
ret = hook(self, revision_id)
1381
1368
def _check_if_descendant_or_diverged(self, revision_a, revision_b, graph,
1383
1370
"""Ensure that revision_b is a descendant of revision_a.
1447
1434
return not (self == other)
1450
def find_format(klass, a_bzrdir, name=None):
1437
def find_format(klass, a_bzrdir):
1451
1438
"""Return the format for the branch object in a_bzrdir."""
1453
transport = a_bzrdir.get_branch_transport(None, name=name)
1440
transport = a_bzrdir.get_branch_transport(None)
1454
1441
format_string = transport.get_bytes("format")
1455
1442
return klass._formats[format_string]
1456
1443
except errors.NoSuchFile:
1496
1483
"""Return the short format description for this format."""
1497
1484
raise NotImplementedError(self.get_format_description)
1499
def _initialize_helper(self, a_bzrdir, utf8_files, name=None,
1500
lock_type='metadir', set_format=True):
1486
def _initialize_helper(self, a_bzrdir, utf8_files, lock_type='metadir',
1501
1488
"""Initialize a branch in a bzrdir, with specified files
1503
1490
:param a_bzrdir: The bzrdir to initialize the branch in
1504
1491
:param utf8_files: The files to create as a list of
1505
1492
(filename, content) tuples
1506
:param name: Name of colocated branch to create, if any
1507
1493
:param set_format: If True, set the format with
1508
1494
self.get_format_string. (BzrBranch4 has its format set
1510
1496
:return: a branch in this format
1512
1498
mutter('creating branch %r in %s', self, a_bzrdir.transport.base)
1513
branch_transport = a_bzrdir.get_branch_transport(self, name=name)
1499
branch_transport = a_bzrdir.get_branch_transport(self)
1515
1501
'metadir': ('lock', lockdir.LockDir),
1516
1502
'branch4': ('branch-lock', lockable_files.TransportLock),
1539
1525
control_files.unlock()
1540
return self.open(a_bzrdir, name, _found=True)
1526
return self.open(a_bzrdir, _found=True)
1542
def initialize(self, a_bzrdir, name=None):
1543
"""Create a branch of this format in a_bzrdir.
1545
:param name: Name of the colocated branch to create.
1528
def initialize(self, a_bzrdir):
1529
"""Create a branch of this format in a_bzrdir."""
1547
1530
raise NotImplementedError(self.initialize)
1549
1532
def is_supported(self):
1580
1563
raise NotImplementedError(self.network_name)
1582
def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False):
1565
def open(self, a_bzrdir, _found=False, ignore_fallbacks=False):
1583
1566
"""Return the branch object for a_bzrdir
1585
1568
:param a_bzrdir: A BzrDir that contains a branch.
1586
:param name: Name of colocated branch to open
1587
1569
:param _found: a private parameter, do not use it. It is used to
1588
1570
indicate if format probing has already be done.
1589
1571
:param ignore_fallbacks: when set, no fallback branches will be opened
1697
1679
"multiple hooks installed for transform_fallback_location, "
1698
1680
"all are called with the url returned from the previous hook."
1699
1681
"The order is however undefined.", (1, 9), None))
1700
self.create_hook(HookPoint('automatic_tag_name',
1701
"Called to determine an automatic tag name for a revision."
1702
"automatic_tag_name is called with (branch, revision_id) and "
1703
"should return a tag name or None if no tag name could be "
1704
"determined. The first non-None tag name returned will be used.",
1709
1684
# install the default hooks into the Branch class.
1760
1735
"""See BranchFormat.get_format_description()."""
1761
1736
return "Branch format 4"
1763
def initialize(self, a_bzrdir, name=None):
1738
def initialize(self, a_bzrdir):
1764
1739
"""Create a branch of this format in a_bzrdir."""
1765
1740
utf8_files = [('revision-history', ''),
1766
1741
('branch-name', ''),
1768
return self._initialize_helper(a_bzrdir, utf8_files, name=name,
1743
return self._initialize_helper(a_bzrdir, utf8_files,
1769
1744
lock_type='branch4', set_format=False)
1771
1746
def __init__(self):
1776
1751
"""The network name for this format is the control dirs disk label."""
1777
1752
return self._matchingbzrdir.get_format_string()
1779
def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False):
1754
def open(self, a_bzrdir, _found=False, ignore_fallbacks=False):
1780
1755
"""See BranchFormat.open()."""
1782
1757
# we are being called directly and must probe.
1806
1780
return self.get_format_string()
1808
def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False):
1782
def open(self, a_bzrdir, _found=False, ignore_fallbacks=False):
1809
1783
"""See BranchFormat.open()."""
1811
format = BranchFormat.find_format(a_bzrdir, name=name)
1785
format = BranchFormat.find_format(a_bzrdir)
1812
1786
if format.__class__ != self.__class__:
1813
1787
raise AssertionError("wrong format %r found for %r" %
1814
1788
(format, self))
1816
transport = a_bzrdir.get_branch_transport(None, name=name)
1790
transport = a_bzrdir.get_branch_transport(None)
1817
1791
control_files = lockable_files.LockableFiles(transport, 'lock',
1818
1792
lockdir.LockDir)
1819
1793
return self._branch_class()(_format=self,
1820
1794
_control_files=control_files,
1822
1795
a_bzrdir=a_bzrdir,
1823
1796
_repository=a_bzrdir.find_repository(),
1824
1797
ignore_fallbacks=ignore_fallbacks)
1858
1831
"""See BranchFormat.get_format_description()."""
1859
1832
return "Branch format 5"
1861
def initialize(self, a_bzrdir, name=None):
1834
def initialize(self, a_bzrdir):
1862
1835
"""Create a branch of this format in a_bzrdir."""
1863
1836
utf8_files = [('revision-history', ''),
1864
1837
('branch-name', ''),
1866
return self._initialize_helper(a_bzrdir, utf8_files, name)
1839
return self._initialize_helper(a_bzrdir, utf8_files)
1868
1841
def supports_tags(self):
1891
1864
"""See BranchFormat.get_format_description()."""
1892
1865
return "Branch format 6"
1894
def initialize(self, a_bzrdir, name=None):
1867
def initialize(self, a_bzrdir):
1895
1868
"""Create a branch of this format in a_bzrdir."""
1896
1869
utf8_files = [('last-revision', '0 null:\n'),
1897
1870
('branch.conf', ''),
1900
return self._initialize_helper(a_bzrdir, utf8_files, name)
1873
return self._initialize_helper(a_bzrdir, utf8_files)
1902
1875
def make_tags(self, branch):
1903
1876
"""See bzrlib.branch.BranchFormat.make_tags()."""
1921
1894
"""See BranchFormat.get_format_description()."""
1922
1895
return "Branch format 8"
1924
def initialize(self, a_bzrdir, name=None):
1897
def initialize(self, a_bzrdir):
1925
1898
"""Create a branch of this format in a_bzrdir."""
1926
1899
utf8_files = [('last-revision', '0 null:\n'),
1927
1900
('branch.conf', ''),
1929
1902
('references', '')
1931
return self._initialize_helper(a_bzrdir, utf8_files, name)
1904
return self._initialize_helper(a_bzrdir, utf8_files)
1933
1906
def __init__(self):
1934
1907
super(BzrBranchFormat8, self).__init__()
1957
1930
This format was introduced in bzr 1.6.
1960
def initialize(self, a_bzrdir, name=None):
1933
def initialize(self, a_bzrdir):
1961
1934
"""Create a branch of this format in a_bzrdir."""
1962
1935
utf8_files = [('last-revision', '0 null:\n'),
1963
1936
('branch.conf', ''),
1966
return self._initialize_helper(a_bzrdir, utf8_files, name)
1939
return self._initialize_helper(a_bzrdir, utf8_files)
1968
1941
def _branch_class(self):
1969
1942
return BzrBranch7
2011
1984
transport = a_bzrdir.get_branch_transport(None)
2012
1985
location = transport.put_bytes('location', to_branch.base)
2014
def initialize(self, a_bzrdir, name=None, target_branch=None):
1987
def initialize(self, a_bzrdir, target_branch=None):
2015
1988
"""Create a branch of this format in a_bzrdir."""
2016
1989
if target_branch is None:
2017
1990
# this format does not implement branch itself, thus the implicit
2018
1991
# creation contract must see it as uninitializable
2019
1992
raise errors.UninitializableFormat(self)
2020
1993
mutter('creating branch reference in %s', a_bzrdir.transport.base)
2021
branch_transport = a_bzrdir.get_branch_transport(self, name=name)
1994
branch_transport = a_bzrdir.get_branch_transport(self)
2022
1995
branch_transport.put_bytes('location',
2023
1996
target_branch.bzrdir.root_transport.base)
2024
1997
branch_transport.put_bytes('format', self.get_format_string())
2025
1998
return self.open(
2026
a_bzrdir, name, _found=True,
1999
a_bzrdir, _found=True,
2027
2000
possible_transports=[target_branch.bzrdir.root_transport])
2029
2002
def __init__(self):
2036
2009
def clone(to_bzrdir, revision_id=None,
2037
2010
repository_policy=None):
2038
2011
"""See Branch.clone()."""
2039
return format.initialize(to_bzrdir, target_branch=a_branch)
2012
return format.initialize(to_bzrdir, a_branch)
2040
2013
# cannot obey revision_id limits when cloning a reference ...
2041
2014
# FIXME RBC 20060210 either nuke revision_id for clone, or
2042
2015
# emit some sort of warning/error to the caller ?!
2045
def open(self, a_bzrdir, name=None, _found=False, location=None,
2018
def open(self, a_bzrdir, _found=False, location=None,
2046
2019
possible_transports=None, ignore_fallbacks=False):
2047
2020
"""Return the branch that the branch reference in a_bzrdir points at.
2049
2022
:param a_bzrdir: A BzrDir that contains a branch.
2050
:param name: Name of colocated branch to open, if any
2051
2023
:param _found: a private parameter, do not use it. It is used to
2052
2024
indicate if format probing has already be done.
2053
2025
:param ignore_fallbacks: when set, no fallback branches will be opened
2058
2030
:param possible_transports: An optional reusable transports list.
2061
format = BranchFormat.find_format(a_bzrdir, name=name)
2033
format = BranchFormat.find_format(a_bzrdir)
2062
2034
if format.__class__ != self.__class__:
2063
2035
raise AssertionError("wrong format %r found for %r" %
2064
2036
(format, self))
2066
2038
location = self.get_reference(a_bzrdir)
2067
2039
real_bzrdir = bzrdir.BzrDir.open(
2068
2040
location, possible_transports=possible_transports)
2069
result = real_bzrdir.open_branch(name=name,
2070
ignore_fallbacks=ignore_fallbacks)
2041
result = real_bzrdir.open_branch(ignore_fallbacks=ignore_fallbacks)
2071
2042
# this changes the behaviour of result.clone to create a new reference
2072
2043
# rather than a copy of the content of the branch.
2073
2044
# I did not use a proxy object because that needs much more extensive
2119
2090
:ivar repository: Repository for this branch.
2120
2091
:ivar base: The url of the base directory for this branch; the one
2121
2092
containing the .bzr directory.
2122
:ivar name: Optional colocated branch name as it exists in the control
2126
2095
def __init__(self, _format=None,
2127
_control_files=None, a_bzrdir=None, name=None,
2128
_repository=None, ignore_fallbacks=False):
2096
_control_files=None, a_bzrdir=None, _repository=None,
2097
ignore_fallbacks=False):
2129
2098
"""Create new branch object at a particular location."""
2130
2099
if a_bzrdir is None:
2131
2100
raise ValueError('a_bzrdir must be supplied')
2133
2102
self.bzrdir = a_bzrdir
2134
2103
self._base = self.bzrdir.transport.clone('..').base
2136
2104
# XXX: We should be able to just do
2137
2105
# self.base = self.bzrdir.root_transport.base
2138
2106
# but this does not quite work yet -- mbp 20080522
2145
2113
Branch.__init__(self)
2147
2115
def __str__(self):
2148
if self.name is None:
2149
return '%s(%r)' % (self.__class__.__name__, self.base)
2151
return '%s(%r,%r)' % (self.__class__.__name__, self.base, self.name)
2116
return '%s(%r)' % (self.__class__.__name__, self.base)
2153
2118
__repr__ = __str__