/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
1
# Copyright (C) 2005, 2006, 2007 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
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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.
21
"""
22
1910.7.17 by Andrew Bennetts
Various cosmetic changes.
23
# TODO: Can we move specific formats into separate modules to make this file
24
# smaller?
25
1773.4.1 by Martin Pool
Add pyflakes makefile target; fix many warnings
26
from cStringIO import StringIO
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
27
import os
1996.3.3 by John Arbash Meinel
Shave off another 40ms by demand loading branch and bzrdir
28
29
from bzrlib.lazy_import import lazy_import
30
lazy_import(globals(), """
1773.4.1 by Martin Pool
Add pyflakes makefile target; fix many warnings
31
from stat import S_ISDIR
2711.2.1 by Martin Pool
Deprecate BzrDir.create_repository
32
import textwrap
33
from warnings import warn
1534.4.39 by Robert Collins
Basic BzrDir support.
34
35
import bzrlib
1996.3.3 by John Arbash Meinel
Shave off another 40ms by demand loading branch and bzrdir
36
from bzrlib import (
37
    errors,
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,
2204.4.1 by Aaron Bentley
Add 'formats' help topic
41
    registry,
2018.5.25 by Andrew Bennetts
Make sure RemoteBzrDirFormat is always registered (John Arbash Meinel, Robert Collins, Andrew Bennetts).
42
    remote,
1996.3.12 by John Arbash Meinel
Change how 'revision' is imported to avoid problems later
43
    revision as _mod_revision,
2204.4.12 by Aaron Bentley
Deprecate bzrdir.BzrDirFormat.set_default_format
44
    symbol_versioning,
2323.6.4 by Martin Pool
BzrDir._check_supported now also takes care of recommending upgrades, which
45
    ui,
1996.3.3 by John Arbash Meinel
Shave off another 40ms by demand loading branch and bzrdir
46
    urlutils,
1996.3.6 by John Arbash Meinel
Find a few places that weren't importing their dependencies.
47
    xml4,
48
    xml5,
2255.12.1 by Robert Collins
Implement upgrade for working trees.
49
    workingtree,
50
    workingtree_4,
1996.3.3 by John Arbash Meinel
Shave off another 40ms by demand loading branch and bzrdir
51
    )
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
52
from bzrlib.osutils import (
1996.3.3 by John Arbash Meinel
Shave off another 40ms by demand loading branch and bzrdir
53
    sha_strings,
54
    sha_string,
55
    )
2018.5.159 by Andrew Bennetts
Rename SmartClient to _SmartClient.
56
from bzrlib.smart.client import _SmartClient
2432.3.1 by Andrew Bennetts
Try a version 1 hello probe to determine if we can use RemoteBzrDir on a particular transport, allowing smooth interoperation with older servers.
57
from bzrlib.smart import protocol
1563.2.28 by Robert Collins
Add total_size to the revision_store api.
58
from bzrlib.store.revision.text import TextRevisionStore
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
59
from bzrlib.store.text import TextStore
1563.2.25 by Robert Collins
Merge in upstream.
60
from bzrlib.store.versioned import WeaveStore
1563.2.34 by Robert Collins
Remove the commit and rollback transaction methods as misleading, and implement a WriteTransaction
61
from bzrlib.transactions import WriteTransaction
2164.2.21 by Vincent Ladeuil
Take bundles into account.
62
from bzrlib.transport import (
63
    do_catching_redirections,
64
    get_transport,
65
    )
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
66
from bzrlib.weave import Weave
1996.3.3 by John Arbash Meinel
Shave off another 40ms by demand loading branch and bzrdir
67
""")
68
2164.2.1 by v.ladeuil+lp at free
First rough http branch redirection implementation.
69
from bzrlib.trace import (
70
    mutter,
71
    note,
72
    )
1996.3.3 by John Arbash Meinel
Shave off another 40ms by demand loading branch and bzrdir
73
from bzrlib.transport.local import LocalTransport
2711.2.1 by Martin Pool
Deprecate BzrDir.create_repository
74
from bzrlib.symbol_versioning import (
75
    deprecated_function,
76
    deprecated_method,
77
    zero_ninetyone,
78
    )
1534.4.39 by Robert Collins
Basic BzrDir support.
79
80
81
class BzrDir(object):
82
    """A .bzr control diretory.
83
    
84
    BzrDir instances let you create or open any of the things that can be
85
    found within .bzr - checkouts, branches and repositories.
86
    
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
87
    transport
88
        the transport which this bzr dir is rooted at (i.e. file:///.../.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.
89
    root_transport
90
        a transport connected to the directory this bzr was opened from.
1534.4.39 by Robert Collins
Basic BzrDir support.
91
    """
92
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
93
    def break_lock(self):
94
        """Invoke break_lock on the first object in the bzrdir.
95
96
        If there is a tree, the tree is opened and break_lock() called.
97
        Otherwise, branch is tried, and finally repository.
98
        """
1752.2.52 by Andrew Bennetts
Flesh out more Remote* methods needed to open and initialise remote branches/trees/repositories.
99
        # XXX: This seems more like a UI function than something that really
100
        # belongs in this class.
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
101
        try:
102
            thing_to_unlock = self.open_workingtree()
103
        except (errors.NotLocalUrl, errors.NoWorkingTree):
104
            try:
105
                thing_to_unlock = self.open_branch()
106
            except errors.NotBranchError:
107
                try:
108
                    thing_to_unlock = self.open_repository()
109
                except errors.NoRepositoryPresent:
110
                    return
111
        thing_to_unlock.break_lock()
112
1534.5.16 by Robert Collins
Review feedback.
113
    def can_convert_format(self):
114
        """Return true if this bzrdir is one whose format we can convert from."""
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
115
        return True
116
1910.2.12 by Aaron Bentley
Implement knit repo format 2
117
    def check_conversion_target(self, target_format):
118
        target_repo_format = target_format.repository_format
119
        source_repo_format = self._format.repository_format
120
        source_repo_format.check_conversion_target(target_repo_format)
121
1596.2.1 by Robert Collins
Fix BzrDir.open_containing of unsupported branches.
122
    @staticmethod
2323.6.4 by Martin Pool
BzrDir._check_supported now also takes care of recommending upgrades, which
123
    def _check_supported(format, allow_unsupported,
124
        recommend_upgrade=True,
125
        basedir=None):
126
        """Give an error or warning on old formats.
127
128
        :param format: may be any kind of format - workingtree, branch, 
129
        or repository.
130
131
        :param allow_unsupported: If true, allow opening 
132
        formats that are strongly deprecated, and which may 
133
        have limited functionality.
134
135
        :param recommend_upgrade: If true (default), warn
136
        the user through the ui object that they may wish
137
        to upgrade the object.
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
138
        """
2323.5.19 by Martin Pool
No upgrade recommendation on source when cloning
139
        # TODO: perhaps move this into a base Format class; it's not BzrDir
140
        # specific. mbp 20070323
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
141
        if not allow_unsupported and not format.is_supported():
1596.2.1 by Robert Collins
Fix BzrDir.open_containing of unsupported branches.
142
            # see open_downlevel to open legacy branches.
1740.5.6 by Martin Pool
Clean up many exception classes.
143
            raise errors.UnsupportedFormatError(format=format)
2323.6.4 by Martin Pool
BzrDir._check_supported now also takes care of recommending upgrades, which
144
        if recommend_upgrade \
145
            and getattr(format, 'upgrade_recommended', False):
146
            ui.ui_factory.recommend_upgrade(
147
                format.get_format_description(),
148
                basedir)
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
149
2387.1.1 by Robert Collins
Remove the --basis parameter to clone etc. (Robert Collins)
150
    def clone(self, url, revision_id=None, force_new_repo=False):
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.
151
        """Clone this bzrdir and its contents to url verbatim.
152
153
        If urls last component does not exist, it will be created.
154
155
        if revision_id is not None, then the clone operation may tune
156
            itself to download less data.
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.
157
        :param force_new_repo: Do not use a shared repository for the target 
158
                               even if one is available.
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.
159
        """
2475.3.1 by John Arbash Meinel
Fix bug #75721. Update the BzrDir api to add clone_on_transport()
160
        return self.clone_on_transport(get_transport(url),
161
                                       revision_id=revision_id,
162
                                       force_new_repo=force_new_repo)
163
164
    def clone_on_transport(self, transport, revision_id=None,
165
                           force_new_repo=False):
166
        """Clone this bzrdir and its contents to transport verbatim.
167
168
        If the target directory does not exist, it will be created.
169
170
        if revision_id is not None, then the clone operation may tune
171
            itself to download less data.
172
        :param force_new_repo: Do not use a shared repository for the target 
173
                               even if one is available.
174
        """
2475.3.3 by John Arbash Meinel
Change calls to try/mkdir('.')/except FileExists to ensure_base()
175
        transport.ensure_base()
2475.3.1 by John Arbash Meinel
Fix bug #75721. Update the BzrDir api to add clone_on_transport()
176
        result = self._format.initialize_on_transport(transport)
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.
177
        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.
178
            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.
179
        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.
180
            local_repo = None
181
        if local_repo:
182
            # may need to copy content in
183
            if force_new_repo:
1707.1.1 by Robert Collins
Bugfixes to bzrdir.sprout and clone. Sprout was failing to reset the
184
                result_repo = local_repo.clone(
185
                    result,
2387.1.1 by Robert Collins
Remove the --basis parameter to clone etc. (Robert Collins)
186
                    revision_id=revision_id)
1707.1.1 by Robert Collins
Bugfixes to bzrdir.sprout and clone. Sprout was failing to reset the
187
                result_repo.set_make_working_trees(local_repo.make_working_trees())
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.
188
            else:
189
                try:
190
                    result_repo = result.find_repository()
191
                    # fetch content this dir needs.
192
                    result_repo.fetch(local_repo, revision_id=revision_id)
193
                except errors.NoRepositoryPresent:
194
                    # needed to make one anyway.
1707.1.1 by Robert Collins
Bugfixes to bzrdir.sprout and clone. Sprout was failing to reset the
195
                    result_repo = local_repo.clone(
196
                        result,
2387.1.1 by Robert Collins
Remove the --basis parameter to clone etc. (Robert Collins)
197
                        revision_id=revision_id)
1707.1.1 by Robert Collins
Bugfixes to bzrdir.sprout and clone. Sprout was failing to reset the
198
                    result_repo.set_make_working_trees(local_repo.make_working_trees())
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.
199
        # 1 if there is a branch present
200
        #   make sure its content is available in the target repository
201
        #   clone it.
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.
202
        try:
203
            self.open_branch().clone(result, revision_id=revision_id)
204
        except errors.NotBranchError:
205
            pass
206
        try:
2387.1.1 by Robert Collins
Remove the --basis parameter to clone etc. (Robert Collins)
207
            self.open_workingtree().clone(result)
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
208
        except (errors.NoWorkingTree, errors.NotLocalUrl):
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.
209
            pass
210
        return result
211
1685.1.61 by Martin Pool
[broken] Change BzrDir._make_tail to use urlutils.split
212
    # TODO: This should be given a Transport, and should chdir up; otherwise
213
    # 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.
214
    def _make_tail(self, url):
2475.3.3 by John Arbash Meinel
Change calls to try/mkdir('.')/except FileExists to ensure_base()
215
        t = get_transport(url)
216
        t.ensure_base()
2475.3.1 by John Arbash Meinel
Fix bug #75721. Update the BzrDir api to add clone_on_transport()
217
1553.5.71 by Martin Pool
Change branch format 5 to use LockDirs, not transport locks
218
    @classmethod
2476.3.8 by Vincent Ladeuil
Mark transports that need to be instrumented or refactored to check
219
    def create(cls, base, format=None, possible_transports=None):
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
220
        """Create a new BzrDir at the url 'base'.
1534.4.39 by Robert Collins
Basic BzrDir support.
221
        
222
        This will call the current default formats initialize with base
223
        as the only parameter.
224
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
225
        :param format: If supplied, the format of branch to create.  If not
226
            supplied, the default is used.
2476.3.8 by Vincent Ladeuil
Mark transports that need to be instrumented or refactored to check
227
        :param possible_transports: If supplied, a list of transports that 
228
            can be reused to share a remote connection.
1534.4.39 by Robert Collins
Basic BzrDir support.
229
        """
1553.5.71 by Martin Pool
Change branch format 5 to use LockDirs, not transport locks
230
        if cls is not BzrDir:
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
231
            raise AssertionError("BzrDir.create always creates the default"
232
                " format, not one of %r" % cls)
2476.3.8 by Vincent Ladeuil
Mark transports that need to be instrumented or refactored to check
233
        t = get_transport(base, possible_transports)
2475.3.3 by John Arbash Meinel
Change calls to try/mkdir('.')/except FileExists to ensure_base()
234
        t.ensure_base()
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
235
        if format is None:
236
            format = BzrDirFormat.get_default_format()
2485.8.45 by Vincent Ladeuil
Take jam's remarks into account.
237
        return format.initialize(base, possible_transports)
1534.4.39 by Robert Collins
Basic BzrDir support.
238
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
239
    def create_branch(self):
240
        """Create a branch in this BzrDir.
241
242
        The bzrdirs format will control what branch format is created.
243
        For more control see BranchFormatXX.create(a_bzrdir).
244
        """
245
        raise NotImplementedError(self.create_branch)
246
247
    @staticmethod
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
248
    def create_branch_and_repo(base, force_new_repo=False, format=None):
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
249
        """Create a new BzrDir, Branch and Repository at the url 'base'.
250
251
        This will use the current default BzrDirFormat, and use whatever 
252
        repository format that that uses via bzrdir.create_branch and
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.
253
        create_repository. If a shared repository is available that is used
254
        preferentially.
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
255
256
        The created Branch object is returned.
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.
257
258
        :param base: The URL to create the branch at.
259
        :param force_new_repo: If True a new repository is always created.
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
260
        """
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
261
        bzrdir = BzrDir.create(base, format)
1534.6.11 by Robert Collins
Review feedback.
262
        bzrdir._find_or_create_repository(force_new_repo)
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
263
        return bzrdir.create_branch()
1534.6.11 by Robert Collins
Review feedback.
264
265
    def _find_or_create_repository(self, force_new_repo):
266
        """Create a new repository if needed, returning the repository."""
267
        if force_new_repo:
268
            return self.create_repository()
269
        try:
270
            return self.find_repository()
271
        except errors.NoRepositoryPresent:
272
            return self.create_repository()
2476.3.6 by Vincent Ladeuil
Fix the 'init connects multiple times' in a different way.
273
        
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
274
    @staticmethod
2476.3.6 by Vincent Ladeuil
Fix the 'init connects multiple times' in a different way.
275
    def create_branch_convenience(base, force_new_repo=False,
276
                                  force_new_tree=None, format=None,
2476.3.11 by Vincent Ladeuil
Cosmetic changes.
277
                                  possible_transports=None):
1534.6.10 by Robert Collins
Finish use of repositories support.
278
        """Create a new BzrDir, Branch and Repository at the url 'base'.
279
280
        This is a convenience function - it will use an existing repository
281
        if possible, can be told explicitly whether to create a working tree or
1534.6.12 by Robert Collins
Typo found by John Meinel.
282
        not.
1534.6.10 by Robert Collins
Finish use of repositories support.
283
284
        This will use the current default BzrDirFormat, and use whatever 
285
        repository format that that uses via bzrdir.create_branch and
286
        create_repository. If a shared repository is available that is used
287
        preferentially. Whatever repository is used, its tree creation policy
288
        is followed.
289
290
        The created Branch object is returned.
291
        If a working tree cannot be made due to base not being a file:// url,
1563.1.6 by Robert Collins
Add tests for sftp push, and NonLocalTets for BzrDir.create_branch_convenience, before fixing the failure of it to work on non-local urls.
292
        no error is raised unless force_new_tree is True, in which case no 
293
        data is created on disk and NotLocalUrl is raised.
1534.6.10 by Robert Collins
Finish use of repositories support.
294
295
        :param base: The URL to create the branch at.
296
        :param force_new_repo: If True a new repository is always created.
297
        :param force_new_tree: If True or False force creation of a tree or 
298
                               prevent such creation respectively.
2476.3.6 by Vincent Ladeuil
Fix the 'init connects multiple times' in a different way.
299
        :param format: Override for the for the bzrdir format to create.
2476.3.8 by Vincent Ladeuil
Mark transports that need to be instrumented or refactored to check
300
        :param possible_transports: An optional reusable transports list.
1534.6.10 by Robert Collins
Finish use of repositories support.
301
        """
1563.1.6 by Robert Collins
Add tests for sftp push, and NonLocalTets for BzrDir.create_branch_convenience, before fixing the failure of it to work on non-local urls.
302
        if force_new_tree:
303
            # check for non local urls
2485.8.45 by Vincent Ladeuil
Take jam's remarks into account.
304
            t = get_transport(base, possible_transports)
2476.3.6 by Vincent Ladeuil
Fix the 'init connects multiple times' in a different way.
305
            if not isinstance(t, LocalTransport):
306
                raise errors.NotLocalUrl(base)
2476.3.8 by Vincent Ladeuil
Mark transports that need to be instrumented or refactored to check
307
        bzrdir = BzrDir.create(base, format, possible_transports)
1534.6.11 by Robert Collins
Review feedback.
308
        repo = bzrdir._find_or_create_repository(force_new_repo)
1534.6.10 by Robert Collins
Finish use of repositories support.
309
        result = bzrdir.create_branch()
2476.3.4 by Vincent Ladeuil
Add tests.
310
        if force_new_tree or (repo.make_working_trees() and
1534.6.10 by Robert Collins
Finish use of repositories support.
311
                              force_new_tree is None):
1563.1.6 by Robert Collins
Add tests for sftp push, and NonLocalTets for BzrDir.create_branch_convenience, before fixing the failure of it to work on non-local urls.
312
            try:
313
                bzrdir.create_workingtree()
314
            except errors.NotLocalUrl:
315
                pass
1534.6.10 by Robert Collins
Finish use of repositories support.
316
        return result
2476.3.4 by Vincent Ladeuil
Add tests.
317
1551.8.2 by Aaron Bentley
Add create_checkout_convenience
318
    @staticmethod
2711.2.1 by Martin Pool
Deprecate BzrDir.create_repository
319
    @deprecated_function(zero_ninetyone)
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
320
    def create_repository(base, shared=False, format=None):
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
321
        """Create a new BzrDir and Repository at the url 'base'.
322
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
323
        If no format is supplied, this will default to the current default
324
        BzrDirFormat by default, and use whatever repository format that that
325
        uses for bzrdirformat.create_repository.
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
326
1910.7.17 by Andrew Bennetts
Various cosmetic changes.
327
        :param shared: Create a shared repository rather than a standalone
1534.6.1 by Robert Collins
allow API creation of shared repositories
328
                       repository.
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
329
        The Repository object is returned.
330
331
        This must be overridden as an instance method in child classes, where
332
        it should take no parameters and construct whatever repository format
333
        that child class desires.
2711.2.1 by Martin Pool
Deprecate BzrDir.create_repository
334
335
        This method is deprecated, please call create_repository on a bzrdir
336
        instance instead.
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
337
        """
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
338
        bzrdir = BzrDir.create(base, format)
1841.2.1 by Jelmer Vernooij
Fix handling of `shared' parameter in BzrDir.create_repository().
339
        return bzrdir.create_repository(shared)
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
340
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
341
    @staticmethod
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
342
    def create_standalone_workingtree(base, format=None):
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
343
        """Create a new BzrDir, WorkingTree, Branch and Repository at 'base'.
344
345
        'base' must be a local path or a file:// url.
346
347
        This will use the current default BzrDirFormat, and use whatever 
348
        repository format that that uses for bzrdirformat.create_workingtree,
349
        create_branch and create_repository.
350
1910.7.17 by Andrew Bennetts
Various cosmetic changes.
351
        :return: The WorkingTree object.
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
352
        """
2485.8.45 by Vincent Ladeuil
Take jam's remarks into account.
353
        t = get_transport(base)
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
354
        if not isinstance(t, LocalTransport):
355
            raise errors.NotLocalUrl(base)
2485.8.45 by Vincent Ladeuil
Take jam's remarks into account.
356
        bzrdir = BzrDir.create_branch_and_repo(base,
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
357
                                               force_new_repo=True,
358
                                               format=format).bzrdir
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
359
        return bzrdir.create_workingtree()
360
1508.1.21 by Robert Collins
Implement -r limit for checkout command.
361
    def create_workingtree(self, revision_id=None):
362
        """Create a working tree at this BzrDir.
363
        
364
        revision_id: create it as of this revision id.
365
        """
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
366
        raise NotImplementedError(self.create_workingtree)
367
2255.14.1 by Martin Pool
Add BzrDir.retire_bzrdir and partly fix subsume
368
    def retire_bzrdir(self):
369
        """Permanently disable the bzrdir.
370
371
        This is done by renaming it to give the user some ability to recover
372
        if there was a problem.
373
374
        This will have horrible consequences if anyone has anything locked or
375
        in use.
376
        """
377
        for i in xrange(10000):
378
            try:
379
                to_path = '.bzr.retired.%d' % i
380
                self.root_transport.rename('.bzr', to_path)
381
                note("renamed %s to %s"
382
                    % (self.root_transport.abspath('.bzr'), to_path))
383
                break
384
            except (errors.TransportError, IOError, errors.PathError):
385
                pass
386
1551.8.37 by Aaron Bentley
Cleaner implementation of destroy_working_tree
387
    def destroy_workingtree(self):
1551.8.36 by Aaron Bentley
Introduce BzrDir.destroy_workingtree
388
        """Destroy the working tree at this BzrDir.
389
390
        Formats that do not support this may raise UnsupportedOperation.
391
        """
392
        raise NotImplementedError(self.destroy_workingtree)
393
1551.8.37 by Aaron Bentley
Cleaner implementation of destroy_working_tree
394
    def destroy_workingtree_metadata(self):
395
        """Destroy the control files for the working tree at this BzrDir.
396
397
        The contents of working tree files are not affected.
398
        Formats that do not support this may raise UnsupportedOperation.
399
        """
400
        raise NotImplementedError(self.destroy_workingtree_metadata)
401
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.
402
    def find_repository(self):
403
        """Find the repository that should be used for a_bzrdir.
404
405
        This does not require a branch as we use it to find the repo for
406
        new branches as well as to hook existing branches up to their
407
        repository.
408
        """
409
        try:
410
            return self.open_repository()
411
        except errors.NoRepositoryPresent:
412
            pass
413
        next_transport = self.root_transport.clone('..')
414
        while True:
1725.2.5 by Robert Collins
Bugfix create_branch_convenience at the root of a file system to not loop
415
            # find the next containing bzrdir
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.
416
            try:
1534.6.11 by Robert Collins
Review feedback.
417
                found_bzrdir = BzrDir.open_containing_from_transport(
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.
418
                    next_transport)[0]
419
            except errors.NotBranchError:
1725.2.5 by Robert Collins
Bugfix create_branch_convenience at the root of a file system to not loop
420
                # none found
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.
421
                raise errors.NoRepositoryPresent(self)
1725.2.5 by Robert Collins
Bugfix create_branch_convenience at the root of a file system to not loop
422
            # 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.
423
            try:
424
                repository = found_bzrdir.open_repository()
425
            except errors.NoRepositoryPresent:
426
                next_transport = found_bzrdir.root_transport.clone('..')
1725.2.5 by Robert Collins
Bugfix create_branch_convenience at the root of a file system to not loop
427
                if (found_bzrdir.root_transport.base == next_transport.base):
428
                    # top of the file system
429
                    break
430
                else:
431
                    continue
2018.6.1 by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS.
432
            if ((found_bzrdir.root_transport.base ==
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.
433
                 self.root_transport.base) or repository.is_shared()):
434
                return repository
435
            else:
436
                raise errors.NoRepositoryPresent(self)
437
        raise errors.NoRepositoryPresent(self)
438
2414.2.1 by Andrew Bennetts
Some miscellaneous new APIs, tests and other changes from the hpss branch.
439
    def get_branch_reference(self):
440
        """Return the referenced URL for the branch in this bzrdir.
441
442
        :raises NotBranchError: If there is no Branch.
443
        :return: The URL the branch in this bzrdir references if it is a
444
            reference branch, or None for regular branches.
445
        """
446
        return None
447
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
448
    def get_branch_transport(self, branch_format):
449
        """Get the transport for use by branch format in this BzrDir.
450
451
        Note that bzr dirs that do not support format strings will raise
452
        IncompatibleFormat if the branch format they are given has
1759.2.1 by Jelmer Vernooij
Fix some types (found using aspell).
453
        a format string, and vice versa.
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
454
455
        If branch_format is None, the transport is returned with no 
456
        checking. if it is not None, then the returned transport is
457
        guaranteed to point to an existing directory ready for use.
458
        """
459
        raise NotImplementedError(self.get_branch_transport)
460
        
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
461
    def get_repository_transport(self, repository_format):
462
        """Get the transport for use by repository format in this BzrDir.
463
464
        Note that bzr dirs that do not support format strings will raise
465
        IncompatibleFormat if the repository format they are given has
1759.2.1 by Jelmer Vernooij
Fix some types (found using aspell).
466
        a format string, and vice versa.
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
467
468
        If repository_format is None, the transport is returned with no 
469
        checking. if it is not None, then the returned transport is
470
        guaranteed to point to an existing directory ready for use.
471
        """
472
        raise NotImplementedError(self.get_repository_transport)
473
        
1534.4.53 by Robert Collins
Review feedback from John Meinel.
474
    def get_workingtree_transport(self, tree_format):
1534.4.45 by Robert Collins
Start WorkingTree -> .bzr/checkout transition
475
        """Get the transport for use by workingtree format in this BzrDir.
476
477
        Note that bzr dirs that do not support format strings will raise
2100.3.11 by Aaron Bentley
Add join --reference support
478
        IncompatibleFormat if the workingtree format they are given has a
479
        format string, and vice versa.
1534.4.45 by Robert Collins
Start WorkingTree -> .bzr/checkout transition
480
481
        If workingtree_format is None, the transport is returned with no 
482
        checking. if it is not None, then the returned transport is
483
        guaranteed to point to an existing directory ready for use.
484
        """
485
        raise NotImplementedError(self.get_workingtree_transport)
486
        
1534.4.39 by Robert Collins
Basic BzrDir support.
487
    def __init__(self, _transport, _format):
488
        """Initialize a Bzr control dir object.
489
        
490
        Only really common logic should reside here, concrete classes should be
491
        made with varying behaviours.
492
1534.4.53 by Robert Collins
Review feedback from John Meinel.
493
        :param _format: the format that is creating this BzrDir instance.
494
        :param _transport: the transport this dir is based at.
1534.4.39 by Robert Collins
Basic BzrDir support.
495
        """
496
        self._format = _format
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
497
        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.
498
        self.root_transport = _transport
1534.4.39 by Robert Collins
Basic BzrDir support.
499
1713.1.9 by Robert Collins
Paired performance tuning of bzr add. (Robert Collins, Martin Pool).
500
    def is_control_filename(self, filename):
501
        """True if filename is the name of a path which is reserved for bzrdir's.
502
        
503
        :param filename: A filename within the root transport of this bzrdir.
504
505
        This is true IF and ONLY IF the filename is part of the namespace reserved
506
        for bzr control dirs. Currently this is the '.bzr' directory in the root
507
        of the root_transport. it is expected that plugins will need to extend
508
        this in the future - for instance to make bzr talk with svn working
509
        trees.
510
        """
511
        # this might be better on the BzrDirFormat class because it refers to 
512
        # all the possible bzrdir disk formats. 
513
        # This method is tested via the workingtree is_control_filename tests- 
1759.2.1 by Jelmer Vernooij
Fix some types (found using aspell).
514
        # it was extracted from WorkingTree.is_control_filename. If the methods
1713.1.9 by Robert Collins
Paired performance tuning of bzr add. (Robert Collins, Martin Pool).
515
        # contract is extended beyond the current trivial  implementation please
516
        # add new tests for it to the appropriate place.
517
        return filename == '.bzr' or filename.startswith('.bzr/')
518
1534.5.16 by Robert Collins
Review feedback.
519
    def needs_format_conversion(self, format=None):
520
        """Return true if this bzrdir needs convert_format run on it.
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
521
        
522
        For instance, if the repository format is out of date but the 
523
        branch and working tree are not, this should return True.
1534.5.13 by Robert Collins
Correct buggy test.
524
525
        :param format: Optional parameter indicating a specific desired
1534.5.16 by Robert Collins
Review feedback.
526
                       format we plan to arrive at.
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
527
        """
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.
528
        raise NotImplementedError(self.needs_format_conversion)
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
529
1534.4.39 by Robert Collins
Basic BzrDir support.
530
    @staticmethod
531
    def open_unsupported(base):
532
        """Open a branch which is not supported."""
533
        return BzrDir.open(base, _unsupported=True)
534
        
535
    @staticmethod
536
    def open(base, _unsupported=False):
1534.4.53 by Robert Collins
Review feedback from John Meinel.
537
        """Open an existing bzrdir, rooted at 'base' (url)
1534.4.39 by Robert Collins
Basic BzrDir support.
538
        
539
        _unsupported is a private parameter to the BzrDir class.
540
        """
541
        t = get_transport(base)
1910.11.1 by Andrew Bennetts
Add BzrDir.open_from_transport, refactored from duplicate code, no explicit tests.
542
        return BzrDir.open_from_transport(t, _unsupported=_unsupported)
543
544
    @staticmethod
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.
545
    def open_from_transport(transport, _unsupported=False,
546
                            _server_formats=True):
1910.11.1 by Andrew Bennetts
Add BzrDir.open_from_transport, refactored from duplicate code, no explicit tests.
547
        """Open a bzrdir within a particular directory.
548
549
        :param transport: Transport containing the bzrdir.
550
        :param _unsupported: private.
551
        """
2164.2.21 by Vincent Ladeuil
Take bundles into account.
552
        base = transport.base
553
554
        def find_format(transport):
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.
555
            return transport, BzrDirFormat.find_format(
556
                transport, _server_formats=_server_formats)
2164.2.21 by Vincent Ladeuil
Take bundles into account.
557
558
        def redirected(transport, e, redirection_notice):
559
            qualified_source = e.get_source_url()
560
            relpath = transport.relpath(qualified_source)
561
            if not e.target.endswith(relpath):
562
                # Not redirected to a branch-format, not a branch
563
                raise errors.NotBranchError(path=e.target)
564
            target = e.target[:-len(relpath)]
565
            note('%s is%s redirected to %s',
566
                 transport.base, e.permanently, target)
567
            # Let's try with a new transport
568
            qualified_target = e.get_target_url()[:-len(relpath)]
2164.2.22 by Vincent Ladeuil
Take Aaron's review comments into account.
569
            # FIXME: If 'transport' has a qualifier, this should
2164.2.21 by Vincent Ladeuil
Take bundles into account.
570
            # be applied again to the new transport *iff* the
571
            # schemes used are the same. It's a bit tricky to
572
            # verify, so I'll punt for now
573
            # -- vila20070212
574
            return get_transport(target)
575
2164.2.22 by Vincent Ladeuil
Take Aaron's review comments into account.
576
        try:
2164.2.28 by Vincent Ladeuil
TestingHTTPServer.test_case_server renamed from test_case to avoid confusions.
577
            transport, format = do_catching_redirections(find_format,
578
                                                         transport,
2164.2.22 by Vincent Ladeuil
Take Aaron's review comments into account.
579
                                                         redirected)
580
        except errors.TooManyRedirections:
581
            raise errors.NotBranchError(base)
2164.2.21 by Vincent Ladeuil
Take bundles into account.
582
1596.2.1 by Robert Collins
Fix BzrDir.open_containing of unsupported branches.
583
        BzrDir._check_supported(format, _unsupported)
1910.11.1 by Andrew Bennetts
Add BzrDir.open_from_transport, refactored from duplicate code, no explicit tests.
584
        return format.open(transport, _found=True)
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
585
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
586
    def open_branch(self, unsupported=False):
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
587
        """Open the branch object at this BzrDir if one is present.
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
588
589
        If unsupported is True, then no longer supported branch formats can
590
        still be opened.
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
591
        
592
        TODO: static convenience version of this?
593
        """
594
        raise NotImplementedError(self.open_branch)
1534.4.39 by Robert Collins
Basic BzrDir support.
595
596
    @staticmethod
2485.8.37 by Vincent Ladeuil
Fix merge multiple connections. Test suite *not* passing (sftp
597
    def open_containing(url, possible_transports=None):
1534.4.39 by Robert Collins
Basic BzrDir support.
598
        """Open an existing branch which contains url.
599
        
1534.6.3 by Robert Collins
find_repository sufficiently robust.
600
        :param url: url to search from.
1534.6.11 by Robert Collins
Review feedback.
601
        See open_containing_from_transport for more detail.
1534.6.3 by Robert Collins
find_repository sufficiently robust.
602
        """
2485.8.37 by Vincent Ladeuil
Fix merge multiple connections. Test suite *not* passing (sftp
603
        transport = get_transport(url, possible_transports)
604
        return BzrDir.open_containing_from_transport(transport)
1534.6.3 by Robert Collins
find_repository sufficiently robust.
605
    
606
    @staticmethod
1534.6.11 by Robert Collins
Review feedback.
607
    def open_containing_from_transport(a_transport):
1534.6.3 by Robert Collins
find_repository sufficiently robust.
608
        """Open an existing branch which contains a_transport.base
609
610
        This probes for a branch at a_transport, and searches upwards from there.
1534.4.39 by Robert Collins
Basic BzrDir support.
611
612
        Basically we keep looking up until we find the control directory or
613
        run into the root.  If there isn't one, raises NotBranchError.
614
        If there is one and it is either an unrecognised format or an unsupported 
615
        format, UnknownFormatError or UnsupportedFormatError are raised.
616
        If there is one, it is returned, along with the unused portion of url.
1685.1.27 by John Arbash Meinel
BzrDir works in URLs, but WorkingTree works in unicode paths
617
1685.1.28 by John Arbash Meinel
Changing open_containing to always return a unicode path.
618
        :return: The BzrDir that contains the path, and a Unicode path 
619
                for the rest of the URL.
1534.4.39 by Robert Collins
Basic BzrDir support.
620
        """
621
        # this gets the normalised url back. I.e. '.' -> the full path.
1534.6.3 by Robert Collins
find_repository sufficiently robust.
622
        url = a_transport.base
1534.4.39 by Robert Collins
Basic BzrDir support.
623
        while True:
624
            try:
1910.11.1 by Andrew Bennetts
Add BzrDir.open_from_transport, refactored from duplicate code, no explicit tests.
625
                result = BzrDir.open_from_transport(a_transport)
626
                return result, urlutils.unescape(a_transport.relpath(url))
1534.4.39 by Robert Collins
Basic BzrDir support.
627
            except errors.NotBranchError, e:
1685.1.60 by Martin Pool
[broken] NotBranchError should unescape the url if possible
628
                pass
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
629
            try:
630
                new_t = a_transport.clone('..')
631
            except errors.InvalidURLJoin:
632
                # reached the root, whatever that may be
633
                raise errors.NotBranchError(path=url)
1534.6.3 by Robert Collins
find_repository sufficiently robust.
634
            if new_t.base == a_transport.base:
1534.4.39 by Robert Collins
Basic BzrDir support.
635
                # reached the root, whatever that may be
636
                raise errors.NotBranchError(path=url)
1534.6.3 by Robert Collins
find_repository sufficiently robust.
637
            a_transport = new_t
1534.4.39 by Robert Collins
Basic BzrDir support.
638
2215.3.2 by Aaron Bentley
Add open_containing_tree_or_branch
639
    @classmethod
640
    def open_containing_tree_or_branch(klass, location):
641
        """Return the branch and working tree contained by a location.
642
643
        Returns (tree, branch, relpath).
644
        If there is no tree at containing the location, tree will be None.
645
        If there is no branch containing the location, an exception will be
646
        raised
647
        relpath is the portion of the path that is contained by the branch.
648
        """
649
        bzrdir, relpath = klass.open_containing(location)
650
        try:
651
            tree = bzrdir.open_workingtree()
2215.3.5 by Aaron Bentley
Add support for remote ls
652
        except (errors.NoWorkingTree, errors.NotLocalUrl):
2215.3.2 by Aaron Bentley
Add open_containing_tree_or_branch
653
            tree = None
654
            branch = bzrdir.open_branch()
655
        else:
656
            branch = tree.branch
657
        return tree, branch, relpath
658
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
659
    def open_repository(self, _unsupported=False):
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
660
        """Open the repository object at this BzrDir if one is present.
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
661
662
        This will not follow the Branch object pointer - its strictly a direct
663
        open facility. Most client code should use open_branch().repository to
664
        get at a repository.
665
666
        _unsupported is a private parameter, not part of the api.
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
667
        TODO: static convenience version of this?
668
        """
669
        raise NotImplementedError(self.open_repository)
670
2400.2.2 by Robert Collins
Document BzrDir.open_workingtree's new recommend_upgrade parameter.
671
    def open_workingtree(self, _unsupported=False,
672
            recommend_upgrade=True):
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
673
        """Open the workingtree object at this BzrDir if one is present.
2400.2.2 by Robert Collins
Document BzrDir.open_workingtree's new recommend_upgrade parameter.
674
675
        :param recommend_upgrade: Optional keyword parameter, when True (the
676
            default), emit through the ui module a recommendation that the user
677
            upgrade the working tree when the workingtree being opened is old
678
            (but still fully supported).
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
679
        """
680
        raise NotImplementedError(self.open_workingtree)
681
1662.1.19 by Martin Pool
Better error message when initting existing tree
682
    def has_branch(self):
683
        """Tell if this bzrdir contains a branch.
684
        
685
        Note: if you're going to open the branch, you should just go ahead
686
        and try, and not ask permission first.  (This method just opens the 
687
        branch and discards it, and that's somewhat expensive.) 
688
        """
689
        try:
690
            self.open_branch()
691
            return True
692
        except errors.NotBranchError:
693
            return False
694
695
    def has_workingtree(self):
696
        """Tell if this bzrdir contains a working tree.
697
698
        This will still raise an exception if the bzrdir has a workingtree that
699
        is remote & inaccessible.
700
        
701
        Note: if you're going to open the working tree, you should just go ahead
702
        and try, and not ask permission first.  (This method just opens the 
703
        workingtree and discards it, and that's somewhat expensive.) 
704
        """
705
        try:
2323.6.4 by Martin Pool
BzrDir._check_supported now also takes care of recommending upgrades, which
706
            self.open_workingtree(recommend_upgrade=False)
1662.1.19 by Martin Pool
Better error message when initting existing tree
707
            return True
708
        except errors.NoWorkingTree:
709
            return False
710
2018.5.96 by Andrew Bennetts
Merge from bzr.dev, resolving the worst of the semantic conflicts, but there's
711
    def _cloning_metadir(self):
1910.2.41 by Aaron Bentley
Clean up clone format creation
712
        """Produce a metadir suitable for cloning with"""
2387.1.1 by Robert Collins
Remove the --basis parameter to clone etc. (Robert Collins)
713
        result_format = self._format.__class__()
714
        try:
1910.2.41 by Aaron Bentley
Clean up clone format creation
715
            try:
2387.1.1 by Robert Collins
Remove the --basis parameter to clone etc. (Robert Collins)
716
                branch = self.open_branch()
717
                source_repository = branch.repository
1910.2.41 by Aaron Bentley
Clean up clone format creation
718
            except errors.NotBranchError:
719
                source_branch = None
2387.1.1 by Robert Collins
Remove the --basis parameter to clone etc. (Robert Collins)
720
                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.
721
        except errors.NoRepositoryPresent:
2100.3.24 by Aaron Bentley
Get all tests passing again
722
            source_repository = None
2305.3.1 by Andrew Bennetts
Tidy up BzrDir.cloning_metadir: bogus try/except, and basis argument isn't actually used.
723
        else:
2018.5.138 by Robert Collins
Merge bzr.dev.
724
            # XXX TODO: This isinstance is here because we have not implemented
725
            # the fix recommended in bug # 103195 - to delegate this choice the
726
            # repository itself.
2018.5.94 by Andrew Bennetts
Various small changes in aid of making tests pass (including deleting one invalid test).
727
            repo_format = source_repository._format
728
            if not isinstance(repo_format, remote.RemoteRepositoryFormat):
729
                result_format.repository_format = repo_format
2100.3.28 by Aaron Bentley
Make sprout recursive
730
        try:
2323.5.19 by Martin Pool
No upgrade recommendation on source when cloning
731
            # TODO: Couldn't we just probe for the format in these cases,
732
            # rather than opening the whole tree?  It would be a little
733
            # faster. mbp 20070401
734
            tree = self.open_workingtree(recommend_upgrade=False)
2100.3.28 by Aaron Bentley
Make sprout recursive
735
        except (errors.NoWorkingTree, errors.NotLocalUrl):
736
            result_format.workingtree_format = None
737
        else:
738
            result_format.workingtree_format = tree._format.__class__()
2100.3.21 by Aaron Bentley
Work on checking out by-reference trees
739
        return result_format, source_repository
740
2018.5.96 by Andrew Bennetts
Merge from bzr.dev, resolving the worst of the semantic conflicts, but there's
741
    def cloning_metadir(self):
2100.3.32 by Aaron Bentley
fix tree format, basis_tree call, in sprout
742
        """Produce a metadir suitable for cloning or sprouting with.
1910.2.41 by Aaron Bentley
Clean up clone format creation
743
2100.3.32 by Aaron Bentley
fix tree format, basis_tree call, in sprout
744
        These operations may produce workingtrees (yes, even though they're
745
        "cloning" something that doesn't have a tree, so a viable workingtree
746
        format must be selected.
747
        """
2100.3.21 by Aaron Bentley
Work on checking out by-reference trees
748
        format, repository = self._cloning_metadir()
2100.3.32 by Aaron Bentley
fix tree format, basis_tree call, in sprout
749
        if format._workingtree_format is None:
2100.3.34 by Aaron Bentley
Fix BzrDir.cloning_metadir with no format
750
            if repository is None:
751
                return format
2100.3.21 by Aaron Bentley
Work on checking out by-reference trees
752
            tree_format = repository._format._matchingbzrdir.workingtree_format
2100.3.28 by Aaron Bentley
Make sprout recursive
753
            format.workingtree_format = tree_format.__class__()
2100.3.21 by Aaron Bentley
Work on checking out by-reference trees
754
        return format
755
2100.3.32 by Aaron Bentley
fix tree format, basis_tree call, in sprout
756
    def checkout_metadir(self):
757
        return self.cloning_metadir()
758
2387.1.1 by Robert Collins
Remove the --basis parameter to clone etc. (Robert Collins)
759
    def sprout(self, url, revision_id=None, force_new_repo=False,
2485.8.56 by Vincent Ladeuil
Fix bug #112173 and bzr branch multiple connections.
760
               recurse='down', possible_transports=None):
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.
761
        """Create a copy of this bzrdir prepared for use as a new line of
762
        development.
763
764
        If urls last component does not exist, it will be created.
765
766
        Attributes related to the identity of the source branch like
767
        branch nickname will be cleaned, a working tree is created
768
        whether one existed before or not; and a local branch is always
769
        created.
770
771
        if revision_id is not None, then the clone operation may tune
772
            itself to download less data.
773
        """
2485.8.56 by Vincent Ladeuil
Fix bug #112173 and bzr branch multiple connections.
774
        target_transport = get_transport(url, possible_transports)
2475.3.3 by John Arbash Meinel
Change calls to try/mkdir('.')/except FileExists to ensure_base()
775
        target_transport.ensure_base()
2305.3.1 by Andrew Bennetts
Tidy up BzrDir.cloning_metadir: bogus try/except, and basis argument isn't actually used.
776
        cloning_format = self.cloning_metadir()
2475.3.1 by John Arbash Meinel
Fix bug #75721. Update the BzrDir api to add clone_on_transport()
777
        result = cloning_format.initialize_on_transport(target_transport)
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.
778
        try:
779
            source_branch = self.open_branch()
780
            source_repository = source_branch.repository
781
        except errors.NotBranchError:
782
            source_branch = None
783
            try:
784
                source_repository = self.open_repository()
785
            except errors.NoRepositoryPresent:
2387.1.1 by Robert Collins
Remove the --basis parameter to clone etc. (Robert Collins)
786
                source_repository = None
1534.6.9 by Robert Collins
sprouting into shared repositories
787
        if force_new_repo:
788
            result_repo = None
789
        else:
790
            try:
791
                result_repo = result.find_repository()
792
            except errors.NoRepositoryPresent:
793
                result_repo = None
794
        if source_repository is None and result_repo is not None:
795
            pass
796
        elif source_repository is None and result_repo is None:
797
            # no repo available, make a new one
798
            result.create_repository()
799
        elif source_repository is not None and result_repo is None:
1707.1.1 by Robert Collins
Bugfixes to bzrdir.sprout and clone. Sprout was failing to reset the
800
            # have source, and want to make a new target repo
2485.8.56 by Vincent Ladeuil
Fix bug #112173 and bzr branch multiple connections.
801
            result_repo = source_repository.sprout(result,
802
                                                   revision_id=revision_id)
2440.1.1 by Martin Pool
Add new Repository.sprout,
803
        else:
1534.6.9 by Robert Collins
sprouting into shared repositories
804
            # fetch needed content into target.
1910.4.10 by Andrew Bennetts
Skip various test_sprout* tests when sprouting to non-local bzrdirs that can't have working trees; plus fix a test method naming clash and the bug it revealed in bzrdir.sprout.
805
            if source_repository is not None:
2018.18.20 by Martin Pool
Route branch operations through remote copy_content_into
806
                # would rather do 
2485.8.56 by Vincent Ladeuil
Fix bug #112173 and bzr branch multiple connections.
807
                # source_repository.copy_content_into(result_repo,
808
                #                                     revision_id=revision_id)
2018.18.20 by Martin Pool
Route branch operations through remote copy_content_into
809
                # so we can override the copy method
1910.4.10 by Andrew Bennetts
Skip various test_sprout* tests when sprouting to non-local bzrdirs that can't have working trees; plus fix a test method naming clash and the bug it revealed in bzrdir.sprout.
810
                result_repo.fetch(source_repository, revision_id=revision_id)
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.
811
        if source_branch is not None:
812
            source_branch.sprout(result, revision_id=revision_id)
813
        else:
814
            result.create_branch()
2485.8.56 by Vincent Ladeuil
Fix bug #112173 and bzr branch multiple connections.
815
        if isinstance(target_transport, LocalTransport) and (
816
            result_repo is None or result_repo.make_working_trees()):
1731.1.33 by Aaron Bentley
Revert no-special-root changes
817
            wt = result.create_workingtree()
2255.2.77 by Robert Collins
Tune working inventory generation more: walk the blocks, skipping deleted rows.
818
            wt.lock_write()
819
            try:
820
                if wt.path2id('') is None:
821
                    try:
822
                        wt.set_root_id(self.open_workingtree.get_root_id())
823
                    except errors.NoWorkingTree:
824
                        pass
825
            finally:
826
                wt.unlock()
2100.3.28 by Aaron Bentley
Make sprout recursive
827
        else:
828
            wt = None
829
        if recurse == 'down':
830
            if wt is not None:
2255.2.226 by Robert Collins
Get merge_nested finally working: change nested tree iterators to take file_ids, and ensure the right branch is connected to in the merge logic. May not be suitable for shared repositories yet.
831
                basis = wt.basis_tree()
832
                basis.lock_read()
833
                subtrees = basis.iter_references()
2100.3.28 by Aaron Bentley
Make sprout recursive
834
                recurse_branch = wt.branch
835
            elif source_branch is not None:
2255.2.226 by Robert Collins
Get merge_nested finally working: change nested tree iterators to take file_ids, and ensure the right branch is connected to in the merge logic. May not be suitable for shared repositories yet.
836
                basis = source_branch.basis_tree()
837
                basis.lock_read()
838
                subtrees = basis.iter_references()
2100.3.28 by Aaron Bentley
Make sprout recursive
839
                recurse_branch = source_branch
840
            else:
2255.2.226 by Robert Collins
Get merge_nested finally working: change nested tree iterators to take file_ids, and ensure the right branch is connected to in the merge logic. May not be suitable for shared repositories yet.
841
                subtrees = []
842
                basis = None
843
            try:
844
                for path, file_id in subtrees:
845
                    target = urlutils.join(url, urlutils.escape(path))
846
                    sublocation = source_branch.reference_parent(file_id, path)
847
                    sublocation.bzrdir.sprout(target,
848
                        basis.get_reference_revision(file_id, path),
849
                        force_new_repo=force_new_repo, recurse=recurse)
850
            finally:
851
                if basis is not None:
852
                    basis.unlock()
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.
853
        return result
854
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
855
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
856
class BzrDirPreSplitOut(BzrDir):
857
    """A common class for the all-in-one formats."""
858
1534.5.3 by Robert Collins
Make format 4/5/6 branches share a single LockableFiles instance across wt/branch/repository.
859
    def __init__(self, _transport, _format):
860
        """See BzrDir.__init__."""
861
        super(BzrDirPreSplitOut, self).__init__(_transport, _format)
1996.3.3 by John Arbash Meinel
Shave off another 40ms by demand loading branch and bzrdir
862
        assert self._format._lock_class == lockable_files.TransportLock
1553.5.69 by Martin Pool
BzrDirFormat subclasses can now control what kind of overall lock is used.
863
        assert self._format._lock_file_name == 'branch-lock'
1996.3.3 by John Arbash Meinel
Shave off another 40ms by demand loading branch and bzrdir
864
        self._control_files = lockable_files.LockableFiles(
865
                                            self.get_branch_transport(None),
1553.5.69 by Martin Pool
BzrDirFormat subclasses can now control what kind of overall lock is used.
866
                                            self._format._lock_file_name,
867
                                            self._format._lock_class)
1534.5.3 by Robert Collins
Make format 4/5/6 branches share a single LockableFiles instance across wt/branch/repository.
868
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
869
    def break_lock(self):
870
        """Pre-splitout bzrdirs do not suffer from stale locks."""
871
        raise NotImplementedError(self.break_lock)
872
2387.1.1 by Robert Collins
Remove the --basis parameter to clone etc. (Robert Collins)
873
    def clone(self, url, revision_id=None, force_new_repo=False):
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.
874
        """See BzrDir.clone()."""
875
        from bzrlib.workingtree import WorkingTreeFormat2
876
        self._make_tail(url)
1651.1.6 by Martin Pool
Clean up clone-bzrdir code
877
        result = self._format._initialize_for_clone(url)
2387.1.1 by Robert Collins
Remove the --basis parameter to clone etc. (Robert Collins)
878
        self.open_repository().clone(result, revision_id=revision_id)
1692.7.9 by Martin Pool
Don't create broken standalone branches over sftp (Malone #43064)
879
        from_branch = self.open_branch()
880
        from_branch.clone(result, revision_id=revision_id)
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.
881
        try:
2387.1.1 by Robert Collins
Remove the --basis parameter to clone etc. (Robert Collins)
882
            self.open_workingtree().clone(result)
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.
883
        except errors.NotLocalUrl:
884
            # make a new one, this format always has to have one.
1563.2.38 by Robert Collins
make push preserve tree formats.
885
            try:
886
                WorkingTreeFormat2().initialize(result)
887
            except errors.NotLocalUrl:
1692.7.9 by Martin Pool
Don't create broken standalone branches over sftp (Malone #43064)
888
                # but we cannot do it for remote trees.
889
                to_branch = result.open_branch()
890
                WorkingTreeFormat2().stub_initialize_remote(to_branch.control_files)
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.
891
        return result
892
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
893
    def create_branch(self):
894
        """See BzrDir.create_branch."""
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.
895
        return self.open_branch()
896
1534.6.1 by Robert Collins
allow API creation of shared repositories
897
    def create_repository(self, shared=False):
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.
898
        """See BzrDir.create_repository."""
1534.6.1 by Robert Collins
allow API creation of shared repositories
899
        if shared:
900
            raise errors.IncompatibleFormat('shared repository', self._format)
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.
901
        return self.open_repository()
902
1508.1.21 by Robert Collins
Implement -r limit for checkout command.
903
    def create_workingtree(self, revision_id=None):
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.
904
        """See BzrDir.create_workingtree."""
1508.1.21 by Robert Collins
Implement -r limit for checkout command.
905
        # this looks buggy but is not -really-
2323.6.4 by Martin Pool
BzrDir._check_supported now also takes care of recommending upgrades, which
906
        # because this format creates the workingtree when the bzrdir is
907
        # created
1508.1.21 by Robert Collins
Implement -r limit for checkout command.
908
        # clone and sprout will have set the revision_id
909
        # and that will have set it for us, its only
910
        # specific uses of create_workingtree in isolation
911
        # that can do wonky stuff here, and that only
912
        # happens for creating checkouts, which cannot be 
913
        # done on this format anyway. So - acceptable wart.
2323.6.4 by Martin Pool
BzrDir._check_supported now also takes care of recommending upgrades, which
914
        result = self.open_workingtree(recommend_upgrade=False)
1508.1.24 by Robert Collins
Add update command for use with checkouts.
915
        if revision_id is not None:
1996.3.12 by John Arbash Meinel
Change how 'revision' is imported to avoid problems later
916
            if revision_id == _mod_revision.NULL_REVISION:
1551.8.20 by Aaron Bentley
Fix BzrDir.create_workingtree for NULL_REVISION
917
                result.set_parent_ids([])
918
            else:
919
                result.set_parent_ids([revision_id])
1508.1.21 by Robert Collins
Implement -r limit for checkout command.
920
        return result
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
921
1551.8.37 by Aaron Bentley
Cleaner implementation of destroy_working_tree
922
    def destroy_workingtree(self):
1551.8.36 by Aaron Bentley
Introduce BzrDir.destroy_workingtree
923
        """See BzrDir.destroy_workingtree."""
924
        raise errors.UnsupportedOperation(self.destroy_workingtree, self)
925
1551.8.37 by Aaron Bentley
Cleaner implementation of destroy_working_tree
926
    def destroy_workingtree_metadata(self):
927
        """See BzrDir.destroy_workingtree_metadata."""
928
        raise errors.UnsupportedOperation(self.destroy_workingtree_metadata, 
929
                                          self)
930
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
931
    def get_branch_transport(self, branch_format):
932
        """See BzrDir.get_branch_transport()."""
933
        if branch_format is None:
934
            return self.transport
935
        try:
936
            branch_format.get_format_string()
937
        except NotImplementedError:
938
            return self.transport
939
        raise errors.IncompatibleFormat(branch_format, self._format)
940
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
941
    def get_repository_transport(self, repository_format):
942
        """See BzrDir.get_repository_transport()."""
943
        if repository_format is None:
944
            return self.transport
945
        try:
946
            repository_format.get_format_string()
947
        except NotImplementedError:
948
            return self.transport
949
        raise errors.IncompatibleFormat(repository_format, self._format)
950
1534.4.45 by Robert Collins
Start WorkingTree -> .bzr/checkout transition
951
    def get_workingtree_transport(self, workingtree_format):
952
        """See BzrDir.get_workingtree_transport()."""
953
        if workingtree_format is None:
954
            return self.transport
955
        try:
956
            workingtree_format.get_format_string()
957
        except NotImplementedError:
958
            return self.transport
959
        raise errors.IncompatibleFormat(workingtree_format, self._format)
960
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.
961
    def needs_format_conversion(self, format=None):
962
        """See BzrDir.needs_format_conversion()."""
963
        # if the format is not the same as the system default,
964
        # an upgrade is needed.
965
        if format is None:
966
            format = BzrDirFormat.get_default_format()
967
        return not isinstance(self._format, format.__class__)
968
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
969
    def open_branch(self, unsupported=False):
970
        """See BzrDir.open_branch."""
971
        from bzrlib.branch import BzrBranchFormat4
972
        format = BzrBranchFormat4()
973
        self._check_supported(format, unsupported)
974
        return format.open(self, _found=True)
975
2485.8.56 by Vincent Ladeuil
Fix bug #112173 and bzr branch multiple connections.
976
    def sprout(self, url, revision_id=None, force_new_repo=False,
977
               possible_transports=None):
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.
978
        """See BzrDir.sprout()."""
979
        from bzrlib.workingtree import WorkingTreeFormat2
980
        self._make_tail(url)
1651.1.6 by Martin Pool
Clean up clone-bzrdir code
981
        result = self._format._initialize_for_clone(url)
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.
982
        try:
2387.1.1 by Robert Collins
Remove the --basis parameter to clone etc. (Robert Collins)
983
            self.open_repository().clone(result, revision_id=revision_id)
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.
984
        except errors.NoRepositoryPresent:
985
            pass
986
        try:
987
            self.open_branch().sprout(result, revision_id=revision_id)
988
        except errors.NotBranchError:
989
            pass
1587.1.5 by Robert Collins
Put bzr branch behaviour back to the 0.7 ignore-working-tree state.
990
        # we always want a working tree
991
        WorkingTreeFormat2().initialize(result)
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.
992
        return result
993
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
994
995
class BzrDir4(BzrDirPreSplitOut):
1508.1.25 by Robert Collins
Update per review comments.
996
    """A .bzr version 4 control object.
997
    
998
    This is a deprecated format and may be removed after sept 2006.
999
    """
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
1000
1534.6.1 by Robert Collins
allow API creation of shared repositories
1001
    def create_repository(self, shared=False):
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
1002
        """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.
1003
        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.
1004
1534.5.16 by Robert Collins
Review feedback.
1005
    def needs_format_conversion(self, format=None):
1006
        """Format 4 dirs are always in need of conversion."""
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
1007
        return True
1008
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
1009
    def open_repository(self):
1010
        """See BzrDir.open_repository."""
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
1011
        from bzrlib.repofmt.weaverepo import RepositoryFormat4
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
1012
        return RepositoryFormat4().open(self, _found=True)
1013
1014
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
1015
class BzrDir5(BzrDirPreSplitOut):
1508.1.25 by Robert Collins
Update per review comments.
1016
    """A .bzr version 5 control object.
1017
1018
    This is a deprecated format and may be removed after sept 2006.
1019
    """
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
1020
1021
    def open_repository(self):
1022
        """See BzrDir.open_repository."""
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
1023
        from bzrlib.repofmt.weaverepo import RepositoryFormat5
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
1024
        return RepositoryFormat5().open(self, _found=True)
1025
2323.6.4 by Martin Pool
BzrDir._check_supported now also takes care of recommending upgrades, which
1026
    def open_workingtree(self, _unsupported=False,
1027
            recommend_upgrade=True):
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
1028
        """See BzrDir.create_workingtree."""
1029
        from bzrlib.workingtree import WorkingTreeFormat2
2323.6.4 by Martin Pool
BzrDir._check_supported now also takes care of recommending upgrades, which
1030
        wt_format = WorkingTreeFormat2()
1031
        # we don't warn here about upgrades; that ought to be handled for the
1032
        # bzrdir as a whole
1033
        return wt_format.open(self, _found=True)
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
1034
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
1035
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
1036
class BzrDir6(BzrDirPreSplitOut):
1508.1.25 by Robert Collins
Update per review comments.
1037
    """A .bzr version 6 control object.
1038
1039
    This is a deprecated format and may be removed after sept 2006.
1040
    """
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
1041
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
1042
    def open_repository(self):
1043
        """See BzrDir.open_repository."""
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
1044
        from bzrlib.repofmt.weaverepo import RepositoryFormat6
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
1045
        return RepositoryFormat6().open(self, _found=True)
1046
2323.6.4 by Martin Pool
BzrDir._check_supported now also takes care of recommending upgrades, which
1047
    def open_workingtree(self, _unsupported=False,
1048
        recommend_upgrade=True):
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
1049
        """See BzrDir.create_workingtree."""
2323.6.4 by Martin Pool
BzrDir._check_supported now also takes care of recommending upgrades, which
1050
        # we don't warn here about upgrades; that ought to be handled for the
1051
        # bzrdir as a whole
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
1052
        from bzrlib.workingtree import WorkingTreeFormat2
1053
        return WorkingTreeFormat2().open(self, _found=True)
1054
1055
1056
class BzrDirMeta1(BzrDir):
1057
    """A .bzr meta version 1 control object.
1058
    
1059
    This is the first control object where the 
1553.5.67 by Martin Pool
doc
1060
    individual aspects are really split out: there are separate repository,
1061
    workingtree and branch subdirectories and any subset of the three can be
1062
    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.
1063
    """
1064
1534.5.16 by Robert Collins
Review feedback.
1065
    def can_convert_format(self):
1066
        """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.
1067
        return True
1534.5.10 by Robert Collins
Make upgrade driver unaware of the specific formats in play.
1068
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
1069
    def create_branch(self):
1070
        """See BzrDir.create_branch."""
2230.3.55 by Aaron Bentley
Updates from review
1071
        return self._format.get_branch_format().initialize(self)
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
1072
1534.6.1 by Robert Collins
allow API creation of shared repositories
1073
    def create_repository(self, shared=False):
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
1074
        """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.
1075
        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.
1076
1508.1.21 by Robert Collins
Implement -r limit for checkout command.
1077
    def create_workingtree(self, revision_id=None):
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
1078
        """See BzrDir.create_workingtree."""
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
1079
        from bzrlib.workingtree import WorkingTreeFormat
2100.3.10 by Aaron Bentley
Ensure added references are serialized properly, beef up Workingtreee3
1080
        return self._format.workingtree_format.initialize(self, revision_id)
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
1081
1551.8.37 by Aaron Bentley
Cleaner implementation of destroy_working_tree
1082
    def destroy_workingtree(self):
1551.8.36 by Aaron Bentley
Introduce BzrDir.destroy_workingtree
1083
        """See BzrDir.destroy_workingtree."""
2323.6.4 by Martin Pool
BzrDir._check_supported now also takes care of recommending upgrades, which
1084
        wt = self.open_workingtree(recommend_upgrade=False)
1551.8.37 by Aaron Bentley
Cleaner implementation of destroy_working_tree
1085
        repository = wt.branch.repository
2094.3.5 by John Arbash Meinel
Fix imports to ensure modules are loaded before they are used
1086
        empty = repository.revision_tree(_mod_revision.NULL_REVISION)
1551.8.37 by Aaron Bentley
Cleaner implementation of destroy_working_tree
1087
        wt.revert([], old_tree=empty)
1088
        self.destroy_workingtree_metadata()
1089
1090
    def destroy_workingtree_metadata(self):
1091
        self.transport.delete_tree('checkout')
1551.8.36 by Aaron Bentley
Introduce BzrDir.destroy_workingtree
1092
2414.2.1 by Andrew Bennetts
Some miscellaneous new APIs, tests and other changes from the hpss branch.
1093
    def find_branch_format(self):
1094
        """Find the branch 'format' for this bzrdir.
1095
1096
        This might be a synthetic object for e.g. RemoteBranch and SVN.
1097
        """
1098
        from bzrlib.branch import BranchFormat
1099
        return BranchFormat.find_format(self)
1100
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
1101
    def _get_mkdir_mode(self):
1102
        """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
1103
        temp_control = lockable_files.LockableFiles(self.transport, '',
1104
                                     lockable_files.TransportLock)
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
1105
        return temp_control._dir_mode
1106
2414.2.1 by Andrew Bennetts
Some miscellaneous new APIs, tests and other changes from the hpss branch.
1107
    def get_branch_reference(self):
1108
        """See BzrDir.get_branch_reference()."""
1109
        from bzrlib.branch import BranchFormat
1110
        format = BranchFormat.find_format(self)
1111
        return format.get_reference(self)
1112
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
1113
    def get_branch_transport(self, branch_format):
1114
        """See BzrDir.get_branch_transport()."""
1115
        if branch_format is None:
1116
            return self.transport.clone('branch')
1117
        try:
1118
            branch_format.get_format_string()
1119
        except NotImplementedError:
1120
            raise errors.IncompatibleFormat(branch_format, self._format)
1121
        try:
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
1122
            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.
1123
        except errors.FileExists:
1124
            pass
1125
        return self.transport.clone('branch')
1126
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
1127
    def get_repository_transport(self, repository_format):
1128
        """See BzrDir.get_repository_transport()."""
1129
        if repository_format is None:
1130
            return self.transport.clone('repository')
1131
        try:
1132
            repository_format.get_format_string()
1133
        except NotImplementedError:
1134
            raise errors.IncompatibleFormat(repository_format, self._format)
1135
        try:
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
1136
            self.transport.mkdir('repository', mode=self._get_mkdir_mode())
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
1137
        except errors.FileExists:
1138
            pass
1139
        return self.transport.clone('repository')
1140
1534.4.45 by Robert Collins
Start WorkingTree -> .bzr/checkout transition
1141
    def get_workingtree_transport(self, workingtree_format):
1142
        """See BzrDir.get_workingtree_transport()."""
1143
        if workingtree_format is None:
1144
            return self.transport.clone('checkout')
1145
        try:
1146
            workingtree_format.get_format_string()
1147
        except NotImplementedError:
1148
            raise errors.IncompatibleFormat(workingtree_format, self._format)
1149
        try:
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
1150
            self.transport.mkdir('checkout', mode=self._get_mkdir_mode())
1534.4.45 by Robert Collins
Start WorkingTree -> .bzr/checkout transition
1151
        except errors.FileExists:
1152
            pass
1153
        return self.transport.clone('checkout')
1154
1534.5.16 by Robert Collins
Review feedback.
1155
    def needs_format_conversion(self, format=None):
1156
        """See BzrDir.needs_format_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.
1157
        if format is None:
1158
            format = BzrDirFormat.get_default_format()
1159
        if not isinstance(self._format, format.__class__):
1160
            # it is not a meta dir format, conversion is needed.
1161
            return True
1162
        # we might want to push this down to the repository?
1163
        try:
1164
            if not isinstance(self.open_repository()._format,
1165
                              format.repository_format.__class__):
1166
                # the repository needs an upgrade.
1167
                return True
1168
        except errors.NoRepositoryPresent:
1169
            pass
2230.3.29 by Aaron Bentley
Implement conversion to branch 6
1170
        try:
1171
            if not isinstance(self.open_branch()._format,
2230.3.55 by Aaron Bentley
Updates from review
1172
                              format.get_branch_format().__class__):
2255.12.1 by Robert Collins
Implement upgrade for working trees.
1173
                # the branch needs an upgrade.
1174
                return True
1175
        except errors.NotBranchError:
1176
            pass
1177
        try:
2323.6.4 by Martin Pool
BzrDir._check_supported now also takes care of recommending upgrades, which
1178
            my_wt = self.open_workingtree(recommend_upgrade=False)
1179
            if not isinstance(my_wt._format,
2255.12.1 by Robert Collins
Implement upgrade for working trees.
1180
                              format.workingtree_format.__class__):
1181
                # the workingtree needs an upgrade.
1182
                return True
2255.2.196 by Robert Collins
Fix test_upgrade defects related to non local or absent working trees.
1183
        except (errors.NoWorkingTree, errors.NotLocalUrl):
2255.12.1 by Robert Collins
Implement upgrade for working trees.
1184
            pass
1534.5.10 by Robert Collins
Make upgrade driver unaware of the specific formats in play.
1185
        return False
1186
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
1187
    def open_branch(self, unsupported=False):
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
1188
        """See BzrDir.open_branch."""
2414.2.1 by Andrew Bennetts
Some miscellaneous new APIs, tests and other changes from the hpss branch.
1189
        format = self.find_branch_format()
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
1190
        self._check_supported(format, unsupported)
1191
        return format.open(self, _found=True)
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
1192
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
1193
    def open_repository(self, unsupported=False):
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
1194
        """See BzrDir.open_repository."""
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
1195
        from bzrlib.repository import RepositoryFormat
1196
        format = RepositoryFormat.find_format(self)
1197
        self._check_supported(format, unsupported)
1198
        return format.open(self, _found=True)
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
1199
2323.6.4 by Martin Pool
BzrDir._check_supported now also takes care of recommending upgrades, which
1200
    def open_workingtree(self, unsupported=False,
1201
            recommend_upgrade=True):
1508.1.21 by Robert Collins
Implement -r limit for checkout command.
1202
        """See BzrDir.open_workingtree."""
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
1203
        from bzrlib.workingtree import WorkingTreeFormat
1204
        format = WorkingTreeFormat.find_format(self)
2323.6.4 by Martin Pool
BzrDir._check_supported now also takes care of recommending upgrades, which
1205
        self._check_supported(format, unsupported,
1206
            recommend_upgrade,
2323.6.5 by Martin Pool
Recommended-upgrade message should give base dir not the control dir url
1207
            basedir=self.root_transport.base)
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
1208
        return format.open(self, _found=True)
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
1209
1534.4.39 by Robert Collins
Basic BzrDir support.
1210
1211
class BzrDirFormat(object):
1212
    """An encapsulation of the initialization and open routines for a format.
1213
1214
    Formats provide three things:
1215
     * An initialization routine,
1216
     * a format string,
1217
     * an open routine.
1218
1219
    Formats are placed in an dict by their format string for reference 
1220
    during bzrdir opening. These should be subclasses of BzrDirFormat
1221
    for consistency.
1222
1223
    Once a format is deprecated, just deprecate the initialize and open
1224
    methods on the format class. Do not deprecate the object, as the 
1225
    object will be created every system load.
1226
    """
1227
1228
    _default_format = None
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
1229
    """The default format used for new .bzr dirs."""
1534.4.39 by Robert Collins
Basic BzrDir support.
1230
1231
    _formats = {}
1232
    """The known formats."""
1233
1733.1.7 by Jelmer Vernooij
Change set of control dir formats to list.
1234
    _control_formats = []
1733.1.6 by Jelmer Vernooij
Fix a couple of minor issues after review by Martin.
1235
    """The registered control formats - .bzr, ....
1236
    
1733.1.7 by Jelmer Vernooij
Change set of control dir formats to list.
1237
    This is a list of BzrDirFormat objects.
1733.1.6 by Jelmer Vernooij
Fix a couple of minor issues after review by Martin.
1238
    """
1733.1.1 by Robert Collins
Support non '.bzr' control directories in bzrdir.
1239
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.
1240
    _control_server_formats = []
1241
    """The registered control server formats, e.g. RemoteBzrDirs.
1242
1243
    This is a list of BzrDirFormat objects.
1244
    """
1245
1553.5.69 by Martin Pool
BzrDirFormat subclasses can now control what kind of overall lock is used.
1246
    _lock_file_name = 'branch-lock'
1247
1248
    # _lock_class must be set in subclasses to the lock type, typ.
1249
    # TransportLock or LockDir
1250
1534.4.39 by Robert Collins
Basic BzrDir support.
1251
    @classmethod
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.
1252
    def find_format(klass, transport, _server_formats=True):
1733.1.1 by Robert Collins
Support non '.bzr' control directories in bzrdir.
1253
        """Return the format present at transport."""
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.
1254
        if _server_formats:
1255
            formats = klass._control_server_formats + klass._control_formats
1256
        else:
1257
            formats = klass._control_formats
1258
        for format in formats:
1733.1.1 by Robert Collins
Support non '.bzr' control directories in bzrdir.
1259
            try:
1260
                return format.probe_transport(transport)
1261
            except errors.NotBranchError:
1262
                # this format does not find a control dir here.
1263
                pass
1264
        raise errors.NotBranchError(path=transport.base)
1265
1266
    @classmethod
1267
    def probe_transport(klass, transport):
1752.2.52 by Andrew Bennetts
Flesh out more Remote* methods needed to open and initialise remote branches/trees/repositories.
1268
        """Return the .bzrdir style format present in a directory."""
1534.4.39 by Robert Collins
Basic BzrDir support.
1269
        try:
2164.2.18 by Vincent Ladeuil
Take Aaron comments into account.
1270
            format_string = transport.get(".bzr/branch-format").read()
1733.2.3 by Michael Ellerman
Don't coallesce try blocks, it can lead to confusing exceptions.
1271
        except errors.NoSuchFile:
1272
            raise errors.NotBranchError(path=transport.base)
1273
1274
        try:
1534.4.39 by Robert Collins
Basic BzrDir support.
1275
            return klass._formats[format_string]
1276
        except KeyError:
1740.5.6 by Martin Pool
Clean up many exception classes.
1277
            raise errors.UnknownFormatError(format=format_string)
1534.4.39 by Robert Collins
Basic BzrDir support.
1278
1279
    @classmethod
1280
    def get_default_format(klass):
1281
        """Return the current default format."""
1282
        return klass._default_format
1283
1284
    def get_format_string(self):
1285
        """Return the ASCII format string that identifies this format."""
1286
        raise NotImplementedError(self.get_format_string)
1287
1624.3.19 by Olaf Conradi
New call get_format_description to give a user-friendly description of a
1288
    def get_format_description(self):
1289
        """Return the short description for this format."""
1290
        raise NotImplementedError(self.get_format_description)
1291
1534.5.16 by Robert Collins
Review feedback.
1292
    def get_converter(self, format=None):
1293
        """Return the converter to use to convert bzrdirs needing converts.
1534.5.10 by Robert Collins
Make upgrade driver unaware of the specific formats in play.
1294
1295
        This returns a bzrlib.bzrdir.Converter object.
1296
1297
        This should return the best upgrader to step this format towards the
1759.2.1 by Jelmer Vernooij
Fix some types (found using aspell).
1298
        current default format. In the case of plugins we can/should provide
1534.5.10 by Robert Collins
Make upgrade driver unaware of the specific formats in play.
1299
        some means for them to extend the range of returnable converters.
1534.5.13 by Robert Collins
Correct buggy test.
1300
1759.2.1 by Jelmer Vernooij
Fix some types (found using aspell).
1301
        :param format: Optional format to override the default format of the 
1534.5.13 by Robert Collins
Correct buggy test.
1302
                       library.
1534.5.10 by Robert Collins
Make upgrade driver unaware of the specific formats in play.
1303
        """
1534.5.16 by Robert Collins
Review feedback.
1304
        raise NotImplementedError(self.get_converter)
1534.5.10 by Robert Collins
Make upgrade driver unaware of the specific formats in play.
1305
2476.3.8 by Vincent Ladeuil
Mark transports that need to be instrumented or refactored to check
1306
    def initialize(self, url, possible_transports=None):
1608.2.8 by Martin Pool
Separate out BzrDir.initialize_on_transport so it
1307
        """Create a bzr control dir at this url and return an opened copy.
1308
        
1309
        Subclasses should typically override initialize_on_transport
1310
        instead of this method.
1311
        """
2476.3.8 by Vincent Ladeuil
Mark transports that need to be instrumented or refactored to check
1312
        return self.initialize_on_transport(get_transport(url,
1313
                                                          possible_transports))
1608.2.8 by Martin Pool
Separate out BzrDir.initialize_on_transport so it
1314
1651.1.6 by Martin Pool
Clean up clone-bzrdir code
1315
    def initialize_on_transport(self, transport):
1608.2.8 by Martin Pool
Separate out BzrDir.initialize_on_transport so it
1316
        """Initialize a new bzrdir in the base directory of a Transport."""
1759.2.1 by Jelmer Vernooij
Fix some types (found using aspell).
1317
        # Since we don't have a .bzr directory, inherit the
1534.4.39 by Robert Collins
Basic BzrDir support.
1318
        # mode from the root directory
1996.3.3 by John Arbash Meinel
Shave off another 40ms by demand loading branch and bzrdir
1319
        temp_control = lockable_files.LockableFiles(transport,
1320
                            '', lockable_files.TransportLock)
1534.4.39 by Robert Collins
Basic BzrDir support.
1321
        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.
1322
                                      # FIXME: RBC 20060121 don't peek under
1534.4.39 by Robert Collins
Basic BzrDir support.
1323
                                      # the covers
1324
                                      mode=temp_control._dir_mode)
1325
        file_mode = temp_control._file_mode
1326
        del temp_control
1608.2.8 by Martin Pool
Separate out BzrDir.initialize_on_transport so it
1327
        mutter('created control directory in ' + transport.base)
1328
        control = transport.clone('.bzr')
1534.4.39 by Robert Collins
Basic BzrDir support.
1329
        utf8_files = [('README', 
1330
                       "This is a Bazaar-NG control directory.\n"
1331
                       "Do not change any files in this directory.\n"),
1332
                      ('branch-format', self.get_format_string()),
1333
                      ]
1334
        # NB: no need to escape relative paths that are url safe.
1996.3.3 by John Arbash Meinel
Shave off another 40ms by demand loading branch and bzrdir
1335
        control_files = lockable_files.LockableFiles(control,
1336
                            self._lock_file_name, self._lock_class)
1553.5.60 by Martin Pool
New LockableFiles.create_lock() method
1337
        control_files.create_lock()
1534.4.39 by Robert Collins
Basic BzrDir support.
1338
        control_files.lock_write()
1339
        try:
1340
            for file, content in utf8_files:
1341
                control_files.put_utf8(file, content)
1342
        finally:
1343
            control_files.unlock()
1608.2.8 by Martin Pool
Separate out BzrDir.initialize_on_transport so it
1344
        return self.open(transport, _found=True)
1534.4.39 by Robert Collins
Basic BzrDir support.
1345
1346
    def is_supported(self):
1347
        """Is this format supported?
1348
1349
        Supported formats must be initializable and openable.
1350
        Unsupported formats may not support initialization or committing or 
1351
        some other features depending on the reason for not being supported.
1352
        """
1353
        return True
1354
1910.2.14 by Aaron Bentley
Fail when trying to use interrepository on Knit2 and Knit1
1355
    def same_model(self, target_format):
1356
        return (self.repository_format.rich_root_data == 
1357
            target_format.rich_root_data)
1358
1733.1.3 by Robert Collins
Extend the test suite to run bzrdir conformance tests on non .bzr based control dirs.
1359
    @classmethod
1360
    def known_formats(klass):
1361
        """Return all the known formats.
1362
        
1363
        Concrete formats should override _known_formats.
1364
        """
1733.1.6 by Jelmer Vernooij
Fix a couple of minor issues after review by Martin.
1365
        # There is double indirection here to make sure that control 
1366
        # formats used by more than one dir format will only be probed 
1367
        # once. This can otherwise be quite expensive for remote connections.
1733.1.3 by Robert Collins
Extend the test suite to run bzrdir conformance tests on non .bzr based control dirs.
1368
        result = set()
1369
        for format in klass._control_formats:
1370
            result.update(format._known_formats())
1371
        return result
1372
    
1373
    @classmethod
1374
    def _known_formats(klass):
1375
        """Return the known format instances for this control format."""
1376
        return set(klass._formats.values())
1377
1534.4.39 by Robert Collins
Basic BzrDir support.
1378
    def open(self, transport, _found=False):
1379
        """Return an instance of this format for the dir transport points at.
1380
        
1381
        _found is a private parameter, do not use it.
1382
        """
1383
        if not _found:
2090.2.2 by Martin Pool
Fix an assertion with side effects
1384
            found_format = BzrDirFormat.find_format(transport)
1385
            if not isinstance(found_format, self.__class__):
1386
                raise AssertionError("%s was asked to open %s, but it seems to need "
1387
                        "format %s" 
1388
                        % (self, transport, found_format))
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
1389
        return self._open(transport)
1390
1391
    def _open(self, transport):
1392
        """Template method helper for opening BzrDirectories.
1393
1394
        This performs the actual open and any additional logic or parameter
1395
        passing.
1396
        """
1397
        raise NotImplementedError(self._open)
1534.4.39 by Robert Collins
Basic BzrDir support.
1398
1399
    @classmethod
1400
    def register_format(klass, format):
1401
        klass._formats[format.get_format_string()] = format
1402
1403
    @classmethod
1733.1.1 by Robert Collins
Support non '.bzr' control directories in bzrdir.
1404
    def register_control_format(klass, format):
2164.2.13 by v.ladeuil+lp at free
Add tests for redirection. Preserve transport decorations.
1405
        """Register a format that does not use '.bzr' for its control dir.
1733.1.1 by Robert Collins
Support non '.bzr' control directories in bzrdir.
1406
1407
        TODO: This should be pulled up into a 'ControlDirFormat' base class
1408
        which BzrDirFormat can inherit from, and renamed to register_format 
1409
        there. It has been done without that for now for simplicity of
1410
        implementation.
1411
        """
1733.1.7 by Jelmer Vernooij
Change set of control dir formats to list.
1412
        klass._control_formats.append(format)
1733.1.1 by Robert Collins
Support non '.bzr' control directories in bzrdir.
1413
1414
    @classmethod
2018.5.163 by Andrew Bennetts
Deal with various review comments from Robert.
1415
    def register_control_server_format(klass, format):
1416
        """Register a control format for client-server environments.
1417
1418
        These formats will be tried before ones registered with
1419
        register_control_format.  This gives implementations that decide to the
1420
        chance to grab it before anything looks at the contents of the format
1421
        file.
1422
        """
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.
1423
        klass._control_server_formats.append(format)
2018.5.163 by Andrew Bennetts
Deal with various review comments from Robert.
1424
1425
    @classmethod
2204.4.12 by Aaron Bentley
Deprecate bzrdir.BzrDirFormat.set_default_format
1426
    @symbol_versioning.deprecated_method(symbol_versioning.zero_fourteen)
1534.4.39 by Robert Collins
Basic BzrDir support.
1427
    def set_default_format(klass, format):
2204.5.2 by Aaron Bentley
Tweak set_default_format
1428
        klass._set_default_format(format)
1534.4.39 by Robert Collins
Basic BzrDir support.
1429
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
1430
    @classmethod
1431
    def _set_default_format(klass, format):
1432
        """Set default format (for testing behavior of defaults only)"""
1433
        klass._default_format = format
1434
1534.5.1 by Robert Collins
Give info some reasonable output and tests.
1435
    def __str__(self):
1436
        return self.get_format_string()[:-1]
1437
1534.4.39 by Robert Collins
Basic BzrDir support.
1438
    @classmethod
1439
    def unregister_format(klass, format):
1440
        assert klass._formats[format.get_format_string()] is format
1441
        del klass._formats[format.get_format_string()]
1442
1733.1.1 by Robert Collins
Support non '.bzr' control directories in bzrdir.
1443
    @classmethod
1444
    def unregister_control_format(klass, format):
1445
        klass._control_formats.remove(format)
1446
1447
1534.4.39 by Robert Collins
Basic BzrDir support.
1448
class BzrDirFormat4(BzrDirFormat):
1449
    """Bzr dir format 4.
1450
1451
    This format is a combined format for working tree, branch and repository.
1452
    It has:
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.
1453
     - Format 1 working trees [always]
1454
     - Format 4 branches [always]
1455
     - Format 4 repositories [always]
1534.4.39 by Robert Collins
Basic BzrDir support.
1456
1457
    This format is deprecated: it indexes texts using a text it which is
1458
    removed in format 5; write support for this format has been removed.
1459
    """
1460
1996.3.3 by John Arbash Meinel
Shave off another 40ms by demand loading branch and bzrdir
1461
    _lock_class = lockable_files.TransportLock
1553.5.69 by Martin Pool
BzrDirFormat subclasses can now control what kind of overall lock is used.
1462
1534.4.39 by Robert Collins
Basic BzrDir support.
1463
    def get_format_string(self):
1464
        """See BzrDirFormat.get_format_string()."""
1465
        return "Bazaar-NG branch, format 0.0.4\n"
1466
1624.3.19 by Olaf Conradi
New call get_format_description to give a user-friendly description of a
1467
    def get_format_description(self):
1468
        """See BzrDirFormat.get_format_description()."""
1469
        return "All-in-one format 4"
1470
1534.5.16 by Robert Collins
Review feedback.
1471
    def get_converter(self, format=None):
1472
        """See BzrDirFormat.get_converter()."""
1534.5.13 by Robert Collins
Correct buggy test.
1473
        # there is one and only one upgrade path here.
1534.5.10 by Robert Collins
Make upgrade driver unaware of the specific formats in play.
1474
        return ConvertBzrDir4To5()
1475
        
1651.1.6 by Martin Pool
Clean up clone-bzrdir code
1476
    def initialize_on_transport(self, transport):
1534.4.39 by Robert Collins
Basic BzrDir support.
1477
        """Format 4 branches cannot be created."""
1478
        raise errors.UninitializableFormat(self)
1479
1480
    def is_supported(self):
1481
        """Format 4 is not supported.
1482
1483
        It is not supported because the model changed from 4 to 5 and the
1484
        conversion logic is expensive - so doing it on the fly was not 
1485
        feasible.
1486
        """
1487
        return False
1488
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
1489
    def _open(self, transport):
1490
        """See BzrDirFormat._open."""
1491
        return BzrDir4(transport, self)
1492
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.
1493
    def __return_repository_format(self):
1494
        """Circular import protection."""
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
1495
        from bzrlib.repofmt.weaverepo import RepositoryFormat4
1910.2.12 by Aaron Bentley
Implement knit repo format 2
1496
        return RepositoryFormat4()
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.
1497
    repository_format = property(__return_repository_format)
1498
1534.4.39 by Robert Collins
Basic BzrDir support.
1499
1500
class BzrDirFormat5(BzrDirFormat):
1501
    """Bzr control format 5.
1502
1503
    This format is a combined format for working tree, branch and repository.
1504
    It has:
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.
1505
     - Format 2 working trees [always] 
1506
     - Format 4 branches [always] 
1534.4.53 by Robert Collins
Review feedback from John Meinel.
1507
     - Format 5 repositories [always]
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.
1508
       Unhashed stores in the repository.
1534.4.39 by Robert Collins
Basic BzrDir support.
1509
    """
1510
1996.3.3 by John Arbash Meinel
Shave off another 40ms by demand loading branch and bzrdir
1511
    _lock_class = lockable_files.TransportLock
1553.5.69 by Martin Pool
BzrDirFormat subclasses can now control what kind of overall lock is used.
1512
1534.4.39 by Robert Collins
Basic BzrDir support.
1513
    def get_format_string(self):
1514
        """See BzrDirFormat.get_format_string()."""
1515
        return "Bazaar-NG branch, format 5\n"
1516
1624.3.19 by Olaf Conradi
New call get_format_description to give a user-friendly description of a
1517
    def get_format_description(self):
1518
        """See BzrDirFormat.get_format_description()."""
1519
        return "All-in-one format 5"
1520
1534.5.16 by Robert Collins
Review feedback.
1521
    def get_converter(self, format=None):
1522
        """See BzrDirFormat.get_converter()."""
1534.5.13 by Robert Collins
Correct buggy test.
1523
        # there is one and only one upgrade path here.
1534.5.10 by Robert Collins
Make upgrade driver unaware of the specific formats in play.
1524
        return ConvertBzrDir5To6()
1651.1.6 by Martin Pool
Clean up clone-bzrdir code
1525
1526
    def _initialize_for_clone(self, url):
1527
        return self.initialize_on_transport(get_transport(url), _cloning=True)
1534.5.10 by Robert Collins
Make upgrade driver unaware of the specific formats in play.
1528
        
1608.2.8 by Martin Pool
Separate out BzrDir.initialize_on_transport so it
1529
    def initialize_on_transport(self, transport, _cloning=False):
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.
1530
        """Format 5 dirs always have working tree, branch and repository.
1531
        
1532
        Except when they are being cloned.
1533
        """
1534
        from bzrlib.branch import BzrBranchFormat4
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
1535
        from bzrlib.repofmt.weaverepo import RepositoryFormat5
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.
1536
        from bzrlib.workingtree import WorkingTreeFormat2
1651.1.6 by Martin Pool
Clean up clone-bzrdir code
1537
        result = (super(BzrDirFormat5, self).initialize_on_transport(transport))
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.
1538
        RepositoryFormat5().initialize(result, _internal=True)
1539
        if not _cloning:
1910.5.1 by Andrew Bennetts
Make some old formats create at least a stub working tree rather than incomplete bzrdirs, and change some tests to use the test suite transport rather than hard-coded to local-only.
1540
            branch = BzrBranchFormat4().initialize(result)
1541
            try:
1542
                WorkingTreeFormat2().initialize(result)
1543
            except errors.NotLocalUrl:
1544
                # Even though we can't access the working tree, we need to
1545
                # create its control files.
1546
                WorkingTreeFormat2().stub_initialize_remote(branch.control_files)
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.
1547
        return result
1548
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
1549
    def _open(self, transport):
1550
        """See BzrDirFormat._open."""
1551
        return BzrDir5(transport, self)
1552
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.
1553
    def __return_repository_format(self):
1554
        """Circular import protection."""
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
1555
        from bzrlib.repofmt.weaverepo import RepositoryFormat5
1910.2.12 by Aaron Bentley
Implement knit repo format 2
1556
        return RepositoryFormat5()
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.
1557
    repository_format = property(__return_repository_format)
1558
1534.4.39 by Robert Collins
Basic BzrDir support.
1559
1560
class BzrDirFormat6(BzrDirFormat):
1561
    """Bzr control format 6.
1562
1563
    This format is a combined format for working tree, branch and repository.
1564
    It has:
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.
1565
     - Format 2 working trees [always] 
1566
     - Format 4 branches [always] 
1567
     - Format 6 repositories [always]
1534.4.39 by Robert Collins
Basic BzrDir support.
1568
    """
1569
1996.3.3 by John Arbash Meinel
Shave off another 40ms by demand loading branch and bzrdir
1570
    _lock_class = lockable_files.TransportLock
1553.5.69 by Martin Pool
BzrDirFormat subclasses can now control what kind of overall lock is used.
1571
1534.4.39 by Robert Collins
Basic BzrDir support.
1572
    def get_format_string(self):
1573
        """See BzrDirFormat.get_format_string()."""
1574
        return "Bazaar-NG branch, format 6\n"
1575
1624.3.19 by Olaf Conradi
New call get_format_description to give a user-friendly description of a
1576
    def get_format_description(self):
1577
        """See BzrDirFormat.get_format_description()."""
1578
        return "All-in-one format 6"
1579
1534.5.16 by Robert Collins
Review feedback.
1580
    def get_converter(self, format=None):
1581
        """See BzrDirFormat.get_converter()."""
1534.5.13 by Robert Collins
Correct buggy test.
1582
        # there is one and only one upgrade path here.
1534.5.10 by Robert Collins
Make upgrade driver unaware of the specific formats in play.
1583
        return ConvertBzrDir6ToMeta()
1584
        
1651.1.6 by Martin Pool
Clean up clone-bzrdir code
1585
    def _initialize_for_clone(self, url):
1586
        return self.initialize_on_transport(get_transport(url), _cloning=True)
1587
1608.2.8 by Martin Pool
Separate out BzrDir.initialize_on_transport so it
1588
    def initialize_on_transport(self, transport, _cloning=False):
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.
1589
        """Format 6 dirs always have working tree, branch and repository.
1590
        
1591
        Except when they are being cloned.
1592
        """
1593
        from bzrlib.branch import BzrBranchFormat4
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
1594
        from bzrlib.repofmt.weaverepo import RepositoryFormat6
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.
1595
        from bzrlib.workingtree import WorkingTreeFormat2
1651.1.6 by Martin Pool
Clean up clone-bzrdir code
1596
        result = super(BzrDirFormat6, self).initialize_on_transport(transport)
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.
1597
        RepositoryFormat6().initialize(result, _internal=True)
1598
        if not _cloning:
1910.5.1 by Andrew Bennetts
Make some old formats create at least a stub working tree rather than incomplete bzrdirs, and change some tests to use the test suite transport rather than hard-coded to local-only.
1599
            branch = BzrBranchFormat4().initialize(result)
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.
1600
            try:
1601
                WorkingTreeFormat2().initialize(result)
1602
            except errors.NotLocalUrl:
1910.5.1 by Andrew Bennetts
Make some old formats create at least a stub working tree rather than incomplete bzrdirs, and change some tests to use the test suite transport rather than hard-coded to local-only.
1603
                # Even though we can't access the working tree, we need to
1604
                # create its control files.
1605
                WorkingTreeFormat2().stub_initialize_remote(branch.control_files)
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.
1606
        return result
1607
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
1608
    def _open(self, transport):
1609
        """See BzrDirFormat._open."""
1610
        return BzrDir6(transport, self)
1611
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.
1612
    def __return_repository_format(self):
1613
        """Circular import protection."""
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
1614
        from bzrlib.repofmt.weaverepo import RepositoryFormat6
1910.2.12 by Aaron Bentley
Implement knit repo format 2
1615
        return RepositoryFormat6()
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.
1616
    repository_format = property(__return_repository_format)
1617
1534.4.39 by Robert Collins
Basic BzrDir support.
1618
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
1619
class BzrDirMetaFormat1(BzrDirFormat):
1620
    """Bzr meta control format 1
1621
1622
    This is the first format with split out working tree, branch and repository
1623
    disk storage.
1624
    It has:
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.
1625
     - Format 3 working trees [optional]
1626
     - Format 5 branches [optional]
1627
     - 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.
1628
    """
1629
1996.3.3 by John Arbash Meinel
Shave off another 40ms by demand loading branch and bzrdir
1630
    _lock_class = lockdir.LockDir
1553.5.69 by Martin Pool
BzrDirFormat subclasses can now control what kind of overall lock is used.
1631
2100.3.10 by Aaron Bentley
Ensure added references are serialized properly, beef up Workingtreee3
1632
    def __init__(self):
1633
        self._workingtree_format = None
2230.3.1 by Aaron Bentley
Get branch6 creation working
1634
        self._branch_format = None
2100.3.10 by Aaron Bentley
Ensure added references are serialized properly, beef up Workingtreee3
1635
2100.3.15 by Aaron Bentley
get test suite passing
1636
    def __eq__(self, other):
1637
        if other.__class__ is not self.__class__:
1638
            return False
1639
        if other.repository_format != self.repository_format:
1640
            return False
1641
        if other.workingtree_format != self.workingtree_format:
1642
            return False
1643
        return True
1644
2100.3.35 by Aaron Bentley
equality operations on bzrdir
1645
    def __ne__(self, other):
1646
        return not self == other
1647
2230.3.55 by Aaron Bentley
Updates from review
1648
    def get_branch_format(self):
2230.3.1 by Aaron Bentley
Get branch6 creation working
1649
        if self._branch_format is None:
1650
            from bzrlib.branch import BranchFormat
1651
            self._branch_format = BranchFormat.get_default_format()
1652
        return self._branch_format
1653
2230.3.55 by Aaron Bentley
Updates from review
1654
    def set_branch_format(self, format):
2230.3.1 by Aaron Bentley
Get branch6 creation working
1655
        self._branch_format = format
1656
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.
1657
    def get_converter(self, format=None):
1658
        """See BzrDirFormat.get_converter()."""
1659
        if format is None:
1660
            format = BzrDirFormat.get_default_format()
1661
        if not isinstance(self, format.__class__):
1662
            # converting away from metadir is not implemented
1663
            raise NotImplementedError(self.get_converter)
1664
        return ConvertMetaToMeta(format)
1665
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
1666
    def get_format_string(self):
1667
        """See BzrDirFormat.get_format_string()."""
1668
        return "Bazaar-NG meta directory, format 1\n"
1669
1624.3.19 by Olaf Conradi
New call get_format_description to give a user-friendly description of a
1670
    def get_format_description(self):
1671
        """See BzrDirFormat.get_format_description()."""
1672
        return "Meta directory format 1"
1673
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
1674
    def _open(self, transport):
1675
        """See BzrDirFormat._open."""
2230.3.24 by Aaron Bentley
Remove format-on-open code
1676
        return BzrDirMeta1(transport, self)
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
1677
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.
1678
    def __return_repository_format(self):
1679
        """Circular import protection."""
1680
        if getattr(self, '_repository_format', None):
1681
            return self._repository_format
1682
        from bzrlib.repository import RepositoryFormat
1683
        return RepositoryFormat.get_default_format()
1684
1685
    def __set_repository_format(self, value):
1686
        """Allow changint the repository format for metadir formats."""
1687
        self._repository_format = value
1553.5.72 by Martin Pool
Clean up test for Branch5 lockdirs
1688
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.
1689
    repository_format = property(__return_repository_format, __set_repository_format)
1690
2100.3.10 by Aaron Bentley
Ensure added references are serialized properly, beef up Workingtreee3
1691
    def __get_workingtree_format(self):
1692
        if self._workingtree_format is None:
1693
            from bzrlib.workingtree import WorkingTreeFormat
1694
            self._workingtree_format = WorkingTreeFormat.get_default_format()
1695
        return self._workingtree_format
1696
1697
    def __set_workingtree_format(self, wt_format):
1698
        self._workingtree_format = wt_format
1699
1700
    workingtree_format = property(__get_workingtree_format,
1701
                                  __set_workingtree_format)
1702
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
1703
2164.2.19 by Vincent Ladeuil
Revert BzrDirFormat1 registering.
1704
# Register bzr control format
1705
BzrDirFormat.register_control_format(BzrDirFormat)
2164.2.13 by v.ladeuil+lp at free
Add tests for redirection. Preserve transport decorations.
1706
1707
# Register bzr formats
1534.4.39 by Robert Collins
Basic BzrDir support.
1708
BzrDirFormat.register_format(BzrDirFormat4())
1709
BzrDirFormat.register_format(BzrDirFormat5())
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
1710
BzrDirFormat.register_format(BzrDirFormat6())
1711
__default_format = BzrDirMetaFormat1()
1534.4.39 by Robert Collins
Basic BzrDir support.
1712
BzrDirFormat.register_format(__default_format)
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
1713
BzrDirFormat._default_format = __default_format
1534.4.39 by Robert Collins
Basic BzrDir support.
1714
1715
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
1716
class Converter(object):
1717
    """Converts a disk format object from one format to another."""
1718
1534.5.10 by Robert Collins
Make upgrade driver unaware of the specific formats in play.
1719
    def convert(self, to_convert, pb):
1720
        """Perform the conversion of to_convert, giving feedback via pb.
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
1721
1534.5.10 by Robert Collins
Make upgrade driver unaware of the specific formats in play.
1722
        :param to_convert: The disk object to convert.
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
1723
        :param pb: a progress bar to use for progress information.
1724
        """
1725
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.
1726
    def step(self, message):
1727
        """Update the pb by a step."""
1728
        self.count +=1
1729
        self.pb.update(message, self.count, self.total)
1730
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
1731
1732
class ConvertBzrDir4To5(Converter):
1733
    """Converts format 4 bzr dirs to format 5."""
1734
1534.5.10 by Robert Collins
Make upgrade driver unaware of the specific formats in play.
1735
    def __init__(self):
1736
        super(ConvertBzrDir4To5, self).__init__()
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
1737
        self.converted_revs = set()
1738
        self.absent_revisions = set()
1739
        self.text_count = 0
1740
        self.revisions = {}
1741
        
1534.5.10 by Robert Collins
Make upgrade driver unaware of the specific formats in play.
1742
    def convert(self, to_convert, pb):
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
1743
        """See Converter.convert()."""
1534.5.10 by Robert Collins
Make upgrade driver unaware of the specific formats in play.
1744
        self.bzrdir = to_convert
1745
        self.pb = pb
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
1746
        self.pb.note('starting upgrade from format 4 to 5')
1747
        if isinstance(self.bzrdir.transport, LocalTransport):
1748
            self.bzrdir.get_workingtree_transport(None).delete('stat-cache')
1749
        self._convert_to_weaves()
1750
        return BzrDir.open(self.bzrdir.root_transport.base)
1751
1752
    def _convert_to_weaves(self):
1753
        self.pb.note('note: upgrade may be faster if all store files are ungzipped first')
1754
        try:
1755
            # TODO permissions
1756
            stat = self.bzrdir.transport.stat('weaves')
1757
            if not S_ISDIR(stat.st_mode):
1758
                self.bzrdir.transport.delete('weaves')
1759
                self.bzrdir.transport.mkdir('weaves')
1760
        except errors.NoSuchFile:
1761
            self.bzrdir.transport.mkdir('weaves')
1563.2.10 by Robert Collins
Change weave store to be a versioned store, using WeaveFiles which maintain integrity without needing explicit 'put' operations.
1762
        # deliberately not a WeaveFile as we want to build it up slowly.
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
1763
        self.inv_weave = Weave('inventory')
1764
        # holds in-memory weaves for all files
1765
        self.text_weaves = {}
1766
        self.bzrdir.transport.delete('branch-format')
1767
        self.branch = self.bzrdir.open_branch()
1768
        self._convert_working_inv()
1769
        rev_history = self.branch.revision_history()
1770
        # to_read is a stack holding the revisions we still need to process;
1771
        # appending to it adds new highest-priority revisions
1772
        self.known_revisions = set(rev_history)
1773
        self.to_read = rev_history[-1:]
1774
        while self.to_read:
1775
            rev_id = self.to_read.pop()
1776
            if (rev_id not in self.revisions
1777
                and rev_id not in self.absent_revisions):
1778
                self._load_one_rev(rev_id)
1779
        self.pb.clear()
1780
        to_import = self._make_order()
1781
        for i, rev_id in enumerate(to_import):
1782
            self.pb.update('converting revision', i, len(to_import))
1783
            self._convert_one_rev(rev_id)
1784
        self.pb.clear()
1785
        self._write_all_weaves()
1786
        self._write_all_revs()
1787
        self.pb.note('upgraded to weaves:')
1788
        self.pb.note('  %6d revisions and inventories', len(self.revisions))
1789
        self.pb.note('  %6d revisions not present', len(self.absent_revisions))
1790
        self.pb.note('  %6d texts', self.text_count)
1791
        self._cleanup_spare_files_after_format4()
1792
        self.branch.control_files.put_utf8('branch-format', BzrDirFormat5().get_format_string())
1793
1794
    def _cleanup_spare_files_after_format4(self):
1795
        # FIXME working tree upgrade foo.
1796
        for n in 'merged-patches', 'pending-merged-patches':
1797
            try:
1798
                ## assert os.path.getsize(p) == 0
1799
                self.bzrdir.transport.delete(n)
1800
            except errors.NoSuchFile:
1801
                pass
1802
        self.bzrdir.transport.delete_tree('inventory-store')
1803
        self.bzrdir.transport.delete_tree('text-store')
1804
1805
    def _convert_working_inv(self):
1996.3.6 by John Arbash Meinel
Find a few places that weren't importing their dependencies.
1806
        inv = xml4.serializer_v4.read_inventory(
1807
                    self.branch.control_files.get('inventory'))
1808
        new_inv_xml = xml5.serializer_v5.write_inventory_to_string(inv)
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
1809
        # FIXME inventory is a working tree change.
1955.3.4 by John Arbash Meinel
Fix 2 calls to 'put()' that were using strings instead of files
1810
        self.branch.control_files.put('inventory', StringIO(new_inv_xml))
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
1811
1812
    def _write_all_weaves(self):
1813
        controlweaves = WeaveStore(self.bzrdir.transport, prefixed=False)
1814
        weave_transport = self.bzrdir.transport.clone('weaves')
1815
        weaves = WeaveStore(weave_transport, prefixed=False)
1563.2.34 by Robert Collins
Remove the commit and rollback transaction methods as misleading, and implement a WriteTransaction
1816
        transaction = WriteTransaction()
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
1817
1818
        try:
1563.2.10 by Robert Collins
Change weave store to be a versioned store, using WeaveFiles which maintain integrity without needing explicit 'put' operations.
1819
            i = 0
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
1820
            for file_id, file_weave in self.text_weaves.items():
1821
                self.pb.update('writing weave', i, len(self.text_weaves))
1563.2.10 by Robert Collins
Change weave store to be a versioned store, using WeaveFiles which maintain integrity without needing explicit 'put' operations.
1822
                weaves._put_weave(file_id, file_weave, transaction)
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
1823
                i += 1
1563.2.10 by Robert Collins
Change weave store to be a versioned store, using WeaveFiles which maintain integrity without needing explicit 'put' operations.
1824
            self.pb.update('inventory', 0, 1)
1825
            controlweaves._put_weave('inventory', self.inv_weave, transaction)
1826
            self.pb.update('inventory', 1, 1)
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
1827
        finally:
1828
            self.pb.clear()
1829
1830
    def _write_all_revs(self):
1831
        """Write all revisions out in new form."""
1832
        self.bzrdir.transport.delete_tree('revision-store')
1833
        self.bzrdir.transport.mkdir('revision-store')
1834
        revision_transport = self.bzrdir.transport.clone('revision-store')
1835
        # TODO permissions
1563.2.28 by Robert Collins
Add total_size to the revision_store api.
1836
        _revision_store = TextRevisionStore(TextStore(revision_transport,
1837
                                                      prefixed=False,
1838
                                                      compressed=True))
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
1839
        try:
1996.3.3 by John Arbash Meinel
Shave off another 40ms by demand loading branch and bzrdir
1840
            transaction = WriteTransaction()
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
1841
            for i, rev_id in enumerate(self.converted_revs):
1842
                self.pb.update('write revision', i, len(self.converted_revs))
1563.2.28 by Robert Collins
Add total_size to the revision_store api.
1843
                _revision_store.add_revision(self.revisions[rev_id], transaction)
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
1844
        finally:
1845
            self.pb.clear()
1846
            
1847
    def _load_one_rev(self, rev_id):
1848
        """Load a revision object into memory.
1849
1850
        Any parents not either loaded or abandoned get queued to be
1851
        loaded."""
1852
        self.pb.update('loading revision',
1853
                       len(self.revisions),
1854
                       len(self.known_revisions))
1563.2.22 by Robert Collins
Move responsibility for repository.has_revision into RevisionStore
1855
        if not self.branch.repository.has_revision(rev_id):
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
1856
            self.pb.clear()
1857
            self.pb.note('revision {%s} not present in branch; '
1858
                         'will be converted as a ghost',
1859
                         rev_id)
1860
            self.absent_revisions.add(rev_id)
1861
        else:
1563.2.28 by Robert Collins
Add total_size to the revision_store api.
1862
            rev = self.branch.repository._revision_store.get_revision(rev_id,
1863
                self.branch.repository.get_transaction())
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
1864
            for parent_id in rev.parent_ids:
1865
                self.known_revisions.add(parent_id)
1866
                self.to_read.append(parent_id)
1867
            self.revisions[rev_id] = rev
1868
1869
    def _load_old_inventory(self, rev_id):
1870
        assert rev_id not in self.converted_revs
1871
        old_inv_xml = self.branch.repository.inventory_store.get(rev_id).read()
1996.3.6 by John Arbash Meinel
Find a few places that weren't importing their dependencies.
1872
        inv = xml4.serializer_v4.read_inventory_from_string(old_inv_xml)
1910.2.36 by Aaron Bentley
Get upgrade from format4 under test and fixed for all formats
1873
        inv.revision_id = rev_id
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
1874
        rev = self.revisions[rev_id]
1875
        if rev.inventory_sha1:
1876
            assert rev.inventory_sha1 == sha_string(old_inv_xml), \
1877
                'inventory sha mismatch for {%s}' % rev_id
1878
        return inv
1879
1880
    def _load_updated_inventory(self, rev_id):
1881
        assert rev_id in self.converted_revs
1882
        inv_xml = self.inv_weave.get_text(rev_id)
1996.3.6 by John Arbash Meinel
Find a few places that weren't importing their dependencies.
1883
        inv = xml5.serializer_v5.read_inventory_from_string(inv_xml)
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
1884
        return inv
1885
1886
    def _convert_one_rev(self, rev_id):
1887
        """Convert revision and all referenced objects to new format."""
1888
        rev = self.revisions[rev_id]
1889
        inv = self._load_old_inventory(rev_id)
1890
        present_parents = [p for p in rev.parent_ids
1891
                           if p not in self.absent_revisions]
1892
        self._convert_revision_contents(rev, inv, present_parents)
1893
        self._store_new_weave(rev, inv, present_parents)
1894
        self.converted_revs.add(rev_id)
1895
1896
    def _store_new_weave(self, rev, inv, present_parents):
1897
        # the XML is now updated with text versions
1898
        if __debug__:
1907.1.8 by Aaron Bentley
Remove is_root
1899
            entries = inv.iter_entries()
1900
            entries.next()
1901
            for path, ie in entries:
1963.2.6 by Robey Pointer
pychecker is on crack; go back to using 'is None'.
1902
                assert getattr(ie, 'revision', None) is not None, \
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
1903
                    'no revision on {%s} in {%s}' % \
1904
                    (file_id, rev.revision_id)
1996.3.6 by John Arbash Meinel
Find a few places that weren't importing their dependencies.
1905
        new_inv_xml = xml5.serializer_v5.write_inventory_to_string(inv)
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
1906
        new_inv_sha1 = sha_string(new_inv_xml)
1563.2.28 by Robert Collins
Add total_size to the revision_store api.
1907
        self.inv_weave.add_lines(rev.revision_id, 
1908
                                 present_parents,
1909
                                 new_inv_xml.splitlines(True))
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
1910
        rev.inventory_sha1 = new_inv_sha1
1911
1912
    def _convert_revision_contents(self, rev, inv, present_parents):
1913
        """Convert all the files within a revision.
1914
1915
        Also upgrade the inventory to refer to the text revision ids."""
1916
        rev_id = rev.revision_id
1917
        mutter('converting texts of revision {%s}',
1918
               rev_id)
1919
        parent_invs = map(self._load_updated_inventory, present_parents)
1731.1.62 by Aaron Bentley
Changes from review comments
1920
        entries = inv.iter_entries()
1921
        entries.next()
1922
        for path, ie in entries:
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
1923
            self._convert_file_version(rev, ie, parent_invs)
1924
1925
    def _convert_file_version(self, rev, ie, parent_invs):
1926
        """Convert one version of one file.
1927
1928
        The file needs to be added into the weave if it is a merge
1929
        of >=2 parents or if it's changed from its parent.
1930
        """
1931
        file_id = ie.file_id
1932
        rev_id = rev.revision_id
1933
        w = self.text_weaves.get(file_id)
1934
        if w is None:
1935
            w = Weave(file_id)
1936
            self.text_weaves[file_id] = w
1937
        text_changed = False
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
1938
        parent_candiate_entries = ie.parent_candidates(parent_invs)
1939
        for old_revision in parent_candiate_entries.keys():
1940
            # if this fails, its a ghost ?
1941
            assert old_revision in self.converted_revs, \
1942
                "Revision {%s} not in converted_revs" % old_revision
1943
        heads = graph.Graph(self).heads(parent_candiate_entries.keys())
1944
        # XXX: Note that this is unordered - and this is tolerable because 
1945
        # the previous code was also unordered.
1946
        previous_entries = dict((head, parent_candiate_entries[head]) for head
1947
            in heads)
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
1948
        self.snapshot_ie(previous_entries, ie, w, rev_id)
1949
        del ie.text_id
1950
        assert getattr(ie, 'revision', None) is not None
1951
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
1952
    def get_parents(self, revision_ids):
1953
        for revision_id in revision_ids:
1954
            yield self.revisions[revision_id].parent_ids
1955
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
1956
    def snapshot_ie(self, previous_revisions, ie, w, rev_id):
1957
        # TODO: convert this logic, which is ~= snapshot to
1958
        # a call to:. This needs the path figured out. rather than a work_tree
1959
        # a v4 revision_tree can be given, or something that looks enough like
1960
        # one to give the file content to the entry if it needs it.
1961
        # and we need something that looks like a weave store for snapshot to 
1962
        # save against.
1963
        #ie.snapshot(rev, PATH, previous_revisions, REVISION_TREE, InMemoryWeaveStore(self.text_weaves))
1964
        if len(previous_revisions) == 1:
1965
            previous_ie = previous_revisions.values()[0]
1966
            if ie._unchanged(previous_ie):
1967
                ie.revision = previous_ie.revision
1968
                return
1969
        if ie.has_text():
2661.1.1 by Robert Collins
Ancient unused Repository.text_store attribute has been removed. (Robert Collins)
1970
            text = self.branch.repository.weave_store.get(ie.text_id)
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
1971
            file_lines = text.readlines()
1972
            assert sha_strings(file_lines) == ie.text_sha1
1973
            assert sum(map(len, file_lines)) == ie.text_size
1563.2.18 by Robert Collins
get knit repositories really using knits for text storage.
1974
            w.add_lines(rev_id, previous_revisions, file_lines)
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
1975
            self.text_count += 1
1976
        else:
1563.2.18 by Robert Collins
get knit repositories really using knits for text storage.
1977
            w.add_lines(rev_id, previous_revisions, [])
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
1978
        ie.revision = rev_id
1979
1980
    def _make_order(self):
1981
        """Return a suitable order for importing revisions.
1982
1983
        The order must be such that an revision is imported after all
1984
        its (present) parents.
1985
        """
1986
        todo = set(self.revisions.keys())
1987
        done = self.absent_revisions.copy()
1534.5.11 by Robert Collins
Implement upgrades to Metaformat trees.
1988
        order = []
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
1989
        while todo:
1990
            # scan through looking for a revision whose parents
1991
            # are all done
1992
            for rev_id in sorted(list(todo)):
1993
                rev = self.revisions[rev_id]
1994
                parent_ids = set(rev.parent_ids)
1995
                if parent_ids.issubset(done):
1996
                    # can take this one now
1534.5.11 by Robert Collins
Implement upgrades to Metaformat trees.
1997
                    order.append(rev_id)
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
1998
                    todo.remove(rev_id)
1999
                    done.add(rev_id)
1534.5.11 by Robert Collins
Implement upgrades to Metaformat trees.
2000
        return order
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
2001
2002
2003
class ConvertBzrDir5To6(Converter):
2004
    """Converts format 5 bzr dirs to format 6."""
2005
1534.5.10 by Robert Collins
Make upgrade driver unaware of the specific formats in play.
2006
    def convert(self, to_convert, pb):
2007
        """See Converter.convert()."""
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
2008
        self.bzrdir = to_convert
1534.5.10 by Robert Collins
Make upgrade driver unaware of the specific formats in play.
2009
        self.pb = pb
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
2010
        self.pb.note('starting upgrade from format 5 to 6')
2011
        self._convert_to_prefixed()
2012
        return BzrDir.open(self.bzrdir.root_transport.base)
2013
2014
    def _convert_to_prefixed(self):
1608.2.1 by Martin Pool
[merge] Storage filename escaping
2015
        from bzrlib.store import TransportStore
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
2016
        self.bzrdir.transport.delete('branch-format')
2017
        for store_name in ["weaves", "revision-store"]:
1608.2.1 by Martin Pool
[merge] Storage filename escaping
2018
            self.pb.note("adding prefixes to %s" % store_name)
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
2019
            store_transport = self.bzrdir.transport.clone(store_name)
1608.2.1 by Martin Pool
[merge] Storage filename escaping
2020
            store = TransportStore(store_transport, prefixed=True)
1608.1.1 by Martin Pool
[patch] LocalTransport.list_dir should return url-quoted strings (ddaa)
2021
            for urlfilename in store_transport.list_dir('.'):
1685.1.45 by John Arbash Meinel
Moved url functions into bzrlib.urlutils
2022
                filename = urlutils.unescape(urlfilename)
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
2023
                if (filename.endswith(".weave") or
2024
                    filename.endswith(".gz") or
2025
                    filename.endswith(".sig")):
2026
                    file_id = os.path.splitext(filename)[0]
2027
                else:
2028
                    file_id = filename
1608.2.1 by Martin Pool
[merge] Storage filename escaping
2029
                prefix_dir = store.hash_prefix(file_id)
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
2030
                # FIXME keep track of the dirs made RBC 20060121
2031
                try:
2032
                    store_transport.move(filename, prefix_dir + '/' + filename)
2033
                except errors.NoSuchFile: # catches missing dirs strangely enough
2034
                    store_transport.mkdir(prefix_dir)
2035
                    store_transport.move(filename, prefix_dir + '/' + filename)
2036
        self.bzrdir._control_files.put_utf8('branch-format', BzrDirFormat6().get_format_string())
2037
2038
1534.5.10 by Robert Collins
Make upgrade driver unaware of the specific formats in play.
2039
class ConvertBzrDir6ToMeta(Converter):
2040
    """Converts format 6 bzr dirs to metadirs."""
2041
2042
    def convert(self, to_convert, pb):
2043
        """See Converter.convert()."""
2241.1.11 by Martin Pool
Get rid of RepositoryFormat*_instance objects. Instead the format
2044
        from bzrlib.repofmt.weaverepo import RepositoryFormat7
2094.3.5 by John Arbash Meinel
Fix imports to ensure modules are loaded before they are used
2045
        from bzrlib.branch import BzrBranchFormat5
1534.5.10 by Robert Collins
Make upgrade driver unaware of the specific formats in play.
2046
        self.bzrdir = to_convert
2047
        self.pb = pb
1534.5.11 by Robert Collins
Implement upgrades to Metaformat trees.
2048
        self.count = 0
2049
        self.total = 20 # the steps we know about
2050
        self.garbage_inventories = []
2051
1534.5.13 by Robert Collins
Correct buggy test.
2052
        self.pb.note('starting upgrade from format 6 to metadir')
1534.5.11 by Robert Collins
Implement upgrades to Metaformat trees.
2053
        self.bzrdir._control_files.put_utf8('branch-format', "Converting to format 6")
2054
        # its faster to move specific files around than to open and use the apis...
2055
        # first off, nuke ancestry.weave, it was never used.
2056
        try:
2057
            self.step('Removing ancestry.weave')
2058
            self.bzrdir.transport.delete('ancestry.weave')
2059
        except errors.NoSuchFile:
2060
            pass
2061
        # find out whats there
2062
        self.step('Finding branch files')
1666.1.3 by Robert Collins
Fix and test upgrades from bzrdir 6 over SFTP.
2063
        last_revision = self.bzrdir.open_branch().last_revision()
1534.5.11 by Robert Collins
Implement upgrades to Metaformat trees.
2064
        bzrcontents = self.bzrdir.transport.list_dir('.')
2065
        for name in bzrcontents:
2066
            if name.startswith('basis-inventory.'):
2067
                self.garbage_inventories.append(name)
2068
        # create new directories for repository, working tree and branch
1553.5.79 by Martin Pool
upgrade to metadir should create LockDirs not files
2069
        self.dir_mode = self.bzrdir._control_files._dir_mode
1534.5.11 by Robert Collins
Implement upgrades to Metaformat trees.
2070
        self.file_mode = self.bzrdir._control_files._file_mode
2071
        repository_names = [('inventory.weave', True),
2072
                            ('revision-store', True),
2073
                            ('weaves', True)]
2074
        self.step('Upgrading repository  ')
1553.5.79 by Martin Pool
upgrade to metadir should create LockDirs not files
2075
        self.bzrdir.transport.mkdir('repository', mode=self.dir_mode)
1534.5.11 by Robert Collins
Implement upgrades to Metaformat trees.
2076
        self.make_lock('repository')
2077
        # we hard code the formats here because we are converting into
2078
        # the meta format. The meta format upgrader can take this to a 
2079
        # future format within each component.
2241.1.11 by Martin Pool
Get rid of RepositoryFormat*_instance objects. Instead the format
2080
        self.put_format('repository', RepositoryFormat7())
1534.5.11 by Robert Collins
Implement upgrades to Metaformat trees.
2081
        for entry in repository_names:
2082
            self.move_entry('repository', entry)
2083
2084
        self.step('Upgrading branch      ')
1553.5.79 by Martin Pool
upgrade to metadir should create LockDirs not files
2085
        self.bzrdir.transport.mkdir('branch', mode=self.dir_mode)
1534.5.11 by Robert Collins
Implement upgrades to Metaformat trees.
2086
        self.make_lock('branch')
2094.3.5 by John Arbash Meinel
Fix imports to ensure modules are loaded before they are used
2087
        self.put_format('branch', BzrBranchFormat5())
1534.5.11 by Robert Collins
Implement upgrades to Metaformat trees.
2088
        branch_files = [('revision-history', True),
2089
                        ('branch-name', True),
2090
                        ('parent', False)]
2091
        for entry in branch_files:
2092
            self.move_entry('branch', entry)
2093
2094
        checkout_files = [('pending-merges', True),
2095
                          ('inventory', True),
2096
                          ('stat-cache', False)]
1959.3.1 by John Arbash Meinel
David Allouche: bzr upgrade should work if there is no working tree
2097
        # If a mandatory checkout file is not present, the branch does not have
2098
        # a functional checkout. Do not create a checkout in the converted
2099
        # branch.
2100
        for name, mandatory in checkout_files:
2101
            if mandatory and name not in bzrcontents:
2102
                has_checkout = False
2103
                break
2104
        else:
2105
            has_checkout = True
2106
        if not has_checkout:
2107
            self.pb.note('No working tree.')
2108
            # If some checkout files are there, we may as well get rid of them.
2109
            for name, mandatory in checkout_files:
2110
                if name in bzrcontents:
2111
                    self.bzrdir.transport.delete(name)
2112
        else:
2123.2.1 by John Arbash Meinel
Fix bug #70716, make bzrlib.bzrdir directly import bzrlib.workingtree
2113
            from bzrlib.workingtree import WorkingTreeFormat3
1959.3.1 by John Arbash Meinel
David Allouche: bzr upgrade should work if there is no working tree
2114
            self.step('Upgrading working tree')
2115
            self.bzrdir.transport.mkdir('checkout', mode=self.dir_mode)
2116
            self.make_lock('checkout')
2117
            self.put_format(
2123.2.1 by John Arbash Meinel
Fix bug #70716, make bzrlib.bzrdir directly import bzrlib.workingtree
2118
                'checkout', WorkingTreeFormat3())
1959.3.1 by John Arbash Meinel
David Allouche: bzr upgrade should work if there is no working tree
2119
            self.bzrdir.transport.delete_multi(
2120
                self.garbage_inventories, self.pb)
2121
            for entry in checkout_files:
2122
                self.move_entry('checkout', entry)
2123
            if last_revision is not None:
2124
                self.bzrdir._control_files.put_utf8(
2125
                    'checkout/last-revision', last_revision)
2126
        self.bzrdir._control_files.put_utf8(
2127
            'branch-format', BzrDirMetaFormat1().get_format_string())
1534.5.10 by Robert Collins
Make upgrade driver unaware of the specific formats in play.
2128
        return BzrDir.open(self.bzrdir.root_transport.base)
2129
1534.5.11 by Robert Collins
Implement upgrades to Metaformat trees.
2130
    def make_lock(self, name):
2131
        """Make a lock for the new control dir name."""
2132
        self.step('Make %s lock' % name)
1996.3.3 by John Arbash Meinel
Shave off another 40ms by demand loading branch and bzrdir
2133
        ld = lockdir.LockDir(self.bzrdir.transport,
2134
                             '%s/lock' % name,
2135
                             file_modebits=self.file_mode,
2136
                             dir_modebits=self.dir_mode)
1553.5.79 by Martin Pool
upgrade to metadir should create LockDirs not files
2137
        ld.create()
1534.5.11 by Robert Collins
Implement upgrades to Metaformat trees.
2138
2139
    def move_entry(self, new_dir, entry):
2140
        """Move then entry name into new_dir."""
2141
        name = entry[0]
2142
        mandatory = entry[1]
2143
        self.step('Moving %s' % name)
2144
        try:
2145
            self.bzrdir.transport.move(name, '%s/%s' % (new_dir, name))
2146
        except errors.NoSuchFile:
2147
            if mandatory:
2148
                raise
2149
2150
    def put_format(self, dirname, format):
2151
        self.bzrdir._control_files.put_utf8('%s/format' % dirname, format.get_format_string())
2152
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.
2153
2154
class ConvertMetaToMeta(Converter):
2155
    """Converts the components of metadirs."""
2156
2157
    def __init__(self, target_format):
2158
        """Create a metadir to metadir converter.
2159
2160
        :param target_format: The final metadir format that is desired.
2161
        """
2162
        self.target_format = target_format
2163
2164
    def convert(self, to_convert, pb):
2165
        """See Converter.convert()."""
2166
        self.bzrdir = to_convert
2167
        self.pb = pb
2168
        self.count = 0
2169
        self.total = 1
2170
        self.step('checking repository format')
2171
        try:
2172
            repo = self.bzrdir.open_repository()
2173
        except errors.NoRepositoryPresent:
2174
            pass
2175
        else:
2176
            if not isinstance(repo._format, self.target_format.repository_format.__class__):
2177
                from bzrlib.repository import CopyConverter
2178
                self.pb.note('starting repository conversion')
2179
                converter = CopyConverter(self.target_format.repository_format)
2180
                converter.convert(repo, pb)
2230.3.29 by Aaron Bentley
Implement conversion to branch 6
2181
        try:
2182
            branch = self.bzrdir.open_branch()
2183
        except errors.NotBranchError:
2184
            pass
2185
        else:
2255.12.1 by Robert Collins
Implement upgrade for working trees.
2186
            # TODO: conversions of Branch and Tree should be done by
2187
            # InterXFormat lookups
2230.3.29 by Aaron Bentley
Implement conversion to branch 6
2188
            # Avoid circular imports
2189
            from bzrlib import branch as _mod_branch
2190
            if (branch._format.__class__ is _mod_branch.BzrBranchFormat5 and
2230.3.55 by Aaron Bentley
Updates from review
2191
                self.target_format.get_branch_format().__class__ is
2230.3.29 by Aaron Bentley
Implement conversion to branch 6
2192
                _mod_branch.BzrBranchFormat6):
2193
                branch_converter = _mod_branch.Converter5to6()
2194
                branch_converter.convert(branch)
2255.12.1 by Robert Collins
Implement upgrade for working trees.
2195
        try:
2323.6.4 by Martin Pool
BzrDir._check_supported now also takes care of recommending upgrades, which
2196
            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.
2197
        except (errors.NoWorkingTree, errors.NotLocalUrl):
2255.12.1 by Robert Collins
Implement upgrade for working trees.
2198
            pass
2199
        else:
2200
            # TODO: conversions of Branch and Tree should be done by
2201
            # InterXFormat lookups
2202
            if (isinstance(tree, workingtree.WorkingTree3) and
2255.2.212 by Robert Collins
Fix upgrade bug exposed via repository tests, dont replace dirstate format trees during upgrade.
2203
                not isinstance(tree, workingtree_4.WorkingTree4) and
2255.12.1 by Robert Collins
Implement upgrade for working trees.
2204
                isinstance(self.target_format.workingtree_format,
2205
                    workingtree_4.WorkingTreeFormat4)):
2206
                workingtree_4.Converter3to4().convert(tree)
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.
2207
        return to_convert
1731.2.18 by Aaron Bentley
Get extract in repository under test
2208
2209
2018.5.25 by Andrew Bennetts
Make sure RemoteBzrDirFormat is always registered (John Arbash Meinel, Robert Collins, Andrew Bennetts).
2210
# This is not in remote.py because it's small, and needs to be registered.
2211
# Putting it in remote.py creates a circular import problem.
2018.5.28 by Robert Collins
Fix RemoteBzrDirFormat probe api usage.
2212
# we can make it a lazy object if the control formats is turned into something
2213
# like a registry.
2018.5.25 by Andrew Bennetts
Make sure RemoteBzrDirFormat is always registered (John Arbash Meinel, Robert Collins, Andrew Bennetts).
2214
class RemoteBzrDirFormat(BzrDirMetaFormat1):
2215
    """Format representing bzrdirs accessed via a smart server"""
2216
2217
    def get_format_description(self):
2218
        return 'bzr remote bzrdir'
2219
    
2018.5.28 by Robert Collins
Fix RemoteBzrDirFormat probe api usage.
2220
    @classmethod
2221
    def probe_transport(klass, transport):
2222
        """Return a RemoteBzrDirFormat object if it looks possible."""
2018.5.25 by Andrew Bennetts
Make sure RemoteBzrDirFormat is always registered (John Arbash Meinel, Robert Collins, Andrew Bennetts).
2223
        try:
2432.3.1 by Andrew Bennetts
Try a version 1 hello probe to determine if we can use RemoteBzrDir on a particular transport, allowing smooth interoperation with older servers.
2224
            client = transport.get_smart_client()
2018.5.25 by Andrew Bennetts
Make sure RemoteBzrDirFormat is always registered (John Arbash Meinel, Robert Collins, Andrew Bennetts).
2225
        except (NotImplementedError, AttributeError,
2226
                errors.TransportNotPossible):
2018.5.28 by Robert Collins
Fix RemoteBzrDirFormat probe api usage.
2227
            # no smart server, so not a branch for this format type.
2228
            raise errors.NotBranchError(path=transport.base)
2018.5.25 by Andrew Bennetts
Make sure RemoteBzrDirFormat is always registered (John Arbash Meinel, Robert Collins, Andrew Bennetts).
2229
        else:
2432.3.3 by Andrew Bennetts
Update comment according to Martin's suggestion.
2230
            # Send a 'hello' request in protocol version one, and decline to
2231
            # open it if the server doesn't support our required version (2) so
2232
            # that the VFS-based transport will do it.
2432.3.1 by Andrew Bennetts
Try a version 1 hello probe to determine if we can use RemoteBzrDir on a particular transport, allowing smooth interoperation with older servers.
2233
            request = client.get_request()
2234
            smart_protocol = protocol.SmartClientRequestProtocolOne(request)
2432.3.2 by Andrew Bennetts
Add test, and tidy implementation.
2235
            server_version = smart_protocol.query_version()
2236
            if server_version != 2:
2432.3.1 by Andrew Bennetts
Try a version 1 hello probe to determine if we can use RemoteBzrDir on a particular transport, allowing smooth interoperation with older servers.
2237
                raise errors.NotBranchError(path=transport.base)
2018.5.28 by Robert Collins
Fix RemoteBzrDirFormat probe api usage.
2238
            return klass()
2018.5.25 by Andrew Bennetts
Make sure RemoteBzrDirFormat is always registered (John Arbash Meinel, Robert Collins, Andrew Bennetts).
2239
2018.5.42 by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :).
2240
    def initialize_on_transport(self, transport):
2018.5.128 by Robert Collins
Have RemoteBzrDirFormat create a local format object when it is asked to initialize something on a non-smart transport - allowing sprout to work cleanly.
2241
        try:
2242
            # hand off the request to the smart server
2485.8.54 by Vincent Ladeuil
Refactor medium uses by making a distinction betweem shared and real medium.
2243
            shared_medium = transport.get_shared_medium()
2018.5.128 by Robert Collins
Have RemoteBzrDirFormat create a local format object when it is asked to initialize something on a non-smart transport - allowing sprout to work cleanly.
2244
        except errors.NoSmartMedium:
2245
            # TODO: lookup the local format from a server hint.
2246
            local_dir_format = BzrDirMetaFormat1()
2247
            return local_dir_format.initialize_on_transport(transport)
2485.8.54 by Vincent Ladeuil
Refactor medium uses by making a distinction betweem shared and real medium.
2248
        client = _SmartClient(shared_medium)
2018.5.42 by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :).
2249
        path = client.remote_path_from_transport(transport)
2485.8.54 by Vincent Ladeuil
Refactor medium uses by making a distinction betweem shared and real medium.
2250
        response = _SmartClient(shared_medium).call('BzrDirFormat.initialize',
2251
                                                    path)
2018.5.52 by Wouter van Heyst
Provide more information when encountering unexpected responses from a smart
2252
        assert response[0] in ('ok', ), 'unexpected response code %s' % (response,)
2018.5.42 by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :).
2253
        return remote.RemoteBzrDir(transport)
2254
2018.5.25 by Andrew Bennetts
Make sure RemoteBzrDirFormat is always registered (John Arbash Meinel, Robert Collins, Andrew Bennetts).
2255
    def _open(self, transport):
2256
        return remote.RemoteBzrDir(transport)
2257
2258
    def __eq__(self, other):
2259
        if not isinstance(other, RemoteBzrDirFormat):
2260
            return False
2261
        return self.get_format_description() == other.get_format_description()
2262
2263
2018.5.163 by Andrew Bennetts
Deal with various review comments from Robert.
2264
BzrDirFormat.register_control_server_format(RemoteBzrDirFormat)
2018.5.45 by Andrew Bennetts
Merge from bzr.dev
2265
2266
2204.4.4 by Aaron Bentley
Use BzrDirFormatInfo to distinguish native and deprecated formats
2267
class BzrDirFormatInfo(object):
2268
1551.13.2 by Aaron Bentley
Hide dirstate-with-subtree format
2269
    def __init__(self, native, deprecated, hidden):
2204.4.4 by Aaron Bentley
Use BzrDirFormatInfo to distinguish native and deprecated formats
2270
        self.deprecated = deprecated
2271
        self.native = native
1551.13.2 by Aaron Bentley
Hide dirstate-with-subtree format
2272
        self.hidden = hidden
2204.4.4 by Aaron Bentley
Use BzrDirFormatInfo to distinguish native and deprecated formats
2273
2274
2204.4.1 by Aaron Bentley
Add 'formats' help topic
2275
class BzrDirFormatRegistry(registry.Registry):
2276
    """Registry of user-selectable BzrDir subformats.
2277
    
2278
    Differs from BzrDirFormat._control_formats in that it provides sub-formats,
2279
    e.g. BzrDirMeta1 with weave repository.  Also, it's more user-oriented.
2280
    """
2281
2255.2.158 by Martin Pool
Most of the integration of dirstate and subtree
2282
    def register_metadir(self, key,
2283
             repository_format, help, native=True, deprecated=False,
2284
             branch_format=None,
1551.13.2 by Aaron Bentley
Hide dirstate-with-subtree format
2285
             tree_format=None,
2286
             hidden=False):
2204.4.1 by Aaron Bentley
Add 'formats' help topic
2287
        """Register a metadir subformat.
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
2288
2289
        These all use a BzrDirMetaFormat1 bzrdir, but can be parameterized
2290
        by the Repository format.
2291
2255.2.158 by Martin Pool
Most of the integration of dirstate and subtree
2292
        :param repository_format: The fully-qualified repository format class
2293
            name as a string.
2294
        :param branch_format: Fully-qualified branch format class name as
2295
            a string.
2296
        :param tree_format: Fully-qualified tree format class name as
2297
            a string.
2204.4.1 by Aaron Bentley
Add 'formats' help topic
2298
        """
2299
        # This should be expanded to support setting WorkingTree and Branch
2300
        # formats, once BzrDirMetaFormat1 supports that.
2255.2.158 by Martin Pool
Most of the integration of dirstate and subtree
2301
        def _load(full_name):
2302
            mod_name, factory_name = full_name.rsplit('.', 1)
2241.1.21 by Martin Pool
Change register_metadir to take fully-qualified repository class name.
2303
            try:
2304
                mod = __import__(mod_name, globals(), locals(),
2255.2.158 by Martin Pool
Most of the integration of dirstate and subtree
2305
                        [factory_name])
2241.1.21 by Martin Pool
Change register_metadir to take fully-qualified repository class name.
2306
            except ImportError, e:
2255.2.158 by Martin Pool
Most of the integration of dirstate and subtree
2307
                raise ImportError('failed to load %s: %s' % (full_name, e))
2241.1.21 by Martin Pool
Change register_metadir to take fully-qualified repository class name.
2308
            try:
2255.2.158 by Martin Pool
Most of the integration of dirstate and subtree
2309
                factory = getattr(mod, factory_name)
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
2310
            except AttributeError:
2255.2.158 by Martin Pool
Most of the integration of dirstate and subtree
2311
                raise AttributeError('no factory %s in module %r'
2312
                    % (full_name, mod))
2313
            return factory()
2314
2315
        def helper():
2204.4.1 by Aaron Bentley
Add 'formats' help topic
2316
            bd = BzrDirMetaFormat1()
2230.3.1 by Aaron Bentley
Get branch6 creation working
2317
            if branch_format is not None:
2255.2.158 by Martin Pool
Most of the integration of dirstate and subtree
2318
                bd.set_branch_format(_load(branch_format))
2319
            if tree_format is not None:
2320
                bd.workingtree_format = _load(tree_format)
2321
            if repository_format is not None:
2322
                bd.repository_format = _load(repository_format)
2204.4.1 by Aaron Bentley
Add 'formats' help topic
2323
            return bd
1551.13.2 by Aaron Bentley
Hide dirstate-with-subtree format
2324
        self.register(key, helper, help, native, deprecated, hidden)
2204.4.1 by Aaron Bentley
Add 'formats' help topic
2325
1551.13.2 by Aaron Bentley
Hide dirstate-with-subtree format
2326
    def register(self, key, factory, help, native=True, deprecated=False,
2327
                 hidden=False):
2204.4.1 by Aaron Bentley
Add 'formats' help topic
2328
        """Register a BzrDirFormat factory.
2329
        
2330
        The factory must be a callable that takes one parameter: the key.
2331
        It must produce an instance of the BzrDirFormat when called.
2332
2333
        This function mainly exists to prevent the info object from being
2334
        supplied directly.
2335
        """
2204.4.4 by Aaron Bentley
Use BzrDirFormatInfo to distinguish native and deprecated formats
2336
        registry.Registry.register(self, key, factory, help, 
1551.13.2 by Aaron Bentley
Hide dirstate-with-subtree format
2337
            BzrDirFormatInfo(native, deprecated, hidden))
2204.4.1 by Aaron Bentley
Add 'formats' help topic
2338
2204.4.7 by Aaron Bentley
restore register_lazy, remove register_factory, other updates
2339
    def register_lazy(self, key, module_name, member_name, help, native=True,
1551.13.2 by Aaron Bentley
Hide dirstate-with-subtree format
2340
                      deprecated=False, hidden=False):
2204.4.7 by Aaron Bentley
restore register_lazy, remove register_factory, other updates
2341
        registry.Registry.register_lazy(self, key, module_name, member_name, 
1551.13.2 by Aaron Bentley
Hide dirstate-with-subtree format
2342
            help, BzrDirFormatInfo(native, deprecated, hidden))
2204.4.1 by Aaron Bentley
Add 'formats' help topic
2343
2344
    def set_default(self, key):
2345
        """Set the 'default' key to be a clone of the supplied key.
2346
        
2347
        This method must be called once and only once.
2348
        """
2204.4.4 by Aaron Bentley
Use BzrDirFormatInfo to distinguish native and deprecated formats
2349
        registry.Registry.register(self, 'default', self.get(key), 
2350
            self.get_help(key), info=self.get_info(key))
2204.4.1 by Aaron Bentley
Add 'formats' help topic
2351
2204.4.11 by Aaron Bentley
deprecate Repository.set_default_format, update upgrade tests
2352
    def set_default_repository(self, key):
2353
        """Set the FormatRegistry default and Repository default.
2354
        
2355
        This is a transitional method while Repository.set_default_format
2356
        is deprecated.
2357
        """
2358
        if 'default' in self:
2359
            self.remove('default')
2360
        self.set_default(key)
2361
        format = self.get('default')()
2362
        assert isinstance(format, BzrDirMetaFormat1)
2363
2204.4.1 by Aaron Bentley
Add 'formats' help topic
2364
    def make_bzrdir(self, key):
2204.4.7 by Aaron Bentley
restore register_lazy, remove register_factory, other updates
2365
        return self.get(key)()
2204.4.1 by Aaron Bentley
Add 'formats' help topic
2366
2367
    def help_topic(self, topic):
2368
        output = textwrap.dedent("""\
2369
            These formats can be used for creating branches, working trees, and
2370
            repositories.
2204.4.2 by Aaron Bentley
Tweak topic appearance
2371
2204.4.1 by Aaron Bentley
Add 'formats' help topic
2372
            """)
2711.2.4 by Martin Pool
Fix unbound variable error in BzrDirFormatRegistry.get_help (test order dependent)
2373
        default_realkey = None
2204.4.1 by Aaron Bentley
Add 'formats' help topic
2374
        default_help = self.get_help('default')
2375
        help_pairs = []
2376
        for key in self.keys():
2377
            if key == 'default':
2378
                continue
2379
            help = self.get_help(key)
2380
            if help == default_help:
2381
                default_realkey = key
2382
            else:
2383
                help_pairs.append((key, help))
2384
2204.4.4 by Aaron Bentley
Use BzrDirFormatInfo to distinguish native and deprecated formats
2385
        def wrapped(key, help, info):
2386
            if info.native:
2387
                help = '(native) ' + help
2666.1.1 by Ian Clatworthy
Bazaar User Reference generated from online help
2388
            return ':%s:\n%s\n\n' % (key, 
2204.4.1 by Aaron Bentley
Add 'formats' help topic
2389
                    textwrap.fill(help, initial_indent='    ', 
2390
                    subsequent_indent='    '))
2711.2.4 by Martin Pool
Fix unbound variable error in BzrDirFormatRegistry.get_help (test order dependent)
2391
        if default_realkey is not None:
2392
            output += wrapped(default_realkey, '(default) %s' % default_help,
2393
                              self.get_info('default'))
2204.4.4 by Aaron Bentley
Use BzrDirFormatInfo to distinguish native and deprecated formats
2394
        deprecated_pairs = []
2204.4.1 by Aaron Bentley
Add 'formats' help topic
2395
        for key, help in help_pairs:
2204.4.4 by Aaron Bentley
Use BzrDirFormatInfo to distinguish native and deprecated formats
2396
            info = self.get_info(key)
1551.13.2 by Aaron Bentley
Hide dirstate-with-subtree format
2397
            if info.hidden:
2398
                continue
2399
            elif info.deprecated:
2204.4.4 by Aaron Bentley
Use BzrDirFormatInfo to distinguish native and deprecated formats
2400
                deprecated_pairs.append((key, help))
2401
            else:
2402
                output += wrapped(key, help, info)
2403
        if len(deprecated_pairs) > 0:
2666.1.1 by Ian Clatworthy
Bazaar User Reference generated from online help
2404
            output += "Deprecated formats are shown below.\n\n"
2204.4.4 by Aaron Bentley
Use BzrDirFormatInfo to distinguish native and deprecated formats
2405
            for key, help in deprecated_pairs:
2406
                info = self.get_info(key)
2407
                output += wrapped(key, help, info)
2408
2204.4.1 by Aaron Bentley
Add 'formats' help topic
2409
        return output
2410
2411
2412
format_registry = BzrDirFormatRegistry()
2204.4.7 by Aaron Bentley
restore register_lazy, remove register_factory, other updates
2413
format_registry.register('weave', BzrDirFormat6,
2204.4.4 by Aaron Bentley
Use BzrDirFormatInfo to distinguish native and deprecated formats
2414
    'Pre-0.8 format.  Slower than knit and does not'
2241.1.6 by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and
2415
    ' support checkouts or shared repositories.',
2416
    deprecated=True)
2417
format_registry.register_metadir('knit',
2241.1.21 by Martin Pool
Change register_metadir to take fully-qualified repository class name.
2418
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2255.12.1 by Robert Collins
Implement upgrade for working trees.
2419
    'Format using knits.  Recommended for interoperation with bzr <= 0.14.',
2420
    branch_format='bzrlib.branch.BzrBranchFormat5',
2255.2.199 by Robert Collins
Fix definition of knit format; typos are not good.
2421
    tree_format='bzrlib.workingtree.WorkingTreeFormat3')
2241.1.21 by Martin Pool
Change register_metadir to take fully-qualified repository class name.
2422
format_registry.register_metadir('metaweave',
2423
    'bzrlib.repofmt.weaverepo.RepositoryFormat7',
2230.3.30 by Aaron Bentley
Fix whitespace issues
2424
    'Transitional format in 0.8.  Slower than knit.',
2255.12.1 by Robert Collins
Implement upgrade for working trees.
2425
    branch_format='bzrlib.branch.BzrBranchFormat5',
2255.2.209 by Robert Collins
Remove circular imports in bzrdir format definitions.
2426
    tree_format='bzrlib.workingtree.WorkingTreeFormat3',
2204.4.4 by Aaron Bentley
Use BzrDirFormatInfo to distinguish native and deprecated formats
2427
    deprecated=True)
2255.12.1 by Robert Collins
Implement upgrade for working trees.
2428
format_registry.register_metadir('dirstate',
2429
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2430
    help='New in 0.15: Fast local operations. Compatible with bzr 0.8 and '
2431
        'above when accessed over the network.',
2432
    branch_format='bzrlib.branch.BzrBranchFormat5',
2255.2.209 by Robert Collins
Remove circular imports in bzrdir format definitions.
2433
    # this uses bzrlib.workingtree.WorkingTreeFormat4 because importing
2434
    # directly from workingtree_4 triggers a circular import.
2435
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2255.12.1 by Robert Collins
Implement upgrade for working trees.
2436
    )
1551.13.1 by Aaron Bentley
Introduce dirstate-tags format
2437
format_registry.register_metadir('dirstate-tags',
2438
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2439
    help='New in 0.15: Fast local operations and improved scaling for '
1551.13.2 by Aaron Bentley
Hide dirstate-with-subtree format
2440
        'network operations. Additionally adds support for tags.'
2441
        ' Incompatible with bzr < 0.15.',
1551.13.1 by Aaron Bentley
Introduce dirstate-tags format
2442
    branch_format='bzrlib.branch.BzrBranchFormat6',
2443
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2444
    )
2255.12.1 by Robert Collins
Implement upgrade for working trees.
2445
format_registry.register_metadir('dirstate-with-subtree',
2446
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
2447
    help='New in 0.15: Fast local operations and improved scaling for '
2448
        'network operations. Additionally adds support for versioning nested '
2449
        'bzr branches. Incompatible with bzr < 0.15.',
2450
    branch_format='bzrlib.branch.BzrBranchFormat6',
2255.2.209 by Robert Collins
Remove circular imports in bzrdir format definitions.
2451
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
1551.13.2 by Aaron Bentley
Hide dirstate-with-subtree format
2452
    hidden=True,
2255.12.1 by Robert Collins
Implement upgrade for working trees.
2453
    )
2696.3.1 by Martin Pool
(broken) start switching format to dirstate-tags
2454
format_registry.set_default('dirstate-tags')