170
170
return control.open_branch(unsupported=_unsupported)
173
def open_from_transport(transport, _unsupported=False):
173
def open_from_transport(transport, name=None, _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(unsupported=_unsupported)
176
return control.open_branch(name=name, 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_bzrdir = bzrdir.BzrDir.open(url,
220
a_branch = Branch.open(url,
221
221
possible_transports=[self.bzrdir.root_transport])
222
return a_bzrdir.open_branch().repository
222
return a_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, self)
1320
from_branch = BranchReferenceFormat().initialize(checkout,
1322
1323
format = self._get_checkout_format()
1323
1324
checkout_branch = bzrdir.BzrDir.create_branch_convenience(
1434
1435
return not (self == other)
1437
def find_format(klass, a_bzrdir):
1438
def find_format(klass, a_bzrdir, name=None):
1438
1439
"""Return the format for the branch object in a_bzrdir."""
1440
transport = a_bzrdir.get_branch_transport(None)
1441
transport = a_bzrdir.get_branch_transport(None, name=name)
1441
1442
format_string = transport.get_bytes("format")
1442
1443
return klass._formats[format_string]
1443
1444
except errors.NoSuchFile:
1483
1484
"""Return the short format description for this format."""
1484
1485
raise NotImplementedError(self.get_format_description)
1486
def _initialize_helper(self, a_bzrdir, utf8_files, lock_type='metadir',
1487
def _initialize_helper(self, a_bzrdir, utf8_files, name=None,
1488
lock_type='metadir', set_format=True):
1488
1489
"""Initialize a branch in a bzrdir, with specified files
1490
1491
:param a_bzrdir: The bzrdir to initialize the branch in
1491
1492
:param utf8_files: The files to create as a list of
1492
1493
(filename, content) tuples
1494
:param name: Name of colocated branch to create, if any
1493
1495
:param set_format: If True, set the format with
1494
1496
self.get_format_string. (BzrBranch4 has its format set
1496
1498
:return: a branch in this format
1498
1500
mutter('creating branch %r in %s', self, a_bzrdir.transport.base)
1499
branch_transport = a_bzrdir.get_branch_transport(self)
1501
branch_transport = a_bzrdir.get_branch_transport(self, name=name)
1501
1503
'metadir': ('lock', lockdir.LockDir),
1502
1504
'branch4': ('branch-lock', lockable_files.TransportLock),
1525
1527
control_files.unlock()
1526
return self.open(a_bzrdir, _found=True)
1528
return self.open(a_bzrdir, name, _found=True)
1528
def initialize(self, a_bzrdir):
1529
"""Create a branch of this format in a_bzrdir."""
1530
def initialize(self, a_bzrdir, name=None):
1531
"""Create a branch of this format in a_bzrdir.
1533
:param name: Name of the colocated branch to create.
1530
1535
raise NotImplementedError(self.initialize)
1532
1537
def is_supported(self):
1563
1568
raise NotImplementedError(self.network_name)
1565
def open(self, a_bzrdir, _found=False, ignore_fallbacks=False):
1570
def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False):
1566
1571
"""Return the branch object for a_bzrdir
1568
1573
:param a_bzrdir: A BzrDir that contains a branch.
1574
:param name: Name of colocated branch to open
1569
1575
:param _found: a private parameter, do not use it. It is used to
1570
1576
indicate if format probing has already be done.
1571
1577
:param ignore_fallbacks: when set, no fallback branches will be opened
1735
1741
"""See BranchFormat.get_format_description()."""
1736
1742
return "Branch format 4"
1738
def initialize(self, a_bzrdir):
1744
def initialize(self, a_bzrdir, name=None):
1739
1745
"""Create a branch of this format in a_bzrdir."""
1740
1746
utf8_files = [('revision-history', ''),
1741
1747
('branch-name', ''),
1743
return self._initialize_helper(a_bzrdir, utf8_files,
1749
return self._initialize_helper(a_bzrdir, utf8_files, name=name,
1744
1750
lock_type='branch4', set_format=False)
1746
1752
def __init__(self):
1751
1757
"""The network name for this format is the control dirs disk label."""
1752
1758
return self._matchingbzrdir.get_format_string()
1754
def open(self, a_bzrdir, _found=False, ignore_fallbacks=False):
1760
def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False):
1755
1761
"""See BranchFormat.open()."""
1762
if name is not None:
1763
raise errors.NoColocatedBranchSupport(a_bzrdir)
1757
1765
# we are being called directly and must probe.
1758
1766
raise NotImplementedError
1780
1788
return self.get_format_string()
1782
def open(self, a_bzrdir, _found=False, ignore_fallbacks=False):
1790
def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False):
1783
1791
"""See BranchFormat.open()."""
1785
format = BranchFormat.find_format(a_bzrdir)
1793
format = BranchFormat.find_format(a_bzrdir, name=name)
1786
1794
if format.__class__ != self.__class__:
1787
1795
raise AssertionError("wrong format %r found for %r" %
1788
1796
(format, self))
1790
transport = a_bzrdir.get_branch_transport(None)
1798
transport = a_bzrdir.get_branch_transport(None, name=name)
1791
1799
control_files = lockable_files.LockableFiles(transport, 'lock',
1792
1800
lockdir.LockDir)
1793
1801
return self._branch_class()(_format=self,
1831
1839
"""See BranchFormat.get_format_description()."""
1832
1840
return "Branch format 5"
1834
def initialize(self, a_bzrdir):
1842
def initialize(self, a_bzrdir, name=None):
1835
1843
"""Create a branch of this format in a_bzrdir."""
1836
1844
utf8_files = [('revision-history', ''),
1837
1845
('branch-name', ''),
1839
return self._initialize_helper(a_bzrdir, utf8_files)
1847
return self._initialize_helper(a_bzrdir, utf8_files, name)
1841
1849
def supports_tags(self):
1864
1872
"""See BranchFormat.get_format_description()."""
1865
1873
return "Branch format 6"
1867
def initialize(self, a_bzrdir):
1875
def initialize(self, a_bzrdir, name=None):
1868
1876
"""Create a branch of this format in a_bzrdir."""
1869
1877
utf8_files = [('last-revision', '0 null:\n'),
1870
1878
('branch.conf', ''),
1873
return self._initialize_helper(a_bzrdir, utf8_files)
1881
return self._initialize_helper(a_bzrdir, utf8_files, name)
1875
1883
def make_tags(self, branch):
1876
1884
"""See bzrlib.branch.BranchFormat.make_tags()."""
1894
1902
"""See BranchFormat.get_format_description()."""
1895
1903
return "Branch format 8"
1897
def initialize(self, a_bzrdir):
1905
def initialize(self, a_bzrdir, name=None):
1898
1906
"""Create a branch of this format in a_bzrdir."""
1899
1907
utf8_files = [('last-revision', '0 null:\n'),
1900
1908
('branch.conf', ''),
1902
1910
('references', '')
1904
return self._initialize_helper(a_bzrdir, utf8_files)
1912
return self._initialize_helper(a_bzrdir, utf8_files, name)
1906
1914
def __init__(self):
1907
1915
super(BzrBranchFormat8, self).__init__()
1930
1938
This format was introduced in bzr 1.6.
1933
def initialize(self, a_bzrdir):
1941
def initialize(self, a_bzrdir, name=None):
1934
1942
"""Create a branch of this format in a_bzrdir."""
1935
1943
utf8_files = [('last-revision', '0 null:\n'),
1936
1944
('branch.conf', ''),
1939
return self._initialize_helper(a_bzrdir, utf8_files)
1947
return self._initialize_helper(a_bzrdir, utf8_files, name)
1941
1949
def _branch_class(self):
1942
1950
return BzrBranch7
1984
1992
transport = a_bzrdir.get_branch_transport(None)
1985
1993
location = transport.put_bytes('location', to_branch.base)
1987
def initialize(self, a_bzrdir, target_branch=None):
1995
def initialize(self, a_bzrdir, name=None, target_branch=None):
1988
1996
"""Create a branch of this format in a_bzrdir."""
1989
1997
if target_branch is None:
1990
1998
# this format does not implement branch itself, thus the implicit
1991
1999
# creation contract must see it as uninitializable
1992
2000
raise errors.UninitializableFormat(self)
1993
2001
mutter('creating branch reference in %s', a_bzrdir.transport.base)
1994
branch_transport = a_bzrdir.get_branch_transport(self)
2002
branch_transport = a_bzrdir.get_branch_transport(self, name=name)
1995
2003
branch_transport.put_bytes('location',
1996
2004
target_branch.bzrdir.root_transport.base)
1997
2005
branch_transport.put_bytes('format', self.get_format_string())
1998
2006
return self.open(
1999
a_bzrdir, _found=True,
2007
a_bzrdir, name, _found=True,
2000
2008
possible_transports=[target_branch.bzrdir.root_transport])
2002
2010
def __init__(self):
2009
2017
def clone(to_bzrdir, revision_id=None,
2010
2018
repository_policy=None):
2011
2019
"""See Branch.clone()."""
2012
return format.initialize(to_bzrdir, a_branch)
2020
return format.initialize(to_bzrdir, target_branch=a_branch)
2013
2021
# cannot obey revision_id limits when cloning a reference ...
2014
2022
# FIXME RBC 20060210 either nuke revision_id for clone, or
2015
2023
# emit some sort of warning/error to the caller ?!
2018
def open(self, a_bzrdir, _found=False, location=None,
2026
def open(self, a_bzrdir, name=None, _found=False, location=None,
2019
2027
possible_transports=None, ignore_fallbacks=False):
2020
2028
"""Return the branch that the branch reference in a_bzrdir points at.
2022
2030
:param a_bzrdir: A BzrDir that contains a branch.
2031
:param name: Name of colocated branch to open, if any
2023
2032
:param _found: a private parameter, do not use it. It is used to
2024
2033
indicate if format probing has already be done.
2025
2034
:param ignore_fallbacks: when set, no fallback branches will be opened
2030
2039
:param possible_transports: An optional reusable transports list.
2033
format = BranchFormat.find_format(a_bzrdir)
2042
format = BranchFormat.find_format(a_bzrdir, name=name)
2034
2043
if format.__class__ != self.__class__:
2035
2044
raise AssertionError("wrong format %r found for %r" %
2036
2045
(format, self))
2038
2047
location = self.get_reference(a_bzrdir)
2039
2048
real_bzrdir = bzrdir.BzrDir.open(
2040
2049
location, possible_transports=possible_transports)
2041
result = real_bzrdir.open_branch(ignore_fallbacks=ignore_fallbacks)
2050
result = real_bzrdir.open_branch(name=name,
2051
ignore_fallbacks=ignore_fallbacks)
2042
2052
# this changes the behaviour of result.clone to create a new reference
2043
2053
# rather than a copy of the content of the branch.
2044
2054
# I did not use a proxy object because that needs much more extensive