~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Martin Pool
  • Date: 2010-04-28 07:03:38 UTC
  • mfrom: (5188 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5189.
  • Revision ID: mbp@sourcefrog.net-20100428070338-2af8y3takgfkrkyp
merge news

Show diffs side-by-side

added added

removed removed

Lines of Context:
1540
1540
        """Return the short format description for this format."""
1541
1541
        raise NotImplementedError(self.get_format_description)
1542
1542
 
 
1543
    def _run_post_branch_init_hooks(self, a_bzrdir, name, branch):
 
1544
        hooks = Branch.hooks['post_branch_init']
 
1545
        if not hooks:
 
1546
            return
 
1547
        params = BranchInitHookParams(self, a_bzrdir, name, branch)
 
1548
        for hook in hooks:
 
1549
            hook(params)
 
1550
 
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
1581
1589
        finally:
1582
1590
            if lock_taken:
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)
 
1594
        return branch
1585
1595
 
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.",
1749
1759
            (2, 2), None))
 
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))
1750
1770
 
1751
1771
 
1752
1772
 
1792
1812
            self.old_revno, self.old_revid, self.new_revno, self.new_revid)
1793
1813
 
1794
1814
 
 
1815
class BranchInitHookParams(object):
 
1816
    """Object holding parameters passed to *_branch_init hooks.
 
1817
 
 
1818
    There are 4 fields that hooks may wish to access:
 
1819
 
 
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
 
1824
 
 
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.
 
1828
    """
 
1829
 
 
1830
    def __init__(self, format, a_bzrdir, name, branch):
 
1831
        """Create a group of BranchInitHook parameters.
 
1832
 
 
1833
        :param format: the branch format
 
1834
        :param a_bzrdir: the BzrDir where the branch will be/has been
 
1835
            initialized
 
1836
        :param name: name of colocated branch, if any (or None)
 
1837
        :param branch: the branch created
 
1838
 
 
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.
 
1842
        """
 
1843
        self.format = format
 
1844
        self.bzrdir = a_bzrdir
 
1845
        self.name = name
 
1846
        self.branch = branch
 
1847
 
 
1848
    def __eq__(self, other):
 
1849
        return self.__dict__ == other.__dict__
 
1850
 
 
1851
    def __repr__(self):
 
1852
        if self.branch:
 
1853
            return "<%s of %s>" % (self.__class__.__name__, self.branch)
 
1854
        else:
 
1855
            return "<%s of format:%s bzrdir:%s>" % (
 
1856
                self.__class__.__name__, self.branch,
 
1857
                self.format, self.bzrdir)
 
1858
 
 
1859
 
 
1860
class SwitchHookParams(object):
 
1861
    """Object holding parameters passed to *_switch hooks.
 
1862
 
 
1863
    There are 4 fields that hooks may wish to access:
 
1864
 
 
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)
 
1869
    """
 
1870
 
 
1871
    def __init__(self, control_dir, to_branch, force, revision_id):
 
1872
        """Create a group of SwitchHook parameters.
 
1873
 
 
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)
 
1878
        """
 
1879
        self.control_dir = control_dir
 
1880
        self.to_branch = to_branch
 
1881
        self.force = force
 
1882
        self.revision_id = revision_id
 
1883
 
 
1884
    def __eq__(self, other):
 
1885
        return self.__dict__ == other.__dict__
 
1886
 
 
1887
    def __repr__(self):
 
1888
        return "<%s for %s to (%s, %s)>" % (self.__class__.__name__,
 
1889
            self.control_dir, self.to_branch,
 
1890
            self.revision_id)
 
1891
 
 
1892
 
1795
1893
class BzrBranchFormat4(BranchFormat):
1796
1894
    """Bzr branch format 4.
1797
1895
 
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())
2069
 
        return self.open(
 
2167
        branch = self.open(
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)
 
2171
        return branch
2072
2172
 
2073
2173
    def __init__(self):
2074
2174
        super(BranchReferenceFormat, self).__init__()
2768
2868
        return stacked_url
2769
2869
 
2770
2870
    def _get_append_revisions_only(self):
2771
 
        value = self.get_config().get_user_option('append_revisions_only')
2772
 
        return value == 'True'
 
2871
        return self.get_config(
 
2872
            ).get_user_option_as_bool('append_revisions_only')
2773
2873
 
2774
2874
    @needs_write_lock
2775
2875
    def generate_revision_history(self, revision_id, last_rev=None,