1543
1543
"""Return the short format description for this format."""
1544
1544
raise NotImplementedError(self.get_format_description)
1546
def _run_post_branch_init_hooks(self, a_bzrdir, name, branch):
1547
hooks = Branch.hooks['post_branch_init']
1550
params = BranchInitHookParams(self, a_bzrdir, name, branch)
1546
1554
def _initialize_helper(self, a_bzrdir, utf8_files, name=None,
1547
1555
lock_type='metadir', set_format=True):
1548
1556
"""Initialize a branch in a bzrdir, with specified files
1586
1594
control_files.unlock()
1587
return self.open(a_bzrdir, name, _found=True)
1595
branch = self.open(a_bzrdir, name, _found=True)
1596
self._run_post_branch_init_hooks(a_bzrdir, name, branch)
1589
1599
def initialize(self, a_bzrdir, name=None):
1590
1600
"""Create a branch of this format in a_bzrdir.
1750
1760
"should return a tag name or None if no tag name could be "
1751
1761
"determined. The first non-None tag name returned will be used.",
1763
self.create_hook(HookPoint('post_branch_init',
1764
"Called after new branch initialization completes. "
1765
"post_branch_init is called with a "
1766
"bzrlib.branch.BranchInitHookParams. "
1767
"Note that init, branch and checkout (both heavyweight and "
1768
"lightweight) will all trigger this hook.", (2, 2), None))
1769
self.create_hook(HookPoint('post_switch',
1770
"Called after a checkout switches branch. "
1771
"post_switch is called with a "
1772
"bzrlib.branch.SwitchHookParams.", (2, 2), None))
1795
1815
self.old_revno, self.old_revid, self.new_revno, self.new_revid)
1818
class BranchInitHookParams(object):
1819
"""Object holding parameters passed to *_branch_init hooks.
1821
There are 4 fields that hooks may wish to access:
1823
:ivar format: the branch format
1824
:ivar bzrdir: the BzrDir where the branch will be/has been initialized
1825
:ivar name: name of colocated branch, if any (or None)
1826
:ivar branch: the branch created
1828
Note that for lightweight checkouts, the bzrdir and format fields refer to
1829
the checkout, hence they are different from the corresponding fields in
1830
branch, which refer to the original branch.
1833
def __init__(self, format, a_bzrdir, name, branch):
1834
"""Create a group of BranchInitHook parameters.
1836
:param format: the branch format
1837
:param a_bzrdir: the BzrDir where the branch will be/has been
1839
:param name: name of colocated branch, if any (or None)
1840
:param branch: the branch created
1842
Note that for lightweight checkouts, the bzrdir and format fields refer
1843
to the checkout, hence they are different from the corresponding fields
1844
in branch, which refer to the original branch.
1846
self.format = format
1847
self.bzrdir = a_bzrdir
1849
self.branch = branch
1851
def __eq__(self, other):
1852
return self.__dict__ == other.__dict__
1856
return "<%s of %s>" % (self.__class__.__name__, self.branch)
1858
return "<%s of format:%s bzrdir:%s>" % (
1859
self.__class__.__name__, self.branch,
1860
self.format, self.bzrdir)
1863
class SwitchHookParams(object):
1864
"""Object holding parameters passed to *_switch hooks.
1866
There are 4 fields that hooks may wish to access:
1868
:ivar control_dir: BzrDir of the checkout to change
1869
:ivar to_branch: branch that the checkout is to reference
1870
:ivar force: skip the check for local commits in a heavy checkout
1871
:ivar revision_id: revision ID to switch to (or None)
1874
def __init__(self, control_dir, to_branch, force, revision_id):
1875
"""Create a group of SwitchHook parameters.
1877
:param control_dir: BzrDir of the checkout to change
1878
:param to_branch: branch that the checkout is to reference
1879
:param force: skip the check for local commits in a heavy checkout
1880
:param revision_id: revision ID to switch to (or None)
1882
self.control_dir = control_dir
1883
self.to_branch = to_branch
1885
self.revision_id = revision_id
1887
def __eq__(self, other):
1888
return self.__dict__ == other.__dict__
1891
return "<%s for %s to (%s, %s)>" % (self.__class__.__name__,
1892
self.control_dir, self.to_branch,
1798
1896
class BzrBranchFormat4(BranchFormat):
1799
1897
"""Bzr branch format 4.
2069
2167
branch_transport.put_bytes('location',
2070
2168
target_branch.bzrdir.root_transport.base)
2071
2169
branch_transport.put_bytes('format', self.get_format_string())
2073
2171
a_bzrdir, name, _found=True,
2074
2172
possible_transports=[target_branch.bzrdir.root_transport])
2173
self._run_post_branch_init_hooks(a_bzrdir, name, branch)
2076
2176
def __init__(self):
2077
2177
super(BranchReferenceFormat, self).__init__()