1540
1540
"""Return the short format description for this format."""
1541
1541
raise NotImplementedError(self.get_format_description)
1543
def _run_post_branch_init_hooks(self, a_bzrdir, name, branch):
1544
hooks = Branch.hooks['post_branch_init']
1547
params = BranchInitHookParams(self, a_bzrdir, name, branch)
1543
1551
def _initialize_helper(self, a_bzrdir, utf8_files, name=None,
1544
1552
lock_type='metadir', set_format=True):
1545
1553
"""Initialize a branch in a bzrdir, with specified files
1583
1591
control_files.unlock()
1584
return self.open(a_bzrdir, name, _found=True)
1592
branch = self.open(a_bzrdir, name, _found=True)
1593
self._run_post_branch_init_hooks(a_bzrdir, name, branch)
1586
1596
def initialize(self, a_bzrdir, name=None):
1587
1597
"""Create a branch of this format in a_bzrdir.
1747
1757
"should return a tag name or None if no tag name could be "
1748
1758
"determined. The first non-None tag name returned will be used.",
1760
self.create_hook(HookPoint('post_branch_init',
1761
"Called after new branch initialization completes. "
1762
"post_branch_init is called with a "
1763
"bzrlib.branch.BranchInitHookParams. "
1764
"Note that init, branch and checkout (both heavyweight and "
1765
"lightweight) will all trigger this hook.", (2, 2), None))
1766
self.create_hook(HookPoint('post_switch',
1767
"Called after a checkout switches branch. "
1768
"post_switch is called with a "
1769
"bzrlib.branch.SwitchHookParams.", (2, 2), None))
1792
1812
self.old_revno, self.old_revid, self.new_revno, self.new_revid)
1815
class BranchInitHookParams(object):
1816
"""Object holding parameters passed to *_branch_init hooks.
1818
There are 4 fields that hooks may wish to access:
1820
:ivar format: the branch format
1821
:ivar bzrdir: the BzrDir where the branch will be/has been initialized
1822
:ivar name: name of colocated branch, if any (or None)
1823
:ivar branch: the branch created
1825
Note that for lightweight checkouts, the bzrdir and format fields refer to
1826
the checkout, hence they are different from the corresponding fields in
1827
branch, which refer to the original branch.
1830
def __init__(self, format, a_bzrdir, name, branch):
1831
"""Create a group of BranchInitHook parameters.
1833
:param format: the branch format
1834
:param a_bzrdir: the BzrDir where the branch will be/has been
1836
:param name: name of colocated branch, if any (or None)
1837
:param branch: the branch created
1839
Note that for lightweight checkouts, the bzrdir and format fields refer
1840
to the checkout, hence they are different from the corresponding fields
1841
in branch, which refer to the original branch.
1843
self.format = format
1844
self.bzrdir = a_bzrdir
1846
self.branch = branch
1848
def __eq__(self, other):
1849
return self.__dict__ == other.__dict__
1853
return "<%s of %s>" % (self.__class__.__name__, self.branch)
1855
return "<%s of format:%s bzrdir:%s>" % (
1856
self.__class__.__name__, self.branch,
1857
self.format, self.bzrdir)
1860
class SwitchHookParams(object):
1861
"""Object holding parameters passed to *_switch hooks.
1863
There are 4 fields that hooks may wish to access:
1865
:ivar control_dir: BzrDir of the checkout to change
1866
:ivar to_branch: branch that the checkout is to reference
1867
:ivar force: skip the check for local commits in a heavy checkout
1868
:ivar revision_id: revision ID to switch to (or None)
1871
def __init__(self, control_dir, to_branch, force, revision_id):
1872
"""Create a group of SwitchHook parameters.
1874
:param control_dir: BzrDir of the checkout to change
1875
:param to_branch: branch that the checkout is to reference
1876
:param force: skip the check for local commits in a heavy checkout
1877
:param revision_id: revision ID to switch to (or None)
1879
self.control_dir = control_dir
1880
self.to_branch = to_branch
1882
self.revision_id = revision_id
1884
def __eq__(self, other):
1885
return self.__dict__ == other.__dict__
1888
return "<%s for %s to (%s, %s)>" % (self.__class__.__name__,
1889
self.control_dir, self.to_branch,
1795
1893
class BzrBranchFormat4(BranchFormat):
1796
1894
"""Bzr branch format 4.
2066
2164
branch_transport.put_bytes('location',
2067
2165
target_branch.bzrdir.user_url)
2068
2166
branch_transport.put_bytes('format', self.get_format_string())
2070
2168
a_bzrdir, name, _found=True,
2071
2169
possible_transports=[target_branch.bzrdir.root_transport])
2170
self._run_post_branch_init_hooks(a_bzrdir, name, branch)
2073
2173
def __init__(self):
2074
2174
super(BranchReferenceFormat, self).__init__()