165
170
format.get_format_description(),
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.
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.
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)
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.
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,
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()
515
501
format=format).bzrdir
516
502
return bzrdir.create_workingtree()
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."""
521
name = "%s.~%d~" % (base, counter)
522
while self.root_transport.has(name):
524
name = "%s.~%d~" % (base, counter)
506
return self._available_backup_name(base)
508
def _available_backup_name(self, base):
509
"""Find a non-existing backup file name based on base.
511
See bzrlib.osutils.available_backup_name about race conditions.
513
return osutils.available_backup_name(base, self.root_transport.has)
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
533
backup_dir=self.generate_backup_name('backup.bzr')
534
521
pb = ui.ui_factory.nested_progress_bar()
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.
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)
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()
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)
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())
1744
1732
class BzrDirFormat4(BzrDirFormat):
2147
2135
__set_workingtree_format)
2150
network_format_registry = registry.FormatRegistry()
2151
"""Registry of formats indexed by their network name.
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.
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"""
2685
supports_workingtrees = False
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
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'
3118
3099
def _load(full_name):
3119
3100
mod_name, factory_name = full_name.rsplit('.', 1)
3121
mod = __import__(mod_name, globals(), locals(),
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))
3126
factory = getattr(mod, factory_name)
3127
3105
except AttributeError:
3128
3106
raise AttributeError('no factory %s in module %r'
3107
% (full_name, sys.modules[mod_name]))
3130
3108
return factory()
3371
3349
help='Same as 2a.')
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')
3356
controldir.format_registry.set_default(format_name)
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