1496
1496
"""Return the short format description for this format."""
1497
1497
raise NotImplementedError(self.get_format_description)
1499
def _run_post_branch_hooks(self, a_bzrdir, name, branch):
1500
hooks = Branch.hooks['post_branch']
1503
params = BranchHookParams(self, a_bzrdir, name, branch)
1499
1507
def _initialize_helper(self, a_bzrdir, utf8_files, name=None,
1500
1508
lock_type='metadir', set_format=True):
1501
1509
"""Initialize a branch in a bzrdir, with specified files
1539
1547
control_files.unlock()
1540
return self.open(a_bzrdir, name, _found=True)
1548
branch = self.open(a_bzrdir, name, _found=True)
1549
if Branch.hooks['post_branch']:
1550
self._run_post_branch_hooks(a_bzrdir, name, branch)
1542
1553
def initialize(self, a_bzrdir, name=None):
1543
1554
"""Create a branch of this format in a_bzrdir.
1703
1714
"should return a tag name or None if no tag name could be "
1704
1715
"determined. The first non-None tag name returned will be used.",
1717
self.create_hook(HookPoint('post_branch',
1718
"Called after new branch initialization completes. "
1719
"post_branch is called with a bzrlib.branch.BranchHookParams. "
1720
"Note that init, branch and checkout will trigger this hook.",
1722
self.create_hook(HookPoint('post_switch',
1723
"Called after a checkout switches branch. "
1724
"post_switch is called with a "
1725
"bzrlib.branch.SwitchHookParams.", (2, 2), None))
1747
1767
self.__class__.__name__, self.branch,
1748
1768
self.old_revno, self.old_revid, self.new_revno, self.new_revid)
1770
class BranchHookParams(object):
1771
"""Object holding parameters passed to *_branch hooks.
1773
There are 4 fields that hooks may wish to access:
1775
:ivar format: the branch format
1776
:ivar bzrdir: the bzrdir where the branch will be/has been initialized
1777
:ivar name: name of colocated branch, if any (or None)
1778
:ivar branch: the branch
1781
def __init__(self, format, a_bzrdir, name, branch):
1782
"""Create a group of BranchHook parameters.
1784
:param format: the branch format
1785
:param a_bzrdir: the bzrdir where the branch will be/has been initialized
1786
:param name: name of colocated branch, if any (or None)
1787
:param branch: the branch
1789
self.format = format
1790
self.bzrdir = a_bzrdir
1792
self.branch = branch
1794
def __eq__(self, other):
1795
return self.__dict__ == other.__dict__
1799
return "<%s of %s>" % (self.__class__.__name__, self.branch)
1801
return "<%s of format:%s bzrdir:%s>" % (
1802
self.__class__.__name__, self.branch,
1803
self.format, self.bzrdir)
1805
class SwitchHookParams(object):
1806
"""Object holding parameters passed to *_switch hooks.
1808
There are 4 fields that hooks may wish to access:
1810
:ivar control_dir: BzrDir of the checkout to change
1811
:ivar to_branch: branch that the checkout is to reference
1812
:ivar force: skip the check for local commits in a heavy checkout
1813
:ivar revision_id: revision ID to switch to (or None)
1816
def __init__(self, control_dir, to_branch, force, revision_id):
1817
"""Create a group of SwitchHook parameters.
1819
:param control_dir: BzrDir of the checkout to change
1820
:param to_branch: branch that the checkout is to reference
1821
:param force: skip the check for local commits in a heavy checkout
1822
:param revision_id: revision ID to switch to (or None)
1824
self.control_dir = control_dir
1825
self.to_branch = to_branch
1827
self.revision_id = revision_id
1829
def __eq__(self, other):
1830
return self.__dict__ == other.__dict__
1833
return "<%s for %s to (%s, %s)>" % (self.__class__.__name__,
1834
self.control_dir, self.to_branch,
1751
1837
class BzrBranchFormat4(BranchFormat):
1752
1838
"""Bzr branch format 4.
2022
2108
branch_transport.put_bytes('location',
2023
2109
target_branch.bzrdir.root_transport.base)
2024
2110
branch_transport.put_bytes('format', self.get_format_string())
2026
2112
a_bzrdir, name, _found=True,
2027
2113
possible_transports=[target_branch.bzrdir.root_transport])
2114
if Branch.hooks['post_branch']:
2115
self._run_post_branch_hooks(a_bzrdir, name, branch)
2029
2118
def __init__(self):
2030
2119
super(BranchReferenceFormat, self).__init__()