152
170
format.get_format_description(),
155
def clone(self, url, revision_id=None, force_new_repo=False):
156
"""Clone this bzrdir and its contents to url verbatim.
158
If url's last component does not exist, it will be created.
160
if revision_id is not None, then the clone operation may tune
161
itself to download less data.
162
:param force_new_repo: Do not use a shared repository for the target
163
even if one is available.
165
return self.clone_on_transport(get_transport(url),
166
revision_id=revision_id,
167
force_new_repo=force_new_repo)
169
173
def clone_on_transport(self, transport, revision_id=None,
170
force_new_repo=False):
174
force_new_repo=False, preserve_stacking=False, stacked_on=None,
175
create_prefix=False, use_existing_dir=True, no_tree=False):
171
176
"""Clone this bzrdir and its contents to transport verbatim.
173
If the target directory does not exist, it will be created.
175
if revision_id is not None, then the clone operation may tune
178
:param transport: The transport for the location to produce the clone
179
at. If the target directory does not exist, it will be created.
180
:param revision_id: The tip revision-id to use for any branch or
181
working tree. If not None, then the clone operation may tune
176
182
itself to download less data.
177
:param force_new_repo: Do not use a shared repository for the target
183
:param force_new_repo: Do not use a shared repository for the target,
178
184
even if one is available.
185
:param preserve_stacking: When cloning a stacked branch, stack the
186
new branch on top of the other branch's stacked-on branch.
187
:param create_prefix: Create any missing directories leading up to
189
:param use_existing_dir: Use an existing directory if one exists.
180
transport.ensure_base()
181
result = self._format.initialize_on_transport(transport)
191
# Overview: put together a broad description of what we want to end up
192
# with; then make as few api calls as possible to do it.
194
# We may want to create a repo/branch/tree, if we do so what format
195
# would we want for each:
196
require_stacking = (stacked_on is not None)
197
format = self.cloning_metadir(require_stacking)
199
# Figure out what objects we want:
183
201
local_repo = self.find_repository()
184
202
except errors.NoRepositoryPresent:
185
203
local_repo = None
205
local_branch = self.open_branch()
206
except errors.NotBranchError:
209
# enable fallbacks when branch is not a branch reference
210
if local_branch.repository.has_same_location(local_repo):
211
local_repo = local_branch.repository
212
if preserve_stacking:
214
stacked_on = local_branch.get_stacked_on_url()
215
except (errors.UnstackableBranchFormat,
216
errors.UnstackableRepositoryFormat,
219
# Bug: We create a metadir without knowing if it can support stacking,
220
# we should look up the policy needs first, or just use it as a hint,
187
# may need to copy content in
189
result_repo = local_repo.clone(
191
revision_id=revision_id)
192
result_repo.set_make_working_trees(local_repo.make_working_trees())
195
result_repo = result.find_repository()
196
# fetch content this dir needs.
223
make_working_trees = local_repo.make_working_trees() and not no_tree
224
want_shared = local_repo.is_shared()
225
repo_format_name = format.repository_format.network_name()
227
make_working_trees = False
229
repo_format_name = None
231
result_repo, result, require_stacking, repository_policy = \
232
format.initialize_on_transport_ex(transport,
233
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
234
force_new_repo=force_new_repo, stacked_on=stacked_on,
235
stack_on_pwd=self.root_transport.base,
236
repo_format_name=repo_format_name,
237
make_working_trees=make_working_trees, shared_repo=want_shared)
240
# If the result repository is in the same place as the
241
# resulting bzr dir, it will have no content, further if the
242
# result is not stacked then we know all content should be
243
# copied, and finally if we are copying up to a specific
244
# revision_id then we can use the pending-ancestry-result which
245
# does not require traversing all of history to describe it.
246
if (result_repo.user_url == result.user_url
247
and not require_stacking and
248
revision_id is not None):
249
fetch_spec = graph.PendingAncestryResult(
250
[revision_id], local_repo)
251
result_repo.fetch(local_repo, fetch_spec=fetch_spec)
197
253
result_repo.fetch(local_repo, revision_id=revision_id)
198
except errors.NoRepositoryPresent:
199
# needed to make one anyway.
200
result_repo = local_repo.clone(
202
revision_id=revision_id)
203
result_repo.set_make_working_trees(local_repo.make_working_trees())
257
if result_repo is not None:
258
raise AssertionError('result_repo not None(%r)' % result_repo)
204
259
# 1 if there is a branch present
205
260
# make sure its content is available in the target repository
208
self.open_branch().clone(result, revision_id=revision_id)
209
except errors.NotBranchError:
212
result_repo = result.find_repository()
213
except errors.NoRepositoryPresent:
215
if result_repo is None or result_repo.make_working_trees():
262
if local_branch is not None:
263
result_branch = local_branch.clone(result, revision_id=revision_id,
264
repository_policy=repository_policy)
266
# Cheaper to check if the target is not local, than to try making
268
result.root_transport.local_abspath('.')
269
if result_repo is None or result_repo.make_working_trees():
217
270
self.open_workingtree().clone(result)
218
except (errors.NoWorkingTree, errors.NotLocalUrl):
271
except (errors.NoWorkingTree, errors.NotLocalUrl):
222
275
# TODO: This should be given a Transport, and should chdir up; otherwise
763
881
result_format.workingtree_format = tree._format.__class__()
764
882
return result_format, source_repository
766
def cloning_metadir(self):
884
def cloning_metadir(self, require_stacking=False):
767
885
"""Produce a metadir suitable for cloning or sprouting with.
769
887
These operations may produce workingtrees (yes, even though they're
770
888
"cloning" something that doesn't have a tree), so a viable workingtree
771
889
format must be selected.
891
:require_stacking: If True, non-stackable formats will be upgraded
892
to similar stackable formats.
893
:returns: a BzrDirFormat with all component formats either set
894
appropriately or set to None if that component should not be
773
897
format, repository = self._cloning_metadir()
774
898
if format._workingtree_format is None:
775
900
if repository is None:
901
# No repository either
903
# We have a repository, so set a working tree? (Why? This seems to
904
# contradict the stated return value in the docstring).
777
905
tree_format = repository._format._matchingbzrdir.workingtree_format
778
906
format.workingtree_format = tree_format.__class__()
908
format.require_stacking()
781
def checkout_metadir(self):
782
return self.cloning_metadir()
784
def sprout(self, url, revision_id=None, force_new_repo=False,
785
recurse='down', possible_transports=None):
786
"""Create a copy of this bzrdir prepared for use as a new line of
789
If url's last component does not exist, it will be created.
791
Attributes related to the identity of the source branch like
792
branch nickname will be cleaned, a working tree is created
793
whether one existed before or not; and a local branch is always
796
if revision_id is not None, then the clone operation may tune
797
itself to download less data.
799
target_transport = get_transport(url, possible_transports)
800
target_transport.ensure_base()
801
cloning_format = self.cloning_metadir()
802
result = cloning_format.initialize_on_transport(target_transport)
804
source_branch = self.open_branch()
805
source_repository = source_branch.repository
806
except errors.NotBranchError:
809
source_repository = self.open_repository()
810
except errors.NoRepositoryPresent:
811
source_repository = None
816
result_repo = result.find_repository()
817
except errors.NoRepositoryPresent:
819
if source_repository is None and result_repo is not None:
821
elif source_repository is None and result_repo is None:
822
# no repo available, make a new one
823
result.create_repository()
824
elif source_repository is not None and result_repo is None:
825
# have source, and want to make a new target repo
826
result_repo = source_repository.sprout(result,
827
revision_id=revision_id)
829
# fetch needed content into target.
830
if source_repository is not None:
832
# source_repository.copy_content_into(result_repo,
833
# revision_id=revision_id)
834
# so we can override the copy method
835
result_repo.fetch(source_repository, revision_id=revision_id)
836
if source_branch is not None:
837
source_branch.sprout(result, revision_id=revision_id)
839
result.create_branch()
840
if isinstance(target_transport, LocalTransport) and (
841
result_repo is None or result_repo.make_working_trees()):
842
wt = result.create_workingtree()
845
if wt.path2id('') is None:
847
wt.set_root_id(self.open_workingtree.get_root_id())
848
except errors.NoWorkingTree:
854
if recurse == 'down':
856
basis = wt.basis_tree()
858
subtrees = basis.iter_references()
859
recurse_branch = wt.branch
860
elif source_branch is not None:
861
basis = source_branch.basis_tree()
863
subtrees = basis.iter_references()
864
recurse_branch = source_branch
869
for path, file_id in subtrees:
870
target = urlutils.join(url, urlutils.escape(path))
871
sublocation = source_branch.reference_parent(file_id, path)
872
sublocation.bzrdir.sprout(target,
873
basis.get_reference_revision(file_id, path),
874
force_new_repo=force_new_repo, recurse=recurse)
876
if basis is not None:
912
def create(cls, base, format=None, possible_transports=None):
913
"""Create a new BzrDir at the url 'base'.
915
:param format: If supplied, the format of branch to create. If not
916
supplied, the default is used.
917
:param possible_transports: If supplied, a list of transports that
918
can be reused to share a remote connection.
920
if cls is not BzrDir:
921
raise AssertionError("BzrDir.create always creates the"
922
"default format, not one of %r" % cls)
923
t = get_transport(base, possible_transports)
926
format = controldir.ControlDirFormat.get_default_format()
927
return format.initialize_on_transport(t)
931
class BzrDirHooks(hooks.Hooks):
932
"""Hooks for BzrDir operations."""
935
"""Create the default hooks."""
936
hooks.Hooks.__init__(self)
937
self.create_hook(hooks.HookPoint('pre_open',
938
"Invoked before attempting to open a BzrDir with the transport "
939
"that the open will use.", (1, 14), None))
940
self.create_hook(hooks.HookPoint('post_repo_init',
941
"Invoked after a repository has been initialized. "
942
"post_repo_init is called with a "
943
"bzrlib.bzrdir.RepoInitHookParams.",
946
# install the default hooks
947
BzrDir.hooks = BzrDirHooks()
950
class RepoInitHookParams(object):
951
"""Object holding parameters passed to *_repo_init hooks.
953
There are 4 fields that hooks may wish to access:
955
:ivar repository: Repository created
956
:ivar format: Repository format
957
:ivar bzrdir: The bzrdir for the repository
958
:ivar shared: The repository is shared
961
def __init__(self, repository, format, a_bzrdir, shared):
962
"""Create a group of RepoInitHook parameters.
964
:param repository: Repository created
965
:param format: Repository format
966
:param bzrdir: The bzrdir for the repository
967
:param shared: The repository is shared
969
self.repository = repository
971
self.bzrdir = a_bzrdir
974
def __eq__(self, other):
975
return self.__dict__ == other.__dict__
979
return "<%s for %s>" % (self.__class__.__name__,
982
return "<%s for %s>" % (self.__class__.__name__,
881
986
class BzrDirPreSplitOut(BzrDir):
1240
1447
basedir=self.root_transport.base)
1241
1448
return format.open(self, _found=True)
1244
class BzrDirFormat(object):
1245
"""An encapsulation of the initialization and open routines for a format.
1247
Formats provide three things:
1248
* An initialization routine,
1252
Formats are placed in a dict by their format string for reference
1450
def _get_config(self):
1451
return config.TransportConfig(self.transport, 'control.conf')
1454
class BzrProber(controldir.Prober):
1455
"""Prober for formats that use a .bzr/ control directory."""
1458
"""The known .bzr formats."""
1461
def register_bzrdir_format(klass, format):
1462
klass._formats[format.get_format_string()] = format
1465
def unregister_bzrdir_format(klass, format):
1466
del klass._formats[format.get_format_string()]
1469
def probe_transport(klass, transport):
1470
"""Return the .bzrdir style format present in a directory."""
1472
format_string = transport.get_bytes(".bzr/branch-format")
1473
except errors.NoSuchFile:
1474
raise errors.NotBranchError(path=transport.base)
1476
return klass._formats[format_string]
1478
raise errors.UnknownFormatError(format=format_string, kind='bzrdir')
1481
controldir.ControlDirFormat.register_prober(BzrProber)
1484
class RemoteBzrProber(controldir.Prober):
1485
"""Prober for remote servers that provide a Bazaar smart server."""
1488
def probe_transport(klass, transport):
1489
"""Return a RemoteBzrDirFormat object if it looks possible."""
1491
medium = transport.get_smart_medium()
1492
except (NotImplementedError, AttributeError,
1493
errors.TransportNotPossible, errors.NoSmartMedium,
1494
errors.SmartProtocolError):
1495
# no smart server, so not a branch for this format type.
1496
raise errors.NotBranchError(path=transport.base)
1498
# Decline to open it if the server doesn't support our required
1499
# version (3) so that the VFS-based transport will do it.
1500
if medium.should_probe():
1502
server_version = medium.protocol_version()
1503
except errors.SmartProtocolError:
1504
# Apparently there's no usable smart server there, even though
1505
# the medium supports the smart protocol.
1506
raise errors.NotBranchError(path=transport.base)
1507
if server_version != '2':
1508
raise errors.NotBranchError(path=transport.base)
1509
return RemoteBzrDirFormat()
1512
class BzrDirFormat(controldir.ControlDirFormat):
1513
"""ControlDirFormat base class for .bzr/ directories.
1515
Formats are placed in a dict by their format string for reference
1253
1516
during bzrdir opening. These should be subclasses of BzrDirFormat
1254
1517
for consistency.
1256
1519
Once a format is deprecated, just deprecate the initialize and open
1257
methods on the format class. Do not deprecate the object, as the
1520
methods on the format class. Do not deprecate the object, as the
1258
1521
object will be created every system load.
1261
_default_format = None
1262
"""The default format used for new .bzr dirs."""
1265
"""The known formats."""
1267
_control_formats = []
1268
"""The registered control formats - .bzr, ....
1270
This is a list of BzrDirFormat objects.
1273
_control_server_formats = []
1274
"""The registered control server formats, e.g. RemoteBzrDirs.
1276
This is a list of BzrDirFormat objects.
1279
1524
_lock_file_name = 'branch-lock'
1281
1526
# _lock_class must be set in subclasses to the lock type, typ.
1282
1527
# TransportLock or LockDir
1285
def find_format(klass, transport, _server_formats=True):
1286
"""Return the format present at transport."""
1288
formats = klass._control_server_formats + klass._control_formats
1290
formats = klass._control_formats
1291
for format in formats:
1293
return format.probe_transport(transport)
1294
except errors.NotBranchError:
1295
# this format does not find a control dir here.
1297
raise errors.NotBranchError(path=transport.base)
1300
def probe_transport(klass, transport):
1301
"""Return the .bzrdir style format present in a directory."""
1303
format_string = transport.get(".bzr/branch-format").read()
1304
except errors.NoSuchFile:
1305
raise errors.NotBranchError(path=transport.base)
1308
return klass._formats[format_string]
1310
raise errors.UnknownFormatError(format=format_string)
1313
def get_default_format(klass):
1314
"""Return the current default format."""
1315
return klass._default_format
1317
1529
def get_format_string(self):
1318
1530
"""Return the ASCII format string that identifies this format."""
1319
1531
raise NotImplementedError(self.get_format_string)
1321
def get_format_description(self):
1322
"""Return the short description for this format."""
1323
raise NotImplementedError(self.get_format_description)
1325
def get_converter(self, format=None):
1326
"""Return the converter to use to convert bzrdirs needing converts.
1328
This returns a bzrlib.bzrdir.Converter object.
1330
This should return the best upgrader to step this format towards the
1331
current default format. In the case of plugins we can/should provide
1332
some means for them to extend the range of returnable converters.
1334
:param format: Optional format to override the default format of the
1337
raise NotImplementedError(self.get_converter)
1339
def initialize(self, url, possible_transports=None):
1340
"""Create a bzr control dir at this url and return an opened copy.
1342
Subclasses should typically override initialize_on_transport
1343
instead of this method.
1345
return self.initialize_on_transport(get_transport(url,
1346
possible_transports))
1348
1533
def initialize_on_transport(self, transport):
1349
1534
"""Initialize a new bzrdir in the base directory of a Transport."""
1350
# Since we don't have a .bzr directory, inherit the
1536
# can we hand off the request to the smart server rather than using
1538
client_medium = transport.get_smart_medium()
1539
except errors.NoSmartMedium:
1540
return self._initialize_on_transport_vfs(transport)
1542
# Current RPC's only know how to create bzr metadir1 instances, so
1543
# we still delegate to vfs methods if the requested format is not a
1545
if type(self) != BzrDirMetaFormat1:
1546
return self._initialize_on_transport_vfs(transport)
1547
remote_format = RemoteBzrDirFormat()
1548
self._supply_sub_formats_to(remote_format)
1549
return remote_format.initialize_on_transport(transport)
1551
def initialize_on_transport_ex(self, transport, use_existing_dir=False,
1552
create_prefix=False, force_new_repo=False, stacked_on=None,
1553
stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
1554
shared_repo=False, vfs_only=False):
1555
"""Create this format on transport.
1557
The directory to initialize will be created.
1559
:param force_new_repo: Do not use a shared repository for the target,
1560
even if one is available.
1561
:param create_prefix: Create any missing directories leading up to
1563
:param use_existing_dir: Use an existing directory if one exists.
1564
:param stacked_on: A url to stack any created branch on, None to follow
1565
any target stacking policy.
1566
:param stack_on_pwd: If stack_on is relative, the location it is
1568
:param repo_format_name: If non-None, a repository will be
1569
made-or-found. Should none be found, or if force_new_repo is True
1570
the repo_format_name is used to select the format of repository to
1572
:param make_working_trees: Control the setting of make_working_trees
1573
for a new shared repository when one is made. None to use whatever
1574
default the format has.
1575
:param shared_repo: Control whether made repositories are shared or
1577
:param vfs_only: If True do not attempt to use a smart server
1578
:return: repo, bzrdir, require_stacking, repository_policy. repo is
1579
None if none was created or found, bzrdir is always valid.
1580
require_stacking is the result of examining the stacked_on
1581
parameter and any stacking policy found for the target.
1584
# Try to hand off to a smart server
1586
client_medium = transport.get_smart_medium()
1587
except errors.NoSmartMedium:
1590
# TODO: lookup the local format from a server hint.
1591
remote_dir_format = RemoteBzrDirFormat()
1592
remote_dir_format._network_name = self.network_name()
1593
self._supply_sub_formats_to(remote_dir_format)
1594
return remote_dir_format.initialize_on_transport_ex(transport,
1595
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
1596
force_new_repo=force_new_repo, stacked_on=stacked_on,
1597
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
1598
make_working_trees=make_working_trees, shared_repo=shared_repo)
1599
# XXX: Refactor the create_prefix/no_create_prefix code into a
1600
# common helper function
1601
# The destination may not exist - if so make it according to policy.
1602
def make_directory(transport):
1603
transport.mkdir('.')
1605
def redirected(transport, e, redirection_notice):
1606
note(redirection_notice)
1607
return transport._redirected_to(e.source, e.target)
1609
transport = do_catching_redirections(make_directory, transport,
1611
except errors.FileExists:
1612
if not use_existing_dir:
1614
except errors.NoSuchFile:
1615
if not create_prefix:
1617
transport.create_prefix()
1619
require_stacking = (stacked_on is not None)
1620
# Now the target directory exists, but doesn't have a .bzr
1621
# directory. So we need to create it, along with any work to create
1622
# all of the dependent branches, etc.
1624
result = self.initialize_on_transport(transport)
1625
if repo_format_name:
1627
# use a custom format
1628
result._format.repository_format = \
1629
repository.network_format_registry.get(repo_format_name)
1630
except AttributeError:
1631
# The format didn't permit it to be set.
1633
# A repository is desired, either in-place or shared.
1634
repository_policy = result.determine_repository_policy(
1635
force_new_repo, stacked_on, stack_on_pwd,
1636
require_stacking=require_stacking)
1637
result_repo, is_new_repo = repository_policy.acquire_repository(
1638
make_working_trees, shared_repo)
1639
if not require_stacking and repository_policy._require_stacking:
1640
require_stacking = True
1641
result._format.require_stacking()
1642
result_repo.lock_write()
1645
repository_policy = None
1646
return result_repo, result, require_stacking, repository_policy
1648
def _initialize_on_transport_vfs(self, transport):
1649
"""Initialize a new bzrdir using VFS calls.
1651
:param transport: The transport to create the .bzr directory in.
1654
# Since we are creating a .bzr directory, inherit the
1351
1655
# mode from the root directory
1352
1656
temp_control = lockable_files.LockableFiles(transport,
1353
1657
'', lockable_files.TransportLock)
2234
2661
# TODO: conversions of Branch and Tree should be done by
2235
2662
# InterXFormat lookups
2236
2663
if (isinstance(tree, workingtree.WorkingTree3) and
2237
not isinstance(tree, workingtree_4.WorkingTree4) and
2664
not isinstance(tree, workingtree_4.DirStateWorkingTree) and
2238
2665
isinstance(self.target_format.workingtree_format,
2239
workingtree_4.WorkingTreeFormat4)):
2666
workingtree_4.DirStateWorkingTreeFormat)):
2240
2667
workingtree_4.Converter3to4().convert(tree)
2668
if (isinstance(tree, workingtree_4.DirStateWorkingTree) and
2669
not isinstance(tree, workingtree_4.WorkingTree5) and
2670
isinstance(self.target_format.workingtree_format,
2671
workingtree_4.WorkingTreeFormat5)):
2672
workingtree_4.Converter4to5().convert(tree)
2673
if (isinstance(tree, workingtree_4.DirStateWorkingTree) and
2674
not isinstance(tree, workingtree_4.WorkingTree6) and
2675
isinstance(self.target_format.workingtree_format,
2676
workingtree_4.WorkingTreeFormat6)):
2677
workingtree_4.Converter4or5to6().convert(tree)
2241
2679
return to_convert
2244
# This is not in remote.py because it's small, and needs to be registered.
2245
# Putting it in remote.py creates a circular import problem.
2682
# This is not in remote.py because it's relatively small, and needs to be
2683
# registered. Putting it in remote.py creates a circular import problem.
2246
2684
# we can make it a lazy object if the control formats is turned into something
2247
2685
# like a registry.
2248
2686
class RemoteBzrDirFormat(BzrDirMetaFormat1):
2249
2687
"""Format representing bzrdirs accessed via a smart server"""
2689
supports_workingtrees = False
2692
BzrDirMetaFormat1.__init__(self)
2693
# XXX: It's a bit ugly that the network name is here, because we'd
2694
# like to believe that format objects are stateless or at least
2695
# immutable, However, we do at least avoid mutating the name after
2696
# it's returned. See <https://bugs.launchpad.net/bzr/+bug/504102>
2697
self._network_name = None
2700
return "%s(_network_name=%r)" % (self.__class__.__name__,
2251
2703
def get_format_description(self):
2704
if self._network_name:
2705
real_format = controldir.network_format_registry.get(self._network_name)
2706
return 'Remote: ' + real_format.get_format_description()
2252
2707
return 'bzr remote bzrdir'
2255
def probe_transport(klass, transport):
2256
"""Return a RemoteBzrDirFormat object if it looks possible."""
2258
client = transport.get_smart_client()
2259
except (NotImplementedError, AttributeError,
2260
errors.TransportNotPossible):
2261
# no smart server, so not a branch for this format type.
2262
raise errors.NotBranchError(path=transport.base)
2709
def get_format_string(self):
2710
raise NotImplementedError(self.get_format_string)
2712
def network_name(self):
2713
if self._network_name:
2714
return self._network_name
2264
# Send a 'hello' request in protocol version one, and decline to
2265
# open it if the server doesn't support our required version (2) so
2266
# that the VFS-based transport will do it.
2267
request = client.get_request()
2268
smart_protocol = protocol.SmartClientRequestProtocolOne(request)
2269
server_version = smart_protocol.query_version()
2270
if server_version != 2:
2271
raise errors.NotBranchError(path=transport.base)
2716
raise AssertionError("No network name set.")
2274
2718
def initialize_on_transport(self, transport):
2276
2720
# hand off the request to the smart server
2277
shared_medium = transport.get_shared_medium()
2721
client_medium = transport.get_smart_medium()
2278
2722
except errors.NoSmartMedium:
2279
2723
# TODO: lookup the local format from a server hint.
2280
2724
local_dir_format = BzrDirMetaFormat1()
2281
2725
return local_dir_format.initialize_on_transport(transport)
2282
client = _SmartClient(shared_medium)
2726
client = _SmartClient(client_medium)
2283
2727
path = client.remote_path_from_transport(transport)
2284
response = _SmartClient(shared_medium).call('BzrDirFormat.initialize',
2286
assert response[0] in ('ok', ), 'unexpected response code %s' % (response,)
2287
return remote.RemoteBzrDir(transport)
2729
response = client.call('BzrDirFormat.initialize', path)
2730
except errors.ErrorFromSmartServer, err:
2731
remote._translate_error(err, path=path)
2732
if response[0] != 'ok':
2733
raise errors.SmartProtocolError('unexpected response code %s' % (response,))
2734
format = RemoteBzrDirFormat()
2735
self._supply_sub_formats_to(format)
2736
return remote.RemoteBzrDir(transport, format)
2738
def parse_NoneTrueFalse(self, arg):
2745
raise AssertionError("invalid arg %r" % arg)
2747
def _serialize_NoneTrueFalse(self, arg):
2754
def _serialize_NoneString(self, arg):
2757
def initialize_on_transport_ex(self, transport, use_existing_dir=False,
2758
create_prefix=False, force_new_repo=False, stacked_on=None,
2759
stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
2762
# hand off the request to the smart server
2763
client_medium = transport.get_smart_medium()
2764
except errors.NoSmartMedium:
2767
# Decline to open it if the server doesn't support our required
2768
# version (3) so that the VFS-based transport will do it.
2769
if client_medium.should_probe():
2771
server_version = client_medium.protocol_version()
2772
if server_version != '2':
2776
except errors.SmartProtocolError:
2777
# Apparently there's no usable smart server there, even though
2778
# the medium supports the smart protocol.
2783
client = _SmartClient(client_medium)
2784
path = client.remote_path_from_transport(transport)
2785
if client_medium._is_remote_before((1, 16)):
2788
# TODO: lookup the local format from a server hint.
2789
local_dir_format = BzrDirMetaFormat1()
2790
self._supply_sub_formats_to(local_dir_format)
2791
return local_dir_format.initialize_on_transport_ex(transport,
2792
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
2793
force_new_repo=force_new_repo, stacked_on=stacked_on,
2794
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
2795
make_working_trees=make_working_trees, shared_repo=shared_repo,
2797
return self._initialize_on_transport_ex_rpc(client, path, transport,
2798
use_existing_dir, create_prefix, force_new_repo, stacked_on,
2799
stack_on_pwd, repo_format_name, make_working_trees, shared_repo)
2801
def _initialize_on_transport_ex_rpc(self, client, path, transport,
2802
use_existing_dir, create_prefix, force_new_repo, stacked_on,
2803
stack_on_pwd, repo_format_name, make_working_trees, shared_repo):
2805
args.append(self._serialize_NoneTrueFalse(use_existing_dir))
2806
args.append(self._serialize_NoneTrueFalse(create_prefix))
2807
args.append(self._serialize_NoneTrueFalse(force_new_repo))
2808
args.append(self._serialize_NoneString(stacked_on))
2809
# stack_on_pwd is often/usually our transport
2812
stack_on_pwd = transport.relpath(stack_on_pwd)
2813
if not stack_on_pwd:
2815
except errors.PathNotChild:
2817
args.append(self._serialize_NoneString(stack_on_pwd))
2818
args.append(self._serialize_NoneString(repo_format_name))
2819
args.append(self._serialize_NoneTrueFalse(make_working_trees))
2820
args.append(self._serialize_NoneTrueFalse(shared_repo))
2821
request_network_name = self._network_name or \
2822
BzrDirFormat.get_default_format().network_name()
2824
response = client.call('BzrDirFormat.initialize_ex_1.16',
2825
request_network_name, path, *args)
2826
except errors.UnknownSmartMethod:
2827
client._medium._remember_remote_is_before((1,16))
2828
local_dir_format = BzrDirMetaFormat1()
2829
self._supply_sub_formats_to(local_dir_format)
2830
return local_dir_format.initialize_on_transport_ex(transport,
2831
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
2832
force_new_repo=force_new_repo, stacked_on=stacked_on,
2833
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
2834
make_working_trees=make_working_trees, shared_repo=shared_repo,
2836
except errors.ErrorFromSmartServer, err:
2837
remote._translate_error(err, path=path)
2838
repo_path = response[0]
2839
bzrdir_name = response[6]
2840
require_stacking = response[7]
2841
require_stacking = self.parse_NoneTrueFalse(require_stacking)
2842
format = RemoteBzrDirFormat()
2843
format._network_name = bzrdir_name
2844
self._supply_sub_formats_to(format)
2845
bzrdir = remote.RemoteBzrDir(transport, format, _client=client)
2847
repo_format = remote.response_tuple_to_repo_format(response[1:])
2848
if repo_path == '.':
2851
repo_bzrdir_format = RemoteBzrDirFormat()
2852
repo_bzrdir_format._network_name = response[5]
2853
repo_bzr = remote.RemoteBzrDir(transport.clone(repo_path),
2857
final_stack = response[8] or None
2858
final_stack_pwd = response[9] or None
2860
final_stack_pwd = urlutils.join(
2861
transport.base, final_stack_pwd)
2862
remote_repo = remote.RemoteRepository(repo_bzr, repo_format)
2863
if len(response) > 10:
2864
# Updated server verb that locks remotely.
2865
repo_lock_token = response[10] or None
2866
remote_repo.lock_write(repo_lock_token, _skip_rpc=True)
2868
remote_repo.dont_leave_lock_in_place()
2870
remote_repo.lock_write()
2871
policy = UseExistingRepository(remote_repo, final_stack,
2872
final_stack_pwd, require_stacking)
2873
policy.acquire_repository()
2877
bzrdir._format.set_branch_format(self.get_branch_format())
2878
if require_stacking:
2879
# The repo has already been created, but we need to make sure that
2880
# we'll make a stackable branch.
2881
bzrdir._format.require_stacking(_skip_repo=True)
2882
return remote_repo, bzrdir, require_stacking, policy
2289
2884
def _open(self, transport):
2290
return remote.RemoteBzrDir(transport)
2885
return remote.RemoteBzrDir(transport, self)
2292
2887
def __eq__(self, other):
2293
2888
if not isinstance(other, RemoteBzrDirFormat):
2295
2890
return self.get_format_description() == other.get_format_description()
2298
BzrDirFormat.register_control_server_format(RemoteBzrDirFormat)
2301
class BzrDirFormatInfo(object):
2303
def __init__(self, native, deprecated, hidden, experimental):
2304
self.deprecated = deprecated
2305
self.native = native
2306
self.hidden = hidden
2307
self.experimental = experimental
2310
class BzrDirFormatRegistry(registry.Registry):
2311
"""Registry of user-selectable BzrDir subformats.
2313
Differs from BzrDirFormat._control_formats in that it provides sub-formats,
2314
e.g. BzrDirMeta1 with weave repository. Also, it's more user-oriented.
2317
def register_metadir(self, key,
2318
repository_format, help, native=True, deprecated=False,
2322
experimental=False):
2323
"""Register a metadir subformat.
2325
These all use a BzrDirMetaFormat1 bzrdir, but can be parameterized
2326
by the Repository format.
2328
:param repository_format: The fully-qualified repository format class
2330
:param branch_format: Fully-qualified branch format class name as
2332
:param tree_format: Fully-qualified tree format class name as
2335
# This should be expanded to support setting WorkingTree and Branch
2336
# formats, once BzrDirMetaFormat1 supports that.
2337
def _load(full_name):
2338
mod_name, factory_name = full_name.rsplit('.', 1)
2340
mod = __import__(mod_name, globals(), locals(),
2342
except ImportError, e:
2343
raise ImportError('failed to load %s: %s' % (full_name, e))
2345
factory = getattr(mod, factory_name)
2346
except AttributeError:
2347
raise AttributeError('no factory %s in module %r'
2352
bd = BzrDirMetaFormat1()
2353
if branch_format is not None:
2354
bd.set_branch_format(_load(branch_format))
2355
if tree_format is not None:
2356
bd.workingtree_format = _load(tree_format)
2357
if repository_format is not None:
2358
bd.repository_format = _load(repository_format)
2360
self.register(key, helper, help, native, deprecated, hidden,
2363
def register(self, key, factory, help, native=True, deprecated=False,
2364
hidden=False, experimental=False):
2365
"""Register a BzrDirFormat factory.
2367
The factory must be a callable that takes one parameter: the key.
2368
It must produce an instance of the BzrDirFormat when called.
2370
This function mainly exists to prevent the info object from being
2373
registry.Registry.register(self, key, factory, help,
2374
BzrDirFormatInfo(native, deprecated, hidden, experimental))
2376
def register_lazy(self, key, module_name, member_name, help, native=True,
2377
deprecated=False, hidden=False, experimental=False):
2378
registry.Registry.register_lazy(self, key, module_name, member_name,
2379
help, BzrDirFormatInfo(native, deprecated, hidden, experimental))
2381
def set_default(self, key):
2382
"""Set the 'default' key to be a clone of the supplied key.
2384
This method must be called once and only once.
2386
registry.Registry.register(self, 'default', self.get(key),
2387
self.get_help(key), info=self.get_info(key))
2389
def set_default_repository(self, key):
2390
"""Set the FormatRegistry default and Repository default.
2392
This is a transitional method while Repository.set_default_format
2395
if 'default' in self:
2396
self.remove('default')
2397
self.set_default(key)
2398
format = self.get('default')()
2399
assert isinstance(format, BzrDirMetaFormat1)
2401
def make_bzrdir(self, key):
2402
return self.get(key)()
2404
def help_topic(self, topic):
2405
output = textwrap.dedent("""\
2406
These formats can be used for creating branches, working trees, and
2410
default_realkey = None
2411
default_help = self.get_help('default')
2413
for key in self.keys():
2414
if key == 'default':
2416
help = self.get_help(key)
2417
if help == default_help:
2418
default_realkey = key
2420
help_pairs.append((key, help))
2422
def wrapped(key, help, info):
2424
help = '(native) ' + help
2425
return ':%s:\n%s\n\n' % (key,
2426
textwrap.fill(help, initial_indent=' ',
2427
subsequent_indent=' '))
2428
if default_realkey is not None:
2429
output += wrapped(default_realkey, '(default) %s' % default_help,
2430
self.get_info('default'))
2431
deprecated_pairs = []
2432
experimental_pairs = []
2433
for key, help in help_pairs:
2434
info = self.get_info(key)
2437
elif info.deprecated:
2438
deprecated_pairs.append((key, help))
2439
elif info.experimental:
2440
experimental_pairs.append((key, help))
2442
output += wrapped(key, help, info)
2443
if len(experimental_pairs) > 0:
2444
output += "Experimental formats are shown below.\n\n"
2445
for key, help in experimental_pairs:
2446
info = self.get_info(key)
2447
output += wrapped(key, help, info)
2448
if len(deprecated_pairs) > 0:
2449
output += "Deprecated formats are shown below.\n\n"
2450
for key, help in deprecated_pairs:
2451
info = self.get_info(key)
2452
output += wrapped(key, help, info)
2457
format_registry = BzrDirFormatRegistry()
2458
format_registry.register('weave', BzrDirFormat6,
2892
def __return_repository_format(self):
2893
# Always return a RemoteRepositoryFormat object, but if a specific bzr
2894
# repository format has been asked for, tell the RemoteRepositoryFormat
2895
# that it should use that for init() etc.
2896
result = remote.RemoteRepositoryFormat()
2897
custom_format = getattr(self, '_repository_format', None)
2899
if isinstance(custom_format, remote.RemoteRepositoryFormat):
2900
return custom_format
2902
# We will use the custom format to create repositories over the
2903
# wire; expose its details like rich_root_data for code to
2905
result._custom_format = custom_format
2908
def get_branch_format(self):
2909
result = BzrDirMetaFormat1.get_branch_format(self)
2910
if not isinstance(result, remote.RemoteBranchFormat):
2911
new_result = remote.RemoteBranchFormat()
2912
new_result._custom_format = result
2914
self.set_branch_format(new_result)
2918
repository_format = property(__return_repository_format,
2919
BzrDirMetaFormat1._set_repository_format) #.im_func)
2922
controldir.ControlDirFormat.register_server_prober(RemoteBzrProber)
2925
class RepositoryAcquisitionPolicy(object):
2926
"""Abstract base class for repository acquisition policies.
2928
A repository acquisition policy decides how a BzrDir acquires a repository
2929
for a branch that is being created. The most basic policy decision is
2930
whether to create a new repository or use an existing one.
2932
def __init__(self, stack_on, stack_on_pwd, require_stacking):
2935
:param stack_on: A location to stack on
2936
:param stack_on_pwd: If stack_on is relative, the location it is
2938
:param require_stacking: If True, it is a failure to not stack.
2940
self._stack_on = stack_on
2941
self._stack_on_pwd = stack_on_pwd
2942
self._require_stacking = require_stacking
2944
def configure_branch(self, branch):
2945
"""Apply any configuration data from this policy to the branch.
2947
Default implementation sets repository stacking.
2949
if self._stack_on is None:
2951
if self._stack_on_pwd is None:
2952
stack_on = self._stack_on
2955
stack_on = urlutils.rebase_url(self._stack_on,
2958
except errors.InvalidRebaseURLs:
2959
stack_on = self._get_full_stack_on()
2961
branch.set_stacked_on_url(stack_on)
2962
except (errors.UnstackableBranchFormat,
2963
errors.UnstackableRepositoryFormat):
2964
if self._require_stacking:
2967
def requires_stacking(self):
2968
"""Return True if this policy requires stacking."""
2969
return self._stack_on is not None and self._require_stacking
2971
def _get_full_stack_on(self):
2972
"""Get a fully-qualified URL for the stack_on location."""
2973
if self._stack_on is None:
2975
if self._stack_on_pwd is None:
2976
return self._stack_on
2978
return urlutils.join(self._stack_on_pwd, self._stack_on)
2980
def _add_fallback(self, repository, possible_transports=None):
2981
"""Add a fallback to the supplied repository, if stacking is set."""
2982
stack_on = self._get_full_stack_on()
2983
if stack_on is None:
2986
stacked_dir = BzrDir.open(stack_on,
2987
possible_transports=possible_transports)
2988
except errors.JailBreak:
2989
# We keep the stacking details, but we are in the server code so
2990
# actually stacking is not needed.
2993
stacked_repo = stacked_dir.open_branch().repository
2994
except errors.NotBranchError:
2995
stacked_repo = stacked_dir.open_repository()
2997
repository.add_fallback_repository(stacked_repo)
2998
except errors.UnstackableRepositoryFormat:
2999
if self._require_stacking:
3002
self._require_stacking = True
3004
def acquire_repository(self, make_working_trees=None, shared=False):
3005
"""Acquire a repository for this bzrdir.
3007
Implementations may create a new repository or use a pre-exising
3009
:param make_working_trees: If creating a repository, set
3010
make_working_trees to this value (if non-None)
3011
:param shared: If creating a repository, make it shared if True
3012
:return: A repository, is_new_flag (True if the repository was
3015
raise NotImplemented(RepositoryAcquisitionPolicy.acquire_repository)
3018
class CreateRepository(RepositoryAcquisitionPolicy):
3019
"""A policy of creating a new repository"""
3021
def __init__(self, bzrdir, stack_on=None, stack_on_pwd=None,
3022
require_stacking=False):
3025
:param bzrdir: The bzrdir to create the repository on.
3026
:param stack_on: A location to stack on
3027
:param stack_on_pwd: If stack_on is relative, the location it is
3030
RepositoryAcquisitionPolicy.__init__(self, stack_on, stack_on_pwd,
3032
self._bzrdir = bzrdir
3034
def acquire_repository(self, make_working_trees=None, shared=False):
3035
"""Implementation of RepositoryAcquisitionPolicy.acquire_repository
3037
Creates the desired repository in the bzrdir we already have.
3039
stack_on = self._get_full_stack_on()
3041
format = self._bzrdir._format
3042
format.require_stacking(stack_on=stack_on,
3043
possible_transports=[self._bzrdir.root_transport])
3044
if not self._require_stacking:
3045
# We have picked up automatic stacking somewhere.
3046
note('Using default stacking branch %s at %s', self._stack_on,
3048
repository = self._bzrdir.create_repository(shared=shared)
3049
self._add_fallback(repository,
3050
possible_transports=[self._bzrdir.transport])
3051
if make_working_trees is not None:
3052
repository.set_make_working_trees(make_working_trees)
3053
return repository, True
3056
class UseExistingRepository(RepositoryAcquisitionPolicy):
3057
"""A policy of reusing an existing repository"""
3059
def __init__(self, repository, stack_on=None, stack_on_pwd=None,
3060
require_stacking=False):
3063
:param repository: The repository to use.
3064
:param stack_on: A location to stack on
3065
:param stack_on_pwd: If stack_on is relative, the location it is
3068
RepositoryAcquisitionPolicy.__init__(self, stack_on, stack_on_pwd,
3070
self._repository = repository
3072
def acquire_repository(self, make_working_trees=None, shared=False):
3073
"""Implementation of RepositoryAcquisitionPolicy.acquire_repository
3075
Returns an existing repository to use.
3077
self._add_fallback(self._repository,
3078
possible_transports=[self._repository.bzrdir.transport])
3079
return self._repository, False
3082
def register_metadir(registry, key,
3083
repository_format, help, native=True, deprecated=False,
3089
"""Register a metadir subformat.
3091
These all use a BzrDirMetaFormat1 bzrdir, but can be parameterized
3092
by the Repository/Branch/WorkingTreeformats.
3094
:param repository_format: The fully-qualified repository format class
3096
:param branch_format: Fully-qualified branch format class name as
3098
:param tree_format: Fully-qualified tree format class name as
3101
# This should be expanded to support setting WorkingTree and Branch
3102
# formats, once BzrDirMetaFormat1 supports that.
3103
def _load(full_name):
3104
mod_name, factory_name = full_name.rsplit('.', 1)
3106
factory = pyutils.get_named_object(mod_name, factory_name)
3107
except ImportError, e:
3108
raise ImportError('failed to load %s: %s' % (full_name, e))
3109
except AttributeError:
3110
raise AttributeError('no factory %s in module %r'
3111
% (full_name, sys.modules[mod_name]))
3115
bd = BzrDirMetaFormat1()
3116
if branch_format is not None:
3117
bd.set_branch_format(_load(branch_format))
3118
if tree_format is not None:
3119
bd.workingtree_format = _load(tree_format)
3120
if repository_format is not None:
3121
bd.repository_format = _load(repository_format)
3123
registry.register(key, helper, help, native, deprecated, hidden,
3124
experimental, alias)
3126
# The pre-0.8 formats have their repository format network name registered in
3127
# repository.py. MetaDir formats have their repository format network name
3128
# inferred from their disk format string.
3129
controldir.format_registry.register('weave', BzrDirFormat6,
2459
3130
'Pre-0.8 format. Slower than knit and does not'
2460
3131
' support checkouts or shared repositories.',
2461
3133
deprecated=True)
2462
format_registry.register_metadir('knit',
2463
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2464
'Format using knits. Recommended for interoperation with bzr <= 0.14.',
2465
branch_format='bzrlib.branch.BzrBranchFormat5',
2466
tree_format='bzrlib.workingtree.WorkingTreeFormat3')
2467
format_registry.register_metadir('metaweave',
3134
register_metadir(controldir.format_registry, 'metaweave',
2468
3135
'bzrlib.repofmt.weaverepo.RepositoryFormat7',
2469
3136
'Transitional format in 0.8. Slower than knit.',
2470
3137
branch_format='bzrlib.branch.BzrBranchFormat5',
2471
3138
tree_format='bzrlib.workingtree.WorkingTreeFormat3',
2473
format_registry.register_metadir('dirstate',
3141
register_metadir(controldir.format_registry, 'knit',
3142
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
3143
'Format using knits. Recommended for interoperation with bzr <= 0.14.',
3144
branch_format='bzrlib.branch.BzrBranchFormat5',
3145
tree_format='bzrlib.workingtree.WorkingTreeFormat3',
3148
register_metadir(controldir.format_registry, 'dirstate',
2474
3149
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2475
3150
help='New in 0.15: Fast local operations. Compatible with bzr 0.8 and '
2476
3151
'above when accessed over the network.',
2478
3153
# this uses bzrlib.workingtree.WorkingTreeFormat4 because importing
2479
3154
# directly from workingtree_4 triggers a circular import.
2480
3155
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2482
format_registry.register_metadir('dirstate-tags',
3158
register_metadir(controldir.format_registry, 'dirstate-tags',
2483
3159
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2484
3160
help='New in 0.15: Fast local operations and improved scaling for '
2485
3161
'network operations. Additionally adds support for tags.'
2486
3162
' Incompatible with bzr < 0.15.',
2487
3163
branch_format='bzrlib.branch.BzrBranchFormat6',
2488
3164
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2490
format_registry.register_metadir('rich-root',
3167
register_metadir(controldir.format_registry, 'rich-root',
2491
3168
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit4',
2492
3169
help='New in 1.0. Better handling of tree roots. Incompatible with'
2494
3171
branch_format='bzrlib.branch.BzrBranchFormat6',
2495
3172
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2498
format_registry.register_metadir('dirstate-with-subtree',
3175
register_metadir(controldir.format_registry, 'dirstate-with-subtree',
2499
3176
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
2500
3177
help='New in 0.15: Fast local operations and improved scaling for '
2501
3178
'network operations. Additionally adds support for versioning nested '
2502
3179
'bzr branches. Incompatible with bzr < 0.15.',
2503
3180
branch_format='bzrlib.branch.BzrBranchFormat6',
2504
3181
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2507
format_registry.register_metadir('pack-0.92',
3185
register_metadir(controldir.format_registry, 'pack-0.92',
2508
3186
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack1',
2509
3187
help='New in 0.92: Pack-based format with data compatible with '
2510
3188
'dirstate-tags format repositories. Interoperates with '
2511
3189
'bzr repositories before 0.92 but cannot be read by bzr < 0.92. '
2512
'Previously called knitpack-experimental. '
2513
'For more information, see '
2514
'http://doc.bazaar-vcs.org/latest/developers/packrepo.html.',
2515
3191
branch_format='bzrlib.branch.BzrBranchFormat6',
2516
3192
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2519
format_registry.register_metadir('pack-0.92-subtree',
3194
register_metadir(controldir.format_registry, 'pack-0.92-subtree',
2520
3195
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack3',
2521
3196
help='New in 0.92: Pack-based format with data compatible with '
2522
3197
'dirstate-with-subtree format repositories. Interoperates with '
2523
3198
'bzr repositories before 0.92 but cannot be read by bzr < 0.92. '
2524
'Previously called knitpack-experimental. '
2525
'For more information, see '
2526
'http://doc.bazaar-vcs.org/latest/developers/packrepo.html.',
2527
3200
branch_format='bzrlib.branch.BzrBranchFormat6',
2528
3201
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2530
3203
experimental=True,
2532
format_registry.register_metadir('rich-root-pack',
3205
register_metadir(controldir.format_registry, 'rich-root-pack',
2533
3206
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack4',
2534
help='New in 1.0: Pack-based format with data compatible with '
2535
'rich-root format repositories. Interoperates with '
2536
'bzr repositories before 0.92 but cannot be read by bzr < 1.0. '
2537
'NOTE: This format is experimental. Before using it, please read '
2538
'http://doc.bazaar-vcs.org/latest/developers/knitpack.html.',
3207
help='New in 1.0: A variant of pack-0.92 that supports rich-root data '
3208
'(needed for bzr-svn and bzr-git).',
2539
3209
branch_format='bzrlib.branch.BzrBranchFormat6',
2540
3210
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2544
format_registry.set_default('dirstate-tags')
3213
register_metadir(controldir.format_registry, '1.6',
3214
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack5',
3215
help='A format that allows a branch to indicate that there is another '
3216
'(stacked) repository that should be used to access data that is '
3217
'not present locally.',
3218
branch_format='bzrlib.branch.BzrBranchFormat7',
3219
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3222
register_metadir(controldir.format_registry, '1.6.1-rich-root',
3223
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack5RichRoot',
3224
help='A variant of 1.6 that supports rich-root data '
3225
'(needed for bzr-svn and bzr-git).',
3226
branch_format='bzrlib.branch.BzrBranchFormat7',
3227
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3230
register_metadir(controldir.format_registry, '1.9',
3231
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6',
3232
help='A repository format using B+tree indexes. These indexes '
3233
'are smaller in size, have smarter caching and provide faster '
3234
'performance for most operations.',
3235
branch_format='bzrlib.branch.BzrBranchFormat7',
3236
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3239
register_metadir(controldir.format_registry, '1.9-rich-root',
3240
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6RichRoot',
3241
help='A variant of 1.9 that supports rich-root data '
3242
'(needed for bzr-svn and bzr-git).',
3243
branch_format='bzrlib.branch.BzrBranchFormat7',
3244
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3247
register_metadir(controldir.format_registry, '1.14',
3248
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6',
3249
help='A working-tree format that supports content filtering.',
3250
branch_format='bzrlib.branch.BzrBranchFormat7',
3251
tree_format='bzrlib.workingtree.WorkingTreeFormat5',
3253
register_metadir(controldir.format_registry, '1.14-rich-root',
3254
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6RichRoot',
3255
help='A variant of 1.14 that supports rich-root data '
3256
'(needed for bzr-svn and bzr-git).',
3257
branch_format='bzrlib.branch.BzrBranchFormat7',
3258
tree_format='bzrlib.workingtree.WorkingTreeFormat5',
3260
# The following un-numbered 'development' formats should always just be aliases.
3261
register_metadir(controldir.format_registry, 'development-subtree',
3262
'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2aSubtree',
3263
help='Current development format, subtree variant. Can convert data to and '
3264
'from pack-0.92-subtree (and anything compatible with '
3265
'pack-0.92-subtree) format repositories. Repositories and branches in '
3266
'this format can only be read by bzr.dev. Please read '
3267
'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
3269
branch_format='bzrlib.branch.BzrBranchFormat7',
3270
tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3273
alias=False, # Restore to being an alias when an actual development subtree format is added
3274
# This current non-alias status is simply because we did not introduce a
3275
# chk based subtree format.
3277
register_metadir(controldir.format_registry, 'development5-subtree',
3278
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment2Subtree',
3279
help='Development format, subtree variant. Can convert data to and '
3280
'from pack-0.92-subtree (and anything compatible with '
3281
'pack-0.92-subtree) format repositories. Repositories and branches in '
3282
'this format can only be read by bzr.dev. Please read '
3283
'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
3285
branch_format='bzrlib.branch.BzrBranchFormat7',
3286
tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3292
# And the development formats above will have aliased one of the following:
3294
# Finally, the current format.
3295
register_metadir(controldir.format_registry, '2a',
3296
'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2a',
3297
help='First format for bzr 2.0 series.\n'
3298
'Uses group-compress storage.\n'
3299
'Provides rich roots which are a one-way transition.\n',
3300
# 'storage in packs, 255-way hashed CHK inventory, bencode revision, group compress, '
3301
# 'rich roots. Supported by bzr 1.16 and later.',
3302
branch_format='bzrlib.branch.BzrBranchFormat7',
3303
tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3307
# The following format should be an alias for the rich root equivalent
3308
# of the default format
3309
register_metadir(controldir.format_registry, 'default-rich-root',
3310
'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2a',
3311
branch_format='bzrlib.branch.BzrBranchFormat7',
3312
tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3317
# The current format that is made on 'bzr init'.
3318
format_name = config.GlobalConfig().get_user_option('default_format')
3319
if format_name is None:
3320
controldir.format_registry.set_default('2a')
3322
controldir.format_registry.set_default(format_name)
3324
# XXX 2010-08-20 JRV: There is still a lot of code relying on
3325
# bzrlib.bzrdir.format_registry existing. When BzrDir.create/BzrDir.open/etc
3326
# get changed to ControlDir.create/ControlDir.open/etc this should be removed.
3327
format_registry = controldir.format_registry