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