/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5557.1.7 by John Arbash Meinel
Merge in the bzr.dev 5582
1
# Copyright (C) 2006-2011 Canonical Ltd
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
2
#
1534.4.39 by Robert Collins
Basic BzrDir support.
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
7
#
1534.4.39 by Robert Collins
Basic BzrDir support.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
12
#
1534.4.39 by Robert Collins
Basic BzrDir support.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1534.4.39 by Robert Collins
Basic BzrDir support.
16
17
"""BzrDir logic. The BzrDir is the basic control directory used by bzr.
18
19
At format 7 this was split out into Branch, Repository and Checkout control
20
directories.
2830.1.1 by Ian Clatworthy
bzrdir.py code clean-ups
21
22
Note: This module has a lot of ``open`` functions/methods that return
23
references to in-memory objects. As a rule, there are no matching ``close``
24
methods. To free any associated resources, simply stop referencing the
25
objects returned.
1534.4.39 by Robert Collins
Basic BzrDir support.
26
"""
27
3023.1.1 by Alexander Belchenko
Mark .bzr directories as "hidden" on Windows (#71147)
28
import sys
1996.3.3 by John Arbash Meinel
Shave off another 40ms by demand loading branch and bzrdir
29
30
from bzrlib.lazy_import import lazy_import
31
lazy_import(globals(), """
1534.4.39 by Robert Collins
Basic BzrDir support.
32
import bzrlib
1996.3.3 by John Arbash Meinel
Shave off another 40ms by demand loading branch and bzrdir
33
from bzrlib import (
5753.2.1 by Jelmer Vernooij
Work around lazy import issues.
34
    branch as _mod_branch,
5735.1.1 by Jelmer Vernooij
Move ControlDir.sprout to BzrDir.
35
    cleanup,
1996.3.3 by John Arbash Meinel
Shave off another 40ms by demand loading branch and bzrdir
36
    errors,
5735.1.1 by Jelmer Vernooij
Move ControlDir.sprout to BzrDir.
37
    fetch,
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
38
    graph,
1996.3.3 by John Arbash Meinel
Shave off another 40ms by demand loading branch and bzrdir
39
    lockable_files,
40
    lockdir,
3350.6.1 by Robert Collins
* New ``versionedfile.KeyMapper`` interface to abstract out the access to
41
    osutils,
5436.2.1 by Andrew Bennetts
Add bzrlib.pyutils, which has get_named_object, a wrapper around __import__.
42
    pyutils,
2018.5.25 by Andrew Bennetts
Make sure RemoteBzrDirFormat is always registered (John Arbash Meinel, Robert Collins, Andrew Bennetts).
43
    remote,
4294.2.5 by Robert Collins
Reasonable unit test coverage for initialize_on_transport_ex.
44
    repository,
1996.3.12 by John Arbash Meinel
Change how 'revision' is imported to avoid problems later
45
    revision as _mod_revision,
5609.9.1 by Martin
Blindly change all users of get_transport to address the function via the transport module
46
    transport as _mod_transport,
2323.6.4 by Martin Pool
BzrDir._check_supported now also takes care of recommending upgrades, which
47
    ui,
1996.3.3 by John Arbash Meinel
Shave off another 40ms by demand loading branch and bzrdir
48
    urlutils,
6341.1.4 by Jelmer Vernooij
Move more functionality to vf_search.
49
    vf_search,
3023.1.2 by Alexander Belchenko
Martin's review.
50
    win32utils,
5816.5.1 by Jelmer Vernooij
Move WorkingTree3 to bzrlib.workingtree_3.
51
    workingtree_3,
3023.1.2 by Alexander Belchenko
Martin's review.
52
    workingtree_4,
3978.3.14 by Jelmer Vernooij
Move BranchBzrDirInter.push() to BzrDir.push().
53
    )
5757.1.2 by Jelmer Vernooij
Add separate file for knit pack repository formats.
54
from bzrlib.repofmt import knitpack_repo
2164.2.21 by Vincent Ladeuil
Take bundles into account.
55
from bzrlib.transport import (
56
    do_catching_redirections,
3224.5.24 by Andrew Bennetts
More minor import tidying suggested by pyflakes.
57
    local,
2164.2.21 by Vincent Ladeuil
Take bundles into account.
58
    )
6138.3.1 by Jonathan Riddell
use gettext() in more files
59
from bzrlib.i18n import gettext
1996.3.3 by John Arbash Meinel
Shave off another 40ms by demand loading branch and bzrdir
60
""")
61
2164.2.1 by v.ladeuil+lp at free
First rough http branch redirection implementation.
62
from bzrlib.trace import (
5735.1.1 by Jelmer Vernooij
Move ControlDir.sprout to BzrDir.
63
    mutter,
2164.2.1 by v.ladeuil+lp at free
First rough http branch redirection implementation.
64
    note,
65
    )
3224.5.24 by Andrew Bennetts
More minor import tidying suggested by pyflakes.
66
67
from bzrlib import (
5904.1.2 by Martin Pool
Various pyflakes import fixes.
68
    config,
69
    controldir,
5712.3.8 by Jelmer Vernooij
Support lazy registration of BzrDir formats.
70
    registry,
2711.2.1 by Martin Pool
Deprecate BzrDir.create_repository
71
    )
5409.5.4 by Vincent Ladeuil
Deprecate BzrDir.generate_backup_name and use osutils.available_backup_name.
72
from bzrlib.symbol_versioning import (
73
    deprecated_in,
74
    deprecated_method,
75
    )
5363.2.2 by Jelmer Vernooij
Rename per_bzrdir => per_controldir.
76
77
5363.2.20 by Jelmer Vernooij
use controldir.X
78
class BzrDir(controldir.ControlDir):
1534.4.39 by Robert Collins
Basic BzrDir support.
79
    """A .bzr control diretory.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
80
1534.4.39 by Robert Collins
Basic BzrDir support.
81
    BzrDir instances let you create or open any of the things that can be
82
    found within .bzr - checkouts, branches and repositories.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
83
3407.2.13 by Martin Pool
Remove indirection through control_files to get transports
84
    :ivar transport:
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
85
        the transport which this bzr dir is rooted at (i.e. file:///.../.bzr/)
3407.2.13 by Martin Pool
Remove indirection through control_files to get transports
86
    :ivar root_transport:
2830.1.1 by Ian Clatworthy
bzrdir.py code clean-ups
87
        a transport connected to the directory this bzr was opened from
88
        (i.e. the parent directory holding the .bzr directory).
3416.2.1 by Martin Pool
Add BzrDir._get_file_mode and _get_dir_mode
89
90
    Everything in the bzrdir should have the same file permissions.
4160.1.1 by Robert Collins
Add a BzrDir.pre_open hook for use by the smart server gaol.
91
92
    :cvar hooks: An instance of BzrDirHooks.
1534.4.39 by Robert Collins
Basic BzrDir support.
93
    """
94
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
95
    def break_lock(self):
96
        """Invoke break_lock on the first object in the bzrdir.
97
98
        If there is a tree, the tree is opened and break_lock() called.
99
        Otherwise, branch is tried, and finally repository.
100
        """
1752.2.52 by Andrew Bennetts
Flesh out more Remote* methods needed to open and initialise remote branches/trees/repositories.
101
        # XXX: This seems more like a UI function than something that really
102
        # belongs in this class.
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
103
        try:
104
            thing_to_unlock = self.open_workingtree()
105
        except (errors.NotLocalUrl, errors.NoWorkingTree):
106
            try:
107
                thing_to_unlock = self.open_branch()
108
            except errors.NotBranchError:
109
                try:
110
                    thing_to_unlock = self.open_repository()
111
                except errors.NoRepositoryPresent:
112
                    return
113
        thing_to_unlock.break_lock()
114
1910.2.12 by Aaron Bentley
Implement knit repo format 2
115
    def check_conversion_target(self, target_format):
4634.2.1 by Robert Collins
Fix regression in upgrade introduced with the change to upgrade in rev 4622.
116
        """Check that a bzrdir as a whole can be converted to a new format."""
117
        # The only current restriction is that the repository content can be 
118
        # fetched compatibly with the target.
1910.2.12 by Aaron Bentley
Implement knit repo format 2
119
        target_repo_format = target_format.repository_format
4634.2.1 by Robert Collins
Fix regression in upgrade introduced with the change to upgrade in rev 4622.
120
        try:
121
            self.open_repository()._format.check_conversion_target(
122
                target_repo_format)
123
        except errors.NoRepositoryPresent:
124
            # No repo, no problem.
125
            pass
1910.2.12 by Aaron Bentley
Implement knit repo format 2
126
2475.3.1 by John Arbash Meinel
Fix bug #75721. Update the BzrDir api to add clone_on_transport()
127
    def clone_on_transport(self, transport, revision_id=None,
4294.2.2 by Robert Collins
Move use_existing and create_prefix all the way down to clone_on_transport, reducing duplicate work.
128
        force_new_repo=False, preserve_stacking=False, stacked_on=None,
5448.6.1 by Matthew Gordon
Added --no-tree option to pull. Needs testing and help text.
129
        create_prefix=False, use_existing_dir=True, no_tree=False):
2475.3.1 by John Arbash Meinel
Fix bug #75721. Update the BzrDir api to add clone_on_transport()
130
        """Clone this bzrdir and its contents to transport verbatim.
131
3242.3.36 by Aaron Bentley
Updates from review comments
132
        :param transport: The transport for the location to produce the clone
133
            at.  If the target directory does not exist, it will be created.
134
        :param revision_id: The tip revision-id to use for any branch or
135
            working tree.  If not None, then the clone operation may tune
2475.3.1 by John Arbash Meinel
Fix bug #75721. Update the BzrDir api to add clone_on_transport()
136
            itself to download less data.
3242.3.35 by Aaron Bentley
Cleanups and documentation
137
        :param force_new_repo: Do not use a shared repository for the target,
2475.3.1 by John Arbash Meinel
Fix bug #75721. Update the BzrDir api to add clone_on_transport()
138
                               even if one is available.
3242.3.22 by Aaron Bentley
Make clone stacking optional
139
        :param preserve_stacking: When cloning a stacked branch, stack the
140
            new branch on top of the other branch's stacked-on branch.
4294.2.2 by Robert Collins
Move use_existing and create_prefix all the way down to clone_on_transport, reducing duplicate work.
141
        :param create_prefix: Create any missing directories leading up to
142
            to_transport.
143
        :param use_existing_dir: Use an existing directory if one exists.
5664.1.1 by Jelmer Vernooij
Document no_tree option to ControlDir.clone_on_transport.
144
        :param no_tree: If set to true prevents creation of a working tree.
2475.3.1 by John Arbash Meinel
Fix bug #75721. Update the BzrDir api to add clone_on_transport()
145
        """
4294.2.4 by Robert Collins
Move dir, bzrdir and repo acquisition into a single method on bzrdir format.
146
        # Overview: put together a broad description of what we want to end up
147
        # with; then make as few api calls as possible to do it.
5363.2.2 by Jelmer Vernooij
Rename per_bzrdir => per_controldir.
148
4294.2.4 by Robert Collins
Move dir, bzrdir and repo acquisition into a single method on bzrdir format.
149
        # We may want to create a repo/branch/tree, if we do so what format
150
        # would we want for each:
3650.5.1 by Aaron Bentley
Fix push to use clone all the time.
151
        require_stacking = (stacked_on is not None)
4017.2.1 by Robert Collins
Add BzrDirFormatMeta1 test for the amount of rpc calls made initializing over the network.
152
        format = self.cloning_metadir(require_stacking)
5363.2.2 by Jelmer Vernooij
Rename per_bzrdir => per_controldir.
153
4294.2.4 by Robert Collins
Move dir, bzrdir and repo acquisition into a single method on bzrdir format.
154
        # Figure out what objects we want:
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
155
        try:
1534.6.6 by Robert Collins
Move find_repository to bzrdir, its not quite ideal there but its simpler and until someone chooses to vary the search by branch type its completely sufficient.
156
            local_repo = self.find_repository()
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
157
        except errors.NoRepositoryPresent:
1534.6.6 by Robert Collins
Move find_repository to bzrdir, its not quite ideal there but its simpler and until someone chooses to vary the search by branch type its completely sufficient.
158
            local_repo = None
3242.3.30 by Aaron Bentley
Handle adding fallback repositories in acquire_repository
159
        try:
160
            local_branch = self.open_branch()
161
        except errors.NotBranchError:
162
            local_branch = None
163
        else:
164
            # enable fallbacks when branch is not a branch reference
165
            if local_branch.repository.has_same_location(local_repo):
166
                local_repo = local_branch.repository
167
            if preserve_stacking:
168
                try:
3650.5.1 by Aaron Bentley
Fix push to use clone all the time.
169
                    stacked_on = local_branch.get_stacked_on_url()
3242.3.30 by Aaron Bentley
Handle adding fallback repositories in acquire_repository
170
                except (errors.UnstackableBranchFormat,
171
                        errors.UnstackableRepositoryFormat,
172
                        errors.NotStacked):
173
                    pass
4294.2.4 by Robert Collins
Move dir, bzrdir and repo acquisition into a single method on bzrdir format.
174
        # Bug: We create a metadir without knowing if it can support stacking,
175
        # we should look up the policy needs first, or just use it as a hint,
176
        # or something.
1534.6.6 by Robert Collins
Move find_repository to bzrdir, its not quite ideal there but its simpler and until someone chooses to vary the search by branch type its completely sufficient.
177
        if local_repo:
5448.6.1 by Matthew Gordon
Added --no-tree option to pull. Needs testing and help text.
178
            make_working_trees = local_repo.make_working_trees() and not no_tree
4294.2.4 by Robert Collins
Move dir, bzrdir and repo acquisition into a single method on bzrdir format.
179
            want_shared = local_repo.is_shared()
180
            repo_format_name = format.repository_format.network_name()
181
        else:
182
            make_working_trees = False
183
            want_shared = False
184
            repo_format_name = None
185
186
        result_repo, result, require_stacking, repository_policy = \
187
            format.initialize_on_transport_ex(transport,
188
            use_existing_dir=use_existing_dir, create_prefix=create_prefix,
189
            force_new_repo=force_new_repo, stacked_on=stacked_on,
190
            stack_on_pwd=self.root_transport.base,
191
            repo_format_name=repo_format_name,
192
            make_working_trees=make_working_trees, shared_repo=want_shared)
193
        if repo_format_name:
4307.2.2 by Robert Collins
Lock repositories created by BzrDirFormat.initialize_on_transport_ex.
194
            try:
195
                # If the result repository is in the same place as the
196
                # resulting bzr dir, it will have no content, further if the
197
                # result is not stacked then we know all content should be
198
                # copied, and finally if we are copying up to a specific
199
                # revision_id then we can use the pending-ancestry-result which
200
                # does not require traversing all of history to describe it.
5158.6.9 by Martin Pool
Simplify various code to use user_url
201
                if (result_repo.user_url == result.user_url
202
                    and not require_stacking and
4307.2.2 by Robert Collins
Lock repositories created by BzrDirFormat.initialize_on_transport_ex.
203
                    revision_id is not None):
6341.1.4 by Jelmer Vernooij
Move more functionality to vf_search.
204
                    fetch_spec = vf_search.PendingAncestryResult(
4307.2.2 by Robert Collins
Lock repositories created by BzrDirFormat.initialize_on_transport_ex.
205
                        [revision_id], local_repo)
206
                    result_repo.fetch(local_repo, fetch_spec=fetch_spec)
207
                else:
208
                    result_repo.fetch(local_repo, revision_id=revision_id)
209
            finally:
210
                result_repo.unlock()
3242.3.30 by Aaron Bentley
Handle adding fallback repositories in acquire_repository
211
        else:
4307.2.2 by Robert Collins
Lock repositories created by BzrDirFormat.initialize_on_transport_ex.
212
            if result_repo is not None:
213
                raise AssertionError('result_repo not None(%r)' % result_repo)
1534.6.6 by Robert Collins
Move find_repository to bzrdir, its not quite ideal there but its simpler and until someone chooses to vary the search by branch type its completely sufficient.
214
        # 1 if there is a branch present
215
        #   make sure its content is available in the target repository
216
        #   clone it.
3242.3.37 by Aaron Bentley
Updates from reviews
217
        if local_branch is not None:
4050.1.1 by Robert Collins
Fix race condition with branch hooks during cloning when the new branch is stacked.
218
            result_branch = local_branch.clone(result, revision_id=revision_id,
219
                repository_policy=repository_policy)
4044.1.5 by Robert Collins
Stop trying to create working trees during clone when the target bzrdir cannot have a local abspath created for it.
220
        try:
221
            # Cheaper to check if the target is not local, than to try making
222
            # the tree and fail.
223
            result.root_transport.local_abspath('.')
224
            if result_repo is None or result_repo.make_working_trees():
6182.1.18 by Jelmer Vernooij
Fix last test.
225
                self.open_workingtree().clone(result, revision_id=revision_id)
4044.1.5 by Robert Collins
Stop trying to create working trees during clone when the target bzrdir cannot have a local abspath created for it.
226
        except (errors.NoWorkingTree, errors.NotLocalUrl):
227
            pass
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
228
        return result
229
1685.1.61 by Martin Pool
[broken] Change BzrDir._make_tail to use urlutils.split
230
    # TODO: This should be given a Transport, and should chdir up; otherwise
231
    # this will open a new connection.
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
232
    def _make_tail(self, url):
6039.1.9 by Jelmer Vernooij
Fix weave tests.
233
        t = _mod_transport.get_transport(url)
2475.3.3 by John Arbash Meinel
Change calls to try/mkdir('.')/except FileExists to ensure_base()
234
        t.ensure_base()
2475.3.1 by John Arbash Meinel
Fix bug #75721. Update the BzrDir api to add clone_on_transport()
235
3242.3.32 by Aaron Bentley
Defer handling relative stacking URLs as late as possible.
236
    def determine_repository_policy(self, force_new_repo=False, stack_on=None,
3242.3.40 by Aaron Bentley
Turn failing test into KnownFailure
237
                                    stack_on_pwd=None, require_stacking=False):
3242.2.13 by Aaron Bentley
Update docs
238
        """Return an object representing a policy to use.
239
4165.2.1 by Robert Collins
Fix bzr failing to stack when a server requests it and the branch it is pushing from cannot stack but the branch it should stack on can.
240
        This controls whether a new repository is created, and the format of
241
        that repository, or some existing shared repository used instead.
3242.3.35 by Aaron Bentley
Cleanups and documentation
242
243
        If stack_on is supplied, will not seek a containing shared repo.
3575.2.2 by Martin Pool
branch --stacked should force a stacked format
244
3242.3.35 by Aaron Bentley
Cleanups and documentation
245
        :param force_new_repo: If True, require a new repository to be created.
246
        :param stack_on: If supplied, the location to stack on.  If not
247
            supplied, a default_stack_on location may be used.
248
        :param stack_on_pwd: If stack_on is relative, the location it is
249
            relative to.
3242.2.13 by Aaron Bentley
Update docs
250
        """
3242.3.3 by Aaron Bentley
Use _find_containing to determine repository policy
251
        def repository_policy(found_bzrdir):
3242.3.4 by Aaron Bentley
Initial determination of stacking policy
252
            stack_on = None
3242.3.32 by Aaron Bentley
Defer handling relative stacking URLs as late as possible.
253
            stack_on_pwd = None
3641.1.1 by John Arbash Meinel
Merge in 1.6rc5 and revert disabling default stack on policy
254
            config = found_bzrdir.get_config()
3242.3.4 by Aaron Bentley
Initial determination of stacking policy
255
            stop = False
4288.1.1 by Robert Collins
Add support for a RemoteBzrDirConfig to support optimising push operations which need to look for default stacking locations.
256
            stack_on = config.get_default_stack_on()
257
            if stack_on is not None:
5158.6.9 by Martin Pool
Simplify various code to use user_url
258
                stack_on_pwd = found_bzrdir.user_url
4288.1.1 by Robert Collins
Add support for a RemoteBzrDirConfig to support optimising push operations which need to look for default stacking locations.
259
                stop = True
3242.3.3 by Aaron Bentley
Use _find_containing to determine repository policy
260
            # does it have a repository ?
261
            try:
262
                repository = found_bzrdir.open_repository()
263
            except errors.NoRepositoryPresent:
3242.3.4 by Aaron Bentley
Initial determination of stacking policy
264
                repository = None
265
            else:
5158.6.9 by Martin Pool
Simplify various code to use user_url
266
                if (found_bzrdir.user_url != self.user_url 
267
                    and not repository.is_shared()):
4165.2.1 by Robert Collins
Fix bzr failing to stack when a server requests it and the branch it is pushing from cannot stack but the branch it should stack on can.
268
                    # Don't look higher, can't use a higher shared repo.
3242.3.4 by Aaron Bentley
Initial determination of stacking policy
269
                    repository = None
4165.2.1 by Robert Collins
Fix bzr failing to stack when a server requests it and the branch it is pushing from cannot stack but the branch it should stack on can.
270
                    stop = True
3242.3.4 by Aaron Bentley
Initial determination of stacking policy
271
                else:
272
                    stop = True
273
            if not stop:
3242.3.3 by Aaron Bentley
Use _find_containing to determine repository policy
274
                return None, False
3242.3.4 by Aaron Bentley
Initial determination of stacking policy
275
            if repository:
3242.3.32 by Aaron Bentley
Defer handling relative stacking URLs as late as possible.
276
                return UseExistingRepository(repository, stack_on,
3242.3.40 by Aaron Bentley
Turn failing test into KnownFailure
277
                    stack_on_pwd, require_stacking=require_stacking), True
3242.3.3 by Aaron Bentley
Use _find_containing to determine repository policy
278
            else:
3242.3.40 by Aaron Bentley
Turn failing test into KnownFailure
279
                return CreateRepository(self, stack_on, stack_on_pwd,
280
                    require_stacking=require_stacking), True
3242.3.3 by Aaron Bentley
Use _find_containing to determine repository policy
281
3242.2.1 by Aaron Bentley
Abstract policy decisions into determine_repository_policy
282
        if not force_new_repo:
3242.3.30 by Aaron Bentley
Handle adding fallback repositories in acquire_repository
283
            if stack_on is None:
284
                policy = self._find_containing(repository_policy)
285
                if policy is not None:
286
                    return policy
287
            else:
288
                try:
289
                    return UseExistingRepository(self.open_repository(),
3242.3.40 by Aaron Bentley
Turn failing test into KnownFailure
290
                        stack_on, stack_on_pwd,
291
                        require_stacking=require_stacking)
3242.3.30 by Aaron Bentley
Handle adding fallback repositories in acquire_repository
292
                except errors.NoRepositoryPresent:
293
                    pass
3242.3.40 by Aaron Bentley
Turn failing test into KnownFailure
294
        return CreateRepository(self, stack_on, stack_on_pwd,
295
                                require_stacking=require_stacking)
3242.2.1 by Aaron Bentley
Abstract policy decisions into determine_repository_policy
296
1534.6.11 by Robert Collins
Review feedback.
297
    def _find_or_create_repository(self, force_new_repo):
298
        """Create a new repository if needed, returning the repository."""
3242.2.10 by Aaron Bentley
Rename RepositoryPolicy.apply to acquire_repository
299
        policy = self.determine_repository_policy(force_new_repo)
4070.9.2 by Andrew Bennetts
Rough prototype of allowing a SearchResult to be passed to fetch, and using that to improve network conversations.
300
        return policy.acquire_repository()[0]
3242.2.10 by Aaron Bentley
Rename RepositoryPolicy.apply to acquire_repository
301
5735.1.1 by Jelmer Vernooij
Move ControlDir.sprout to BzrDir.
302
    def _find_source_repo(self, add_cleanup, source_branch):
303
        """Find the source branch and repo for a sprout operation.
304
        
305
        This is helper intended for use by _sprout.
306
307
        :returns: (source_branch, source_repository).  Either or both may be
308
            None.  If not None, they will be read-locked (and their unlock(s)
309
            scheduled via the add_cleanup param).
310
        """
311
        if source_branch is not None:
312
            add_cleanup(source_branch.lock_read().unlock)
313
            return source_branch, source_branch.repository
314
        try:
315
            source_branch = self.open_branch()
316
            source_repository = source_branch.repository
317
        except errors.NotBranchError:
318
            source_branch = None
319
            try:
320
                source_repository = self.open_repository()
321
            except errors.NoRepositoryPresent:
322
                source_repository = None
323
            else:
324
                add_cleanup(source_repository.lock_read().unlock)
325
        else:
326
            add_cleanup(source_branch.lock_read().unlock)
327
        return source_branch, source_repository
328
329
    def sprout(self, url, revision_id=None, force_new_repo=False,
330
               recurse='down', possible_transports=None,
331
               accelerator_tree=None, hardlink=False, stacked=False,
332
               source_branch=None, create_tree_if_local=True):
333
        """Create a copy of this controldir prepared for use as a new line of
334
        development.
335
336
        If url's last component does not exist, it will be created.
337
338
        Attributes related to the identity of the source branch like
339
        branch nickname will be cleaned, a working tree is created
340
        whether one existed before or not; and a local branch is always
341
        created.
342
343
        if revision_id is not None, then the clone operation may tune
344
            itself to download less data.
5891.1.2 by Andrew Bennetts
Fix a bunch of docstring formatting nits, making pydoctor a bit happier.
345
5735.1.1 by Jelmer Vernooij
Move ControlDir.sprout to BzrDir.
346
        :param accelerator_tree: A tree which can be used for retrieving file
347
            contents more quickly than the revision tree, i.e. a workingtree.
348
            The revision tree will be used for cases where accelerator_tree's
349
            content is different.
350
        :param hardlink: If true, hard-link files from accelerator_tree,
351
            where possible.
352
        :param stacked: If true, create a stacked branch referring to the
353
            location of this control directory.
354
        :param create_tree_if_local: If true, a working-tree will be created
355
            when working locally.
356
        """
357
        operation = cleanup.OperationWithCleanups(self._sprout)
358
        return operation.run(url, revision_id=revision_id,
359
            force_new_repo=force_new_repo, recurse=recurse,
360
            possible_transports=possible_transports,
361
            accelerator_tree=accelerator_tree, hardlink=hardlink,
362
            stacked=stacked, source_branch=source_branch,
363
            create_tree_if_local=create_tree_if_local)
364
365
    def _sprout(self, op, url, revision_id=None, force_new_repo=False,
366
               recurse='down', possible_transports=None,
367
               accelerator_tree=None, hardlink=False, stacked=False,
368
               source_branch=None, create_tree_if_local=True):
369
        add_cleanup = op.add_cleanup
370
        fetch_spec_factory = fetch.FetchSpecFactory()
371
        if revision_id is not None:
372
            fetch_spec_factory.add_revision_ids([revision_id])
373
            fetch_spec_factory.source_branch_stop_revision_id = revision_id
6305.3.1 by Jelmer Vernooij
Save a connection to the server when using --stacked.
374
        if possible_transports is None:
375
            possible_transports = []
376
        else:
377
            possible_transports = list(possible_transports) + [
6305.3.5 by Jelmer Vernooij
Avoid .control_transport, as it triggers _ensure_real.
378
                self.root_transport]
5735.1.1 by Jelmer Vernooij
Move ControlDir.sprout to BzrDir.
379
        target_transport = _mod_transport.get_transport(url,
380
            possible_transports)
381
        target_transport.ensure_base()
382
        cloning_format = self.cloning_metadir(stacked)
383
        # Create/update the result branch
5268.8.11 by Jelmer Vernooij
Fix sprouting into control directories.
384
        try:
385
            result = controldir.ControlDir.open_from_transport(target_transport)
386
        except errors.NotBranchError:
387
            result = cloning_format.initialize_on_transport(target_transport)
5735.1.1 by Jelmer Vernooij
Move ControlDir.sprout to BzrDir.
388
        source_branch, source_repository = self._find_source_repo(
389
            add_cleanup, source_branch)
390
        fetch_spec_factory.source_branch = source_branch
391
        # if a stacked branch wasn't requested, we don't create one
392
        # even if the origin was stacked
393
        if stacked and source_branch is not None:
394
            stacked_branch_url = self.root_transport.base
395
        else:
396
            stacked_branch_url = None
397
        repository_policy = result.determine_repository_policy(
398
            force_new_repo, stacked_branch_url, require_stacking=stacked)
6305.3.1 by Jelmer Vernooij
Save a connection to the server when using --stacked.
399
        result_repo, is_new_repo = repository_policy.acquire_repository(
400
            possible_transports=possible_transports)
5735.1.1 by Jelmer Vernooij
Move ControlDir.sprout to BzrDir.
401
        add_cleanup(result_repo.lock_write().unlock)
402
        fetch_spec_factory.source_repo = source_repository
403
        fetch_spec_factory.target_repo = result_repo
404
        if stacked or (len(result_repo._fallback_repositories) != 0):
405
            target_repo_kind = fetch.TargetRepoKinds.STACKED
406
        elif is_new_repo:
407
            target_repo_kind = fetch.TargetRepoKinds.EMPTY
408
        else:
409
            target_repo_kind = fetch.TargetRepoKinds.PREEXISTING
410
        fetch_spec_factory.target_repo_kind = target_repo_kind
411
        if source_repository is not None:
412
            fetch_spec = fetch_spec_factory.make_fetch_spec()
413
            result_repo.fetch(source_repository, fetch_spec=fetch_spec)
414
415
        if source_branch is None:
416
            # this is for sprouting a controldir without a branch; is that
417
            # actually useful?
418
            # Not especially, but it's part of the contract.
419
            result_branch = result.create_branch()
420
        else:
421
            result_branch = source_branch.sprout(result,
422
                revision_id=revision_id, repository_policy=repository_policy,
423
                repository=result_repo)
424
        mutter("created new branch %r" % (result_branch,))
425
426
        # Create/update the result working tree
5268.8.11 by Jelmer Vernooij
Fix sprouting into control directories.
427
        if (create_tree_if_local and not result.has_workingtree() and
5735.1.1 by Jelmer Vernooij
Move ControlDir.sprout to BzrDir.
428
            isinstance(target_transport, local.LocalTransport) and
429
            (result_repo is None or result_repo.make_working_trees())):
430
            wt = result.create_workingtree(accelerator_tree=accelerator_tree,
431
                hardlink=hardlink, from_branch=result_branch)
432
            wt.lock_write()
433
            try:
434
                if wt.path2id('') is None:
435
                    try:
436
                        wt.set_root_id(self.open_workingtree.get_root_id())
437
                    except errors.NoWorkingTree:
438
                        pass
439
            finally:
440
                wt.unlock()
441
        else:
442
            wt = None
443
        if recurse == 'down':
444
            basis = None
445
            if wt is not None:
446
                basis = wt.basis_tree()
447
            elif result_branch is not None:
448
                basis = result_branch.basis_tree()
449
            elif source_branch is not None:
450
                basis = source_branch.basis_tree()
451
            if basis is not None:
452
                add_cleanup(basis.lock_read().unlock)
453
                subtrees = basis.iter_references()
454
            else:
455
                subtrees = []
456
            for path, file_id in subtrees:
457
                target = urlutils.join(url, urlutils.escape(path))
458
                sublocation = source_branch.reference_parent(file_id, path)
459
                sublocation.bzrdir.sprout(target,
460
                    basis.get_reference_revision(file_id, path),
461
                    force_new_repo=force_new_repo, recurse=recurse,
462
                    stacked=stacked)
463
        return result
464
5409.5.4 by Vincent Ladeuil
Deprecate BzrDir.generate_backup_name and use osutils.available_backup_name.
465
    @deprecated_method(deprecated_in((2, 3, 0)))
5340.8.4 by Marius Kruger
* gen_backup_name => generate_backup_name
466
    def generate_backup_name(self, base):
5409.5.4 by Vincent Ladeuil
Deprecate BzrDir.generate_backup_name and use osutils.available_backup_name.
467
        return self._available_backup_name(base)
468
469
    def _available_backup_name(self, base):
5409.5.8 by Vincent Ladeuil
Be more explicit about race conditions and LBYL being discouraged
470
        """Find a non-existing backup file name based on base.
471
472
        See bzrlib.osutils.available_backup_name about race conditions.
473
        """
5409.5.4 by Vincent Ladeuil
Deprecate BzrDir.generate_backup_name and use osutils.available_backup_name.
474
        return osutils.available_backup_name(base, self.root_transport.has)
5340.8.1 by Marius Kruger
* make the backup file name generator in bzrdir available to others
475
3872.3.2 by Jelmer Vernooij
make backup_bzrdir determine the name for the backup files.
476
    def backup_bzrdir(self):
3872.3.1 by Jelmer Vernooij
Allow BzrDir implementation to implement backing up of control directory.
477
        """Backup this bzr control directory.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
478
3872.3.2 by Jelmer Vernooij
make backup_bzrdir determine the name for the backup files.
479
        :return: Tuple with old path name and new path name
3872.3.1 by Jelmer Vernooij
Allow BzrDir implementation to implement backing up of control directory.
480
        """
5035.4.1 by Parth Malwankar
fixes 335033.
481
3943.2.4 by Martin Pool
Move backup progress indicators from upgrade.py into backup_bzrdir, and tweak text
482
        pb = ui.ui_factory.nested_progress_bar()
483
        try:
484
            old_path = self.root_transport.abspath('.bzr')
5409.5.4 by Vincent Ladeuil
Deprecate BzrDir.generate_backup_name and use osutils.available_backup_name.
485
            backup_dir = self._available_backup_name('backup.bzr')
5035.4.2 by Parth Malwankar
name_gen now works with all transports.
486
            new_path = self.root_transport.abspath(backup_dir)
6147.1.1 by Jonathan Riddell
use .format() instead of % for string formatting where there are multiple formats in one string to allow for translations
487
            ui.ui_factory.note(gettext('making backup of {0}\n  to {1}').format(
6072.3.2 by Jelmer Vernooij
Use utf8 as encoding for urls passed to note().
488
                urlutils.unescape_for_display(old_path, 'utf-8'),
489
                urlutils.unescape_for_display(new_path, 'utf-8')))
5035.4.2 by Parth Malwankar
name_gen now works with all transports.
490
            self.root_transport.copy_tree('.bzr', backup_dir)
3943.2.4 by Martin Pool
Move backup progress indicators from upgrade.py into backup_bzrdir, and tweak text
491
            return (old_path, new_path)
492
        finally:
493
            pb.finished()
3872.3.1 by Jelmer Vernooij
Allow BzrDir implementation to implement backing up of control directory.
494
2830.1.2 by Ian Clatworthy
Incorporate feedback from poolie's review
495
    def retire_bzrdir(self, limit=10000):
2255.14.1 by Martin Pool
Add BzrDir.retire_bzrdir and partly fix subsume
496
        """Permanently disable the bzrdir.
497
498
        This is done by renaming it to give the user some ability to recover
499
        if there was a problem.
500
501
        This will have horrible consequences if anyone has anything locked or
502
        in use.
2830.1.2 by Ian Clatworthy
Incorporate feedback from poolie's review
503
        :param limit: number of times to retry
2255.14.1 by Martin Pool
Add BzrDir.retire_bzrdir and partly fix subsume
504
        """
2830.1.2 by Ian Clatworthy
Incorporate feedback from poolie's review
505
        i  = 0
506
        while True:
2255.14.1 by Martin Pool
Add BzrDir.retire_bzrdir and partly fix subsume
507
            try:
508
                to_path = '.bzr.retired.%d' % i
509
                self.root_transport.rename('.bzr', to_path)
6138.3.1 by Jonathan Riddell
use gettext() in more files
510
                note(gettext("renamed {0} to {1}").format(
511
                    self.root_transport.abspath('.bzr'), to_path))
2830.1.1 by Ian Clatworthy
bzrdir.py code clean-ups
512
                return
2255.14.1 by Martin Pool
Add BzrDir.retire_bzrdir and partly fix subsume
513
            except (errors.TransportError, IOError, errors.PathError):
2830.1.2 by Ian Clatworthy
Incorporate feedback from poolie's review
514
                i += 1
515
                if i > limit:
516
                    raise
517
                else:
518
                    pass
2255.14.1 by Martin Pool
Add BzrDir.retire_bzrdir and partly fix subsume
519
3242.3.2 by Aaron Bentley
Split _find_containing out of find_repository
520
    def _find_containing(self, evaluate):
3242.2.13 by Aaron Bentley
Update docs
521
        """Find something in a containing control directory.
522
523
        This method will scan containing control dirs, until it finds what
524
        it is looking for, decides that it will never find it, or runs out
525
        of containing control directories to check.
526
527
        It is used to implement find_repository and
528
        determine_repository_policy.
529
530
        :param evaluate: A function returning (value, stop).  If stop is True,
531
            the value will be returned.
532
        """
3242.3.2 by Aaron Bentley
Split _find_containing out of find_repository
533
        found_bzrdir = self
534
        while True:
535
            result, stop = evaluate(found_bzrdir)
536
            if stop:
537
                return result
538
            next_transport = found_bzrdir.root_transport.clone('..')
5158.6.9 by Martin Pool
Simplify various code to use user_url
539
            if (found_bzrdir.user_url == next_transport.base):
3242.3.2 by Aaron Bentley
Split _find_containing out of find_repository
540
                # top of the file system
541
                return None
542
            # find the next containing bzrdir
543
            try:
6207.3.1 by jelmer at samba
use classmethods.
544
                found_bzrdir = self.open_containing_from_transport(
3242.3.2 by Aaron Bentley
Split _find_containing out of find_repository
545
                    next_transport)[0]
546
            except errors.NotBranchError:
547
                return None
548
1534.6.6 by Robert Collins
Move find_repository to bzrdir, its not quite ideal there but its simpler and until someone chooses to vary the search by branch type its completely sufficient.
549
    def find_repository(self):
2830.1.1 by Ian Clatworthy
bzrdir.py code clean-ups
550
        """Find the repository that should be used.
1534.6.6 by Robert Collins
Move find_repository to bzrdir, its not quite ideal there but its simpler and until someone chooses to vary the search by branch type its completely sufficient.
551
552
        This does not require a branch as we use it to find the repo for
553
        new branches as well as to hook existing branches up to their
554
        repository.
555
        """
3242.3.2 by Aaron Bentley
Split _find_containing out of find_repository
556
        def usable_repository(found_bzrdir):
1725.2.5 by Robert Collins
Bugfix create_branch_convenience at the root of a file system to not loop
557
            # does it have a repository ?
1534.6.6 by Robert Collins
Move find_repository to bzrdir, its not quite ideal there but its simpler and until someone chooses to vary the search by branch type its completely sufficient.
558
            try:
559
                repository = found_bzrdir.open_repository()
560
            except errors.NoRepositoryPresent:
3242.3.2 by Aaron Bentley
Split _find_containing out of find_repository
561
                return None, False
5158.6.9 by Martin Pool
Simplify various code to use user_url
562
            if found_bzrdir.user_url == self.user_url:
3242.2.5 by Aaron Bentley
Avoid unnecessary is_shared check
563
                return repository, True
564
            elif repository.is_shared():
3242.3.2 by Aaron Bentley
Split _find_containing out of find_repository
565
                return repository, True
1534.6.6 by Robert Collins
Move find_repository to bzrdir, its not quite ideal there but its simpler and until someone chooses to vary the search by branch type its completely sufficient.
566
            else:
3242.2.5 by Aaron Bentley
Avoid unnecessary is_shared check
567
                return None, True
3242.3.2 by Aaron Bentley
Split _find_containing out of find_repository
568
569
        found_repo = self._find_containing(usable_repository)
570
        if found_repo is None:
571
            raise errors.NoRepositoryPresent(self)
572
        return found_repo
1534.6.6 by Robert Collins
Move find_repository to bzrdir, its not quite ideal there but its simpler and until someone chooses to vary the search by branch type its completely sufficient.
573
3416.2.1 by Martin Pool
Add BzrDir._get_file_mode and _get_dir_mode
574
    def _find_creation_modes(self):
575
        """Determine the appropriate modes for files and directories.
3641.2.1 by John Arbash Meinel
Fix bug #259855, if a Transport returns 0 for permission bits, ignore it
576
3416.2.1 by Martin Pool
Add BzrDir._get_file_mode and _get_dir_mode
577
        They're always set to be consistent with the base directory,
578
        assuming that this transport allows setting modes.
579
        """
580
        # TODO: Do we need or want an option (maybe a config setting) to turn
581
        # this off or override it for particular locations? -- mbp 20080512
582
        if self._mode_check_done:
583
            return
584
        self._mode_check_done = True
585
        try:
586
            st = self.transport.stat('.')
587
        except errors.TransportNotPossible:
588
            self._dir_mode = None
589
            self._file_mode = None
590
        else:
591
            # Check the directory mode, but also make sure the created
592
            # directories and files are read-write for this user. This is
593
            # mostly a workaround for filesystems which lie about being able to
594
            # write to a directory (cygwin & win32)
3641.2.1 by John Arbash Meinel
Fix bug #259855, if a Transport returns 0 for permission bits, ignore it
595
            if (st.st_mode & 07777 == 00000):
596
                # FTP allows stat but does not return dir/file modes
597
                self._dir_mode = None
598
                self._file_mode = None
599
            else:
600
                self._dir_mode = (st.st_mode & 07777) | 00700
601
                # Remove the sticky and execute bits for files
602
                self._file_mode = self._dir_mode & ~07111
3416.2.1 by Martin Pool
Add BzrDir._get_file_mode and _get_dir_mode
603
604
    def _get_file_mode(self):
605
        """Return Unix mode for newly created files, or None.
606
        """
607
        if not self._mode_check_done:
608
            self._find_creation_modes()
609
        return self._file_mode
610
611
    def _get_dir_mode(self):
612
        """Return Unix mode for newly created directories, or None.
613
        """
614
        if not self._mode_check_done:
615
            self._find_creation_modes()
616
        return self._dir_mode
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
617
3242.1.1 by Aaron Bentley
Implement BzrDir configuration
618
    def get_config(self):
4288.1.1 by Robert Collins
Add support for a RemoteBzrDirConfig to support optimising push operations which need to look for default stacking locations.
619
        """Get configuration for this BzrDir."""
620
        return config.BzrDirConfig(self)
621
622
    def _get_config(self):
623
        """By default, no configuration is available."""
624
        return None
3242.1.1 by Aaron Bentley
Implement BzrDir configuration
625
1534.4.39 by Robert Collins
Basic BzrDir support.
626
    def __init__(self, _transport, _format):
627
        """Initialize a Bzr control dir object.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
628
1534.4.39 by Robert Collins
Basic BzrDir support.
629
        Only really common logic should reside here, concrete classes should be
630
        made with varying behaviours.
631
1534.4.53 by Robert Collins
Review feedback from John Meinel.
632
        :param _format: the format that is creating this BzrDir instance.
633
        :param _transport: the transport this dir is based at.
1534.4.39 by Robert Collins
Basic BzrDir support.
634
        """
635
        self._format = _format
5158.6.1 by Martin Pool
Add ControlComponent interface and make BzrDir implement it
636
        # these are also under the more standard names of 
637
        # control_transport and user_transport
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
638
        self.transport = _transport.clone('.bzr')
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
639
        self.root_transport = _transport
3416.2.1 by Martin Pool
Add BzrDir._get_file_mode and _get_dir_mode
640
        self._mode_check_done = False
5363.2.2 by Jelmer Vernooij
Rename per_bzrdir => per_controldir.
641
5158.6.1 by Martin Pool
Add ControlComponent interface and make BzrDir implement it
642
    @property 
643
    def user_transport(self):
644
        return self.root_transport
5363.2.2 by Jelmer Vernooij
Rename per_bzrdir => per_controldir.
645
5158.6.1 by Martin Pool
Add ControlComponent interface and make BzrDir implement it
646
    @property
647
    def control_transport(self):
648
        return self.transport
1534.4.39 by Robert Collins
Basic BzrDir support.
649
1713.1.9 by Robert Collins
Paired performance tuning of bzr add. (Robert Collins, Martin Pool).
650
    def is_control_filename(self, filename):
651
        """True if filename is the name of a path which is reserved for bzrdir's.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
652
1713.1.9 by Robert Collins
Paired performance tuning of bzr add. (Robert Collins, Martin Pool).
653
        :param filename: A filename within the root transport of this bzrdir.
654
655
        This is true IF and ONLY IF the filename is part of the namespace reserved
656
        for bzr control dirs. Currently this is the '.bzr' directory in the root
5363.2.2 by Jelmer Vernooij
Rename per_bzrdir => per_controldir.
657
        of the root_transport. 
1713.1.9 by Robert Collins
Paired performance tuning of bzr add. (Robert Collins, Martin Pool).
658
        """
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
659
        # this might be better on the BzrDirFormat class because it refers to
660
        # all the possible bzrdir disk formats.
661
        # This method is tested via the workingtree is_control_filename tests-
2830.1.1 by Ian Clatworthy
bzrdir.py code clean-ups
662
        # it was extracted from WorkingTree.is_control_filename. If the method's
663
        # contract is extended beyond the current trivial implementation, please
1713.1.9 by Robert Collins
Paired performance tuning of bzr add. (Robert Collins, Martin Pool).
664
        # add new tests for it to the appropriate place.
665
        return filename == '.bzr' or filename.startswith('.bzr/')
666
2018.5.96 by Andrew Bennetts
Merge from bzr.dev, resolving the worst of the semantic conflicts, but there's
667
    def _cloning_metadir(self):
3575.2.2 by Martin Pool
branch --stacked should force a stacked format
668
        """Produce a metadir suitable for cloning with.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
669
3575.2.2 by Martin Pool
branch --stacked should force a stacked format
670
        :returns: (destination_bzrdir_format, source_repository)
671
        """
2387.1.1 by Robert Collins
Remove the --basis parameter to clone etc. (Robert Collins)
672
        result_format = self._format.__class__()
673
        try:
1910.2.41 by Aaron Bentley
Clean up clone format creation
674
            try:
4160.2.6 by Andrew Bennetts
Add ignore_fallbacks flag.
675
                branch = self.open_branch(ignore_fallbacks=True)
2387.1.1 by Robert Collins
Remove the --basis parameter to clone etc. (Robert Collins)
676
                source_repository = branch.repository
3650.2.5 by Aaron Bentley
Stop creating a new instance
677
                result_format._branch_format = branch._format
1910.2.41 by Aaron Bentley
Clean up clone format creation
678
            except errors.NotBranchError:
679
                source_branch = None
2387.1.1 by Robert Collins
Remove the --basis parameter to clone etc. (Robert Collins)
680
                source_repository = self.open_repository()
2305.3.1 by Andrew Bennetts
Tidy up BzrDir.cloning_metadir: bogus try/except, and basis argument isn't actually used.
681
        except errors.NoRepositoryPresent:
2100.3.24 by Aaron Bentley
Get all tests passing again
682
            source_repository = None
2305.3.1 by Andrew Bennetts
Tidy up BzrDir.cloning_metadir: bogus try/except, and basis argument isn't actually used.
683
        else:
2018.5.138 by Robert Collins
Merge bzr.dev.
684
            # XXX TODO: This isinstance is here because we have not implemented
685
            # the fix recommended in bug # 103195 - to delegate this choice the
686
            # repository itself.
2018.5.94 by Andrew Bennetts
Various small changes in aid of making tests pass (including deleting one invalid test).
687
            repo_format = source_repository._format
3705.2.1 by Andrew Bennetts
Possible fix for bug 269214
688
            if isinstance(repo_format, remote.RemoteRepositoryFormat):
689
                source_repository._ensure_real()
690
                repo_format = source_repository._real_repository._format
691
            result_format.repository_format = repo_format
2100.3.28 by Aaron Bentley
Make sprout recursive
692
        try:
2323.5.19 by Martin Pool
No upgrade recommendation on source when cloning
693
            # TODO: Couldn't we just probe for the format in these cases,
694
            # rather than opening the whole tree?  It would be a little
695
            # faster. mbp 20070401
696
            tree = self.open_workingtree(recommend_upgrade=False)
2100.3.28 by Aaron Bentley
Make sprout recursive
697
        except (errors.NoWorkingTree, errors.NotLocalUrl):
698
            result_format.workingtree_format = None
699
        else:
700
            result_format.workingtree_format = tree._format.__class__()
2100.3.21 by Aaron Bentley
Work on checking out by-reference trees
701
        return result_format, source_repository
702
3650.3.13 by Aaron Bentley
Make cloning_metadir handle stacking requirements
703
    def cloning_metadir(self, require_stacking=False):
2100.3.32 by Aaron Bentley
fix tree format, basis_tree call, in sprout
704
        """Produce a metadir suitable for cloning or sprouting with.
1910.2.41 by Aaron Bentley
Clean up clone format creation
705
2100.3.32 by Aaron Bentley
fix tree format, basis_tree call, in sprout
706
        These operations may produce workingtrees (yes, even though they're
2830.1.1 by Ian Clatworthy
bzrdir.py code clean-ups
707
        "cloning" something that doesn't have a tree), so a viable workingtree
2100.3.32 by Aaron Bentley
fix tree format, basis_tree call, in sprout
708
        format must be selected.
3575.2.2 by Martin Pool
branch --stacked should force a stacked format
709
3650.3.13 by Aaron Bentley
Make cloning_metadir handle stacking requirements
710
        :require_stacking: If True, non-stackable formats will be upgraded
711
            to similar stackable formats.
6207.3.1 by jelmer at samba
use classmethods.
712
        :returns: a ControlDirFormat with all component formats either set
3650.3.13 by Aaron Bentley
Make cloning_metadir handle stacking requirements
713
            appropriately or set to None if that component should not be
3575.2.2 by Martin Pool
branch --stacked should force a stacked format
714
            created.
2100.3.32 by Aaron Bentley
fix tree format, basis_tree call, in sprout
715
        """
2100.3.21 by Aaron Bentley
Work on checking out by-reference trees
716
        format, repository = self._cloning_metadir()
2100.3.32 by Aaron Bentley
fix tree format, basis_tree call, in sprout
717
        if format._workingtree_format is None:
4294.2.4 by Robert Collins
Move dir, bzrdir and repo acquisition into a single method on bzrdir format.
718
            # No tree in self.
2100.3.34 by Aaron Bentley
Fix BzrDir.cloning_metadir with no format
719
            if repository is None:
4294.2.4 by Robert Collins
Move dir, bzrdir and repo acquisition into a single method on bzrdir format.
720
                # No repository either
2100.3.34 by Aaron Bentley
Fix BzrDir.cloning_metadir with no format
721
                return format
4294.2.4 by Robert Collins
Move dir, bzrdir and repo acquisition into a single method on bzrdir format.
722
            # We have a repository, so set a working tree? (Why? This seems to
723
            # contradict the stated return value in the docstring).
2100.3.21 by Aaron Bentley
Work on checking out by-reference trees
724
            tree_format = repository._format._matchingbzrdir.workingtree_format
2100.3.28 by Aaron Bentley
Make sprout recursive
725
            format.workingtree_format = tree_format.__class__()
3904.3.1 by Andrew Bennetts
Probable fix for GaryvdM's bug when pushing a stacked qbzr branch to Launchpad.
726
        if require_stacking:
727
            format.require_stacking()
3650.3.13 by Aaron Bentley
Make cloning_metadir handle stacking requirements
728
        return format
729
5699.4.1 by Jelmer Vernooij
Move get_branch_transport, .get_workingtree_transport and .get_repository_transport
730
    def get_branch_transport(self, branch_format, name=None):
5699.4.5 by Jelmer Vernooij
Refer to BzrDir, not ControlDir in docstrings.
731
        """Get the transport for use by branch format in this BzrDir.
5699.4.1 by Jelmer Vernooij
Move get_branch_transport, .get_workingtree_transport and .get_repository_transport
732
733
        Note that bzr dirs that do not support format strings will raise
734
        IncompatibleFormat if the branch format they are given has
735
        a format string, and vice versa.
736
737
        If branch_format is None, the transport is returned with no
738
        checking. If it is not None, then the returned transport is
739
        guaranteed to point to an existing directory ready for use.
740
        """
741
        raise NotImplementedError(self.get_branch_transport)
742
743
    def get_repository_transport(self, repository_format):
5699.4.5 by Jelmer Vernooij
Refer to BzrDir, not ControlDir in docstrings.
744
        """Get the transport for use by repository format in this BzrDir.
5699.4.1 by Jelmer Vernooij
Move get_branch_transport, .get_workingtree_transport and .get_repository_transport
745
746
        Note that bzr dirs that do not support format strings will raise
747
        IncompatibleFormat if the repository format they are given has
748
        a format string, and vice versa.
749
750
        If repository_format is None, the transport is returned with no
751
        checking. If it is not None, then the returned transport is
752
        guaranteed to point to an existing directory ready for use.
753
        """
754
        raise NotImplementedError(self.get_repository_transport)
755
756
    def get_workingtree_transport(self, tree_format):
5699.4.5 by Jelmer Vernooij
Refer to BzrDir, not ControlDir in docstrings.
757
        """Get the transport for use by workingtree format in this BzrDir.
5699.4.1 by Jelmer Vernooij
Move get_branch_transport, .get_workingtree_transport and .get_repository_transport
758
759
        Note that bzr dirs that do not support format strings will raise
760
        IncompatibleFormat if the workingtree format they are given has a
761
        format string, and vice versa.
762
763
        If workingtree_format is None, the transport is returned with no
764
        checking. If it is not None, then the returned transport is
765
        guaranteed to point to an existing directory ready for use.
766
        """
767
        raise NotImplementedError(self.get_workingtree_transport)
768
6207.3.2 by jelmer at samba
Move convenience methods to ControlDir.
769
    @classmethod
770
    def create(cls, base, format=None, possible_transports=None):
771
        """Create a new BzrDir at the url 'base'.
772
773
        :param format: If supplied, the format of branch to create.  If not
774
            supplied, the default is used.
775
        :param possible_transports: If supplied, a list of transports that
776
            can be reused to share a remote connection.
777
        """
778
        if cls is not BzrDir:
6207.3.3 by jelmer at samba
Fix tests and the like.
779
            raise AssertionError("BzrDir.create always creates the "
6207.3.2 by jelmer at samba
Move convenience methods to ControlDir.
780
                "default format, not one of %r" % cls)
781
        return controldir.ControlDir.create(base, format=format,
782
                possible_transports=possible_transports)
5107.3.1 by Marco Pantaleoni
Added the new hooks 'post_branch', 'post_switch' and 'post_repo_init',
783
6240.2.1 by Jelmer Vernooij
Add BzrDir.__repr__.
784
    def __repr__(self):
785
        return "<%s at %r>" % (self.__class__.__name__, self.user_url)
786
5107.3.1 by Marco Pantaleoni
Added the new hooks 'post_branch', 'post_switch' and 'post_repo_init',
787
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
788
class BzrDirMeta1(BzrDir):
789
    """A .bzr meta version 1 control object.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
790
791
    This is the first control object where the
1553.5.67 by Martin Pool
doc
792
    individual aspects are really split out: there are separate repository,
793
    workingtree and branch subdirectories and any subset of the three can be
794
    present within a BzrDir.
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
795
    """
796
1534.5.16 by Robert Collins
Review feedback.
797
    def can_convert_format(self):
798
        """See BzrDir.can_convert_format()."""
1556.1.4 by Robert Collins
Add a new format for what will become knit, and the surrounding logic to upgrade repositories within metadirs, and tests for the same.
799
        return True
1534.5.10 by Robert Collins
Make upgrade driver unaware of the specific formats in play.
800
6123.9.12 by Jelmer Vernooij
Add append_revisions_only argument to BranchFormat.initialize.
801
    def create_branch(self, name=None, repository=None,
802
            append_revisions_only=None):
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
803
        """See BzrDir.create_branch."""
6240.2.2 by Jelmer Vernooij
Put the branch name into the branch URL.
804
        if name is None:
805
            name = self._get_selected_branch()
5536.1.1 by Andrew Bennetts
Avoid reopening (and relocking) the same branches/repositories in ControlDir.sprout. Still a few rough edges, but the tests I've run are passing.
806
        return self._format.get_branch_format().initialize(self, name=name,
6123.9.12 by Jelmer Vernooij
Add append_revisions_only argument to BranchFormat.initialize.
807
                repository=repository,
808
                append_revisions_only=append_revisions_only)
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
809
5051.3.1 by Jelmer Vernooij
Add optional name argument to BzrDir.destroy_branch.
810
    def destroy_branch(self, name=None):
2796.2.6 by Aaron Bentley
Implement destroy_branch
811
        """See BzrDir.create_branch."""
6083.2.8 by Jelmer Vernooij
Write/read branch list.
812
        if name is not None:
6083.2.10 by Jelmer Vernooij
Move more to colo class.
813
            raise errors.NoColocatedBranchSupport(self)
814
        self.transport.delete_tree('branch')
2796.2.6 by Aaron Bentley
Implement destroy_branch
815
1534.6.1 by Robert Collins
allow API creation of shared repositories
816
    def create_repository(self, shared=False):
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
817
        """See BzrDir.create_repository."""
1556.1.4 by Robert Collins
Add a new format for what will become knit, and the surrounding logic to upgrade repositories within metadirs, and tests for the same.
818
        return self._format.repository_format.initialize(self, shared)
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
819
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
820
    def destroy_repository(self):
821
        """See BzrDir.destroy_repository."""
6266.2.2 by Jelmer Vernooij
Fix tests.
822
        try:
823
            self.transport.delete_tree('repository')
824
        except errors.NoSuchFile:
825
            raise errors.NoRepositoryPresent(self)
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
826
3123.5.2 by Aaron Bentley
Allow checkout --files_from
827
    def create_workingtree(self, revision_id=None, from_branch=None,
3136.1.3 by Aaron Bentley
Implement hard-link support for branch and checkout
828
                           accelerator_tree=None, hardlink=False):
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
829
        """See BzrDir.create_workingtree."""
2955.5.3 by Vincent Ladeuil
Fix second unwanted connection by providing the right branch to create_checkout.
830
        return self._format.workingtree_format.initialize(
3123.5.2 by Aaron Bentley
Allow checkout --files_from
831
            self, revision_id, from_branch=from_branch,
3136.1.3 by Aaron Bentley
Implement hard-link support for branch and checkout
832
            accelerator_tree=accelerator_tree, hardlink=hardlink)
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
833
1551.8.37 by Aaron Bentley
Cleaner implementation of destroy_working_tree
834
    def destroy_workingtree(self):
1551.8.36 by Aaron Bentley
Introduce BzrDir.destroy_workingtree
835
        """See BzrDir.destroy_workingtree."""
2323.6.4 by Martin Pool
BzrDir._check_supported now also takes care of recommending upgrades, which
836
        wt = self.open_workingtree(recommend_upgrade=False)
1551.8.37 by Aaron Bentley
Cleaner implementation of destroy_working_tree
837
        repository = wt.branch.repository
2094.3.5 by John Arbash Meinel
Fix imports to ensure modules are loaded before they are used
838
        empty = repository.revision_tree(_mod_revision.NULL_REVISION)
5409.1.7 by Vincent Ladeuil
First orphaning implementation (some tests lacking).
839
        # We ignore the conflicts returned by wt.revert since we're about to
840
        # delete the wt metadata anyway, all that should be left here are
5409.7.3 by Vincent Ladeuil
Orphan unversioned files to avoid 'missing parent' conflicts
841
        # detritus. But see bug #634470 about subtree .bzr dirs.
5409.1.7 by Vincent Ladeuil
First orphaning implementation (some tests lacking).
842
        conflicts = wt.revert(old_tree=empty)
1551.8.37 by Aaron Bentley
Cleaner implementation of destroy_working_tree
843
        self.destroy_workingtree_metadata()
844
845
    def destroy_workingtree_metadata(self):
846
        self.transport.delete_tree('checkout')
1551.8.36 by Aaron Bentley
Introduce BzrDir.destroy_workingtree
847
5147.4.1 by Jelmer Vernooij
Pass branch names in more places.
848
    def find_branch_format(self, name=None):
2414.2.1 by Andrew Bennetts
Some miscellaneous new APIs, tests and other changes from the hpss branch.
849
        """Find the branch 'format' for this bzrdir.
850
851
        This might be a synthetic object for e.g. RemoteBranch and SVN.
852
        """
6349.2.1 by Jelmer Vernooij
Add BzrDirMetaComponentFormat.
853
        from bzrlib.branch import BranchFormatMetadir
854
        return BranchFormatMetadir.find_format(self, name=name)
2414.2.1 by Andrew Bennetts
Some miscellaneous new APIs, tests and other changes from the hpss branch.
855
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
856
    def _get_mkdir_mode(self):
857
        """Figure out the mode to use when creating a bzrdir subdir."""
1996.3.3 by John Arbash Meinel
Shave off another 40ms by demand loading branch and bzrdir
858
        temp_control = lockable_files.LockableFiles(self.transport, '',
859
                                     lockable_files.TransportLock)
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
860
        return temp_control._dir_mode
861
5147.4.3 by Jelmer Vernooij
Support branch name argument to BzrDir.get_branch_reference.
862
    def get_branch_reference(self, name=None):
2414.2.1 by Andrew Bennetts
Some miscellaneous new APIs, tests and other changes from the hpss branch.
863
        """See BzrDir.get_branch_reference()."""
6349.2.1 by Jelmer Vernooij
Add BzrDirMetaComponentFormat.
864
        from bzrlib.branch import BranchFormatMetadir
865
        format = BranchFormatMetadir.find_format(self, name=name)
5147.4.3 by Jelmer Vernooij
Support branch name argument to BzrDir.get_branch_reference.
866
        return format.get_reference(self, name=name)
2414.2.1 by Andrew Bennetts
Some miscellaneous new APIs, tests and other changes from the hpss branch.
867
5051.3.10 by Jelmer Vernooij
Pass colocated branch name around in more places.
868
    def get_branch_transport(self, branch_format, name=None):
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
869
        """See BzrDir.get_branch_transport()."""
6083.2.11 by Jelmer Vernooij
Add development-colo format.
870
        if name is not None:
871
            raise errors.NoColocatedBranchSupport(self)
4570.3.6 by Martin Pool
doc
872
        # XXX: this shouldn't implicitly create the directory if it's just
873
        # promising to get a transport -- mbp 20090727
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
874
        if branch_format is None:
6083.2.11 by Jelmer Vernooij
Add development-colo format.
875
            return self.transport.clone('branch')
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
876
        try:
877
            branch_format.get_format_string()
878
        except NotImplementedError:
879
            raise errors.IncompatibleFormat(branch_format, self._format)
6083.2.5 by Jelmer Vernooij
Fix colocated branch handling.
880
        try:
6083.2.11 by Jelmer Vernooij
Add development-colo format.
881
            self.transport.mkdir('branch', mode=self._get_mkdir_mode())
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
882
        except errors.FileExists:
883
            pass
6083.2.11 by Jelmer Vernooij
Add development-colo format.
884
        return self.transport.clone('branch')
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
885
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
886
    def get_repository_transport(self, repository_format):
887
        """See BzrDir.get_repository_transport()."""
888
        if repository_format is None:
889
            return self.transport.clone('repository')
890
        try:
891
            repository_format.get_format_string()
892
        except NotImplementedError:
893
            raise errors.IncompatibleFormat(repository_format, self._format)
894
        try:
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
895
            self.transport.mkdir('repository', mode=self._get_mkdir_mode())
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
896
        except errors.FileExists:
897
            pass
898
        return self.transport.clone('repository')
899
1534.4.45 by Robert Collins
Start WorkingTree -> .bzr/checkout transition
900
    def get_workingtree_transport(self, workingtree_format):
901
        """See BzrDir.get_workingtree_transport()."""
902
        if workingtree_format is None:
903
            return self.transport.clone('checkout')
904
        try:
905
            workingtree_format.get_format_string()
906
        except NotImplementedError:
907
            raise errors.IncompatibleFormat(workingtree_format, self._format)
908
        try:
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
909
            self.transport.mkdir('checkout', mode=self._get_mkdir_mode())
1534.4.45 by Robert Collins
Start WorkingTree -> .bzr/checkout transition
910
        except errors.FileExists:
911
            pass
912
        return self.transport.clone('checkout')
913
4634.47.5 by Andrew Bennetts
Add tests, and fix BzrDirMeta1.has_workingtree which was failing if the local transport is decorated with a ChrootTransport or similar.
914
    def has_workingtree(self):
915
        """Tell if this bzrdir contains a working tree.
916
917
        Note: if you're going to open the working tree, you should just go
918
        ahead and try, and not ask permission first.
919
        """
6349.2.1 by Jelmer Vernooij
Add BzrDirMetaComponentFormat.
920
        from bzrlib.workingtree import WorkingTreeFormatMetaDir
4634.47.5 by Andrew Bennetts
Add tests, and fix BzrDirMeta1.has_workingtree which was failing if the local transport is decorated with a ChrootTransport or similar.
921
        try:
6349.2.1 by Jelmer Vernooij
Add BzrDirMetaComponentFormat.
922
            WorkingTreeFormatMetaDir.find_format_string(self)
4634.47.5 by Andrew Bennetts
Add tests, and fix BzrDirMeta1.has_workingtree which was failing if the local transport is decorated with a ChrootTransport or similar.
923
        except errors.NoWorkingTree:
924
            return False
925
        return True
926
5670.1.1 by Jelmer Vernooij
Remove all methods and arguments that were deprecated before bzr 2.0.0.
927
    def needs_format_conversion(self, format):
1534.5.16 by Robert Collins
Review feedback.
928
        """See BzrDir.needs_format_conversion()."""
6207.1.1 by Jelmer Vernooij
Support upgrading between 2a and development-colo.
929
        if (not isinstance(self._format, format.__class__) or
930
            self._format.get_format_string() != format.get_format_string()):
1556.1.4 by Robert Collins
Add a new format for what will become knit, and the surrounding logic to upgrade repositories within metadirs, and tests for the same.
931
            # it is not a meta dir format, conversion is needed.
932
            return True
933
        # we might want to push this down to the repository?
934
        try:
935
            if not isinstance(self.open_repository()._format,
936
                              format.repository_format.__class__):
937
                # the repository needs an upgrade.
938
                return True
939
        except errors.NoRepositoryPresent:
940
            pass
5051.3.4 by Jelmer Vernooij
Support name to BzrDir.open_branch.
941
        for branch in self.list_branches():
942
            if not isinstance(branch._format,
2230.3.55 by Aaron Bentley
Updates from review
943
                              format.get_branch_format().__class__):
2255.12.1 by Robert Collins
Implement upgrade for working trees.
944
                # the branch needs an upgrade.
945
                return True
946
        try:
2323.6.4 by Martin Pool
BzrDir._check_supported now also takes care of recommending upgrades, which
947
            my_wt = self.open_workingtree(recommend_upgrade=False)
948
            if not isinstance(my_wt._format,
2255.12.1 by Robert Collins
Implement upgrade for working trees.
949
                              format.workingtree_format.__class__):
950
                # the workingtree needs an upgrade.
951
                return True
2255.2.196 by Robert Collins
Fix test_upgrade defects related to non local or absent working trees.
952
        except (errors.NoWorkingTree, errors.NotLocalUrl):
2255.12.1 by Robert Collins
Implement upgrade for working trees.
953
            pass
1534.5.10 by Robert Collins
Make upgrade driver unaware of the specific formats in play.
954
        return False
955
5051.3.4 by Jelmer Vernooij
Support name to BzrDir.open_branch.
956
    def open_branch(self, name=None, unsupported=False,
6305.3.2 by Jelmer Vernooij
Only make a single connection.
957
                    ignore_fallbacks=False, possible_transports=None):
958
        """See ControlDir.open_branch."""
6240.2.2 by Jelmer Vernooij
Put the branch name into the branch URL.
959
        if name is None:
960
            name = self._get_selected_branch()
5147.4.3 by Jelmer Vernooij
Support branch name argument to BzrDir.get_branch_reference.
961
        format = self.find_branch_format(name=name)
5717.1.7 by Jelmer Vernooij
Rename check_status -> check_support_status.
962
        format.check_support_status(unsupported)
5051.3.13 by Jelmer Vernooij
Pass colocated branch name around rather than raising an exception directly.
963
        return format.open(self, name=name,
6305.3.2 by Jelmer Vernooij
Only make a single connection.
964
            _found=True, ignore_fallbacks=ignore_fallbacks,
965
            possible_transports=possible_transports)
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
966
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
967
    def open_repository(self, unsupported=False):
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
968
        """See BzrDir.open_repository."""
6349.2.1 by Jelmer Vernooij
Add BzrDirMetaComponentFormat.
969
        from bzrlib.repository import RepositoryFormatMetaDir
970
        format = RepositoryFormatMetaDir.find_format(self)
5717.1.7 by Jelmer Vernooij
Rename check_status -> check_support_status.
971
        format.check_support_status(unsupported)
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
972
        return format.open(self, _found=True)
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
973
2323.6.4 by Martin Pool
BzrDir._check_supported now also takes care of recommending upgrades, which
974
    def open_workingtree(self, unsupported=False,
975
            recommend_upgrade=True):
1508.1.21 by Robert Collins
Implement -r limit for checkout command.
976
        """See BzrDir.open_workingtree."""
6349.2.1 by Jelmer Vernooij
Add BzrDirMetaComponentFormat.
977
        from bzrlib.workingtree import WorkingTreeFormatMetaDir
978
        format = WorkingTreeFormatMetaDir.find_format(self)
5717.1.7 by Jelmer Vernooij
Rename check_status -> check_support_status.
979
        format.check_support_status(unsupported, recommend_upgrade,
2323.6.5 by Martin Pool
Recommended-upgrade message should give base dir not the control dir url
980
            basedir=self.root_transport.base)
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
981
        return format.open(self, _found=True)
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
982
3242.1.1 by Aaron Bentley
Implement BzrDir configuration
983
    def _get_config(self):
4288.1.1 by Robert Collins
Add support for a RemoteBzrDirConfig to support optimising push operations which need to look for default stacking locations.
984
        return config.TransportConfig(self.transport, 'control.conf')
3242.1.1 by Aaron Bentley
Implement BzrDir configuration
985
4294.2.4 by Robert Collins
Move dir, bzrdir and repo acquisition into a single method on bzrdir format.
986
6083.2.9 by Jelmer Vernooij
Add development-colo as a separate format.
987
class BzrDirMeta1Colo(BzrDirMeta1):
988
    """BzrDirMeta1 with support for colocated branches.
989
6083.2.13 by Jelmer Vernooij
Fix metadircolo initialization.
990
    This format is experimental, and will eventually be merged back into
991
    BzrDirMeta1.
6083.2.9 by Jelmer Vernooij
Add development-colo as a separate format.
992
    """
993
6083.2.13 by Jelmer Vernooij
Fix metadircolo initialization.
994
    def __init__(self, _transport, _format):
995
        super(BzrDirMeta1Colo, self).__init__(_transport, _format)
6239.1.1 by Jelmer Vernooij
Create lock directories in .bzr/, not .
996
        self.control_files = lockable_files.LockableFiles(self.control_transport,
6083.2.13 by Jelmer Vernooij
Fix metadircolo initialization.
997
            self._format._lock_file_name, self._format._lock_class)
998
6083.2.9 by Jelmer Vernooij
Add development-colo as a separate format.
999
    def _get_branch_path(self, name):
1000
        """Obtain the branch path to use.
1001
1002
        This uses the API specified branch name first, and then falls back to
1003
        the branch name specified in the URL. If neither of those is specified,
1004
        it uses the default branch.
1005
1006
        :param name: Optional branch name to use
6240.2.2 by Jelmer Vernooij
Put the branch name into the branch URL.
1007
        :return: Relative path to branch
6083.2.9 by Jelmer Vernooij
Add development-colo as a separate format.
1008
        """
1009
        if name is None:
6240.2.2 by Jelmer Vernooij
Put the branch name into the branch URL.
1010
            return 'branch'
6240.2.8 by Jelmer Vernooij
Consistent handling of unicode.
1011
        return urlutils.join('branches', name.encode("utf-8"))
6083.2.9 by Jelmer Vernooij
Add development-colo as a separate format.
1012
1013
    def _read_branch_list(self):
1014
        """Read the branch list.
1015
1016
        :return: List of utf-8 encoded branch names.
1017
        """
1018
        try:
1019
            f = self.control_transport.get('branch-list')
1020
        except errors.NoSuchFile:
1021
            return []
1022
1023
        ret = []
1024
        try:
1025
            for name in f:
1026
                ret.append(name.rstrip("\n"))
1027
        finally:
1028
            f.close()
1029
        return ret
1030
1031
    def _write_branch_list(self, branches):
1032
        """Write out the branch list.
1033
1034
        :param branches: List of utf-8 branch names to write
1035
        """
1036
        self.transport.put_bytes('branch-list',
1037
            "".join([name+"\n" for name in branches]))
1038
6083.2.10 by Jelmer Vernooij
Move more to colo class.
1039
    def destroy_branch(self, name=None):
1040
        """See BzrDir.create_branch."""
6240.2.2 by Jelmer Vernooij
Put the branch name into the branch URL.
1041
        if name is None:
1042
            name = self._get_selected_branch()
1043
        path = self._get_branch_path(name)
6083.2.10 by Jelmer Vernooij
Move more to colo class.
1044
        if name is not None:
1045
            self.control_files.lock_write()
1046
            try:
1047
                branches = self._read_branch_list()
1048
                try:
6240.2.8 by Jelmer Vernooij
Consistent handling of unicode.
1049
                    branches.remove(name.encode("utf-8"))
6083.2.10 by Jelmer Vernooij
Move more to colo class.
1050
                except ValueError:
1051
                    raise errors.NotBranchError(name)
6240.2.8 by Jelmer Vernooij
Consistent handling of unicode.
1052
                self._write_branch_list(branches)
6083.2.10 by Jelmer Vernooij
Move more to colo class.
1053
            finally:
1054
                self.control_files.unlock()
1055
        self.transport.delete_tree(path)
1056
6282.5.4 by Neil Martinsen-Burrell
add get_branches method to return a dictionary of names and branches
1057
    def get_branches(self):
1058
        """See ControlDir.get_branches."""
1059
        ret = {}
6083.2.10 by Jelmer Vernooij
Move more to colo class.
1060
        try:
6282.5.4 by Neil Martinsen-Burrell
add get_branches method to return a dictionary of names and branches
1061
            ret[None] = self.open_branch()
6083.2.10 by Jelmer Vernooij
Move more to colo class.
1062
        except (errors.NotBranchError, errors.NoRepositoryPresent):
1063
            pass
1064
6282.5.4 by Neil Martinsen-Burrell
add get_branches method to return a dictionary of names and branches
1065
        for name in self._read_branch_list():
1066
            ret[name] = self.open_branch(name.decode('utf-8'))
1067
6282.5.3 by Neil Martinsen-Burrell
avoid trivial duplicates in BzrDir.list_branches
1068
        return ret
6083.2.10 by Jelmer Vernooij
Move more to colo class.
1069
1070
    def get_branch_transport(self, branch_format, name=None):
1071
        """See BzrDir.get_branch_transport()."""
6240.2.2 by Jelmer Vernooij
Put the branch name into the branch URL.
1072
        path = self._get_branch_path(name)
6083.2.10 by Jelmer Vernooij
Move more to colo class.
1073
        # XXX: this shouldn't implicitly create the directory if it's just
1074
        # promising to get a transport -- mbp 20090727
5268.8.23 by Jelmer Vernooij
Fix branch format check.
1075
        if branch_format is None:
1076
            return self.transport.clone(path)
1077
        try:
1078
            branch_format.get_format_string()
1079
        except NotImplementedError:
1080
            raise errors.IncompatibleFormat(branch_format, self._format)
6083.2.10 by Jelmer Vernooij
Move more to colo class.
1081
        if name is not None:
1082
            try:
1083
                self.transport.mkdir('branches', mode=self._get_mkdir_mode())
1084
            except errors.FileExists:
1085
                pass
1086
            branches = self._read_branch_list()
6240.2.8 by Jelmer Vernooij
Consistent handling of unicode.
1087
            utf8_name = name.encode("utf-8")
1088
            if not utf8_name in branches:
6083.2.10 by Jelmer Vernooij
Move more to colo class.
1089
                self.control_files.lock_write()
1090
                try:
1091
                    branches = self._read_branch_list()
6240.2.8 by Jelmer Vernooij
Consistent handling of unicode.
1092
                    branches.append(utf8_name)
6083.2.10 by Jelmer Vernooij
Move more to colo class.
1093
                    self._write_branch_list(branches)
1094
                finally:
1095
                    self.control_files.unlock()
1096
        try:
1097
            self.transport.mkdir(path, mode=self._get_mkdir_mode())
1098
        except errors.FileExists:
1099
            pass
1100
        return self.transport.clone(path)
6083.2.9 by Jelmer Vernooij
Add development-colo as a separate format.
1101
1102
6349.2.1 by Jelmer Vernooij
Add BzrDirMetaComponentFormat.
1103
class BzrDirMetaComponentFormat(controldir.ControlComponentFormat):
6349.2.4 by Jelmer Vernooij
Add test for WorkingTreeFormat.from_string.
1104
    """Base class for all formats of things living in metadirs.
1105
1106
    This class manages the format string that is stored in the 'format'
1107
    or 'branch-format' file.
6349.2.7 by Jelmer Vernooij
More docs.
1108
1109
    All classes for (branch-, repository-, workingtree-) formats that
1110
    live in meta directories and have their own 'format' file
1111
    (i.e. different from .bzr/branch-format) derive from this class,
1112
    as well as the relevant base class for their kind
1113
    (BranchFormat, WorkingTreeFormat, RepositoryFormat).
6349.2.4 by Jelmer Vernooij
Add test for WorkingTreeFormat.from_string.
1114
    """
6349.2.1 by Jelmer Vernooij
Add BzrDirMetaComponentFormat.
1115
1116
    @classmethod
1117
    def get_format_string(cls):
1118
        """Return the ASCII format string that identifies this format."""
1119
        raise NotImplementedError(cls.get_format_string)
1120
1121
    @classmethod
1122
    def from_string(cls, format_string):
1123
        if format_string != cls.get_format_string():
1124
            raise ValueError("Invalid format header %r" % format_string)
6349.2.3 by Jelmer Vernooij
Simplify.
1125
        return cls()
6349.2.1 by Jelmer Vernooij
Add BzrDirMetaComponentFormat.
1126
1127
    @classmethod
1128
    def _find_format(klass, registry, kind, format_string):
1129
        try:
1130
            cls = registry.get(format_string)
1131
        except KeyError:
1132
            raise errors.UnknownFormatError(format=format_string, kind=kind)
6349.2.2 by Jelmer Vernooij
Fix remaining tests.
1133
        return cls
6349.2.1 by Jelmer Vernooij
Add BzrDirMetaComponentFormat.
1134
1135
    def network_name(self):
1136
        """A simple byte string uniquely identifying this format for RPC calls.
1137
1138
        Metadir branch formats use their format string.
1139
        """
1140
        return self.get_format_string()
1141
1142
    def __eq__(self, other):
1143
        return (self.__class__ is other.__class__)
1144
1145
5363.2.20 by Jelmer Vernooij
use controldir.X
1146
class BzrProber(controldir.Prober):
5363.2.8 by Jelmer Vernooij
Docstrings.
1147
    """Prober for formats that use a .bzr/ control directory."""
5363.2.4 by Jelmer Vernooij
Introduce probers, use controldir in a couple more places.
1148
5712.3.8 by Jelmer Vernooij
Support lazy registration of BzrDir formats.
1149
    formats = registry.FormatRegistry(controldir.network_format_registry)
5363.2.4 by Jelmer Vernooij
Introduce probers, use controldir in a couple more places.
1150
    """The known .bzr formats."""
1151
1152
    @classmethod
5712.3.1 by Jelmer Vernooij
Use registry for BzrProber.formats.
1153
    @deprecated_method(deprecated_in((2, 4, 0)))
5363.2.4 by Jelmer Vernooij
Introduce probers, use controldir in a couple more places.
1154
    def register_bzrdir_format(klass, format):
5712.3.8 by Jelmer Vernooij
Support lazy registration of BzrDir formats.
1155
        klass.formats.register(format.get_format_string(), format)
5363.2.4 by Jelmer Vernooij
Introduce probers, use controldir in a couple more places.
1156
1157
    @classmethod
5712.3.1 by Jelmer Vernooij
Use registry for BzrProber.formats.
1158
    @deprecated_method(deprecated_in((2, 4, 0)))
5363.2.6 by Jelmer Vernooij
Add ControlDirFormat.{un,}register_{server_,}prober.
1159
    def unregister_bzrdir_format(klass, format):
5712.3.8 by Jelmer Vernooij
Support lazy registration of BzrDir formats.
1160
        klass.formats.remove(format.get_format_string())
5363.2.4 by Jelmer Vernooij
Introduce probers, use controldir in a couple more places.
1161
5363.2.7 by Jelmer Vernooij
Fix tests.
1162
    @classmethod
1163
    def probe_transport(klass, transport):
5363.2.4 by Jelmer Vernooij
Introduce probers, use controldir in a couple more places.
1164
        """Return the .bzrdir style format present in a directory."""
1165
        try:
1166
            format_string = transport.get_bytes(".bzr/branch-format")
1167
        except errors.NoSuchFile:
1168
            raise errors.NotBranchError(path=transport.base)
1169
        try:
6349.2.1 by Jelmer Vernooij
Add BzrDirMetaComponentFormat.
1170
            cls = klass.formats.get(format_string)
5363.2.4 by Jelmer Vernooij
Introduce probers, use controldir in a couple more places.
1171
        except KeyError:
1172
            raise errors.UnknownFormatError(format=format_string, kind='bzrdir')
6349.2.1 by Jelmer Vernooij
Add BzrDirMetaComponentFormat.
1173
        return cls.from_string(format_string)
5363.2.4 by Jelmer Vernooij
Introduce probers, use controldir in a couple more places.
1174
5712.3.15 by Jelmer Vernooij
Remove unused register format functions.
1175
    @classmethod
1176
    def known_formats(cls):
5712.3.13 by Jelmer Vernooij
Add Prober.known_formats().
1177
        result = set()
5712.3.15 by Jelmer Vernooij
Remove unused register format functions.
1178
        for name, format in cls.formats.iteritems():
5712.4.9 by Jelmer Vernooij
Fix lazy control directory discovery.
1179
            if callable(format):
1180
                format = format()
5712.3.13 by Jelmer Vernooij
Add Prober.known_formats().
1181
            result.add(format)
1182
        return result
1183
5363.2.4 by Jelmer Vernooij
Introduce probers, use controldir in a couple more places.
1184
5363.2.20 by Jelmer Vernooij
use controldir.X
1185
controldir.ControlDirFormat.register_prober(BzrProber)
1186
1187
1188
class RemoteBzrProber(controldir.Prober):
5363.2.8 by Jelmer Vernooij
Docstrings.
1189
    """Prober for remote servers that provide a Bazaar smart server."""
5363.2.4 by Jelmer Vernooij
Introduce probers, use controldir in a couple more places.
1190
1191
    @classmethod
1192
    def probe_transport(klass, transport):
1193
        """Return a RemoteBzrDirFormat object if it looks possible."""
1194
        try:
1195
            medium = transport.get_smart_medium()
1196
        except (NotImplementedError, AttributeError,
1197
                errors.TransportNotPossible, errors.NoSmartMedium,
1198
                errors.SmartProtocolError):
1199
            # no smart server, so not a branch for this format type.
1200
            raise errors.NotBranchError(path=transport.base)
1201
        else:
1202
            # Decline to open it if the server doesn't support our required
1203
            # version (3) so that the VFS-based transport will do it.
1204
            if medium.should_probe():
1205
                try:
1206
                    server_version = medium.protocol_version()
1207
                except errors.SmartProtocolError:
1208
                    # Apparently there's no usable smart server there, even though
1209
                    # the medium supports the smart protocol.
1210
                    raise errors.NotBranchError(path=transport.base)
1211
                if server_version != '2':
1212
                    raise errors.NotBranchError(path=transport.base)
5712.3.13 by Jelmer Vernooij
Add Prober.known_formats().
1213
            from bzrlib.remote import RemoteBzrDirFormat
5363.2.7 by Jelmer Vernooij
Fix tests.
1214
            return RemoteBzrDirFormat()
5363.2.4 by Jelmer Vernooij
Introduce probers, use controldir in a couple more places.
1215
5712.3.15 by Jelmer Vernooij
Remove unused register format functions.
1216
    @classmethod
1217
    def known_formats(cls):
5712.3.13 by Jelmer Vernooij
Add Prober.known_formats().
1218
        from bzrlib.remote import RemoteBzrDirFormat
1219
        return set([RemoteBzrDirFormat()])
1220
5363.2.4 by Jelmer Vernooij
Introduce probers, use controldir in a couple more places.
1221
5363.2.20 by Jelmer Vernooij
use controldir.X
1222
class BzrDirFormat(controldir.ControlDirFormat):
5363.2.3 by Jelmer Vernooij
Add ControlDirFormat.
1223
    """ControlDirFormat base class for .bzr/ directories.
1534.4.39 by Robert Collins
Basic BzrDir support.
1224
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1225
    Formats are placed in a dict by their format string for reference
1534.4.39 by Robert Collins
Basic BzrDir support.
1226
    during bzrdir opening. These should be subclasses of BzrDirFormat
1227
    for consistency.
1228
1229
    Once a format is deprecated, just deprecate the initialize and open
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1230
    methods on the format class. Do not deprecate the object, as the
1534.4.39 by Robert Collins
Basic BzrDir support.
1231
    object will be created every system load.
2018.5.169 by Andrew Bennetts
Add a _server_formats flag to BzrDir.open_from_transport and BzrDirFormat.find_format, make RemoteBranch.control_files into a property.
1232
    """
1233
1553.5.69 by Martin Pool
BzrDirFormat subclasses can now control what kind of overall lock is used.
1234
    _lock_file_name = 'branch-lock'
1235
1236
    # _lock_class must be set in subclasses to the lock type, typ.
1237
    # TransportLock or LockDir
1238
5712.3.15 by Jelmer Vernooij
Remove unused register format functions.
1239
    @classmethod
1240
    def get_format_string(cls):
1534.4.39 by Robert Collins
Basic BzrDir support.
1241
        """Return the ASCII format string that identifies this format."""
5904.1.2 by Martin Pool
Various pyflakes import fixes.
1242
        raise NotImplementedError(cls.get_format_string)
1534.4.39 by Robert Collins
Basic BzrDir support.
1243
1651.1.6 by Martin Pool
Clean up clone-bzrdir code
1244
    def initialize_on_transport(self, transport):
1608.2.8 by Martin Pool
Separate out BzrDir.initialize_on_transport so it
1245
        """Initialize a new bzrdir in the base directory of a Transport."""
4017.2.2 by Robert Collins
Perform creation of BzrDirMetaFormat1 control directories using an RPC where possible. (Robert Collins)
1246
        try:
1247
            # can we hand off the request to the smart server rather than using
1248
            # vfs calls?
1249
            client_medium = transport.get_smart_medium()
1250
        except errors.NoSmartMedium:
1251
            return self._initialize_on_transport_vfs(transport)
1252
        else:
1253
            # Current RPC's only know how to create bzr metadir1 instances, so
1254
            # we still delegate to vfs methods if the requested format is not a
1255
            # metadir1
1256
            if type(self) != BzrDirMetaFormat1:
1257
                return self._initialize_on_transport_vfs(transport)
5712.3.13 by Jelmer Vernooij
Add Prober.known_formats().
1258
            from bzrlib.remote import RemoteBzrDirFormat
4017.2.2 by Robert Collins
Perform creation of BzrDirMetaFormat1 control directories using an RPC where possible. (Robert Collins)
1259
            remote_format = RemoteBzrDirFormat()
1260
            self._supply_sub_formats_to(remote_format)
1261
            return remote_format.initialize_on_transport(transport)
1262
4294.2.4 by Robert Collins
Move dir, bzrdir and repo acquisition into a single method on bzrdir format.
1263
    def initialize_on_transport_ex(self, transport, use_existing_dir=False,
1264
        create_prefix=False, force_new_repo=False, stacked_on=None,
4294.2.5 by Robert Collins
Reasonable unit test coverage for initialize_on_transport_ex.
1265
        stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
4294.2.8 by Robert Collins
Reduce round trips pushing new branches substantially.
1266
        shared_repo=False, vfs_only=False):
4294.2.4 by Robert Collins
Move dir, bzrdir and repo acquisition into a single method on bzrdir format.
1267
        """Create this format on transport.
1268
4294.2.7 by Robert Collins
Start building up a BzrDir.initialize_ex verb for the smart server.
1269
        The directory to initialize will be created.
1270
4294.2.4 by Robert Collins
Move dir, bzrdir and repo acquisition into a single method on bzrdir format.
1271
        :param force_new_repo: Do not use a shared repository for the target,
1272
                               even if one is available.
1273
        :param create_prefix: Create any missing directories leading up to
1274
            to_transport.
1275
        :param use_existing_dir: Use an existing directory if one exists.
1276
        :param stacked_on: A url to stack any created branch on, None to follow
1277
            any target stacking policy.
1278
        :param stack_on_pwd: If stack_on is relative, the location it is
1279
            relative to.
1280
        :param repo_format_name: If non-None, a repository will be
1281
            made-or-found. Should none be found, or if force_new_repo is True
1282
            the repo_format_name is used to select the format of repository to
1283
            create.
1284
        :param make_working_trees: Control the setting of make_working_trees
4294.2.5 by Robert Collins
Reasonable unit test coverage for initialize_on_transport_ex.
1285
            for a new shared repository when one is made. None to use whatever
1286
            default the format has.
4294.2.4 by Robert Collins
Move dir, bzrdir and repo acquisition into a single method on bzrdir format.
1287
        :param shared_repo: Control whether made repositories are shared or
1288
            not.
4294.2.8 by Robert Collins
Reduce round trips pushing new branches substantially.
1289
        :param vfs_only: If True do not attempt to use a smart server
4294.2.5 by Robert Collins
Reasonable unit test coverage for initialize_on_transport_ex.
1290
        :return: repo, bzrdir, require_stacking, repository_policy. repo is
1291
            None if none was created or found, bzrdir is always valid.
1292
            require_stacking is the result of examining the stacked_on
1293
            parameter and any stacking policy found for the target.
4294.2.4 by Robert Collins
Move dir, bzrdir and repo acquisition into a single method on bzrdir format.
1294
        """
4294.2.8 by Robert Collins
Reduce round trips pushing new branches substantially.
1295
        if not vfs_only:
1296
            # Try to hand off to a smart server 
1297
            try:
1298
                client_medium = transport.get_smart_medium()
1299
            except errors.NoSmartMedium:
1300
                pass
1301
            else:
5712.3.15 by Jelmer Vernooij
Remove unused register format functions.
1302
                from bzrlib.remote import RemoteBzrDirFormat
4294.2.8 by Robert Collins
Reduce round trips pushing new branches substantially.
1303
                # TODO: lookup the local format from a server hint.
1304
                remote_dir_format = RemoteBzrDirFormat()
1305
                remote_dir_format._network_name = self.network_name()
1306
                self._supply_sub_formats_to(remote_dir_format)
1307
                return remote_dir_format.initialize_on_transport_ex(transport,
1308
                    use_existing_dir=use_existing_dir, create_prefix=create_prefix,
1309
                    force_new_repo=force_new_repo, stacked_on=stacked_on,
1310
                    stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
1311
                    make_working_trees=make_working_trees, shared_repo=shared_repo)
4294.2.4 by Robert Collins
Move dir, bzrdir and repo acquisition into a single method on bzrdir format.
1312
        # XXX: Refactor the create_prefix/no_create_prefix code into a
1313
        #      common helper function
1314
        # The destination may not exist - if so make it according to policy.
1315
        def make_directory(transport):
1316
            transport.mkdir('.')
1317
            return transport
1318
        def redirected(transport, e, redirection_notice):
1319
            note(redirection_notice)
1320
            return transport._redirected_to(e.source, e.target)
1321
        try:
1322
            transport = do_catching_redirections(make_directory, transport,
1323
                redirected)
1324
        except errors.FileExists:
1325
            if not use_existing_dir:
1326
                raise
1327
        except errors.NoSuchFile:
1328
            if not create_prefix:
1329
                raise
1330
            transport.create_prefix()
1331
1332
        require_stacking = (stacked_on is not None)
1333
        # Now the target directory exists, but doesn't have a .bzr
1334
        # directory. So we need to create it, along with any work to create
1335
        # all of the dependent branches, etc.
4294.2.5 by Robert Collins
Reasonable unit test coverage for initialize_on_transport_ex.
1336
4294.2.4 by Robert Collins
Move dir, bzrdir and repo acquisition into a single method on bzrdir format.
1337
        result = self.initialize_on_transport(transport)
1338
        if repo_format_name:
4294.2.5 by Robert Collins
Reasonable unit test coverage for initialize_on_transport_ex.
1339
            try:
1340
                # use a custom format
1341
                result._format.repository_format = \
1342
                    repository.network_format_registry.get(repo_format_name)
1343
            except AttributeError:
1344
                # The format didn't permit it to be set.
1345
                pass
4294.2.4 by Robert Collins
Move dir, bzrdir and repo acquisition into a single method on bzrdir format.
1346
            # A repository is desired, either in-place or shared.
1347
            repository_policy = result.determine_repository_policy(
1348
                force_new_repo, stacked_on, stack_on_pwd,
1349
                require_stacking=require_stacking)
1350
            result_repo, is_new_repo = repository_policy.acquire_repository(
1351
                make_working_trees, shared_repo)
1352
            if not require_stacking and repository_policy._require_stacking:
1353
                require_stacking = True
1354
                result._format.require_stacking()
4307.2.2 by Robert Collins
Lock repositories created by BzrDirFormat.initialize_on_transport_ex.
1355
            result_repo.lock_write()
4294.2.4 by Robert Collins
Move dir, bzrdir and repo acquisition into a single method on bzrdir format.
1356
        else:
1357
            result_repo = None
1358
            repository_policy = None
1359
        return result_repo, result, require_stacking, repository_policy
1360
4017.2.2 by Robert Collins
Perform creation of BzrDirMetaFormat1 control directories using an RPC where possible. (Robert Collins)
1361
    def _initialize_on_transport_vfs(self, transport):
1362
        """Initialize a new bzrdir using VFS calls.
4032.1.2 by John Arbash Meinel
Track down a few more files that have trailing whitespace.
1363
4017.2.2 by Robert Collins
Perform creation of BzrDirMetaFormat1 control directories using an RPC where possible. (Robert Collins)
1364
        :param transport: The transport to create the .bzr directory in.
1365
        :return: A
1366
        """
1367
        # Since we are creating a .bzr directory, inherit the
1534.4.39 by Robert Collins
Basic BzrDir support.
1368
        # mode from the root directory
1996.3.3 by John Arbash Meinel
Shave off another 40ms by demand loading branch and bzrdir
1369
        temp_control = lockable_files.LockableFiles(transport,
1370
                            '', lockable_files.TransportLock)
1534.4.39 by Robert Collins
Basic BzrDir support.
1371
        temp_control._transport.mkdir('.bzr',
1759.2.2 by Jelmer Vernooij
Revert some of my spelling fixes and fix some typos after review by Aaron.
1372
                                      # FIXME: RBC 20060121 don't peek under
1534.4.39 by Robert Collins
Basic BzrDir support.
1373
                                      # the covers
1374
                                      mode=temp_control._dir_mode)
3224.5.24 by Andrew Bennetts
More minor import tidying suggested by pyflakes.
1375
        if sys.platform == 'win32' and isinstance(transport, local.LocalTransport):
3023.1.2 by Alexander Belchenko
Martin's review.
1376
            win32utils.set_file_attr_hidden(transport._abspath('.bzr'))
1534.4.39 by Robert Collins
Basic BzrDir support.
1377
        file_mode = temp_control._file_mode
1378
        del temp_control
3407.2.5 by Martin Pool
Deprecate LockableFiles.put_utf8
1379
        bzrdir_transport = transport.clone('.bzr')
1380
        utf8_files = [('README',
3250.2.1 by Marius Kruger
update .bzr/README to not refer to Bazaar-NG, and add link to website.
1381
                       "This is a Bazaar control directory.\n"
1382
                       "Do not change any files in this directory.\n"
5560.2.1 by Vincent Ladeuil
Fix the remaining references to http://bazaar-vcs.org (except the explicitly historical ones).
1383
                       "See http://bazaar.canonical.com/ for more information about Bazaar.\n"),
1534.4.39 by Robert Collins
Basic BzrDir support.
1384
                      ('branch-format', self.get_format_string()),
1385
                      ]
1386
        # NB: no need to escape relative paths that are url safe.
3407.2.5 by Martin Pool
Deprecate LockableFiles.put_utf8
1387
        control_files = lockable_files.LockableFiles(bzrdir_transport,
1388
            self._lock_file_name, self._lock_class)
1553.5.60 by Martin Pool
New LockableFiles.create_lock() method
1389
        control_files.create_lock()
1534.4.39 by Robert Collins
Basic BzrDir support.
1390
        control_files.lock_write()
1391
        try:
3407.2.5 by Martin Pool
Deprecate LockableFiles.put_utf8
1392
            for (filename, content) in utf8_files:
3407.2.12 by Martin Pool
Fix creation mode of control files
1393
                bzrdir_transport.put_bytes(filename, content,
1394
                    mode=file_mode)
1534.4.39 by Robert Collins
Basic BzrDir support.
1395
        finally:
1396
            control_files.unlock()
4017.2.2 by Robert Collins
Perform creation of BzrDirMetaFormat1 control directories using an RPC where possible. (Robert Collins)
1397
        return self.open(transport, _found=True)
1534.4.39 by Robert Collins
Basic BzrDir support.
1398
1399
    def open(self, transport, _found=False):
1400
        """Return an instance of this format for the dir transport points at.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1401
1534.4.39 by Robert Collins
Basic BzrDir support.
1402
        _found is a private parameter, do not use it.
1403
        """
1404
        if not _found:
5363.2.20 by Jelmer Vernooij
use controldir.X
1405
            found_format = controldir.ControlDirFormat.find_format(transport)
2090.2.2 by Martin Pool
Fix an assertion with side effects
1406
            if not isinstance(found_format, self.__class__):
1407
                raise AssertionError("%s was asked to open %s, but it seems to need "
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1408
                        "format %s"
2090.2.2 by Martin Pool
Fix an assertion with side effects
1409
                        % (self, transport, found_format))
4005.2.1 by Robert Collins
Fix RemoteBranch to be used correctly in tests using bzr+ssh, to fire off Branch hooks correctly, and improve the branch_implementations tests to check that making a branch gets the right format under test.
1410
            # Allow subclasses - use the found format.
1411
            self._supply_sub_formats_to(found_format)
1412
            return found_format._open(transport)
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
1413
        return self._open(transport)
1414
1415
    def _open(self, transport):
1416
        """Template method helper for opening BzrDirectories.
1417
1418
        This performs the actual open and any additional logic or parameter
1419
        passing.
1420
        """
1421
        raise NotImplementedError(self._open)
1534.4.39 by Robert Collins
Basic BzrDir support.
1422
4005.2.1 by Robert Collins
Fix RemoteBranch to be used correctly in tests using bzr+ssh, to fire off Branch hooks correctly, and improve the branch_implementations tests to check that making a branch gets the right format under test.
1423
    def _supply_sub_formats_to(self, other_format):
1424
        """Give other_format the same values for sub formats as this has.
1425
1426
        This method is expected to be used when parameterising a
1427
        RemoteBzrDirFormat instance with the parameters from a
1428
        BzrDirMetaFormat1 instance.
1429
1430
        :param other_format: other_format is a format which should be
1431
            compatible with whatever sub formats are supported by self.
1432
        :return: None.
1433
        """
1434
6205.3.1 by Jelmer Vernooij
Add ControlDirFormat.supports_transport.
1435
    def supports_transport(self, transport):
1436
        # bzr formats can be opened over all known transports
1437
        return True
1438
1733.1.1 by Robert Collins
Support non '.bzr' control directories in bzrdir.
1439
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
1440
class BzrDirMetaFormat1(BzrDirFormat):
1441
    """Bzr meta control format 1
1442
1443
    This is the first format with split out working tree, branch and repository
1444
    disk storage.
5891.1.2 by Andrew Bennetts
Fix a bunch of docstring formatting nits, making pydoctor a bit happier.
1445
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
1446
    It has:
5891.1.2 by Andrew Bennetts
Fix a bunch of docstring formatting nits, making pydoctor a bit happier.
1447
1448
    - Format 3 working trees [optional]
6083.2.11 by Jelmer Vernooij
Add development-colo format.
1449
    - Format 5 branches [optional]
5891.1.2 by Andrew Bennetts
Fix a bunch of docstring formatting nits, making pydoctor a bit happier.
1450
    - Format 7 repositories [optional]
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
1451
    """
1452
1996.3.3 by John Arbash Meinel
Shave off another 40ms by demand loading branch and bzrdir
1453
    _lock_class = lockdir.LockDir
1553.5.69 by Martin Pool
BzrDirFormat subclasses can now control what kind of overall lock is used.
1454
5673.1.3 by Jelmer Vernooij
Change flexible_components to fixed_components.
1455
    fixed_components = False
1456
6083.2.10 by Jelmer Vernooij
Move more to colo class.
1457
    colocated_branches = False
6083.2.1 by Jelmer Vernooij
Support passing names to BzrDir methods.
1458
2100.3.10 by Aaron Bentley
Ensure added references are serialized properly, beef up Workingtreee3
1459
    def __init__(self):
1460
        self._workingtree_format = None
2230.3.1 by Aaron Bentley
Get branch6 creation working
1461
        self._branch_format = None
4070.2.3 by Robert Collins
Get BzrDir.cloning_metadir working.
1462
        self._repository_format = None
2100.3.10 by Aaron Bentley
Ensure added references are serialized properly, beef up Workingtreee3
1463
2100.3.15 by Aaron Bentley
get test suite passing
1464
    def __eq__(self, other):
1465
        if other.__class__ is not self.__class__:
1466
            return False
1467
        if other.repository_format != self.repository_format:
1468
            return False
1469
        if other.workingtree_format != self.workingtree_format:
1470
            return False
1471
        return True
1472
2100.3.35 by Aaron Bentley
equality operations on bzrdir
1473
    def __ne__(self, other):
1474
        return not self == other
1475
2230.3.55 by Aaron Bentley
Updates from review
1476
    def get_branch_format(self):
2230.3.1 by Aaron Bentley
Get branch6 creation working
1477
        if self._branch_format is None:
5662.2.2 by Jelmer Vernooij
Move most format registration functions to BranchFormatRegistry.
1478
            from bzrlib.branch import format_registry as branch_format_registry
1479
            self._branch_format = branch_format_registry.get_default()
2230.3.1 by Aaron Bentley
Get branch6 creation working
1480
        return self._branch_format
1481
2230.3.55 by Aaron Bentley
Updates from review
1482
    def set_branch_format(self, format):
2230.3.1 by Aaron Bentley
Get branch6 creation working
1483
        self._branch_format = format
1484
4456.2.1 by Andrew Bennetts
Fix automatic branch format upgrades triggered by a default stacking policy on a 1.16rc1 (or later) smart server.
1485
    def require_stacking(self, stack_on=None, possible_transports=None,
1486
            _skip_repo=False):
4401.1.2 by John Arbash Meinel
Move the logic back up into BzrDirFormat1.require_stacking, passing in the extra params.
1487
        """We have a request to stack, try to ensure the formats support it.
1488
1489
        :param stack_on: If supplied, it is the URL to a branch that we want to
1490
            stack on. Check to see if that format supports stacking before
1491
            forcing an upgrade.
1492
        """
1493
        # Stacking is desired. requested by the target, but does the place it
1494
        # points at support stacking? If it doesn't then we should
1495
        # not implicitly upgrade. We check this here.
1496
        new_repo_format = None
1497
        new_branch_format = None
1498
1499
        # a bit of state for get_target_branch so that we don't try to open it
1500
        # 2 times, for both repo *and* branch
1501
        target = [None, False, None] # target_branch, checked, upgrade anyway
1502
        def get_target_branch():
1503
            if target[1]:
1504
                # We've checked, don't check again
1505
                return target
1506
            if stack_on is None:
1507
                # No target format, that means we want to force upgrading
1508
                target[:] = [None, True, True]
1509
                return target
1510
            try:
1511
                target_dir = BzrDir.open(stack_on,
1512
                    possible_transports=possible_transports)
1513
            except errors.NotBranchError:
1514
                # Nothing there, don't change formats
1515
                target[:] = [None, True, False]
1516
                return target
1517
            except errors.JailBreak:
1518
                # JailBreak, JFDI and upgrade anyway
1519
                target[:] = [None, True, True]
1520
                return target
1521
            try:
1522
                target_branch = target_dir.open_branch()
1523
            except errors.NotBranchError:
1524
                # No branch, don't upgrade formats
1525
                target[:] = [None, True, False]
1526
                return target
1527
            target[:] = [target_branch, True, False]
1528
            return target
1529
4456.2.1 by Andrew Bennetts
Fix automatic branch format upgrades triggered by a default stacking policy on a 1.16rc1 (or later) smart server.
1530
        if (not _skip_repo and
1531
                 not self.repository_format.supports_external_lookups):
4401.1.2 by John Arbash Meinel
Move the logic back up into BzrDirFormat1.require_stacking, passing in the extra params.
1532
            # We need to upgrade the Repository.
1533
            target_branch, _, do_upgrade = get_target_branch()
1534
            if target_branch is None:
1535
                # We don't have a target branch, should we upgrade anyway?
1536
                if do_upgrade:
1537
                    # stack_on is inaccessible, JFDI.
1538
                    # TODO: bad monkey, hard-coded formats...
1539
                    if self.repository_format.rich_root_data:
5757.1.2 by Jelmer Vernooij
Add separate file for knit pack repository formats.
1540
                        new_repo_format = knitpack_repo.RepositoryFormatKnitPack5RichRoot()
4401.1.2 by John Arbash Meinel
Move the logic back up into BzrDirFormat1.require_stacking, passing in the extra params.
1541
                    else:
5757.1.2 by Jelmer Vernooij
Add separate file for knit pack repository formats.
1542
                        new_repo_format = knitpack_repo.RepositoryFormatKnitPack5()
4401.1.2 by John Arbash Meinel
Move the logic back up into BzrDirFormat1.require_stacking, passing in the extra params.
1543
            else:
1544
                # If the target already supports stacking, then we know the
1545
                # project is already able to use stacking, so auto-upgrade
1546
                # for them
1547
                new_repo_format = target_branch.repository._format
1548
                if not new_repo_format.supports_external_lookups:
1549
                    # target doesn't, source doesn't, so don't auto upgrade
1550
                    # repo
1551
                    new_repo_format = None
1552
            if new_repo_format is not None:
1553
                self.repository_format = new_repo_format
6138.3.1 by Jonathan Riddell
use gettext() in more files
1554
                note(gettext('Source repository format does not support stacking,'
1555
                     ' using format:\n  %s'),
4401.1.2 by John Arbash Meinel
Move the logic back up into BzrDirFormat1.require_stacking, passing in the extra params.
1556
                     new_repo_format.get_format_description())
1557
3904.3.1 by Andrew Bennetts
Probable fix for GaryvdM's bug when pushing a stacked qbzr branch to Launchpad.
1558
        if not self.get_branch_format().supports_stacking():
4401.1.2 by John Arbash Meinel
Move the logic back up into BzrDirFormat1.require_stacking, passing in the extra params.
1559
            # We just checked the repo, now lets check if we need to
1560
            # upgrade the branch format
1561
            target_branch, _, do_upgrade = get_target_branch()
1562
            if target_branch is None:
1563
                if do_upgrade:
1564
                    # TODO: bad monkey, hard-coded formats...
5675.2.6 by Jelmer Vernooij
Fix some tests.
1565
                    from bzrlib.branch import BzrBranchFormat7
1566
                    new_branch_format = BzrBranchFormat7()
3904.3.1 by Andrew Bennetts
Probable fix for GaryvdM's bug when pushing a stacked qbzr branch to Launchpad.
1567
            else:
4401.1.2 by John Arbash Meinel
Move the logic back up into BzrDirFormat1.require_stacking, passing in the extra params.
1568
                new_branch_format = target_branch._format
1569
                if not new_branch_format.supports_stacking():
1570
                    new_branch_format = None
1571
            if new_branch_format is not None:
1572
                # Does support stacking, use its format.
1573
                self.set_branch_format(new_branch_format)
6138.3.1 by Jonathan Riddell
use gettext() in more files
1574
                note(gettext('Source branch format does not support stacking,'
1575
                     ' using format:\n  %s'),
4401.1.2 by John Arbash Meinel
Move the logic back up into BzrDirFormat1.require_stacking, passing in the extra params.
1576
                     new_branch_format.get_format_description())
3904.3.1 by Andrew Bennetts
Probable fix for GaryvdM's bug when pushing a stacked qbzr branch to Launchpad.
1577
1556.1.4 by Robert Collins
Add a new format for what will become knit, and the surrounding logic to upgrade repositories within metadirs, and tests for the same.
1578
    def get_converter(self, format=None):
1579
        """See BzrDirFormat.get_converter()."""
1580
        if format is None:
1581
            format = BzrDirFormat.get_default_format()
6207.1.1 by Jelmer Vernooij
Support upgrading between 2a and development-colo.
1582
        if (type(self) is BzrDirMetaFormat1 and
1583
            type(format) is BzrDirMetaFormat1Colo):
1584
            return ConvertMetaToColo(format)
1585
        if (type(self) is BzrDirMetaFormat1Colo and
1586
            type(format) is BzrDirMetaFormat1):
1587
            return ConvertMetaRemoveColo(format)
1556.1.4 by Robert Collins
Add a new format for what will become knit, and the surrounding logic to upgrade repositories within metadirs, and tests for the same.
1588
        if not isinstance(self, format.__class__):
1589
            # converting away from metadir is not implemented
1590
            raise NotImplementedError(self.get_converter)
1591
        return ConvertMetaToMeta(format)
1592
5712.3.15 by Jelmer Vernooij
Remove unused register format functions.
1593
    @classmethod
1594
    def get_format_string(cls):
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
1595
        """See BzrDirFormat.get_format_string()."""
1596
        return "Bazaar-NG meta directory, format 1\n"
1597
1624.3.19 by Olaf Conradi
New call get_format_description to give a user-friendly description of a
1598
    def get_format_description(self):
1599
        """See BzrDirFormat.get_format_description()."""
1600
        return "Meta directory format 1"
1601
6349.2.1 by Jelmer Vernooij
Add BzrDirMetaComponentFormat.
1602
    @classmethod
1603
    def from_string(cls, format_string):
1604
        if format_string != cls.get_format_string():
1605
            raise ValueError("Invalid format string %r" % format_string)
1606
        return cls()
1607
4070.2.1 by Robert Collins
Add a BzrDirFormat.network_name.
1608
    def network_name(self):
1609
        return self.get_format_string()
1610
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
1611
    def _open(self, transport):
1612
        """See BzrDirFormat._open."""
4294.2.12 by Robert Collins
Prevent aliasing issues with BzrDirMetaFormat1 by making a new format object in _open.
1613
        # Create a new format instance because otherwise initialisation of new
1614
        # metadirs share the global default format object leading to alias
1615
        # problems.
1616
        format = BzrDirMetaFormat1()
1617
        self._supply_sub_formats_to(format)
1618
        return BzrDirMeta1(transport, format)
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
1619
1556.1.4 by Robert Collins
Add a new format for what will become knit, and the surrounding logic to upgrade repositories within metadirs, and tests for the same.
1620
    def __return_repository_format(self):
1621
        """Circular import protection."""
4070.2.3 by Robert Collins
Get BzrDir.cloning_metadir working.
1622
        if self._repository_format:
1556.1.4 by Robert Collins
Add a new format for what will become knit, and the surrounding logic to upgrade repositories within metadirs, and tests for the same.
1623
            return self._repository_format
5651.3.2 by Jelmer Vernooij
Fix deprecation warnings in test suite.
1624
        from bzrlib.repository import format_registry
1625
        return format_registry.get_default()
1556.1.4 by Robert Collins
Add a new format for what will become knit, and the surrounding logic to upgrade repositories within metadirs, and tests for the same.
1626
4005.2.1 by Robert Collins
Fix RemoteBranch to be used correctly in tests using bzr+ssh, to fire off Branch hooks correctly, and improve the branch_implementations tests to check that making a branch gets the right format under test.
1627
    def _set_repository_format(self, value):
3015.2.8 by Robert Collins
Typo in __set_repository_format's docstring.
1628
        """Allow changing the repository format for metadir formats."""
1556.1.4 by Robert Collins
Add a new format for what will become knit, and the surrounding logic to upgrade repositories within metadirs, and tests for the same.
1629
        self._repository_format = value
1553.5.72 by Martin Pool
Clean up test for Branch5 lockdirs
1630
4005.2.1 by Robert Collins
Fix RemoteBranch to be used correctly in tests using bzr+ssh, to fire off Branch hooks correctly, and improve the branch_implementations tests to check that making a branch gets the right format under test.
1631
    repository_format = property(__return_repository_format,
1632
        _set_repository_format)
1633
1634
    def _supply_sub_formats_to(self, other_format):
1635
        """Give other_format the same values for sub formats as this has.
1636
1637
        This method is expected to be used when parameterising a
1638
        RemoteBzrDirFormat instance with the parameters from a
1639
        BzrDirMetaFormat1 instance.
1640
1641
        :param other_format: other_format is a format which should be
1642
            compatible with whatever sub formats are supported by self.
1643
        :return: None.
1644
        """
1645
        if getattr(self, '_repository_format', None) is not None:
1646
            other_format.repository_format = self.repository_format
1647
        if self._branch_format is not None:
1648
            other_format._branch_format = self._branch_format
1649
        if self._workingtree_format is not None:
1650
            other_format.workingtree_format = self.workingtree_format
1556.1.4 by Robert Collins
Add a new format for what will become knit, and the surrounding logic to upgrade repositories within metadirs, and tests for the same.
1651
2100.3.10 by Aaron Bentley
Ensure added references are serialized properly, beef up Workingtreee3
1652
    def __get_workingtree_format(self):
1653
        if self._workingtree_format is None:
5662.3.1 by Jelmer Vernooij
Add WorkingTreeFormatRegistry.
1654
            from bzrlib.workingtree import (
1655
                format_registry as wt_format_registry,
1656
                )
1657
            self._workingtree_format = wt_format_registry.get_default()
2100.3.10 by Aaron Bentley
Ensure added references are serialized properly, beef up Workingtreee3
1658
        return self._workingtree_format
1659
1660
    def __set_workingtree_format(self, wt_format):
1661
        self._workingtree_format = wt_format
1662
6349.2.1 by Jelmer Vernooij
Add BzrDirMetaComponentFormat.
1663
    def __repr__(self):
1664
        return "<%r>" % (self.__class__.__name__,)
1665
2100.3.10 by Aaron Bentley
Ensure added references are serialized properly, beef up Workingtreee3
1666
    workingtree_format = property(__get_workingtree_format,
1667
                                  __set_workingtree_format)
1668
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
1669
2164.2.13 by v.ladeuil+lp at free
Add tests for redirection. Preserve transport decorations.
1670
# Register bzr formats
5712.3.23 by Jelmer Vernooij
Register BzrMetaDir1 as a class in the BzrDir subformat registry. This subformat registry inherits from bzrlib.controldir.network_format_registry, which previously contained classes rather than instances.
1671
BzrProber.formats.register(BzrDirMetaFormat1.get_format_string(),
1672
    BzrDirMetaFormat1)
1673
controldir.ControlDirFormat._default_format = BzrDirMetaFormat1()
1534.4.39 by Robert Collins
Basic BzrDir support.
1674
1675
6083.2.10 by Jelmer Vernooij
Move more to colo class.
1676
class BzrDirMetaFormat1Colo(BzrDirMetaFormat1):
6083.2.11 by Jelmer Vernooij
Add development-colo format.
1677
    """BzrDirMeta1 format with support for colocated branches."""
6083.2.10 by Jelmer Vernooij
Move more to colo class.
1678
1679
    colocated_branches = True
1680
1681
    @classmethod
1682
    def get_format_string(cls):
1683
        """See BzrDirFormat.get_format_string()."""
1684
        return "Bazaar meta directory, format 1 (with colocated branches)\n"
1685
1686
    def get_format_description(self):
1687
        """See BzrDirFormat.get_format_description()."""
1688
        return "Meta directory format 1 with support for colocated branches"
1689
6083.2.11 by Jelmer Vernooij
Add development-colo format.
1690
    def _open(self, transport):
1691
        """See BzrDirFormat._open."""
1692
        # Create a new format instance because otherwise initialisation of new
1693
        # metadirs share the global default format object leading to alias
1694
        # problems.
1695
        format = BzrDirMetaFormat1Colo()
1696
        self._supply_sub_formats_to(format)
1697
        return BzrDirMeta1Colo(transport, format)
1698
6083.2.10 by Jelmer Vernooij
Move more to colo class.
1699
1700
BzrProber.formats.register(BzrDirMetaFormat1Colo.get_format_string(),
1701
    BzrDirMetaFormat1Colo)
1702
1703
5692.1.1 by Jelmer Vernooij
Move Converter (which is generic) from bzrlib.bzrdir to bzrlib.controldir.
1704
class ConvertMetaToMeta(controldir.Converter):
1556.1.4 by Robert Collins
Add a new format for what will become knit, and the surrounding logic to upgrade repositories within metadirs, and tests for the same.
1705
    """Converts the components of metadirs."""
1706
1707
    def __init__(self, target_format):
1708
        """Create a metadir to metadir converter.
1709
1710
        :param target_format: The final metadir format that is desired.
1711
        """
1712
        self.target_format = target_format
1713
1714
    def convert(self, to_convert, pb):
1715
        """See Converter.convert()."""
1716
        self.bzrdir = to_convert
4961.2.14 by Martin Pool
Further pb cleanups
1717
        self.pb = ui.ui_factory.nested_progress_bar()
1556.1.4 by Robert Collins
Add a new format for what will become knit, and the surrounding logic to upgrade repositories within metadirs, and tests for the same.
1718
        self.count = 0
1719
        self.total = 1
1720
        self.step('checking repository format')
1721
        try:
1722
            repo = self.bzrdir.open_repository()
1723
        except errors.NoRepositoryPresent:
1724
            pass
1725
        else:
1726
            if not isinstance(repo._format, self.target_format.repository_format.__class__):
1727
                from bzrlib.repository import CopyConverter
6138.3.1 by Jonathan Riddell
use gettext() in more files
1728
                ui.ui_factory.note(gettext('starting repository conversion'))
1556.1.4 by Robert Collins
Add a new format for what will become knit, and the surrounding logic to upgrade repositories within metadirs, and tests for the same.
1729
                converter = CopyConverter(self.target_format.repository_format)
1730
                converter.convert(repo, pb)
4997.1.3 by Jelmer Vernooij
Use list_branches during upgrades.
1731
        for branch in self.bzrdir.list_branches():
2255.12.1 by Robert Collins
Implement upgrade for working trees.
1732
            # TODO: conversions of Branch and Tree should be done by
3221.11.5 by Robert Collins
Correctly handle multi-step branch upgrades.
1733
            # InterXFormat lookups/some sort of registry.
2230.3.29 by Aaron Bentley
Implement conversion to branch 6
1734
            # Avoid circular imports
3221.11.5 by Robert Collins
Correctly handle multi-step branch upgrades.
1735
            old = branch._format.__class__
1736
            new = self.target_format.get_branch_format().__class__
1737
            while old != new:
1738
                if (old == _mod_branch.BzrBranchFormat5 and
1739
                    new in (_mod_branch.BzrBranchFormat6,
4273.1.13 by Aaron Bentley
Implement upgrade from branch format 7 to 8.
1740
                        _mod_branch.BzrBranchFormat7,
1741
                        _mod_branch.BzrBranchFormat8)):
3221.11.5 by Robert Collins
Correctly handle multi-step branch upgrades.
1742
                    branch_converter = _mod_branch.Converter5to6()
1743
                elif (old == _mod_branch.BzrBranchFormat6 and
4273.1.13 by Aaron Bentley
Implement upgrade from branch format 7 to 8.
1744
                    new in (_mod_branch.BzrBranchFormat7,
1745
                            _mod_branch.BzrBranchFormat8)):
3221.11.5 by Robert Collins
Correctly handle multi-step branch upgrades.
1746
                    branch_converter = _mod_branch.Converter6to7()
4273.1.13 by Aaron Bentley
Implement upgrade from branch format 7 to 8.
1747
                elif (old == _mod_branch.BzrBranchFormat7 and
1748
                      new is _mod_branch.BzrBranchFormat8):
1749
                    branch_converter = _mod_branch.Converter7to8()
3221.11.5 by Robert Collins
Correctly handle multi-step branch upgrades.
1750
                else:
4608.1.3 by Martin Pool
BadConversionTarget error includes source format
1751
                    raise errors.BadConversionTarget("No converter", new,
1752
                        branch._format)
2230.3.29 by Aaron Bentley
Implement conversion to branch 6
1753
                branch_converter.convert(branch)
3221.11.5 by Robert Collins
Correctly handle multi-step branch upgrades.
1754
                branch = self.bzrdir.open_branch()
1755
                old = branch._format.__class__
2255.12.1 by Robert Collins
Implement upgrade for working trees.
1756
        try:
2323.6.4 by Martin Pool
BzrDir._check_supported now also takes care of recommending upgrades, which
1757
            tree = self.bzrdir.open_workingtree(recommend_upgrade=False)
2255.2.196 by Robert Collins
Fix test_upgrade defects related to non local or absent working trees.
1758
        except (errors.NoWorkingTree, errors.NotLocalUrl):
2255.12.1 by Robert Collins
Implement upgrade for working trees.
1759
            pass
1760
        else:
1761
            # TODO: conversions of Branch and Tree should be done by
1762
            # InterXFormat lookups
5816.5.1 by Jelmer Vernooij
Move WorkingTree3 to bzrlib.workingtree_3.
1763
            if (isinstance(tree, workingtree_3.WorkingTree3) and
3907.2.3 by Ian Clatworthy
DirStateWorkingTree and DirStateWorkingTreeFormat base classes introduced
1764
                not isinstance(tree, workingtree_4.DirStateWorkingTree) and
2255.12.1 by Robert Collins
Implement upgrade for working trees.
1765
                isinstance(self.target_format.workingtree_format,
3907.2.3 by Ian Clatworthy
DirStateWorkingTree and DirStateWorkingTreeFormat base classes introduced
1766
                    workingtree_4.DirStateWorkingTreeFormat)):
2255.12.1 by Robert Collins
Implement upgrade for working trees.
1767
                workingtree_4.Converter3to4().convert(tree)
3907.2.3 by Ian Clatworthy
DirStateWorkingTree and DirStateWorkingTreeFormat base classes introduced
1768
            if (isinstance(tree, workingtree_4.DirStateWorkingTree) and
1769
                not isinstance(tree, workingtree_4.WorkingTree5) and
3586.1.8 by Ian Clatworthy
add workingtree_5 and initial upgrade code
1770
                isinstance(self.target_format.workingtree_format,
3907.2.3 by Ian Clatworthy
DirStateWorkingTree and DirStateWorkingTreeFormat base classes introduced
1771
                    workingtree_4.WorkingTreeFormat5)):
1772
                workingtree_4.Converter4to5().convert(tree)
4210.4.2 by Ian Clatworthy
split filtered views support out into WorkingTreeFormat6
1773
            if (isinstance(tree, workingtree_4.DirStateWorkingTree) and
1774
                not isinstance(tree, workingtree_4.WorkingTree6) and
1775
                isinstance(self.target_format.workingtree_format,
1776
                    workingtree_4.WorkingTreeFormat6)):
1777
                workingtree_4.Converter4or5to6().convert(tree)
4961.2.14 by Martin Pool
Further pb cleanups
1778
        self.pb.finished()
1556.1.4 by Robert Collins
Add a new format for what will become knit, and the surrounding logic to upgrade repositories within metadirs, and tests for the same.
1779
        return to_convert
1731.2.18 by Aaron Bentley
Get extract in repository under test
1780
1781
6207.1.1 by Jelmer Vernooij
Support upgrading between 2a and development-colo.
1782
class ConvertMetaToColo(controldir.Converter):
1783
    """Add colocated branch support."""
1784
1785
    def __init__(self, target_format):
1786
        """Create a converter.that upgrades a metadir to the colo format.
1787
1788
        :param target_format: The final metadir format that is desired.
1789
        """
1790
        self.target_format = target_format
1791
1792
    def convert(self, to_convert, pb):
1793
        """See Converter.convert()."""
1794
        to_convert.transport.put_bytes('branch-format',
1795
            self.target_format.get_format_string())
1796
        return BzrDir.open_from_transport(to_convert.root_transport)
1797
1798
1799
class ConvertMetaRemoveColo(controldir.Converter):
1800
    """Remove colocated branch support from a bzrdir."""
1801
1802
    def __init__(self, target_format):
1803
        """Create a converter.that downgrades a colocated branch metadir
1804
        to a regular metadir.
1805
1806
        :param target_format: The final metadir format that is desired.
1807
        """
1808
        self.target_format = target_format
1809
1810
    def convert(self, to_convert, pb):
1811
        """See Converter.convert()."""
1812
        to_convert.control_files.lock_write()
1813
        try:
1814
            branches = to_convert.list_branches()
1815
            if len(branches) > 1:
1816
                raise errors.BzrError("remove all but a single "
1817
                    "colocated branch when downgrading")
1818
        finally:
1819
            to_convert.control_files.unlock()
1820
        to_convert.transport.put_bytes('branch-format',
1821
            self.target_format.get_format_string())
1822
        return BzrDir.open_from_transport(to_convert.root_transport)
1823
1824
5363.2.20 by Jelmer Vernooij
use controldir.X
1825
controldir.ControlDirFormat.register_server_prober(RemoteBzrProber)
2204.4.1 by Aaron Bentley
Add 'formats' help topic
1826
1827
3242.2.14 by Aaron Bentley
Update from review comments
1828
class RepositoryAcquisitionPolicy(object):
1829
    """Abstract base class for repository acquisition policies.
3242.3.7 by Aaron Bentley
Delegate stacking to configure_branch
1830
3242.2.14 by Aaron Bentley
Update from review comments
1831
    A repository acquisition policy decides how a BzrDir acquires a repository
1832
    for a branch that is being created.  The most basic policy decision is
1833
    whether to create a new repository or use an existing one.
1834
    """
3242.3.40 by Aaron Bentley
Turn failing test into KnownFailure
1835
    def __init__(self, stack_on, stack_on_pwd, require_stacking):
3242.3.35 by Aaron Bentley
Cleanups and documentation
1836
        """Constructor.
1837
1838
        :param stack_on: A location to stack on
1839
        :param stack_on_pwd: If stack_on is relative, the location it is
1840
            relative to.
3242.3.40 by Aaron Bentley
Turn failing test into KnownFailure
1841
        :param require_stacking: If True, it is a failure to not stack.
3242.3.35 by Aaron Bentley
Cleanups and documentation
1842
        """
3242.3.7 by Aaron Bentley
Delegate stacking to configure_branch
1843
        self._stack_on = stack_on
3242.3.32 by Aaron Bentley
Defer handling relative stacking URLs as late as possible.
1844
        self._stack_on_pwd = stack_on_pwd
3242.3.40 by Aaron Bentley
Turn failing test into KnownFailure
1845
        self._require_stacking = require_stacking
3242.3.7 by Aaron Bentley
Delegate stacking to configure_branch
1846
1847
    def configure_branch(self, branch):
3242.2.13 by Aaron Bentley
Update docs
1848
        """Apply any configuration data from this policy to the branch.
1849
3242.3.18 by Aaron Bentley
Clean up repository-policy work
1850
        Default implementation sets repository stacking.
3242.2.13 by Aaron Bentley
Update docs
1851
        """
3242.3.33 by Aaron Bentley
Handle relative URL stacking cleanly
1852
        if self._stack_on is None:
1853
            return
1854
        if self._stack_on_pwd is None:
1855
            stack_on = self._stack_on
1856
        else:
1857
            try:
3242.3.32 by Aaron Bentley
Defer handling relative stacking URLs as late as possible.
1858
                stack_on = urlutils.rebase_url(self._stack_on,
1859
                    self._stack_on_pwd,
5158.6.9 by Martin Pool
Simplify various code to use user_url
1860
                    branch.user_url)
3242.3.33 by Aaron Bentley
Handle relative URL stacking cleanly
1861
            except errors.InvalidRebaseURLs:
1862
                stack_on = self._get_full_stack_on()
3242.3.37 by Aaron Bentley
Updates from reviews
1863
        try:
3537.3.5 by Martin Pool
merge trunk including stacking policy
1864
            branch.set_stacked_on_url(stack_on)
4126.1.1 by Andrew Bennetts
Fix bug when pushing stackable branch in unstackable repo to default-stacking target.
1865
        except (errors.UnstackableBranchFormat,
1866
                errors.UnstackableRepositoryFormat):
3242.3.40 by Aaron Bentley
Turn failing test into KnownFailure
1867
            if self._require_stacking:
1868
                raise
3242.3.33 by Aaron Bentley
Handle relative URL stacking cleanly
1869
4617.3.1 by Robert Collins
Fix test_stacking tests for 2a as a default format. The change to 2a exposed some actual bugs, both in tests and bzrdir/branch code.
1870
    def requires_stacking(self):
1871
        """Return True if this policy requires stacking."""
1872
        return self._stack_on is not None and self._require_stacking
1873
3242.3.33 by Aaron Bentley
Handle relative URL stacking cleanly
1874
    def _get_full_stack_on(self):
3242.3.35 by Aaron Bentley
Cleanups and documentation
1875
        """Get a fully-qualified URL for the stack_on location."""
3242.3.33 by Aaron Bentley
Handle relative URL stacking cleanly
1876
        if self._stack_on is None:
1877
            return None
1878
        if self._stack_on_pwd is None:
1879
            return self._stack_on
1880
        else:
1881
            return urlutils.join(self._stack_on_pwd, self._stack_on)
3242.3.7 by Aaron Bentley
Delegate stacking to configure_branch
1882
3928.3.2 by John Arbash Meinel
Track down the other cause of us connecting multiple times.
1883
    def _add_fallback(self, repository, possible_transports=None):
3242.3.35 by Aaron Bentley
Cleanups and documentation
1884
        """Add a fallback to the supplied repository, if stacking is set."""
3242.3.33 by Aaron Bentley
Handle relative URL stacking cleanly
1885
        stack_on = self._get_full_stack_on()
1886
        if stack_on is None:
3242.3.30 by Aaron Bentley
Handle adding fallback repositories in acquire_repository
1887
            return
4294.2.8 by Robert Collins
Reduce round trips pushing new branches substantially.
1888
        try:
1889
            stacked_dir = BzrDir.open(stack_on,
1890
                                      possible_transports=possible_transports)
1891
        except errors.JailBreak:
1892
            # We keep the stacking details, but we are in the server code so
1893
            # actually stacking is not needed.
1894
            return
3242.3.30 by Aaron Bentley
Handle adding fallback repositories in acquire_repository
1895
        try:
1896
            stacked_repo = stacked_dir.open_branch().repository
1897
        except errors.NotBranchError:
1898
            stacked_repo = stacked_dir.open_repository()
3242.3.37 by Aaron Bentley
Updates from reviews
1899
        try:
1900
            repository.add_fallback_repository(stacked_repo)
1901
        except errors.UnstackableRepositoryFormat:
3242.3.40 by Aaron Bentley
Turn failing test into KnownFailure
1902
            if self._require_stacking:
1903
                raise
3904.3.1 by Andrew Bennetts
Probable fix for GaryvdM's bug when pushing a stacked qbzr branch to Launchpad.
1904
        else:
1905
            self._require_stacking = True
3242.3.30 by Aaron Bentley
Handle adding fallback repositories in acquire_repository
1906
6305.3.1 by Jelmer Vernooij
Save a connection to the server when using --stacked.
1907
    def acquire_repository(self, make_working_trees=None, shared=False,
1908
            possible_transports=None):
3242.2.14 by Aaron Bentley
Update from review comments
1909
        """Acquire a repository for this bzrdir.
1910
1911
        Implementations may create a new repository or use a pre-exising
1912
        repository.
5891.1.2 by Andrew Bennetts
Fix a bunch of docstring formatting nits, making pydoctor a bit happier.
1913
3242.2.14 by Aaron Bentley
Update from review comments
1914
        :param make_working_trees: If creating a repository, set
1915
            make_working_trees to this value (if non-None)
1916
        :param shared: If creating a repository, make it shared if True
4070.9.8 by Andrew Bennetts
Use MiniSearchResult in clone_on_transport down (further tightening the test_push ratchets), and improve acquire_repository docstrings.
1917
        :return: A repository, is_new_flag (True if the repository was
1918
            created).
3242.2.14 by Aaron Bentley
Update from review comments
1919
        """
1920
        raise NotImplemented(RepositoryAcquisitionPolicy.acquire_repository)
1921
1922
1923
class CreateRepository(RepositoryAcquisitionPolicy):
3242.2.13 by Aaron Bentley
Update docs
1924
    """A policy of creating a new repository"""
3242.2.1 by Aaron Bentley
Abstract policy decisions into determine_repository_policy
1925
3242.3.40 by Aaron Bentley
Turn failing test into KnownFailure
1926
    def __init__(self, bzrdir, stack_on=None, stack_on_pwd=None,
1927
                 require_stacking=False):
5891.1.2 by Andrew Bennetts
Fix a bunch of docstring formatting nits, making pydoctor a bit happier.
1928
        """Constructor.
1929
3242.3.35 by Aaron Bentley
Cleanups and documentation
1930
        :param bzrdir: The bzrdir to create the repository on.
1931
        :param stack_on: A location to stack on
1932
        :param stack_on_pwd: If stack_on is relative, the location it is
1933
            relative to.
1934
        """
3242.3.40 by Aaron Bentley
Turn failing test into KnownFailure
1935
        RepositoryAcquisitionPolicy.__init__(self, stack_on, stack_on_pwd,
1936
                                             require_stacking)
3242.2.1 by Aaron Bentley
Abstract policy decisions into determine_repository_policy
1937
        self._bzrdir = bzrdir
1938
6305.3.1 by Jelmer Vernooij
Save a connection to the server when using --stacked.
1939
    def acquire_repository(self, make_working_trees=None, shared=False,
1940
            possible_transports=None):
3242.2.14 by Aaron Bentley
Update from review comments
1941
        """Implementation of RepositoryAcquisitionPolicy.acquire_repository
3242.2.13 by Aaron Bentley
Update docs
1942
3242.2.14 by Aaron Bentley
Update from review comments
1943
        Creates the desired repository in the bzrdir we already have.
3242.2.13 by Aaron Bentley
Update docs
1944
        """
6305.3.1 by Jelmer Vernooij
Save a connection to the server when using --stacked.
1945
        if possible_transports is None:
1946
            possible_transports = []
1947
        else:
1948
            possible_transports = list(possible_transports)
1949
        possible_transports.append(self._bzrdir.root_transport)
4165.2.1 by Robert Collins
Fix bzr failing to stack when a server requests it and the branch it is pushing from cannot stack but the branch it should stack on can.
1950
        stack_on = self._get_full_stack_on()
1951
        if stack_on:
4401.1.2 by John Arbash Meinel
Move the logic back up into BzrDirFormat1.require_stacking, passing in the extra params.
1952
            format = self._bzrdir._format
1953
            format.require_stacking(stack_on=stack_on,
6305.3.1 by Jelmer Vernooij
Save a connection to the server when using --stacked.
1954
                                    possible_transports=possible_transports)
4401.1.2 by John Arbash Meinel
Move the logic back up into BzrDirFormat1.require_stacking, passing in the extra params.
1955
            if not self._require_stacking:
1956
                # We have picked up automatic stacking somewhere.
6150.3.5 by Jonathan Riddell
more gettext()
1957
                note(gettext('Using default stacking branch {0} at {1}').format(
1958
                    self._stack_on, self._stack_on_pwd))
3650.3.9 by Aaron Bentley
Move responsibility for stackable repo format to _get_metadir
1959
        repository = self._bzrdir.create_repository(shared=shared)
3928.3.2 by John Arbash Meinel
Track down the other cause of us connecting multiple times.
1960
        self._add_fallback(repository,
6305.3.1 by Jelmer Vernooij
Save a connection to the server when using --stacked.
1961
                           possible_transports=possible_transports)
3242.2.4 by Aaron Bentley
Only set working tree policty when specified
1962
        if make_working_trees is not None:
3242.3.6 by Aaron Bentley
Work around strange test failure
1963
            repository.set_make_working_trees(make_working_trees)
4070.9.2 by Andrew Bennetts
Rough prototype of allowing a SearchResult to be passed to fetch, and using that to improve network conversations.
1964
        return repository, True
3242.2.2 by Aaron Bentley
Merge policy updates from stacked-policy thread
1965
1966
3242.2.14 by Aaron Bentley
Update from review comments
1967
class UseExistingRepository(RepositoryAcquisitionPolicy):
3242.2.13 by Aaron Bentley
Update docs
1968
    """A policy of reusing an existing repository"""
3242.2.1 by Aaron Bentley
Abstract policy decisions into determine_repository_policy
1969
3242.3.40 by Aaron Bentley
Turn failing test into KnownFailure
1970
    def __init__(self, repository, stack_on=None, stack_on_pwd=None,
1971
                 require_stacking=False):
3242.3.35 by Aaron Bentley
Cleanups and documentation
1972
        """Constructor.
1973
1974
        :param repository: The repository to use.
1975
        :param stack_on: A location to stack on
1976
        :param stack_on_pwd: If stack_on is relative, the location it is
1977
            relative to.
1978
        """
3242.3.40 by Aaron Bentley
Turn failing test into KnownFailure
1979
        RepositoryAcquisitionPolicy.__init__(self, stack_on, stack_on_pwd,
1980
                                             require_stacking)
3242.2.1 by Aaron Bentley
Abstract policy decisions into determine_repository_policy
1981
        self._repository = repository
1982
6305.3.1 by Jelmer Vernooij
Save a connection to the server when using --stacked.
1983
    def acquire_repository(self, make_working_trees=None, shared=False,
1984
            possible_transports=None):
3242.2.14 by Aaron Bentley
Update from review comments
1985
        """Implementation of RepositoryAcquisitionPolicy.acquire_repository
3242.2.13 by Aaron Bentley
Update docs
1986
4070.9.8 by Andrew Bennetts
Use MiniSearchResult in clone_on_transport down (further tightening the test_push ratchets), and improve acquire_repository docstrings.
1987
        Returns an existing repository to use.
3242.2.13 by Aaron Bentley
Update docs
1988
        """
6305.3.1 by Jelmer Vernooij
Save a connection to the server when using --stacked.
1989
        if possible_transports is None:
1990
            possible_transports = []
1991
        else:
1992
            possible_transports = list(possible_transports)
1993
        possible_transports.append(self._repository.bzrdir.transport)
3928.3.2 by John Arbash Meinel
Track down the other cause of us connecting multiple times.
1994
        self._add_fallback(self._repository,
6305.3.1 by Jelmer Vernooij
Save a connection to the server when using --stacked.
1995
                       possible_transports=possible_transports)
4070.9.2 by Andrew Bennetts
Rough prototype of allowing a SearchResult to be passed to fetch, and using that to improve network conversations.
1996
        return self._repository, False
3242.2.1 by Aaron Bentley
Abstract policy decisions into determine_repository_policy
1997
1998
5363.2.9 by Jelmer Vernooij
Fix some tests.
1999
def register_metadir(registry, key,
5363.2.6 by Jelmer Vernooij
Add ControlDirFormat.{un,}register_{server_,}prober.
2000
         repository_format, help, native=True, deprecated=False,
2001
         branch_format=None,
2002
         tree_format=None,
2003
         hidden=False,
2004
         experimental=False,
6083.2.9 by Jelmer Vernooij
Add development-colo as a separate format.
2005
         alias=False, bzrdir_format=None):
5363.2.6 by Jelmer Vernooij
Add ControlDirFormat.{un,}register_{server_,}prober.
2006
    """Register a metadir subformat.
2007
6083.2.9 by Jelmer Vernooij
Add development-colo as a separate format.
2008
    These all use a meta bzrdir, but can be parameterized by the
2009
    Repository/Branch/WorkingTreeformats.
5363.2.6 by Jelmer Vernooij
Add ControlDirFormat.{un,}register_{server_,}prober.
2010
2011
    :param repository_format: The fully-qualified repository format class
2012
        name as a string.
2013
    :param branch_format: Fully-qualified branch format class name as
2014
        a string.
2015
    :param tree_format: Fully-qualified tree format class name as
2016
        a string.
2017
    """
6083.2.9 by Jelmer Vernooij
Add development-colo as a separate format.
2018
    if bzrdir_format is None:
2019
        bzrdir_format = BzrDirMetaFormat1
5363.2.6 by Jelmer Vernooij
Add ControlDirFormat.{un,}register_{server_,}prober.
2020
    # This should be expanded to support setting WorkingTree and Branch
6083.2.9 by Jelmer Vernooij
Add development-colo as a separate format.
2021
    # formats, once the API supports that.
5363.2.6 by Jelmer Vernooij
Add ControlDirFormat.{un,}register_{server_,}prober.
2022
    def _load(full_name):
2023
        mod_name, factory_name = full_name.rsplit('.', 1)
2024
        try:
5436.2.1 by Andrew Bennetts
Add bzrlib.pyutils, which has get_named_object, a wrapper around __import__.
2025
            factory = pyutils.get_named_object(mod_name, factory_name)
5363.2.6 by Jelmer Vernooij
Add ControlDirFormat.{un,}register_{server_,}prober.
2026
        except ImportError, e:
2027
            raise ImportError('failed to load %s: %s' % (full_name, e))
2028
        except AttributeError:
2029
            raise AttributeError('no factory %s in module %r'
5436.2.1 by Andrew Bennetts
Add bzrlib.pyutils, which has get_named_object, a wrapper around __import__.
2030
                % (full_name, sys.modules[mod_name]))
5363.2.6 by Jelmer Vernooij
Add ControlDirFormat.{un,}register_{server_,}prober.
2031
        return factory()
2032
2033
    def helper():
6083.2.9 by Jelmer Vernooij
Add development-colo as a separate format.
2034
        bd = bzrdir_format()
5363.2.6 by Jelmer Vernooij
Add ControlDirFormat.{un,}register_{server_,}prober.
2035
        if branch_format is not None:
2036
            bd.set_branch_format(_load(branch_format))
2037
        if tree_format is not None:
2038
            bd.workingtree_format = _load(tree_format)
2039
        if repository_format is not None:
2040
            bd.repository_format = _load(repository_format)
2041
        return bd
5363.2.9 by Jelmer Vernooij
Fix some tests.
2042
    registry.register(key, helper, help, native, deprecated, hidden,
5363.2.6 by Jelmer Vernooij
Add ControlDirFormat.{un,}register_{server_,}prober.
2043
        experimental, alias)
2044
5363.2.20 by Jelmer Vernooij
use controldir.X
2045
register_metadir(controldir.format_registry, 'knit',
3892.1.2 by Ian Clatworthy
split formats topic into multiple topics
2046
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2047
    'Format using knits.  Recommended for interoperation with bzr <= 0.14.',
2048
    branch_format='bzrlib.branch.BzrBranchFormat5',
5816.5.1 by Jelmer Vernooij
Move WorkingTree3 to bzrlib.workingtree_3.
2049
    tree_format='bzrlib.workingtree_3.WorkingTreeFormat3',
4976.2.1 by Ian Clatworthy
Hide most storage formats
2050
    hidden=True,
3892.1.2 by Ian Clatworthy
split formats topic into multiple topics
2051
    deprecated=True)
5363.2.20 by Jelmer Vernooij
use controldir.X
2052
register_metadir(controldir.format_registry, 'dirstate',
2255.12.1 by Robert Collins
Implement upgrade for working trees.
2053
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
6294.1.3 by Jelmer Vernooij
Improve descriptions.
2054
    help='Format using dirstate for working trees. '
2055
        'Compatible with bzr 0.8 and '
2056
        'above when accessed over the network. Introduced in bzr 0.15.',
2255.12.1 by Robert Collins
Implement upgrade for working trees.
2057
    branch_format='bzrlib.branch.BzrBranchFormat5',
5816.2.1 by Jelmer Vernooij
Allow lazily setting default for working trees.
2058
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
4976.2.1 by Ian Clatworthy
Hide most storage formats
2059
    hidden=True,
3892.1.1 by Ian Clatworthy
improve help on storage formats
2060
    deprecated=True)
5363.2.20 by Jelmer Vernooij
use controldir.X
2061
register_metadir(controldir.format_registry, 'dirstate-tags',
1551.13.1 by Aaron Bentley
Introduce dirstate-tags format
2062
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
6294.1.3 by Jelmer Vernooij
Improve descriptions.
2063
    help='Variant of dirstate with support for tags. '
2064
        'Introduced in bzr 0.15.',
1551.13.1 by Aaron Bentley
Introduce dirstate-tags format
2065
    branch_format='bzrlib.branch.BzrBranchFormat6',
5816.2.1 by Jelmer Vernooij
Allow lazily setting default for working trees.
2066
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
4976.2.1 by Ian Clatworthy
Hide most storage formats
2067
    hidden=True,
3892.1.1 by Ian Clatworthy
improve help on storage formats
2068
    deprecated=True)
5363.2.20 by Jelmer Vernooij
use controldir.X
2069
register_metadir(controldir.format_registry, 'rich-root',
2996.2.1 by Aaron Bentley
Add KnitRepositoryFormat4
2070
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit4',
6294.1.3 by Jelmer Vernooij
Improve descriptions.
2071
    help='Variant of dirstate with better handling of tree roots. '
2072
        'Introduced in bzr 1.0',
2996.2.1 by Aaron Bentley
Add KnitRepositoryFormat4
2073
    branch_format='bzrlib.branch.BzrBranchFormat6',
5816.2.1 by Jelmer Vernooij
Allow lazily setting default for working trees.
2074
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
4976.2.1 by Ian Clatworthy
Hide most storage formats
2075
    hidden=True,
3892.1.1 by Ian Clatworthy
improve help on storage formats
2076
    deprecated=True)
5363.2.20 by Jelmer Vernooij
use controldir.X
2077
register_metadir(controldir.format_registry, 'dirstate-with-subtree',
2255.12.1 by Robert Collins
Implement upgrade for working trees.
2078
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
6294.1.3 by Jelmer Vernooij
Improve descriptions.
2079
    help='Variant of dirstate with support for nested trees. '
2080
         'Introduced in 0.15.',
2255.12.1 by Robert Collins
Implement upgrade for working trees.
2081
    branch_format='bzrlib.branch.BzrBranchFormat6',
5816.2.1 by Jelmer Vernooij
Allow lazily setting default for working trees.
2082
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
3170.4.3 by Adeodato Simó
Mark the subtree formats as experimental instead of hidden, and remove hidden=True from the rich-root ones.
2083
    experimental=True,
3170.4.4 by Adeodato Simó
Keep the hidden flag for subtree formats after review from Aaron.
2084
    hidden=True,
2255.12.1 by Robert Collins
Implement upgrade for working trees.
2085
    )
5363.2.20 by Jelmer Vernooij
use controldir.X
2086
register_metadir(controldir.format_registry, 'pack-0.92',
5757.1.2 by Jelmer Vernooij
Add separate file for knit pack repository formats.
2087
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack1',
6294.1.3 by Jelmer Vernooij
Improve descriptions.
2088
    help='Pack-based format used in 1.x series. Introduced in 0.92. '
2089
        'Interoperates with bzr repositories before 0.92 but cannot be '
2090
        'read by bzr < 0.92. '
4988.4.2 by Martin Pool
Change url to canonical.com or wiki, plus some doc improvements in passing
2091
        ,
2592.3.22 by Robert Collins
Add new experimental repository formats.
2092
    branch_format='bzrlib.branch.BzrBranchFormat6',
5816.2.1 by Jelmer Vernooij
Allow lazily setting default for working trees.
2093
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
6294.1.3 by Jelmer Vernooij
Improve descriptions.
2094
    deprecated=True,
2592.3.22 by Robert Collins
Add new experimental repository formats.
2095
    )
5363.2.20 by Jelmer Vernooij
use controldir.X
2096
register_metadir(controldir.format_registry, 'pack-0.92-subtree',
5757.1.2 by Jelmer Vernooij
Add separate file for knit pack repository formats.
2097
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack3',
6294.1.3 by Jelmer Vernooij
Improve descriptions.
2098
    help='Pack-based format used in 1.x series, with subtree support. '
2099
        'Introduced in 0.92. Interoperates with '
2939.2.6 by Ian Clatworthy
more review feedback from lifeless and poolie
2100
        'bzr repositories before 0.92 but cannot be read by bzr < 0.92. '
4988.4.2 by Martin Pool
Change url to canonical.com or wiki, plus some doc improvements in passing
2101
        ,
2592.3.22 by Robert Collins
Add new experimental repository formats.
2102
    branch_format='bzrlib.branch.BzrBranchFormat6',
5816.2.1 by Jelmer Vernooij
Allow lazily setting default for working trees.
2103
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
3190.1.2 by Aaron Bentley
Undo spurious change
2104
    hidden=True,
6294.1.3 by Jelmer Vernooij
Improve descriptions.
2105
    deprecated=True,
3170.4.3 by Adeodato Simó
Mark the subtree formats as experimental instead of hidden, and remove hidden=True from the rich-root ones.
2106
    experimental=True,
2592.3.22 by Robert Collins
Add new experimental repository formats.
2107
    )
5363.2.20 by Jelmer Vernooij
use controldir.X
2108
register_metadir(controldir.format_registry, 'rich-root-pack',
5757.1.2 by Jelmer Vernooij
Add separate file for knit pack repository formats.
2109
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack4',
6294.1.3 by Jelmer Vernooij
Improve descriptions.
2110
    help='A variant of pack-0.92 that supports rich-root data '
2111
         '(needed for bzr-svn and bzr-git). Introduced in 1.0.',
2996.2.11 by Aaron Bentley
Implement rich-root-pack format ( #164639)
2112
    branch_format='bzrlib.branch.BzrBranchFormat6',
5816.2.1 by Jelmer Vernooij
Allow lazily setting default for working trees.
2113
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
4976.2.1 by Ian Clatworthy
Hide most storage formats
2114
    hidden=True,
6294.1.3 by Jelmer Vernooij
Improve descriptions.
2115
    deprecated=True,
3152.2.1 by Robert Collins
* A new repository format 'development' has been added. This format will
2116
    )
5363.2.20 by Jelmer Vernooij
use controldir.X
2117
register_metadir(controldir.format_registry, '1.6',
5757.1.2 by Jelmer Vernooij
Add separate file for knit pack repository formats.
2118
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack5',
3892.1.6 by Ian Clatworthy
include feedback from poolie
2119
    help='A format that allows a branch to indicate that there is another '
2120
         '(stacked) repository that should be used to access data that is '
2121
         'not present locally.',
3549.1.5 by Martin Pool
Add stable format names for stacked branches
2122
    branch_format='bzrlib.branch.BzrBranchFormat7',
5816.2.1 by Jelmer Vernooij
Allow lazily setting default for working trees.
2123
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
4976.2.1 by Ian Clatworthy
Hide most storage formats
2124
    hidden=True,
6294.1.3 by Jelmer Vernooij
Improve descriptions.
2125
    deprecated=True,
3549.1.5 by Martin Pool
Add stable format names for stacked branches
2126
    )
5363.2.20 by Jelmer Vernooij
use controldir.X
2127
register_metadir(controldir.format_registry, '1.6.1-rich-root',
5757.1.2 by Jelmer Vernooij
Add separate file for knit pack repository formats.
2128
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack5RichRoot',
3892.1.2 by Ian Clatworthy
split formats topic into multiple topics
2129
    help='A variant of 1.6 that supports rich-root data '
4119.6.2 by Jelmer Vernooij
Use existing alias mechanism for default-rich-root.
2130
         '(needed for bzr-svn and bzr-git).',
3549.1.5 by Martin Pool
Add stable format names for stacked branches
2131
    branch_format='bzrlib.branch.BzrBranchFormat7',
5816.2.1 by Jelmer Vernooij
Allow lazily setting default for working trees.
2132
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
4976.2.1 by Ian Clatworthy
Hide most storage formats
2133
    hidden=True,
6294.1.3 by Jelmer Vernooij
Improve descriptions.
2134
    deprecated=True,
3549.1.5 by Martin Pool
Add stable format names for stacked branches
2135
    )
5363.2.20 by Jelmer Vernooij
use controldir.X
2136
register_metadir(controldir.format_registry, '1.9',
5757.1.2 by Jelmer Vernooij
Add separate file for knit pack repository formats.
2137
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack6',
3892.1.6 by Ian Clatworthy
include feedback from poolie
2138
    help='A repository format using B+tree indexes. These indexes '
3892.1.4 by Ian Clatworthy
rich-root explanation and improved help for 1.6 and 1.9 formats
2139
         'are smaller in size, have smarter caching and provide faster '
2140
         'performance for most operations.',
3805.3.1 by John Arbash Meinel
Add repository 1.9 format, and update the documentation.
2141
    branch_format='bzrlib.branch.BzrBranchFormat7',
5816.2.1 by Jelmer Vernooij
Allow lazily setting default for working trees.
2142
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
4976.2.1 by Ian Clatworthy
Hide most storage formats
2143
    hidden=True,
6294.1.3 by Jelmer Vernooij
Improve descriptions.
2144
    deprecated=True,
3805.3.1 by John Arbash Meinel
Add repository 1.9 format, and update the documentation.
2145
    )
5363.2.20 by Jelmer Vernooij
use controldir.X
2146
register_metadir(controldir.format_registry, '1.9-rich-root',
5757.1.2 by Jelmer Vernooij
Add separate file for knit pack repository formats.
2147
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack6RichRoot',
3892.1.2 by Ian Clatworthy
split formats topic into multiple topics
2148
    help='A variant of 1.9 that supports rich-root data '
4119.6.2 by Jelmer Vernooij
Use existing alias mechanism for default-rich-root.
2149
         '(needed for bzr-svn and bzr-git).',
3805.3.1 by John Arbash Meinel
Add repository 1.9 format, and update the documentation.
2150
    branch_format='bzrlib.branch.BzrBranchFormat7',
5816.2.1 by Jelmer Vernooij
Allow lazily setting default for working trees.
2151
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
4976.2.1 by Ian Clatworthy
Hide most storage formats
2152
    hidden=True,
6294.1.3 by Jelmer Vernooij
Improve descriptions.
2153
    deprecated=True,
3805.3.1 by John Arbash Meinel
Add repository 1.9 format, and update the documentation.
2154
    )
5363.2.20 by Jelmer Vernooij
use controldir.X
2155
register_metadir(controldir.format_registry, '1.14',
5757.1.2 by Jelmer Vernooij
Add separate file for knit pack repository formats.
2156
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack6',
4210.4.2 by Ian Clatworthy
split filtered views support out into WorkingTreeFormat6
2157
    help='A working-tree format that supports content filtering.',
3586.2.6 by Ian Clatworthy
add 1.7 and 1.7-rich-root formats
2158
    branch_format='bzrlib.branch.BzrBranchFormat7',
5816.2.1 by Jelmer Vernooij
Allow lazily setting default for working trees.
2159
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat5',
6294.1.2 by Jelmer Vernooij
Hide 1.14 too.
2160
    hidden=True,
6294.1.3 by Jelmer Vernooij
Improve descriptions.
2161
    deprecated=True,
3586.2.6 by Ian Clatworthy
add 1.7 and 1.7-rich-root formats
2162
    )
5363.2.20 by Jelmer Vernooij
use controldir.X
2163
register_metadir(controldir.format_registry, '1.14-rich-root',
5757.1.2 by Jelmer Vernooij
Add separate file for knit pack repository formats.
2164
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack6RichRoot',
4210.4.1 by Ian Clatworthy
replace experimental development-wt5 formats with 1.14 formats
2165
    help='A variant of 1.14 that supports rich-root data '
4119.6.2 by Jelmer Vernooij
Use existing alias mechanism for default-rich-root.
2166
         '(needed for bzr-svn and bzr-git).',
3586.2.6 by Ian Clatworthy
add 1.7 and 1.7-rich-root formats
2167
    branch_format='bzrlib.branch.BzrBranchFormat7',
5816.2.1 by Jelmer Vernooij
Allow lazily setting default for working trees.
2168
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat5',
6294.1.1 by Jelmer Vernooij
Mark development-colo as experimental and 1.14-rich-root as hidden.
2169
    hidden=True,
6294.1.3 by Jelmer Vernooij
Improve descriptions.
2170
    deprecated=True,
3586.2.6 by Ian Clatworthy
add 1.7 and 1.7-rich-root formats
2171
    )
4241.6.8 by Robert Collins, John Arbash Meinel, Ian Clatworthy, Vincent Ladeuil
Add --development6-rich-root, disabling the legacy and unneeded development2 format, and activating the tests for CHK features disabled pending this format. (Robert Collins, John Arbash Meinel, Ian Clatworthy, Vincent Ladeuil)
2172
# The following un-numbered 'development' formats should always just be aliases.
5363.2.20 by Jelmer Vernooij
use controldir.X
2173
register_metadir(controldir.format_registry, 'development-subtree',
5389.1.1 by Jelmer Vernooij
Add development8-subtree.
2174
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2aSubtree',
3152.2.1 by Robert Collins
* A new repository format 'development' has been added. This format will
2175
    help='Current development format, subtree variant. Can convert data to and '
3221.11.7 by Robert Collins
Merge in real stacked repository work.
2176
        'from pack-0.92-subtree (and anything compatible with '
2177
        'pack-0.92-subtree) format repositories. Repositories and branches in '
2178
        'this format can only be read by bzr.dev. Please read '
4988.4.2 by Martin Pool
Change url to canonical.com or wiki, plus some doc improvements in passing
2179
        'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
3152.2.1 by Robert Collins
* A new repository format 'development' has been added. This format will
2180
        'before use.',
3221.11.2 by Robert Collins
Create basic stackable branch facility.
2181
    branch_format='bzrlib.branch.BzrBranchFormat7',
5816.2.1 by Jelmer Vernooij
Allow lazily setting default for working trees.
2182
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat6',
3152.2.1 by Robert Collins
* A new repository format 'development' has been added. This format will
2183
    experimental=True,
4976.2.1 by Ian Clatworthy
Hide most storage formats
2184
    hidden=True,
4241.6.8 by Robert Collins, John Arbash Meinel, Ian Clatworthy, Vincent Ladeuil
Add --development6-rich-root, disabling the legacy and unneeded development2 format, and activating the tests for CHK features disabled pending this format. (Robert Collins, John Arbash Meinel, Ian Clatworthy, Vincent Ladeuil)
2185
    alias=False, # Restore to being an alias when an actual development subtree format is added
2186
                 # This current non-alias status is simply because we did not introduce a
2187
                 # chk based subtree format.
3152.2.1 by Robert Collins
* A new repository format 'development' has been added. This format will
2188
    )
5546.1.1 by Andrew Bennetts
Remove RepositoryFormatCHK1 and RepositoryFormatCHK2.
2189
register_metadir(controldir.format_registry, 'development5-subtree',
5757.1.2 by Jelmer Vernooij
Add separate file for knit pack repository formats.
2190
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatPackDevelopment2Subtree',
5546.1.1 by Andrew Bennetts
Remove RepositoryFormatCHK1 and RepositoryFormatCHK2.
2191
    help='Development format, subtree variant. Can convert data to and '
2192
        'from pack-0.92-subtree (and anything compatible with '
2193
        'pack-0.92-subtree) format repositories. Repositories and branches in '
2194
        'this format can only be read by bzr.dev. Please read '
2195
        'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
2196
        'before use.',
2197
    branch_format='bzrlib.branch.BzrBranchFormat7',
5816.2.1 by Jelmer Vernooij
Allow lazily setting default for working trees.
2198
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat6',
5546.1.1 by Andrew Bennetts
Remove RepositoryFormatCHK1 and RepositoryFormatCHK2.
2199
    experimental=True,
2200
    hidden=True,
2201
    alias=False,
2202
    )
4241.6.8 by Robert Collins, John Arbash Meinel, Ian Clatworthy, Vincent Ladeuil
Add --development6-rich-root, disabling the legacy and unneeded development2 format, and activating the tests for CHK features disabled pending this format. (Robert Collins, John Arbash Meinel, Ian Clatworthy, Vincent Ladeuil)
2203
6083.2.9 by Jelmer Vernooij
Add development-colo as a separate format.
2204
register_metadir(controldir.format_registry, 'development-colo',
2205
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2a',
2206
    help='The 2a format with experimental support for colocated branches.\n',
2207
    branch_format='bzrlib.branch.BzrBranchFormat7',
2208
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat6',
6294.1.1 by Jelmer Vernooij
Mark development-colo as experimental and 1.14-rich-root as hidden.
2209
    experimental=True,
6083.2.9 by Jelmer Vernooij
Add development-colo as a separate format.
2210
    bzrdir_format=BzrDirMetaFormat1Colo,
2211
    )
2212
2213
3735.1.1 by Robert Collins
Add development2 formats using BTree indices.
2214
# And the development formats above will have aliased one of the following:
5546.1.1 by Andrew Bennetts
Remove RepositoryFormatCHK1 and RepositoryFormatCHK2.
2215
2216
# Finally, the current format.
5363.2.20 by Jelmer Vernooij
use controldir.X
2217
register_metadir(controldir.format_registry, '2a',
4428.2.1 by Martin Pool
Add 2a format
2218
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2a',
6294.1.3 by Jelmer Vernooij
Improve descriptions.
2219
    help='Format for the bzr 2.0 series.\n'
4428.2.5 by Martin Pool
Mark 2a experimental and tweak its help per lifeless's review
2220
        'Uses group-compress storage.\n'
4428.2.6 by Martin Pool
Stupid typo fix
2221
        'Provides rich roots which are a one-way transition.\n',
4428.2.5 by Martin Pool
Mark 2a experimental and tweak its help per lifeless's review
2222
        # 'storage in packs, 255-way hashed CHK inventory, bencode revision, group compress, '
2223
        # 'rich roots. Supported by bzr 1.16 and later.',
4428.2.1 by Martin Pool
Add 2a format
2224
    branch_format='bzrlib.branch.BzrBranchFormat7',
5816.2.1 by Jelmer Vernooij
Allow lazily setting default for working trees.
2225
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat6',
5389.1.1 by Jelmer Vernooij
Add development8-subtree.
2226
    experimental=False,
4428.2.1 by Martin Pool
Add 2a format
2227
    )
4428.2.2 by Martin Pool
Format 2a should not be hidden
2228
4119.6.2 by Jelmer Vernooij
Use existing alias mechanism for default-rich-root.
2229
# The following format should be an alias for the rich root equivalent 
2230
# of the default format
5363.2.20 by Jelmer Vernooij
use controldir.X
2231
register_metadir(controldir.format_registry, 'default-rich-root',
4599.4.37 by Robert Collins
Fix registration of default-rich-root as 2a.
2232
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2a',
2233
    branch_format='bzrlib.branch.BzrBranchFormat7',
5816.2.1 by Jelmer Vernooij
Allow lazily setting default for working trees.
2234
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat6',
4599.4.23 by Robert Collins
default-rich-root should be an alias still.
2235
    alias=True,
4976.2.1 by Ian Clatworthy
Hide most storage formats
2236
    hidden=True,
4599.4.22 by mbp at sourcefrog
Don't forget to set default-rich-root to 2a too.
2237
    help='Same as 2a.')
2238
3221.11.2 by Robert Collins
Create basic stackable branch facility.
2239
# The current format that is made on 'bzr init'.
6056.2.2 by Vincent Ladeuil
Migrate default_format.
2240
format_name = config.GlobalStack().get('default_format')
2241
controldir.format_registry.set_default(format_name)
5363.2.22 by Jelmer Vernooij
Provide bzrlib.bzrdir.format_registry.
2242
2243
# XXX 2010-08-20 JRV: There is still a lot of code relying on
2244
# bzrlib.bzrdir.format_registry existing. When BzrDir.create/BzrDir.open/etc
2245
# get changed to ControlDir.create/ControlDir.open/etc this should be removed.
2246
format_registry = controldir.format_registry