53
from bzrlib.decorators import needs_read_lock, needs_write_lock, only_raises
55
from bzrlib.decorators import (
54
60
from bzrlib.hooks import HookPoint, Hooks
55
61
from bzrlib.inter import InterObject
56
62
from bzrlib.lock import _RelockDebugMixin, LogicalLockResult
1652
1658
def _initialize_helper(self, a_bzrdir, utf8_files, name=None,
1653
repository=None, lock_type='metadir',
1655
1660
"""Initialize a branch in a bzrdir, with specified files
1657
1662
:param a_bzrdir: The bzrdir to initialize the branch in
1658
1663
:param utf8_files: The files to create as a list of
1659
1664
(filename, content) tuples
1660
1665
:param name: Name of colocated branch to create, if any
1661
:param set_format: If True, set the format with
1662
self.get_format_string. (BzrBranch4 has its format set
1664
1666
:return: a branch in this format
1666
1668
mutter('creating branch %r in %s', self, a_bzrdir.user_url)
1667
1669
branch_transport = a_bzrdir.get_branch_transport(self, name=name)
1669
'metadir': ('lock', lockdir.LockDir),
1670
'branch4': ('branch-lock', lockable_files.TransportLock),
1672
lock_name, lock_class = lock_map[lock_type]
1673
1670
control_files = lockable_files.LockableFiles(branch_transport,
1674
lock_name, lock_class)
1671
'lock', lockdir.LockDir)
1675
1672
control_files.create_lock()
1673
control_files.lock_write()
1677
control_files.lock_write()
1678
except errors.LockContention:
1679
if lock_type != 'branch4':
1685
1675
utf8_files += [('format', self.get_format_string())]
1687
1676
for (filename, content) in utf8_files:
1688
1677
branch_transport.put_bytes(
1689
1678
filename, content,
1690
1679
mode=a_bzrdir._get_file_mode())
1693
control_files.unlock()
1681
control_files.unlock()
1694
1682
branch = self.open(a_bzrdir, name, _found=True,
1695
1683
found_repository=repository)
1696
1684
self._run_post_branch_init_hooks(a_bzrdir, name, branch)
2025
2013
self.revision_id)
2028
class BzrBranchFormat4(BranchFormat):
2029
"""Bzr branch format 4.
2032
- a revision-history file.
2033
- a branch-lock lock file [ to be shared with the bzrdir ]
2036
def get_format_description(self):
2037
"""See BranchFormat.get_format_description()."""
2038
return "Branch format 4"
2040
def initialize(self, a_bzrdir, name=None, repository=None):
2041
"""Create a branch of this format in a_bzrdir."""
2042
if repository is not None:
2043
raise NotImplementedError(
2044
"initialize(repository=<not None>) on %r" % (self,))
2045
utf8_files = [('revision-history', ''),
2046
('branch-name', ''),
2048
return self._initialize_helper(a_bzrdir, utf8_files, name=name,
2049
lock_type='branch4', set_format=False)
2052
super(BzrBranchFormat4, self).__init__()
2053
self._matchingbzrdir = bzrdir.BzrDirFormat6()
2055
def network_name(self):
2056
"""The network name for this format is the control dirs disk label."""
2057
return self._matchingbzrdir.get_format_string()
2059
def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False,
2060
found_repository=None):
2061
"""See BranchFormat.open()."""
2063
# we are being called directly and must probe.
2064
raise NotImplementedError
2065
if found_repository is None:
2066
found_repository = a_bzrdir.open_repository()
2067
return BzrBranchPreSplitOut(_format=self,
2068
_control_files=a_bzrdir._control_files,
2071
_repository=found_repository)
2074
return "Bazaar-NG branch format 4"
2076
def supports_leaving_lock(self):
2080
2016
class BranchFormatMetadir(BranchFormat):
2081
2017
"""Common logic for meta-dir based branch formats."""
2404
2340
# formats which have no format string are not discoverable
2405
2341
# and not independently creatable, so are not registered.
2406
__format4 = BzrBranchFormat4()
2407
2342
__format5 = BzrBranchFormat5()
2408
2343
__format6 = BzrBranchFormat6()
2409
2344
__format7 = BzrBranchFormat7()
2414
2349
format_registry.register(__format7)
2415
2350
format_registry.register(__format8)
2416
2351
format_registry.set_default(__format7)
2417
format_registry.register_extra(__format4)
2418
network_format_registry.register(__format4.network_name(), __format4)
2352
format_registry.register_extra_lazy("bzrlib.branch_weave",
2354
network_format_registry.register_lazy("Bazaar-NG branch, format 6\n",
2355
"bzrlib.branch_weave", "BzrBranchFormat4")
2421
2358
class BranchWriteLockResult(LogicalLockResult):
2726
2663
mode=self.bzrdir._get_file_mode())
2729
class BzrBranchPreSplitOut(BzrBranch):
2731
def _get_checkout_format(self):
2732
"""Return the most suitable metadir for a checkout of this branch.
2733
Weaves are used if this branch's repository uses weaves.
2735
from bzrlib.repofmt.weaverepo import RepositoryFormat7
2736
from bzrlib.bzrdir import BzrDirMetaFormat1
2737
format = BzrDirMetaFormat1()
2738
format.repository_format = RepositoryFormat7()
2742
2666
class BzrBranch5(BzrBranch):
2743
2667
"""A format 5 branch. This supports new features over plain branches.