~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: John Arbash Meinel
  • Date: 2011-01-10 22:20:12 UTC
  • mfrom: (5582 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5599.
  • Revision ID: john@arbash-meinel.com-20110110222012-mtcqudkvmzwiufuc
Merge in the bzr.dev 5582

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
105
105
 
106
106
    def _activate_fallback_location(self, url):
107
107
        """Activate the branch/repository from url as a fallback repository."""
 
108
        for existing_fallback_repo in self.repository._fallback_repositories:
 
109
            if existing_fallback_repo.user_url == url:
 
110
                # This fallback is already configured.  This probably only
 
111
                # happens because BzrDir.sprout is a horrible mess.  To avoid
 
112
                # confusing _unstack we don't add this a second time.
 
113
                mutter('duplicate activation of fallback %r on %r', url, self)
 
114
                return
108
115
        repo = self._get_fallback_repository(url)
109
116
        if repo.has_same_location(self.repository):
110
117
            raise errors.UnstackableLocationError(self.user_url, url)
809
816
            old_repository = self.repository
810
817
            if len(old_repository._fallback_repositories) != 1:
811
818
                raise AssertionError("can't cope with fallback repositories "
812
 
                    "of %r" % (self.repository,))
 
819
                    "of %r (fallbacks: %r)" % (old_repository,
 
820
                        old_repository._fallback_repositories))
813
821
            # Open the new repository object.
814
822
            # Repositories don't offer an interface to remove fallback
815
823
            # repositories today; take the conceptually simpler option and just
1266
1274
        return result
1267
1275
 
1268
1276
    @needs_read_lock
1269
 
    def sprout(self, to_bzrdir, revision_id=None, repository_policy=None):
 
1277
    def sprout(self, to_bzrdir, revision_id=None, repository_policy=None,
 
1278
            repository=None):
1270
1279
        """Create a new line of development from the branch, into to_bzrdir.
1271
1280
 
1272
1281
        to_bzrdir controls the branch format.
1277
1286
        if (repository_policy is not None and
1278
1287
            repository_policy.requires_stacking()):
1279
1288
            to_bzrdir._format.require_stacking(_skip_repo=True)
1280
 
        result = to_bzrdir.create_branch()
 
1289
        result = to_bzrdir.create_branch(repository=repository)
1281
1290
        result.lock_write()
1282
1291
        try:
1283
1292
            if repository_policy is not None:
1634
1643
            hook(params)
1635
1644
 
1636
1645
    def _initialize_helper(self, a_bzrdir, utf8_files, name=None,
1637
 
                           lock_type='metadir', set_format=True):
 
1646
                           repository=None, lock_type='metadir',
 
1647
                           set_format=True):
1638
1648
        """Initialize a branch in a bzrdir, with specified files
1639
1649
 
1640
1650
        :param a_bzrdir: The bzrdir to initialize the branch in
1674
1684
        finally:
1675
1685
            if lock_taken:
1676
1686
                control_files.unlock()
1677
 
        branch = self.open(a_bzrdir, name, _found=True)
 
1687
        branch = self.open(a_bzrdir, name, _found=True,
 
1688
                found_repository=repository)
1678
1689
        self._run_post_branch_init_hooks(a_bzrdir, name, branch)
1679
1690
        return branch
1680
1691
 
1681
 
    def initialize(self, a_bzrdir, name=None):
 
1692
    def initialize(self, a_bzrdir, name=None, repository=None):
1682
1693
        """Create a branch of this format in a_bzrdir.
1683
1694
        
1684
1695
        :param name: Name of the colocated branch to create.
1718
1729
        """
1719
1730
        raise NotImplementedError(self.network_name)
1720
1731
 
1721
 
    def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False):
 
1732
    def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False,
 
1733
            found_repository=None):
1722
1734
        """Return the branch object for a_bzrdir
1723
1735
 
1724
1736
        :param a_bzrdir: A BzrDir that contains a branch.
2018
2030
        """See BranchFormat.get_format_description()."""
2019
2031
        return "Branch format 4"
2020
2032
 
2021
 
    def initialize(self, a_bzrdir, name=None):
 
2033
    def initialize(self, a_bzrdir, name=None, repository=None):
2022
2034
        """Create a branch of this format in a_bzrdir."""
 
2035
        if repository is not None:
 
2036
            raise NotImplementedError(
 
2037
                "initialize(repository=<not None>) on %r" % (self,))
2023
2038
        utf8_files = [('revision-history', ''),
2024
2039
                      ('branch-name', ''),
2025
2040
                      ]
2034
2049
        """The network name for this format is the control dirs disk label."""
2035
2050
        return self._matchingbzrdir.get_format_string()
2036
2051
 
2037
 
    def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False):
 
2052
    def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False,
 
2053
            found_repository=None):
2038
2054
        """See BranchFormat.open()."""
2039
2055
        if not _found:
2040
2056
            # we are being called directly and must probe.
2041
2057
            raise NotImplementedError
 
2058
        if found_repository is None:
 
2059
            found_repository = a_bzrdir.open_repository()
2042
2060
        return BzrBranch(_format=self,
2043
2061
                         _control_files=a_bzrdir._control_files,
2044
2062
                         a_bzrdir=a_bzrdir,
2045
2063
                         name=name,
2046
 
                         _repository=a_bzrdir.open_repository())
 
2064
                         _repository=found_repository)
2047
2065
 
2048
2066
    def __str__(self):
2049
2067
        return "Bazaar-NG branch format 4"
2063
2081
        """
2064
2082
        return self.get_format_string()
2065
2083
 
2066
 
    def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False):
 
2084
    def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False,
 
2085
            found_repository=None):
2067
2086
        """See BranchFormat.open()."""
2068
2087
        if not _found:
2069
2088
            format = BranchFormat.find_format(a_bzrdir, name=name)
2074
2093
        try:
2075
2094
            control_files = lockable_files.LockableFiles(transport, 'lock',
2076
2095
                                                         lockdir.LockDir)
 
2096
            if found_repository is None:
 
2097
                found_repository = a_bzrdir.find_repository()
2077
2098
            return self._branch_class()(_format=self,
2078
2099
                              _control_files=control_files,
2079
2100
                              name=name,
2080
2101
                              a_bzrdir=a_bzrdir,
2081
 
                              _repository=a_bzrdir.find_repository(),
 
2102
                              _repository=found_repository,
2082
2103
                              ignore_fallbacks=ignore_fallbacks)
2083
2104
        except errors.NoSuchFile:
2084
2105
            raise errors.NotBranchError(path=transport.base, bzrdir=a_bzrdir)
2116
2137
        """See BranchFormat.get_format_description()."""
2117
2138
        return "Branch format 5"
2118
2139
 
2119
 
    def initialize(self, a_bzrdir, name=None):
 
2140
    def initialize(self, a_bzrdir, name=None, repository=None):
2120
2141
        """Create a branch of this format in a_bzrdir."""
2121
2142
        utf8_files = [('revision-history', ''),
2122
2143
                      ('branch-name', ''),
2123
2144
                      ]
2124
 
        return self._initialize_helper(a_bzrdir, utf8_files, name)
 
2145
        return self._initialize_helper(a_bzrdir, utf8_files, name, repository)
2125
2146
 
2126
2147
    def supports_tags(self):
2127
2148
        return False
2149
2170
        """See BranchFormat.get_format_description()."""
2150
2171
        return "Branch format 6"
2151
2172
 
2152
 
    def initialize(self, a_bzrdir, name=None):
 
2173
    def initialize(self, a_bzrdir, name=None, repository=None):
2153
2174
        """Create a branch of this format in a_bzrdir."""
2154
2175
        utf8_files = [('last-revision', '0 null:\n'),
2155
2176
                      ('branch.conf', ''),
2156
2177
                      ('tags', ''),
2157
2178
                      ]
2158
 
        return self._initialize_helper(a_bzrdir, utf8_files, name)
 
2179
        return self._initialize_helper(a_bzrdir, utf8_files, name, repository)
2159
2180
 
2160
2181
    def make_tags(self, branch):
2161
2182
        """See bzrlib.branch.BranchFormat.make_tags()."""
2179
2200
        """See BranchFormat.get_format_description()."""
2180
2201
        return "Branch format 8"
2181
2202
 
2182
 
    def initialize(self, a_bzrdir, name=None):
 
2203
    def initialize(self, a_bzrdir, name=None, repository=None):
2183
2204
        """Create a branch of this format in a_bzrdir."""
2184
2205
        utf8_files = [('last-revision', '0 null:\n'),
2185
2206
                      ('branch.conf', ''),
2186
2207
                      ('tags', ''),
2187
2208
                      ('references', '')
2188
2209
                      ]
2189
 
        return self._initialize_helper(a_bzrdir, utf8_files, name)
 
2210
        return self._initialize_helper(a_bzrdir, utf8_files, name, repository)
2190
2211
 
2191
2212
    def __init__(self):
2192
2213
        super(BzrBranchFormat8, self).__init__()
2215
2236
    This format was introduced in bzr 1.6.
2216
2237
    """
2217
2238
 
2218
 
    def initialize(self, a_bzrdir, name=None):
 
2239
    def initialize(self, a_bzrdir, name=None, repository=None):
2219
2240
        """Create a branch of this format in a_bzrdir."""
2220
2241
        utf8_files = [('last-revision', '0 null:\n'),
2221
2242
                      ('branch.conf', ''),
2222
2243
                      ('tags', ''),
2223
2244
                      ]
2224
 
        return self._initialize_helper(a_bzrdir, utf8_files, name)
 
2245
        return self._initialize_helper(a_bzrdir, utf8_files, name, repository)
2225
2246
 
2226
2247
    def _branch_class(self):
2227
2248
        return BzrBranch7
2269
2290
        transport = a_bzrdir.get_branch_transport(None, name=name)
2270
2291
        location = transport.put_bytes('location', to_branch.base)
2271
2292
 
2272
 
    def initialize(self, a_bzrdir, name=None, target_branch=None):
 
2293
    def initialize(self, a_bzrdir, name=None, target_branch=None,
 
2294
            repository=None):
2273
2295
        """Create a branch of this format in a_bzrdir."""
2274
2296
        if target_branch is None:
2275
2297
            # this format does not implement branch itself, thus the implicit
2303
2325
        return clone
2304
2326
 
2305
2327
    def open(self, a_bzrdir, name=None, _found=False, location=None,
2306
 
             possible_transports=None, ignore_fallbacks=False):
 
2328
             possible_transports=None, ignore_fallbacks=False,
 
2329
             found_repository=None):
2307
2330
        """Return the branch that the branch reference in a_bzrdir points at.
2308
2331
 
2309
2332
        :param a_bzrdir: A BzrDir that contains a branch.