~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: jelmer at samba
  • Date: 2011-10-11 12:01:51 UTC
  • mto: This revision was merged to the branch mainline in revision 6214.
  • Revision ID: jelmer@samba.org-20111011120151-l1aa35zasaocrev3
Fix tests and the like.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
lazy_import(globals(), """
22
22
import itertools
23
23
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
 
        )
 
24
    bzrdir,
 
25
    controldir,
 
26
    cache_utf8,
 
27
    cleanup,
 
28
    config as _mod_config,
 
29
    debug,
 
30
    errors,
 
31
    fetch,
 
32
    graph as _mod_graph,
 
33
    lockdir,
 
34
    lockable_files,
 
35
    remote,
 
36
    repository,
 
37
    revision as _mod_revision,
 
38
    rio,
 
39
    tag as _mod_tag,
 
40
    transport,
 
41
    ui,
 
42
    urlutils,
 
43
    )
43
44
from bzrlib.i18n import gettext, ngettext
44
45
""")
45
46
 
107
108
        for existing_fallback_repo in self.repository._fallback_repositories:
108
109
            if existing_fallback_repo.user_url == url:
109
110
                # This fallback is already configured.  This probably only
110
 
                # happens because BzrDir.sprout is a horrible mess.  To avoid
 
111
                # happens because ControlDir.sprout is a horrible mess.  To avoid
111
112
                # confusing _unstack we don't add this a second time.
112
113
                mutter('duplicate activation of fallback %r on %r', url, self)
113
114
                return
171
172
        For instance, if the branch is at URL/.bzr/branch,
172
173
        Branch.open(URL) -> a Branch instance.
173
174
        """
174
 
        control = bzrdir.BzrDir.open(base, _unsupported,
 
175
        control = controldir.ControlDir.open(base, _unsupported,
175
176
                                     possible_transports=possible_transports)
176
177
        return control.open_branch(unsupported=_unsupported)
177
178
 
178
179
    @staticmethod
179
180
    def open_from_transport(transport, name=None, _unsupported=False):
180
181
        """Open the branch rooted at transport"""
181
 
        control = bzrdir.BzrDir.open_from_transport(transport, _unsupported)
 
182
        control = controldir.ControlDir.open_from_transport(transport, _unsupported)
182
183
        return control.open_branch(name=name, unsupported=_unsupported)
183
184
 
184
185
    @staticmethod
193
194
        format, UnknownFormatError or UnsupportedFormatError are raised.
194
195
        If there is one, it is returned, along with the unused portion of url.
195
196
        """
196
 
        control, relpath = bzrdir.BzrDir.open_containing(url,
 
197
        control, relpath = controldir.ControlDir.open_containing(url,
197
198
                                                         possible_transports)
198
199
        return control.open_branch(), relpath
199
200
 
881
882
            # stream from one of them to the other.  This does mean doing
882
883
            # separate SSH connection setup, but unstacking is not a
883
884
            # common operation so it's tolerable.
884
 
            new_bzrdir = bzrdir.BzrDir.open(self.bzrdir.root_transport.base)
 
885
            new_bzrdir = controldir.ControlDir.open(
 
886
                self.bzrdir.root_transport.base)
885
887
            new_repository = new_bzrdir.find_repository()
886
888
            if new_repository._fallback_repositories:
887
889
                raise AssertionError("didn't expect %r to have "
1451
1453
            from_branch = BranchReferenceFormat().initialize(checkout, 
1452
1454
                target_branch=self)
1453
1455
        else:
1454
 
            checkout_branch = bzrdir.BzrDir.create_branch_convenience(
 
1456
            checkout_branch = controldir.ControlDir.create_branch_convenience(
1455
1457
                to_location, force_new_tree=False, format=format)
1456
1458
            checkout = checkout_branch.bzrdir
1457
1459
            checkout_branch.bind(self)
1595
1597
        return not (self == other)
1596
1598
 
1597
1599
    @classmethod
1598
 
    def find_format(klass, a_bzrdir, name=None):
1599
 
        """Return the format for the branch object in a_bzrdir."""
 
1600
    def find_format(klass, controldir, name=None):
 
1601
        """Return the format for the branch object in controldir."""
1600
1602
        try:
1601
 
            transport = a_bzrdir.get_branch_transport(None, name=name)
 
1603
            transport = controldir.get_branch_transport(None, name=name)
1602
1604
            format_string = transport.get_bytes("format")
1603
1605
            return format_registry.get(format_string)
1604
1606
        except errors.NoSuchFile:
1605
 
            raise errors.NotBranchError(path=transport.base, bzrdir=a_bzrdir)
 
1607
            raise errors.NotBranchError(path=transport.base, bzrdir=controldir)
1606
1608
        except KeyError:
1607
1609
            raise errors.UnknownFormatError(format=format_string, kind='branch')
1608
1610
 
1622
1624
        """
1623
1625
        return format_registry._get_all()
1624
1626
 
1625
 
    def get_reference(self, a_bzrdir, name=None):
1626
 
        """Get the target reference of the branch in a_bzrdir.
 
1627
    def get_reference(self, controldir, name=None):
 
1628
        """Get the target reference of the branch in controldir.
1627
1629
 
1628
1630
        format probing must have been completed before calling
1629
1631
        this method - it is assumed that the format of the branch
1630
 
        in a_bzrdir is correct.
 
1632
        in controldir is correct.
1631
1633
 
1632
 
        :param a_bzrdir: The bzrdir to get the branch data from.
 
1634
        :param controldir: The controldir to get the branch data from.
1633
1635
        :param name: Name of the colocated branch to fetch
1634
1636
        :return: None if the branch is not a reference branch.
1635
1637
        """
1636
1638
        return None
1637
1639
 
1638
1640
    @classmethod
1639
 
    def set_reference(self, a_bzrdir, name, to_branch):
1640
 
        """Set the target reference of the branch in a_bzrdir.
 
1641
    def set_reference(self, controldir, name, to_branch):
 
1642
        """Set the target reference of the branch in controldir.
1641
1643
 
1642
1644
        format probing must have been completed before calling
1643
1645
        this method - it is assumed that the format of the branch
1644
 
        in a_bzrdir is correct.
 
1646
        in controldir is correct.
1645
1647
 
1646
 
        :param a_bzrdir: The bzrdir to set the branch reference for.
 
1648
        :param controldir: The controldir to set the branch reference for.
1647
1649
        :param name: Name of colocated branch to set, None for default
1648
1650
        :param to_branch: branch that the checkout is to reference
1649
1651
        """
1657
1659
        """Return the short format description for this format."""
1658
1660
        raise NotImplementedError(self.get_format_description)
1659
1661
 
1660
 
    def _run_post_branch_init_hooks(self, a_bzrdir, name, branch):
 
1662
    def _run_post_branch_init_hooks(self, controldir, name, branch):
1661
1663
        hooks = Branch.hooks['post_branch_init']
1662
1664
        if not hooks:
1663
1665
            return
1664
 
        params = BranchInitHookParams(self, a_bzrdir, name, branch)
 
1666
        params = BranchInitHookParams(self, controldir, name, branch)
1665
1667
        for hook in hooks:
1666
1668
            hook(params)
1667
1669
 
1668
 
    def initialize(self, a_bzrdir, name=None, repository=None,
 
1670
    def initialize(self, controldir, name=None, repository=None,
1669
1671
                   append_revisions_only=None):
1670
 
        """Create a branch of this format in a_bzrdir.
1671
 
        
 
1672
        """Create a branch of this format in controldir.
 
1673
 
1672
1674
        :param name: Name of the colocated branch to create.
1673
1675
        """
1674
1676
        raise NotImplementedError(self.initialize)
1706
1708
        """
1707
1709
        raise NotImplementedError(self.network_name)
1708
1710
 
1709
 
    def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False,
 
1711
    def open(self, controldir, name=None, _found=False, ignore_fallbacks=False,
1710
1712
            found_repository=None):
1711
 
        """Return the branch object for a_bzrdir
 
1713
        """Return the branch object for controldir.
1712
1714
 
1713
 
        :param a_bzrdir: A BzrDir that contains a branch.
 
1715
        :param controldir: A ControlDir that contains a branch.
1714
1716
        :param name: Name of colocated branch to open
1715
1717
        :param _found: a private parameter, do not use it. It is used to
1716
1718
            indicate if format probing has already be done.
1936
1938
    There are 4 fields that hooks may wish to access:
1937
1939
 
1938
1940
    :ivar format: the branch format
1939
 
    :ivar bzrdir: the BzrDir where the branch will be/has been initialized
 
1941
    :ivar bzrdir: the ControlDir where the branch will be/has been initialized
1940
1942
    :ivar name: name of colocated branch, if any (or None)
1941
1943
    :ivar branch: the branch created
1942
1944
 
1945
1947
    branch, which refer to the original branch.
1946
1948
    """
1947
1949
 
1948
 
    def __init__(self, format, a_bzrdir, name, branch):
 
1950
    def __init__(self, format, controldir, name, branch):
1949
1951
        """Create a group of BranchInitHook parameters.
1950
1952
 
1951
1953
        :param format: the branch format
1952
 
        :param a_bzrdir: the BzrDir where the branch will be/has been
 
1954
        :param controldir: the ControlDir where the branch will be/has been
1953
1955
            initialized
1954
1956
        :param name: name of colocated branch, if any (or None)
1955
1957
        :param branch: the branch created
1959
1961
        in branch, which refer to the original branch.
1960
1962
        """
1961
1963
        self.format = format
1962
 
        self.bzrdir = a_bzrdir
 
1964
        self.bzrdir = controldir
1963
1965
        self.name = name
1964
1966
        self.branch = branch
1965
1967
 
1975
1977
 
1976
1978
    There are 4 fields that hooks may wish to access:
1977
1979
 
1978
 
    :ivar control_dir: BzrDir of the checkout to change
 
1980
    :ivar control_dir: ControlDir of the checkout to change
1979
1981
    :ivar to_branch: branch that the checkout is to reference
1980
1982
    :ivar force: skip the check for local commits in a heavy checkout
1981
1983
    :ivar revision_id: revision ID to switch to (or None)
1984
1986
    def __init__(self, control_dir, to_branch, force, revision_id):
1985
1987
        """Create a group of SwitchHook parameters.
1986
1988
 
1987
 
        :param control_dir: BzrDir of the checkout to change
 
1989
        :param control_dir: ControlDir of the checkout to change
1988
1990
        :param to_branch: branch that the checkout is to reference
1989
1991
        :param force: skip the check for local commits in a heavy checkout
1990
1992
        :param revision_id: revision ID to switch to (or None)
2336
2338
                    (format, self))
2337
2339
        if location is None:
2338
2340
            location = self.get_reference(a_bzrdir, name)
2339
 
        real_bzrdir = bzrdir.BzrDir.open(
 
2341
        real_bzrdir = controldir.ControlDir.open(
2340
2342
            location, possible_transports=possible_transports)
2341
2343
        result = real_bzrdir.open_branch(name=name, 
2342
2344
            ignore_fallbacks=ignore_fallbacks)