/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

Merge require_testtools_0.9.5_for_selftest to reflect test requirment and resolve news conflict

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):
165
170
                format.get_format_description(),
166
171
                basedir)
167
172
 
168
 
    def clone(self, url, revision_id=None, force_new_repo=False,
169
 
              preserve_stacking=False):
170
 
        """Clone this bzrdir and its contents to url verbatim.
171
 
 
172
 
        :param url: The url create the clone at.  If url's last component does
173
 
            not exist, it will be created.
174
 
        :param revision_id: The tip revision-id to use for any branch or
175
 
            working tree.  If not None, then the clone operation may tune
176
 
            itself to download less data.
177
 
        :param force_new_repo: Do not use a shared repository for the target
178
 
                               even if one is available.
179
 
        :param preserve_stacking: When cloning a stacked branch, stack the
180
 
            new branch on top of the other branch's stacked-on branch.
181
 
        """
182
 
        return self.clone_on_transport(get_transport(url),
183
 
                                       revision_id=revision_id,
184
 
                                       force_new_repo=force_new_repo,
185
 
                                       preserve_stacking=preserve_stacking)
186
 
 
187
173
    def clone_on_transport(self, transport, revision_id=None,
188
174
        force_new_repo=False, preserve_stacking=False, stacked_on=None,
189
 
        create_prefix=False, use_existing_dir=True):
 
175
        create_prefix=False, use_existing_dir=True, no_tree=False):
190
176
        """Clone this bzrdir and its contents to transport verbatim.
191
177
 
192
178
        :param transport: The transport for the location to produce the clone
234
220
        # we should look up the policy needs first, or just use it as a hint,
235
221
        # or something.
236
222
        if local_repo:
237
 
            make_working_trees = local_repo.make_working_trees()
 
223
            make_working_trees = local_repo.make_working_trees() and not no_tree
238
224
            want_shared = local_repo.is_shared()
239
225
            repo_format_name = format.repository_format.network_name()
240
226
        else:
515
501
                                               format=format).bzrdir
516
502
        return bzrdir.create_workingtree()
517
503
 
 
504
    @deprecated_method(deprecated_in((2, 3, 0)))
518
505
    def generate_backup_name(self, base):
519
 
        """Generate a non-existing backup file name based on base."""
520
 
        counter = 1
521
 
        name = "%s.~%d~" % (base, counter)
522
 
        while self.root_transport.has(name):
523
 
            counter += 1
524
 
            name = "%s.~%d~" % (base, counter)
525
 
        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)
526
514
 
527
515
    def backup_bzrdir(self):
528
516
        """Backup this bzr control directory.
530
518
        :return: Tuple with old path name and new path name
531
519
        """
532
520
 
533
 
        backup_dir=self.generate_backup_name('backup.bzr')
534
521
        pb = ui.ui_factory.nested_progress_bar()
535
522
        try:
536
 
            # FIXME: bug 300001 -- the backup fails if the backup directory
537
 
            # already exists, but it should instead either remove it or make
538
 
            # a new backup directory.
539
 
            #
540
523
            old_path = self.root_transport.abspath('.bzr')
 
524
            backup_dir = self._available_backup_name('backup.bzr')
541
525
            new_path = self.root_transport.abspath(backup_dir)
542
 
            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,))
543
528
            self.root_transport.copy_tree('.bzr', backup_dir)
544
529
            return (old_path, new_path)
545
530
        finally:
1309
1294
        wt = self.open_workingtree(recommend_upgrade=False)
1310
1295
        repository = wt.branch.repository
1311
1296
        empty = repository.revision_tree(_mod_revision.NULL_REVISION)
1312
 
        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)
1313
1301
        self.destroy_workingtree_metadata()
1314
1302
 
1315
1303
    def destroy_workingtree_metadata(self):
1719
1707
    def register_format(klass, format):
1720
1708
        BzrProber.register_bzrdir_format(format)
1721
1709
        # bzr native formats have a network name of their format string.
1722
 
        network_format_registry.register(format.get_format_string(), format.__class__)
 
1710
        controldir.network_format_registry.register(format.get_format_string(), format.__class__)
1723
1711
        controldir.ControlDirFormat.register_format(format)
1724
1712
 
1725
1713
    def _supply_sub_formats_to(self, other_format):
1738
1726
    def unregister_format(klass, format):
1739
1727
        BzrProber.unregister_bzrdir_format(format)
1740
1728
        controldir.ControlDirFormat.unregister_format(format)
1741
 
        network_format_registry.remove(format.get_format_string())
 
1729
        controldir.network_format_registry.remove(format.get_format_string())
1742
1730
 
1743
1731
 
1744
1732
class BzrDirFormat4(BzrDirFormat):
2147
2135
                                  __set_workingtree_format)
2148
2136
 
2149
2137
 
2150
 
network_format_registry = registry.FormatRegistry()
2151
 
"""Registry of formats indexed by their network name.
2152
 
 
2153
 
The network name for a BzrDirFormat is an identifier that can be used when
2154
 
referring to formats with smart server operations. See
2155
 
BzrDirFormat.network_name() for more detail.
2156
 
"""
2157
 
 
2158
 
 
2159
2138
# Register bzr formats
2160
2139
BzrDirFormat.register_format(BzrDirFormat4())
2161
2140
BzrDirFormat.register_format(BzrDirFormat5())
2703
2682
class RemoteBzrDirFormat(BzrDirMetaFormat1):
2704
2683
    """Format representing bzrdirs accessed via a smart server"""
2705
2684
 
 
2685
    supports_workingtrees = False
 
2686
 
2706
2687
    def __init__(self):
2707
2688
        BzrDirMetaFormat1.__init__(self)
2708
2689
        # XXX: It's a bit ugly that the network name is here, because we'd
2717
2698
 
2718
2699
    def get_format_description(self):
2719
2700
        if self._network_name:
2720
 
            real_format = network_format_registry.get(self._network_name)
 
2701
            real_format = controldir.network_format_registry.get(self._network_name)
2721
2702
            return 'Remote: ' + real_format.get_format_description()
2722
2703
        return 'bzr remote bzrdir'
2723
2704
 
3118
3099
    def _load(full_name):
3119
3100
        mod_name, factory_name = full_name.rsplit('.', 1)
3120
3101
        try:
3121
 
            mod = __import__(mod_name, globals(), locals(),
3122
 
                    [factory_name])
 
3102
            factory = pyutils.get_named_object(mod_name, factory_name)
3123
3103
        except ImportError, e:
3124
3104
            raise ImportError('failed to load %s: %s' % (full_name, e))
3125
 
        try:
3126
 
            factory = getattr(mod, factory_name)
3127
3105
        except AttributeError:
3128
3106
            raise AttributeError('no factory %s in module %r'
3129
 
                % (full_name, mod))
 
3107
                % (full_name, sys.modules[mod_name]))
3130
3108
        return factory()
3131
3109
 
3132
3110
    def helper():
3371
3349
    help='Same as 2a.')
3372
3350
 
3373
3351
# The current format that is made on 'bzr init'.
3374
 
controldir.format_registry.set_default('2a')
 
3352
format_name = config.GlobalConfig().get_user_option('default_format')
 
3353
if format_name is None:
 
3354
    controldir.format_registry.set_default('2a')
 
3355
else:
 
3356
    controldir.format_registry.set_default(format_name)
3375
3357
 
3376
3358
# XXX 2010-08-20 JRV: There is still a lot of code relying on
3377
3359
# bzrlib.bzrdir.format_registry existing. When BzrDir.create/BzrDir.open/etc