~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-11-22 21:54:24 UTC
  • mfrom: (5546.1.1 remove-old-dev-formats)
  • Revision ID: pqm@pqm.ubuntu.com-20101122215424-tfww6o1rayiyq1m7
(spiv) Remove RepositoryFormatCHK1 and RepositoryFormatCHK2. (Andrew
 Bennetts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
    lockable_files,
46
46
    lockdir,
47
47
    osutils,
 
48
    pyutils,
48
49
    remote,
49
50
    repository,
50
51
    revision as _mod_revision,
86
87
    registry,
87
88
    symbol_versioning,
88
89
    )
 
90
from bzrlib.symbol_versioning import (
 
91
    deprecated_in,
 
92
    deprecated_method,
 
93
    )
89
94
 
90
95
 
91
96
class BzrDir(controldir.ControlDir):
167
172
 
168
173
    def clone_on_transport(self, transport, revision_id=None,
169
174
        force_new_repo=False, preserve_stacking=False, stacked_on=None,
170
 
        create_prefix=False, use_existing_dir=True):
 
175
        create_prefix=False, use_existing_dir=True, no_tree=False):
171
176
        """Clone this bzrdir and its contents to transport verbatim.
172
177
 
173
178
        :param transport: The transport for the location to produce the clone
215
220
        # we should look up the policy needs first, or just use it as a hint,
216
221
        # or something.
217
222
        if local_repo:
218
 
            make_working_trees = local_repo.make_working_trees()
 
223
            make_working_trees = local_repo.make_working_trees() and not no_tree
219
224
            want_shared = local_repo.is_shared()
220
225
            repo_format_name = format.repository_format.network_name()
221
226
        else:
496
501
                                               format=format).bzrdir
497
502
        return bzrdir.create_workingtree()
498
503
 
 
504
    @deprecated_method(deprecated_in((2, 3, 0)))
499
505
    def generate_backup_name(self, base):
500
 
        """Generate a non-existing backup file name based on base."""
501
 
        counter = 1
502
 
        name = "%s.~%d~" % (base, counter)
503
 
        while self.root_transport.has(name):
504
 
            counter += 1
505
 
            name = "%s.~%d~" % (base, counter)
506
 
        return name
 
506
        return self._available_backup_name(base)
 
507
 
 
508
    def _available_backup_name(self, base):
 
509
        """Find a non-existing backup file name based on base.
 
510
 
 
511
        See bzrlib.osutils.available_backup_name about race conditions.
 
512
        """
 
513
        return osutils.available_backup_name(base, self.root_transport.has)
507
514
 
508
515
    def backup_bzrdir(self):
509
516
        """Backup this bzr control directory.
511
518
        :return: Tuple with old path name and new path name
512
519
        """
513
520
 
514
 
        backup_dir=self.generate_backup_name('backup.bzr')
515
521
        pb = ui.ui_factory.nested_progress_bar()
516
522
        try:
517
 
            # FIXME: bug 300001 -- the backup fails if the backup directory
518
 
            # already exists, but it should instead either remove it or make
519
 
            # a new backup directory.
520
 
            #
521
523
            old_path = self.root_transport.abspath('.bzr')
 
524
            backup_dir = self._available_backup_name('backup.bzr')
522
525
            new_path = self.root_transport.abspath(backup_dir)
523
 
            ui.ui_factory.note('making backup of %s\n  to %s' % (old_path, new_path,))
 
526
            ui.ui_factory.note('making backup of %s\n  to %s'
 
527
                               % (old_path, new_path,))
524
528
            self.root_transport.copy_tree('.bzr', backup_dir)
525
529
            return (old_path, new_path)
526
530
        finally:
1290
1294
        wt = self.open_workingtree(recommend_upgrade=False)
1291
1295
        repository = wt.branch.repository
1292
1296
        empty = repository.revision_tree(_mod_revision.NULL_REVISION)
1293
 
        wt.revert(old_tree=empty)
 
1297
        # We ignore the conflicts returned by wt.revert since we're about to
 
1298
        # delete the wt metadata anyway, all that should be left here are
 
1299
        # detritus. But see bug #634470 about subtree .bzr dirs.
 
1300
        conflicts = wt.revert(old_tree=empty)
1294
1301
        self.destroy_workingtree_metadata()
1295
1302
 
1296
1303
    def destroy_workingtree_metadata(self):
3092
3099
    def _load(full_name):
3093
3100
        mod_name, factory_name = full_name.rsplit('.', 1)
3094
3101
        try:
3095
 
            mod = __import__(mod_name, globals(), locals(),
3096
 
                    [factory_name])
 
3102
            factory = pyutils.get_named_object(mod_name, factory_name)
3097
3103
        except ImportError, e:
3098
3104
            raise ImportError('failed to load %s: %s' % (full_name, e))
3099
 
        try:
3100
 
            factory = getattr(mod, factory_name)
3101
3105
        except AttributeError:
3102
3106
            raise AttributeError('no factory %s in module %r'
3103
 
                % (full_name, mod))
 
3107
                % (full_name, sys.modules[mod_name]))
3104
3108
        return factory()
3105
3109
 
3106
3110
    def helper():
3250
3254
    tree_format='bzrlib.workingtree.WorkingTreeFormat5',
3251
3255
    )
3252
3256
# The following un-numbered 'development' formats should always just be aliases.
3253
 
register_metadir(controldir.format_registry, 'development-rich-root',
3254
 
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormatCHK1',
3255
 
    help='Current development format. Supports rich roots. Can convert data '
3256
 
        'to and from rich-root-pack (and anything compatible with '
3257
 
        'rich-root-pack) format repositories. Repositories and branches in '
3258
 
        'this format can only be read by bzr.dev. Please read '
3259
 
        'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
3260
 
        'before use.',
3261
 
    branch_format='bzrlib.branch.BzrBranchFormat7',
3262
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3263
 
    experimental=True,
3264
 
    alias=True,
3265
 
    hidden=True,
3266
 
    )
3267
 
register_metadir(controldir.format_registry, 'development5-subtree',
3268
 
    'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment2Subtree',
3269
 
    help='Development format, subtree variant. Can convert data to and '
3270
 
        'from pack-0.92-subtree (and anything compatible with '
3271
 
        'pack-0.92-subtree) format repositories. Repositories and branches in '
3272
 
        'this format can only be read by bzr.dev. Please read '
3273
 
        'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
3274
 
        'before use.',
3275
 
    branch_format='bzrlib.branch.BzrBranchFormat7',
3276
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3277
 
    experimental=True,
3278
 
    hidden=True,
3279
 
    alias=False,
3280
 
    )
3281
 
 
3282
 
 
3283
3257
register_metadir(controldir.format_registry, 'development-subtree',
3284
3258
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2aSubtree',
3285
3259
    help='Current development format, subtree variant. Can convert data to and '
3296
3270
                 # This current non-alias status is simply because we did not introduce a
3297
3271
                 # chk based subtree format.
3298
3272
    )
 
3273
register_metadir(controldir.format_registry, 'development5-subtree',
 
3274
    'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment2Subtree',
 
3275
    help='Development format, subtree variant. Can convert data to and '
 
3276
        'from pack-0.92-subtree (and anything compatible with '
 
3277
        'pack-0.92-subtree) format repositories. Repositories and branches in '
 
3278
        'this format can only be read by bzr.dev. Please read '
 
3279
        'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
 
3280
        'before use.',
 
3281
    branch_format='bzrlib.branch.BzrBranchFormat7',
 
3282
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
 
3283
    experimental=True,
 
3284
    hidden=True,
 
3285
    alias=False,
 
3286
    )
3299
3287
 
3300
3288
# And the development formats above will have aliased one of the following:
3301
 
register_metadir(controldir.format_registry, 'development6-rich-root',
3302
 
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormatCHK1',
3303
 
    help='pack-1.9 with 255-way hashed CHK inv, group compress, rich roots '
3304
 
        'Please read '
3305
 
        'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
3306
 
        'before use.',
3307
 
    branch_format='bzrlib.branch.BzrBranchFormat7',
3308
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3309
 
    hidden=True,
3310
 
    experimental=True,
3311
 
    )
3312
 
 
3313
 
register_metadir(controldir.format_registry, 'development7-rich-root',
3314
 
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormatCHK2',
3315
 
    help='pack-1.9 with 255-way hashed CHK inv, bencode revision, group compress, '
3316
 
        'rich roots. Please read '
3317
 
        'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
3318
 
        'before use.',
3319
 
    branch_format='bzrlib.branch.BzrBranchFormat7',
3320
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3321
 
    hidden=True,
3322
 
    experimental=True,
3323
 
    )
3324
 
 
 
3289
 
 
3290
# Finally, the current format.
3325
3291
register_metadir(controldir.format_registry, '2a',
3326
3292
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2a',
3327
3293
    help='First format for bzr 2.0 series.\n'
3345
3311
    help='Same as 2a.')
3346
3312
 
3347
3313
# The current format that is made on 'bzr init'.
3348
 
controldir.format_registry.set_default('2a')
 
3314
format_name = config.GlobalConfig().get_user_option('default_format')
 
3315
if format_name is None:
 
3316
    controldir.format_registry.set_default('2a')
 
3317
else:
 
3318
    controldir.format_registry.set_default(format_name)
3349
3319
 
3350
3320
# XXX 2010-08-20 JRV: There is still a lot of code relying on
3351
3321
# bzrlib.bzrdir.format_registry existing. When BzrDir.create/BzrDir.open/etc