/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: Jelmer Vernooij
  • Date: 2011-10-14 13:56:45 UTC
  • mfrom: (6215 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6216.
  • Revision ID: jelmer@samba.org-20111014135645-phc3q3y21k2ks0s2
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
 
17
import bzrlib.bzrdir
17
18
 
18
19
from cStringIO import StringIO
19
20
 
21
22
lazy_import(globals(), """
22
23
import itertools
23
24
from bzrlib import (
24
 
        bzrdir,
25
 
        cache_utf8,
26
 
        cleanup,
27
 
        config as _mod_config,
28
 
        debug,
29
 
        errors,
30
 
        fetch,
31
 
        graph as _mod_graph,
32
 
        lockdir,
33
 
        lockable_files,
34
 
        remote,
35
 
        repository,
36
 
        revision as _mod_revision,
37
 
        rio,
38
 
        tag as _mod_tag,
39
 
        transport,
40
 
        ui,
41
 
        urlutils,
42
 
        )
 
25
    bzrdir,
 
26
    controldir,
 
27
    cache_utf8,
 
28
    cleanup,
 
29
    config as _mod_config,
 
30
    debug,
 
31
    errors,
 
32
    fetch,
 
33
    graph as _mod_graph,
 
34
    lockdir,
 
35
    lockable_files,
 
36
    remote,
 
37
    repository,
 
38
    revision as _mod_revision,
 
39
    rio,
 
40
    tag as _mod_tag,
 
41
    transport,
 
42
    ui,
 
43
    urlutils,
 
44
    )
43
45
from bzrlib.i18n import gettext, ngettext
44
46
""")
45
47
 
107
109
        for existing_fallback_repo in self.repository._fallback_repositories:
108
110
            if existing_fallback_repo.user_url == url:
109
111
                # This fallback is already configured.  This probably only
110
 
                # happens because BzrDir.sprout is a horrible mess.  To avoid
 
112
                # happens because ControlDir.sprout is a horrible mess.  To avoid
111
113
                # confusing _unstack we don't add this a second time.
112
114
                mutter('duplicate activation of fallback %r on %r', url, self)
113
115
                return
171
173
        For instance, if the branch is at URL/.bzr/branch,
172
174
        Branch.open(URL) -> a Branch instance.
173
175
        """
174
 
        control = bzrdir.BzrDir.open(base, _unsupported,
 
176
        control = controldir.ControlDir.open(base, _unsupported,
175
177
                                     possible_transports=possible_transports)
176
178
        return control.open_branch(unsupported=_unsupported)
177
179
 
178
180
    @staticmethod
179
181
    def open_from_transport(transport, name=None, _unsupported=False):
180
182
        """Open the branch rooted at transport"""
181
 
        control = bzrdir.BzrDir.open_from_transport(transport, _unsupported)
 
183
        control = controldir.ControlDir.open_from_transport(transport, _unsupported)
182
184
        return control.open_branch(name=name, unsupported=_unsupported)
183
185
 
184
186
    @staticmethod
193
195
        format, UnknownFormatError or UnsupportedFormatError are raised.
194
196
        If there is one, it is returned, along with the unused portion of url.
195
197
        """
196
 
        control, relpath = bzrdir.BzrDir.open_containing(url,
 
198
        control, relpath = controldir.ControlDir.open_containing(url,
197
199
                                                         possible_transports)
198
200
        return control.open_branch(), relpath
199
201
 
881
883
            # stream from one of them to the other.  This does mean doing
882
884
            # separate SSH connection setup, but unstacking is not a
883
885
            # common operation so it's tolerable.
884
 
            new_bzrdir = bzrdir.BzrDir.open(self.bzrdir.root_transport.base)
 
886
            new_bzrdir = controldir.ControlDir.open(
 
887
                self.bzrdir.root_transport.base)
885
888
            new_repository = new_bzrdir.find_repository()
886
889
            if new_repository._fallback_repositories:
887
890
                raise AssertionError("didn't expect %r to have "
1455
1458
            from_branch = BranchReferenceFormat().initialize(checkout, 
1456
1459
                target_branch=self)
1457
1460
        else:
1458
 
            checkout_branch = bzrdir.BzrDir.create_branch_convenience(
 
1461
            checkout_branch = controldir.ControlDir.create_branch_convenience(
1459
1462
                to_location, force_new_tree=False, format=format)
1460
1463
            checkout = checkout_branch.bzrdir
1461
1464
            checkout_branch.bind(self)
1599
1602
        return not (self == other)
1600
1603
 
1601
1604
    @classmethod
1602
 
    def find_format(klass, a_bzrdir, name=None):
1603
 
        """Return the format for the branch object in a_bzrdir."""
 
1605
    def find_format(klass, controldir, name=None):
 
1606
        """Return the format for the branch object in controldir."""
1604
1607
        try:
1605
 
            transport = a_bzrdir.get_branch_transport(None, name=name)
 
1608
            transport = controldir.get_branch_transport(None, name=name)
1606
1609
            format_string = transport.get_bytes("format")
1607
1610
            return format_registry.get(format_string)
1608
1611
        except errors.NoSuchFile:
1609
 
            raise errors.NotBranchError(path=transport.base, bzrdir=a_bzrdir)
 
1612
            raise errors.NotBranchError(path=transport.base, bzrdir=controldir)
1610
1613
        except KeyError:
1611
1614
            raise errors.UnknownFormatError(format=format_string, kind='branch')
1612
1615
 
1626
1629
        """
1627
1630
        return format_registry._get_all()
1628
1631
 
1629
 
    def get_reference(self, a_bzrdir, name=None):
1630
 
        """Get the target reference of the branch in a_bzrdir.
 
1632
    def get_reference(self, controldir, name=None):
 
1633
        """Get the target reference of the branch in controldir.
1631
1634
 
1632
1635
        format probing must have been completed before calling
1633
1636
        this method - it is assumed that the format of the branch
1634
 
        in a_bzrdir is correct.
 
1637
        in controldir is correct.
1635
1638
 
1636
 
        :param a_bzrdir: The bzrdir to get the branch data from.
 
1639
        :param controldir: The controldir to get the branch data from.
1637
1640
        :param name: Name of the colocated branch to fetch
1638
1641
        :return: None if the branch is not a reference branch.
1639
1642
        """
1640
1643
        return None
1641
1644
 
1642
1645
    @classmethod
1643
 
    def set_reference(self, a_bzrdir, name, to_branch):
1644
 
        """Set the target reference of the branch in a_bzrdir.
 
1646
    def set_reference(self, controldir, name, to_branch):
 
1647
        """Set the target reference of the branch in controldir.
1645
1648
 
1646
1649
        format probing must have been completed before calling
1647
1650
        this method - it is assumed that the format of the branch
1648
 
        in a_bzrdir is correct.
 
1651
        in controldir is correct.
1649
1652
 
1650
 
        :param a_bzrdir: The bzrdir to set the branch reference for.
 
1653
        :param controldir: The controldir to set the branch reference for.
1651
1654
        :param name: Name of colocated branch to set, None for default
1652
1655
        :param to_branch: branch that the checkout is to reference
1653
1656
        """
1661
1664
        """Return the short format description for this format."""
1662
1665
        raise NotImplementedError(self.get_format_description)
1663
1666
 
1664
 
    def _run_post_branch_init_hooks(self, a_bzrdir, name, branch):
 
1667
    def _run_post_branch_init_hooks(self, controldir, name, branch):
1665
1668
        hooks = Branch.hooks['post_branch_init']
1666
1669
        if not hooks:
1667
1670
            return
1668
 
        params = BranchInitHookParams(self, a_bzrdir, name, branch)
 
1671
        params = BranchInitHookParams(self, controldir, name, branch)
1669
1672
        for hook in hooks:
1670
1673
            hook(params)
1671
1674
 
1672
 
    def initialize(self, a_bzrdir, name=None, repository=None,
 
1675
    def initialize(self, controldir, name=None, repository=None,
1673
1676
                   append_revisions_only=None):
1674
 
        """Create a branch of this format in a_bzrdir.
1675
 
        
 
1677
        """Create a branch of this format in controldir.
 
1678
 
1676
1679
        :param name: Name of the colocated branch to create.
1677
1680
        """
1678
1681
        raise NotImplementedError(self.initialize)
1710
1713
        """
1711
1714
        raise NotImplementedError(self.network_name)
1712
1715
 
1713
 
    def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False,
 
1716
    def open(self, controldir, name=None, _found=False, ignore_fallbacks=False,
1714
1717
            found_repository=None):
1715
 
        """Return the branch object for a_bzrdir
 
1718
        """Return the branch object for controldir.
1716
1719
 
1717
 
        :param a_bzrdir: A BzrDir that contains a branch.
 
1720
        :param controldir: A ControlDir that contains a branch.
1718
1721
        :param name: Name of colocated branch to open
1719
1722
        :param _found: a private parameter, do not use it. It is used to
1720
1723
            indicate if format probing has already be done.
1940
1943
    There are 4 fields that hooks may wish to access:
1941
1944
 
1942
1945
    :ivar format: the branch format
1943
 
    :ivar bzrdir: the BzrDir where the branch will be/has been initialized
 
1946
    :ivar bzrdir: the ControlDir where the branch will be/has been initialized
1944
1947
    :ivar name: name of colocated branch, if any (or None)
1945
1948
    :ivar branch: the branch created
1946
1949
 
1949
1952
    branch, which refer to the original branch.
1950
1953
    """
1951
1954
 
1952
 
    def __init__(self, format, a_bzrdir, name, branch):
 
1955
    def __init__(self, format, controldir, name, branch):
1953
1956
        """Create a group of BranchInitHook parameters.
1954
1957
 
1955
1958
        :param format: the branch format
1956
 
        :param a_bzrdir: the BzrDir where the branch will be/has been
 
1959
        :param controldir: the ControlDir where the branch will be/has been
1957
1960
            initialized
1958
1961
        :param name: name of colocated branch, if any (or None)
1959
1962
        :param branch: the branch created
1963
1966
        in branch, which refer to the original branch.
1964
1967
        """
1965
1968
        self.format = format
1966
 
        self.bzrdir = a_bzrdir
 
1969
        self.bzrdir = controldir
1967
1970
        self.name = name
1968
1971
        self.branch = branch
1969
1972
 
1979
1982
 
1980
1983
    There are 4 fields that hooks may wish to access:
1981
1984
 
1982
 
    :ivar control_dir: BzrDir of the checkout to change
 
1985
    :ivar control_dir: ControlDir of the checkout to change
1983
1986
    :ivar to_branch: branch that the checkout is to reference
1984
1987
    :ivar force: skip the check for local commits in a heavy checkout
1985
1988
    :ivar revision_id: revision ID to switch to (or None)
1988
1991
    def __init__(self, control_dir, to_branch, force, revision_id):
1989
1992
        """Create a group of SwitchHook parameters.
1990
1993
 
1991
 
        :param control_dir: BzrDir of the checkout to change
 
1994
        :param control_dir: ControlDir of the checkout to change
1992
1995
        :param to_branch: branch that the checkout is to reference
1993
1996
        :param force: skip the check for local commits in a heavy checkout
1994
1997
        :param revision_id: revision ID to switch to (or None)
2081
2084
        except errors.NoSuchFile:
2082
2085
            raise errors.NotBranchError(path=transport.base, bzrdir=a_bzrdir)
2083
2086
 
2084
 
    def __init__(self):
2085
 
        super(BranchFormatMetadir, self).__init__()
2086
 
        self._matchingbzrdir = bzrdir.BzrDirMetaFormat1()
2087
 
        self._matchingbzrdir.set_branch_format(self)
 
2087
    @property
 
2088
    def _matchingbzrdir(self):
 
2089
        ret = bzrdir.BzrDirMetaFormat1()
 
2090
        ret.set_branch_format(self)
 
2091
        return ret
2088
2092
 
2089
2093
    def supports_tags(self):
2090
2094
        return True
2252
2256
    supports_reference_locations = False
2253
2257
 
2254
2258
 
2255
 
class BranchReferenceFormat(BranchFormat):
 
2259
class BranchReferenceFormat(BranchFormatMetadir):
2256
2260
    """Bzr branch reference format.
2257
2261
 
2258
2262
    Branch references are used in implementing checkouts, they
2301
2305
        self._run_post_branch_init_hooks(a_bzrdir, name, branch)
2302
2306
        return branch
2303
2307
 
2304
 
    def __init__(self):
2305
 
        super(BranchReferenceFormat, self).__init__()
2306
 
        self._matchingbzrdir = bzrdir.BzrDirMetaFormat1()
2307
 
        self._matchingbzrdir.set_branch_format(self)
2308
 
 
2309
2308
    def _make_reference_clone_function(format, a_branch):
2310
2309
        """Create a clone() routine for a branch dynamically."""
2311
2310
        def clone(to_bzrdir, revision_id=None,
2340
2339
                    (format, self))
2341
2340
        if location is None:
2342
2341
            location = self.get_reference(a_bzrdir, name)
2343
 
        real_bzrdir = bzrdir.BzrDir.open(
 
2342
        real_bzrdir = controldir.ControlDir.open(
2344
2343
            location, possible_transports=possible_transports)
2345
2344
        result = real_bzrdir.open_branch(name=name, 
2346
2345
            ignore_fallbacks=ignore_fallbacks)