/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: mbp at sourcefrog
  • Date: 2011-04-11 01:23:58 UTC
  • mfrom: (5777 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5802.
  • Revision ID: mbp@sourcefrog.net-20110411012358-gl07rdtxydlq7fh1
merge news

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
        urlutils,
43
43
        )
44
44
from bzrlib.config import BranchConfig, TransportConfig
45
 
from bzrlib.repofmt.pack_repo import RepositoryFormatKnitPack5RichRoot
46
45
from bzrlib.tag import (
47
46
    BasicTags,
48
47
    DisabledTags,
57
56
    needs_write_lock,
58
57
    only_raises,
59
58
    )
60
 
from bzrlib.hooks import HookPoint, Hooks
 
59
from bzrlib.hooks import Hooks
61
60
from bzrlib.inter import InterObject
62
61
from bzrlib.lock import _RelockDebugMixin, LogicalLockResult
63
62
from bzrlib import registry
682
681
            last_revision.
683
682
        :return: None
684
683
        """
685
 
        if fetch_spec is not None and last_revision is not None:
686
 
            raise AssertionError(
687
 
                "fetch_spec and last_revision are mutually exclusive.")
688
 
        if self.base == from_branch.base:
689
 
            return (0, [])
690
 
        from_branch.lock_read()
691
 
        try:
692
 
            if last_revision is None and fetch_spec is None:
693
 
                last_revision = from_branch.last_revision()
694
 
                last_revision = _mod_revision.ensure_null(last_revision)
695
 
            return self.repository.fetch(from_branch.repository,
696
 
                                         revision_id=last_revision,
697
 
                                         fetch_spec=fetch_spec)
698
 
        finally:
699
 
            from_branch.unlock()
 
684
        return InterBranch.get(from_branch, self).fetch(last_revision,
 
685
            fetch_spec)
700
686
 
701
687
    def get_bound_location(self):
702
688
        """Return the URL of the branch we are bound to.
1658
1644
        for hook in hooks:
1659
1645
            hook(params)
1660
1646
 
1661
 
    def _initialize_helper(self, a_bzrdir, utf8_files, name=None,
1662
 
                           repository=None):
1663
 
        """Initialize a branch in a bzrdir, with specified files
1664
 
 
1665
 
        :param a_bzrdir: The bzrdir to initialize the branch in
1666
 
        :param utf8_files: The files to create as a list of
1667
 
            (filename, content) tuples
1668
 
        :param name: Name of colocated branch to create, if any
1669
 
        :return: a branch in this format
1670
 
        """
1671
 
        mutter('creating branch %r in %s', self, a_bzrdir.user_url)
1672
 
        branch_transport = a_bzrdir.get_branch_transport(self, name=name)
1673
 
        control_files = lockable_files.LockableFiles(branch_transport,
1674
 
            'lock', lockdir.LockDir)
1675
 
        control_files.create_lock()
1676
 
        control_files.lock_write()
1677
 
        try:
1678
 
            utf8_files += [('format', self.get_format_string())]
1679
 
            for (filename, content) in utf8_files:
1680
 
                branch_transport.put_bytes(
1681
 
                    filename, content,
1682
 
                    mode=a_bzrdir._get_file_mode())
1683
 
        finally:
1684
 
            control_files.unlock()
1685
 
        branch = self.open(a_bzrdir, name, _found=True,
1686
 
                found_repository=repository)
1687
 
        self._run_post_branch_init_hooks(a_bzrdir, name, branch)
1688
 
        return branch
1689
 
 
1690
1647
    def initialize(self, a_bzrdir, name=None, repository=None):
1691
1648
        """Create a branch of this format in a_bzrdir.
1692
1649
        
1821
1778
        These are all empty initially, because by default nothing should get
1822
1779
        notified.
1823
1780
        """
1824
 
        Hooks.__init__(self)
1825
 
        self.create_hook(HookPoint('set_rh',
 
1781
        Hooks.__init__(self, "bzrlib.branch", "Branch.hooks")
 
1782
        self.add_hook('set_rh',
1826
1783
            "Invoked whenever the revision history has been set via "
1827
1784
            "set_revision_history. The api signature is (branch, "
1828
1785
            "revision_history), and the branch will be write-locked. "
1829
1786
            "The set_rh hook can be expensive for bzr to trigger, a better "
1830
 
            "hook to use is Branch.post_change_branch_tip.", (0, 15), None))
1831
 
        self.create_hook(HookPoint('open',
 
1787
            "hook to use is Branch.post_change_branch_tip.", (0, 15))
 
1788
        self.add_hook('open',
1832
1789
            "Called with the Branch object that has been opened after a "
1833
 
            "branch is opened.", (1, 8), None))
1834
 
        self.create_hook(HookPoint('post_push',
 
1790
            "branch is opened.", (1, 8))
 
1791
        self.add_hook('post_push',
1835
1792
            "Called after a push operation completes. post_push is called "
1836
1793
            "with a bzrlib.branch.BranchPushResult object and only runs in the "
1837
 
            "bzr client.", (0, 15), None))
1838
 
        self.create_hook(HookPoint('post_pull',
 
1794
            "bzr client.", (0, 15))
 
1795
        self.add_hook('post_pull',
1839
1796
            "Called after a pull operation completes. post_pull is called "
1840
1797
            "with a bzrlib.branch.PullResult object and only runs in the "
1841
 
            "bzr client.", (0, 15), None))
1842
 
        self.create_hook(HookPoint('pre_commit',
 
1798
            "bzr client.", (0, 15))
 
1799
        self.add_hook('pre_commit',
1843
1800
            "Called after a commit is calculated but before it is "
1844
1801
            "completed. pre_commit is called with (local, master, old_revno, "
1845
1802
            "old_revid, future_revno, future_revid, tree_delta, future_tree"
1848
1805
            "basis revision. hooks MUST NOT modify this delta. "
1849
1806
            " future_tree is an in-memory tree obtained from "
1850
1807
            "CommitBuilder.revision_tree() and hooks MUST NOT modify this "
1851
 
            "tree.", (0,91), None))
1852
 
        self.create_hook(HookPoint('post_commit',
 
1808
            "tree.", (0,91))
 
1809
        self.add_hook('post_commit',
1853
1810
            "Called in the bzr client after a commit has completed. "
1854
1811
            "post_commit is called with (local, master, old_revno, old_revid, "
1855
1812
            "new_revno, new_revid). old_revid is NULL_REVISION for the first "
1856
 
            "commit to a branch.", (0, 15), None))
1857
 
        self.create_hook(HookPoint('post_uncommit',
 
1813
            "commit to a branch.", (0, 15))
 
1814
        self.add_hook('post_uncommit',
1858
1815
            "Called in the bzr client after an uncommit completes. "
1859
1816
            "post_uncommit is called with (local, master, old_revno, "
1860
1817
            "old_revid, new_revno, new_revid) where local is the local branch "
1861
1818
            "or None, master is the target branch, and an empty branch "
1862
 
            "receives new_revno of 0, new_revid of None.", (0, 15), None))
1863
 
        self.create_hook(HookPoint('pre_change_branch_tip',
 
1819
            "receives new_revno of 0, new_revid of None.", (0, 15))
 
1820
        self.add_hook('pre_change_branch_tip',
1864
1821
            "Called in bzr client and server before a change to the tip of a "
1865
1822
            "branch is made. pre_change_branch_tip is called with a "
1866
1823
            "bzrlib.branch.ChangeBranchTipParams. Note that push, pull, "
1867
 
            "commit, uncommit will all trigger this hook.", (1, 6), None))
1868
 
        self.create_hook(HookPoint('post_change_branch_tip',
 
1824
            "commit, uncommit will all trigger this hook.", (1, 6))
 
1825
        self.add_hook('post_change_branch_tip',
1869
1826
            "Called in bzr client and server after a change to the tip of a "
1870
1827
            "branch is made. post_change_branch_tip is called with a "
1871
1828
            "bzrlib.branch.ChangeBranchTipParams. Note that push, pull, "
1872
 
            "commit, uncommit will all trigger this hook.", (1, 4), None))
1873
 
        self.create_hook(HookPoint('transform_fallback_location',
 
1829
            "commit, uncommit will all trigger this hook.", (1, 4))
 
1830
        self.add_hook('transform_fallback_location',
1874
1831
            "Called when a stacked branch is activating its fallback "
1875
1832
            "locations. transform_fallback_location is called with (branch, "
1876
1833
            "url), and should return a new url. Returning the same url "
1881
1838
            "fallback locations have not been activated. When there are "
1882
1839
            "multiple hooks installed for transform_fallback_location, "
1883
1840
            "all are called with the url returned from the previous hook."
1884
 
            "The order is however undefined.", (1, 9), None))
1885
 
        self.create_hook(HookPoint('automatic_tag_name',
 
1841
            "The order is however undefined.", (1, 9))
 
1842
        self.add_hook('automatic_tag_name',
1886
1843
            "Called to determine an automatic tag name for a revision. "
1887
1844
            "automatic_tag_name is called with (branch, revision_id) and "
1888
1845
            "should return a tag name or None if no tag name could be "
1889
1846
            "determined. The first non-None tag name returned will be used.",
1890
 
            (2, 2), None))
1891
 
        self.create_hook(HookPoint('post_branch_init',
 
1847
            (2, 2))
 
1848
        self.add_hook('post_branch_init',
1892
1849
            "Called after new branch initialization completes. "
1893
1850
            "post_branch_init is called with a "
1894
1851
            "bzrlib.branch.BranchInitHookParams. "
1895
1852
            "Note that init, branch and checkout (both heavyweight and "
1896
 
            "lightweight) will all trigger this hook.", (2, 2), None))
1897
 
        self.create_hook(HookPoint('post_switch',
 
1853
            "lightweight) will all trigger this hook.", (2, 2))
 
1854
        self.add_hook('post_switch',
1898
1855
            "Called after a checkout switches branch. "
1899
1856
            "post_switch is called with a "
1900
 
            "bzrlib.branch.SwitchHookParams.", (2, 2), None))
 
1857
            "bzrlib.branch.SwitchHookParams.", (2, 2))
1901
1858
 
1902
1859
 
1903
1860
 
2023
1980
        """What class to instantiate on open calls."""
2024
1981
        raise NotImplementedError(self._branch_class)
2025
1982
 
 
1983
    def _initialize_helper(self, a_bzrdir, utf8_files, name=None,
 
1984
                           repository=None):
 
1985
        """Initialize a branch in a bzrdir, with specified files
 
1986
 
 
1987
        :param a_bzrdir: The bzrdir to initialize the branch in
 
1988
        :param utf8_files: The files to create as a list of
 
1989
            (filename, content) tuples
 
1990
        :param name: Name of colocated branch to create, if any
 
1991
        :return: a branch in this format
 
1992
        """
 
1993
        mutter('creating branch %r in %s', self, a_bzrdir.user_url)
 
1994
        branch_transport = a_bzrdir.get_branch_transport(self, name=name)
 
1995
        control_files = lockable_files.LockableFiles(branch_transport,
 
1996
            'lock', lockdir.LockDir)
 
1997
        control_files.create_lock()
 
1998
        control_files.lock_write()
 
1999
        try:
 
2000
            utf8_files += [('format', self.get_format_string())]
 
2001
            for (filename, content) in utf8_files:
 
2002
                branch_transport.put_bytes(
 
2003
                    filename, content,
 
2004
                    mode=a_bzrdir._get_file_mode())
 
2005
        finally:
 
2006
            control_files.unlock()
 
2007
        branch = self.open(a_bzrdir, name, _found=True,
 
2008
                found_repository=repository)
 
2009
        self._run_post_branch_init_hooks(a_bzrdir, name, branch)
 
2010
        return branch
 
2011
 
2026
2012
    def network_name(self):
2027
2013
        """A simple byte string uniquely identifying this format for RPC calls.
2028
2014
 
2161
2147
                      ]
2162
2148
        return self._initialize_helper(a_bzrdir, utf8_files, name, repository)
2163
2149
 
2164
 
    def __init__(self):
2165
 
        super(BzrBranchFormat8, self).__init__()
2166
 
        self._matchingbzrdir.repository_format = \
2167
 
            RepositoryFormatKnitPack5RichRoot()
2168
 
 
2169
2150
    def make_tags(self, branch):
2170
2151
        """See bzrlib.branch.BranchFormat.make_tags()."""
2171
2152
        return BasicTags(branch)
2179
2160
    supports_reference_locations = True
2180
2161
 
2181
2162
 
2182
 
class BzrBranchFormat7(BzrBranchFormat8):
 
2163
class BzrBranchFormat7(BranchFormatMetadir):
2183
2164
    """Branch format with last-revision, tags, and a stacked location pointer.
2184
2165
 
2185
2166
    The stacked location pointer is passed down to the repository and requires
2210
2191
    def supports_set_append_revisions_only(self):
2211
2192
        return True
2212
2193
 
 
2194
    def supports_stacking(self):
 
2195
        return True
 
2196
 
 
2197
    def make_tags(self, branch):
 
2198
        """See bzrlib.branch.BranchFormat.make_tags()."""
 
2199
        return BasicTags(branch)
 
2200
 
2213
2201
    supports_reference_locations = False
2214
2202
 
2215
2203
 
3331
3319
        """
3332
3320
        raise NotImplementedError(self.copy_content_into)
3333
3321
 
 
3322
    @needs_write_lock
 
3323
    def fetch(self, stop_revision=None, fetch_spec=None):
 
3324
        """Fetch revisions.
 
3325
 
 
3326
        :param stop_revision: Last revision to fetch
 
3327
        :param fetch_spec: Fetch spec.
 
3328
        """
 
3329
        raise NotImplementedError(self.fetch)
 
3330
 
3334
3331
 
3335
3332
class GenericInterBranch(InterBranch):
3336
3333
    """InterBranch implementation that uses public Branch functions."""
3371
3368
            self.source.tags.merge_to(self.target.tags)
3372
3369
 
3373
3370
    @needs_write_lock
 
3371
    def fetch(self, stop_revision=None, fetch_spec=None):
 
3372
        if fetch_spec is not None and stop_revision is not None:
 
3373
            raise AssertionError(
 
3374
                "fetch_spec and last_revision are mutually exclusive.")
 
3375
        if self.target.base == self.source.base:
 
3376
            return (0, [])
 
3377
        self.source.lock_read()
 
3378
        try:
 
3379
            if stop_revision is None and fetch_spec is None:
 
3380
                stop_revision = self.source.last_revision()
 
3381
                stop_revision = _mod_revision.ensure_null(stop_revision)
 
3382
            return self.target.repository.fetch(self.source.repository,
 
3383
                revision_id=stop_revision, fetch_spec=fetch_spec)
 
3384
        finally:
 
3385
            self.source.unlock()
 
3386
 
 
3387
    @needs_write_lock
3374
3388
    def update_revisions(self, stop_revision=None, overwrite=False,
3375
3389
        graph=None, fetch_tags=True):
3376
3390
        """See InterBranch.update_revisions()."""