211
215
errors.UnstackableRepositoryFormat,
212
216
errors.NotStacked):
214
# Bug: We create a metadir without knowing if it can support stacking,
215
# we should look up the policy needs first, or just use it as a hint,
220
# may need to copy content in
221
repository_policy = result.determine_repository_policy(
222
force_new_repo, stacked_on, self.root_transport.base,
223
require_stacking=require_stacking)
218
224
make_working_trees = local_repo.make_working_trees()
219
want_shared = local_repo.is_shared()
220
repo_format_name = format.repository_format.network_name()
222
make_working_trees = False
224
repo_format_name = None
226
result_repo, result, require_stacking, repository_policy = \
227
format.initialize_on_transport_ex(transport,
228
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
229
force_new_repo=force_new_repo, stacked_on=stacked_on,
230
stack_on_pwd=self.root_transport.base,
231
repo_format_name=repo_format_name,
232
make_working_trees=make_working_trees, shared_repo=want_shared)
235
# If the result repository is in the same place as the
236
# resulting bzr dir, it will have no content, further if the
237
# result is not stacked then we know all content should be
238
# copied, and finally if we are copying up to a specific
239
# revision_id then we can use the pending-ancestry-result which
240
# does not require traversing all of history to describe it.
241
if (result_repo.user_url == result.user_url
242
and not require_stacking and
243
revision_id is not None):
244
fetch_spec = graph.PendingAncestryResult(
245
[revision_id], local_repo)
246
result_repo.fetch(local_repo, fetch_spec=fetch_spec)
248
result_repo.fetch(local_repo, revision_id=revision_id)
252
if result_repo is not None:
253
raise AssertionError('result_repo not None(%r)' % result_repo)
225
result_repo, is_new_repo = repository_policy.acquire_repository(
226
make_working_trees, local_repo.is_shared())
227
if not require_stacking and repository_policy._require_stacking:
228
require_stacking = True
229
result._format.require_stacking()
230
if is_new_repo and not require_stacking and revision_id is not None:
231
fetch_spec = graph.PendingAncestryResult(
232
[revision_id], local_repo)
233
result_repo.fetch(local_repo, fetch_spec=fetch_spec)
235
result_repo.fetch(local_repo, revision_id=revision_id)
254
238
# 1 if there is a branch present
255
239
# make sure its content is available in the target repository
893
1063
format, repository = self._cloning_metadir()
894
1064
if format._workingtree_format is None:
896
1065
if repository is None:
897
# No repository either
899
# We have a repository, so set a working tree? (Why? This seems to
900
# contradict the stated return value in the docstring).
901
1067
tree_format = repository._format._matchingbzrdir.workingtree_format
902
1068
format.workingtree_format = tree_format.__class__()
903
1069
if require_stacking:
904
1070
format.require_stacking()
908
def create(cls, base, format=None, possible_transports=None):
909
"""Create a new BzrDir at the url 'base'.
911
:param format: If supplied, the format of branch to create. If not
912
supplied, the default is used.
913
:param possible_transports: If supplied, a list of transports that
914
can be reused to share a remote connection.
1073
def checkout_metadir(self):
1074
return self.cloning_metadir()
1076
def sprout(self, url, revision_id=None, force_new_repo=False,
1077
recurse='down', possible_transports=None,
1078
accelerator_tree=None, hardlink=False, stacked=False,
1079
source_branch=None, create_tree_if_local=True):
1080
"""Create a copy of this bzrdir prepared for use as a new line of
1083
If url's last component does not exist, it will be created.
1085
Attributes related to the identity of the source branch like
1086
branch nickname will be cleaned, a working tree is created
1087
whether one existed before or not; and a local branch is always
1090
if revision_id is not None, then the clone operation may tune
1091
itself to download less data.
1092
:param accelerator_tree: A tree which can be used for retrieving file
1093
contents more quickly than the revision tree, i.e. a workingtree.
1094
The revision tree will be used for cases where accelerator_tree's
1095
content is different.
1096
:param hardlink: If true, hard-link files from accelerator_tree,
1098
:param stacked: If true, create a stacked branch referring to the
1099
location of this control directory.
1100
:param create_tree_if_local: If true, a working-tree will be created
1101
when working locally.
916
if cls is not BzrDir:
917
raise AssertionError("BzrDir.create always creates the"
918
"default format, not one of %r" % cls)
919
t = get_transport(base, possible_transports)
922
format = controldir.ControlDirFormat.get_default_format()
923
return format.initialize_on_transport(t)
1103
target_transport = get_transport(url, possible_transports)
1104
target_transport.ensure_base()
1105
cloning_format = self.cloning_metadir(stacked)
1106
# Create/update the result branch
1107
result = cloning_format.initialize_on_transport(target_transport)
1108
# if a stacked branch wasn't requested, we don't create one
1109
# even if the origin was stacked
1110
stacked_branch_url = None
1111
if source_branch is not None:
1113
stacked_branch_url = self.root_transport.base
1114
source_repository = source_branch.repository
1117
source_branch = self.open_branch()
1118
source_repository = source_branch.repository
1120
stacked_branch_url = self.root_transport.base
1121
except errors.NotBranchError:
1122
source_branch = None
1124
source_repository = self.open_repository()
1125
except errors.NoRepositoryPresent:
1126
source_repository = None
1127
repository_policy = result.determine_repository_policy(
1128
force_new_repo, stacked_branch_url, require_stacking=stacked)
1129
result_repo, is_new_repo = repository_policy.acquire_repository()
1130
if is_new_repo and revision_id is not None and not stacked:
1131
fetch_spec = graph.PendingAncestryResult(
1132
[revision_id], source_repository)
1135
if source_repository is not None:
1136
# Fetch while stacked to prevent unstacked fetch from
1138
if fetch_spec is None:
1139
result_repo.fetch(source_repository, revision_id=revision_id)
1141
result_repo.fetch(source_repository, fetch_spec=fetch_spec)
1143
if source_branch is None:
1144
# this is for sprouting a bzrdir without a branch; is that
1146
# Not especially, but it's part of the contract.
1147
result_branch = result.create_branch()
1149
result_branch = source_branch.sprout(result,
1150
revision_id=revision_id, repository_policy=repository_policy)
1151
mutter("created new branch %r" % (result_branch,))
1153
# Create/update the result working tree
1154
if (create_tree_if_local and
1155
isinstance(target_transport, local.LocalTransport) and
1156
(result_repo is None or result_repo.make_working_trees())):
1157
wt = result.create_workingtree(accelerator_tree=accelerator_tree,
1161
if wt.path2id('') is None:
1163
wt.set_root_id(self.open_workingtree.get_root_id())
1164
except errors.NoWorkingTree:
1170
if recurse == 'down':
1172
basis = wt.basis_tree()
1174
subtrees = basis.iter_references()
1175
elif result_branch is not None:
1176
basis = result_branch.basis_tree()
1178
subtrees = basis.iter_references()
1179
elif source_branch is not None:
1180
basis = source_branch.basis_tree()
1182
subtrees = basis.iter_references()
1187
for path, file_id in subtrees:
1188
target = urlutils.join(url, urlutils.escape(path))
1189
sublocation = source_branch.reference_parent(file_id, path)
1190
sublocation.bzrdir.sprout(target,
1191
basis.get_reference_revision(file_id, path),
1192
force_new_repo=force_new_repo, recurse=recurse,
1195
if basis is not None:
927
1200
class BzrDirHooks(hooks.Hooks):
1437
1633
return format.open(self, _found=True)
1439
1635
def _get_config(self):
1440
return config.TransportConfig(self.transport, 'control.conf')
1443
class BzrProber(controldir.Prober):
1444
"""Prober for formats that use a .bzr/ control directory."""
1447
"""The known .bzr formats."""
1450
def register_bzrdir_format(klass, format):
1451
klass._formats[format.get_format_string()] = format
1454
def unregister_bzrdir_format(klass, format):
1455
del klass._formats[format.get_format_string()]
1458
def probe_transport(klass, transport):
1459
"""Return the .bzrdir style format present in a directory."""
1461
format_string = transport.get_bytes(".bzr/branch-format")
1462
except errors.NoSuchFile:
1463
raise errors.NotBranchError(path=transport.base)
1465
return klass._formats[format_string]
1467
raise errors.UnknownFormatError(format=format_string, kind='bzrdir')
1470
controldir.ControlDirFormat.register_prober(BzrProber)
1473
class RemoteBzrProber(controldir.Prober):
1474
"""Prober for remote servers that provide a Bazaar smart server."""
1477
def probe_transport(klass, transport):
1478
"""Return a RemoteBzrDirFormat object if it looks possible."""
1480
medium = transport.get_smart_medium()
1481
except (NotImplementedError, AttributeError,
1482
errors.TransportNotPossible, errors.NoSmartMedium,
1483
errors.SmartProtocolError):
1484
# no smart server, so not a branch for this format type.
1485
raise errors.NotBranchError(path=transport.base)
1487
# Decline to open it if the server doesn't support our required
1488
# version (3) so that the VFS-based transport will do it.
1489
if medium.should_probe():
1491
server_version = medium.protocol_version()
1492
except errors.SmartProtocolError:
1493
# Apparently there's no usable smart server there, even though
1494
# the medium supports the smart protocol.
1495
raise errors.NotBranchError(path=transport.base)
1496
if server_version != '2':
1497
raise errors.NotBranchError(path=transport.base)
1498
return RemoteBzrDirFormat()
1501
class BzrDirFormat(controldir.ControlDirFormat):
1502
"""ControlDirFormat base class for .bzr/ directories.
1636
return config.BzrDirConfig(self.transport)
1639
class BzrDirFormat(object):
1640
"""An encapsulation of the initialization and open routines for a format.
1642
Formats provide three things:
1643
* An initialization routine,
1504
1647
Formats are placed in a dict by their format string for reference
1505
1648
during bzrdir opening. These should be subclasses of BzrDirFormat
1510
1653
object will be created every system load.
1656
_default_format = None
1657
"""The default format used for new .bzr dirs."""
1660
"""The known formats."""
1662
_control_formats = []
1663
"""The registered control formats - .bzr, ....
1665
This is a list of BzrDirFormat objects.
1668
_control_server_formats = []
1669
"""The registered control server formats, e.g. RemoteBzrDirs.
1671
This is a list of BzrDirFormat objects.
1513
1674
_lock_file_name = 'branch-lock'
1515
1676
# _lock_class must be set in subclasses to the lock type, typ.
1516
1677
# TransportLock or LockDir
1680
def find_format(klass, transport, _server_formats=True):
1681
"""Return the format present at transport."""
1683
formats = klass._control_server_formats + klass._control_formats
1685
formats = klass._control_formats
1686
for format in formats:
1688
return format.probe_transport(transport)
1689
except errors.NotBranchError:
1690
# this format does not find a control dir here.
1692
raise errors.NotBranchError(path=transport.base)
1695
def probe_transport(klass, transport):
1696
"""Return the .bzrdir style format present in a directory."""
1698
format_string = transport.get(".bzr/branch-format").read()
1699
except errors.NoSuchFile:
1700
raise errors.NotBranchError(path=transport.base)
1703
return klass._formats[format_string]
1705
raise errors.UnknownFormatError(format=format_string, kind='bzrdir')
1708
def get_default_format(klass):
1709
"""Return the current default format."""
1710
return klass._default_format
1518
1712
def get_format_string(self):
1519
1713
"""Return the ASCII format string that identifies this format."""
1520
1714
raise NotImplementedError(self.get_format_string)
1716
def get_format_description(self):
1717
"""Return the short description for this format."""
1718
raise NotImplementedError(self.get_format_description)
1720
def get_converter(self, format=None):
1721
"""Return the converter to use to convert bzrdirs needing converts.
1723
This returns a bzrlib.bzrdir.Converter object.
1725
This should return the best upgrader to step this format towards the
1726
current default format. In the case of plugins we can/should provide
1727
some means for them to extend the range of returnable converters.
1729
:param format: Optional format to override the default format of the
1732
raise NotImplementedError(self.get_converter)
1734
def initialize(self, url, possible_transports=None):
1735
"""Create a bzr control dir at this url and return an opened copy.
1737
Subclasses should typically override initialize_on_transport
1738
instead of this method.
1740
return self.initialize_on_transport(get_transport(url,
1741
possible_transports))
1522
1743
def initialize_on_transport(self, transport):
1523
1744
"""Initialize a new bzrdir in the base directory of a Transport."""
1537
1758
self._supply_sub_formats_to(remote_format)
1538
1759
return remote_format.initialize_on_transport(transport)
1540
def initialize_on_transport_ex(self, transport, use_existing_dir=False,
1541
create_prefix=False, force_new_repo=False, stacked_on=None,
1542
stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
1543
shared_repo=False, vfs_only=False):
1544
"""Create this format on transport.
1546
The directory to initialize will be created.
1548
:param force_new_repo: Do not use a shared repository for the target,
1549
even if one is available.
1550
:param create_prefix: Create any missing directories leading up to
1552
:param use_existing_dir: Use an existing directory if one exists.
1553
:param stacked_on: A url to stack any created branch on, None to follow
1554
any target stacking policy.
1555
:param stack_on_pwd: If stack_on is relative, the location it is
1557
:param repo_format_name: If non-None, a repository will be
1558
made-or-found. Should none be found, or if force_new_repo is True
1559
the repo_format_name is used to select the format of repository to
1561
:param make_working_trees: Control the setting of make_working_trees
1562
for a new shared repository when one is made. None to use whatever
1563
default the format has.
1564
:param shared_repo: Control whether made repositories are shared or
1566
:param vfs_only: If True do not attempt to use a smart server
1567
:return: repo, bzrdir, require_stacking, repository_policy. repo is
1568
None if none was created or found, bzrdir is always valid.
1569
require_stacking is the result of examining the stacked_on
1570
parameter and any stacking policy found for the target.
1573
# Try to hand off to a smart server
1575
client_medium = transport.get_smart_medium()
1576
except errors.NoSmartMedium:
1579
# TODO: lookup the local format from a server hint.
1580
remote_dir_format = RemoteBzrDirFormat()
1581
remote_dir_format._network_name = self.network_name()
1582
self._supply_sub_formats_to(remote_dir_format)
1583
return remote_dir_format.initialize_on_transport_ex(transport,
1584
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
1585
force_new_repo=force_new_repo, stacked_on=stacked_on,
1586
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
1587
make_working_trees=make_working_trees, shared_repo=shared_repo)
1588
# XXX: Refactor the create_prefix/no_create_prefix code into a
1589
# common helper function
1590
# The destination may not exist - if so make it according to policy.
1591
def make_directory(transport):
1592
transport.mkdir('.')
1594
def redirected(transport, e, redirection_notice):
1595
note(redirection_notice)
1596
return transport._redirected_to(e.source, e.target)
1598
transport = do_catching_redirections(make_directory, transport,
1600
except errors.FileExists:
1601
if not use_existing_dir:
1603
except errors.NoSuchFile:
1604
if not create_prefix:
1606
transport.create_prefix()
1608
require_stacking = (stacked_on is not None)
1609
# Now the target directory exists, but doesn't have a .bzr
1610
# directory. So we need to create it, along with any work to create
1611
# all of the dependent branches, etc.
1613
result = self.initialize_on_transport(transport)
1614
if repo_format_name:
1616
# use a custom format
1617
result._format.repository_format = \
1618
repository.network_format_registry.get(repo_format_name)
1619
except AttributeError:
1620
# The format didn't permit it to be set.
1622
# A repository is desired, either in-place or shared.
1623
repository_policy = result.determine_repository_policy(
1624
force_new_repo, stacked_on, stack_on_pwd,
1625
require_stacking=require_stacking)
1626
result_repo, is_new_repo = repository_policy.acquire_repository(
1627
make_working_trees, shared_repo)
1628
if not require_stacking and repository_policy._require_stacking:
1629
require_stacking = True
1630
result._format.require_stacking()
1631
result_repo.lock_write()
1634
repository_policy = None
1635
return result_repo, result, require_stacking, repository_policy
1637
1761
def _initialize_on_transport_vfs(self, transport):
1638
1762
"""Initialize a new bzrdir using VFS calls.
1962
2135
def set_branch_format(self, format):
1963
2136
self._branch_format = format
1965
def require_stacking(self, stack_on=None, possible_transports=None,
1967
"""We have a request to stack, try to ensure the formats support it.
1969
:param stack_on: If supplied, it is the URL to a branch that we want to
1970
stack on. Check to see if that format supports stacking before
1973
# Stacking is desired. requested by the target, but does the place it
1974
# points at support stacking? If it doesn't then we should
1975
# not implicitly upgrade. We check this here.
1976
new_repo_format = None
1977
new_branch_format = None
1979
# a bit of state for get_target_branch so that we don't try to open it
1980
# 2 times, for both repo *and* branch
1981
target = [None, False, None] # target_branch, checked, upgrade anyway
1982
def get_target_branch():
1984
# We've checked, don't check again
1986
if stack_on is None:
1987
# No target format, that means we want to force upgrading
1988
target[:] = [None, True, True]
1991
target_dir = BzrDir.open(stack_on,
1992
possible_transports=possible_transports)
1993
except errors.NotBranchError:
1994
# Nothing there, don't change formats
1995
target[:] = [None, True, False]
1997
except errors.JailBreak:
1998
# JailBreak, JFDI and upgrade anyway
1999
target[:] = [None, True, True]
2002
target_branch = target_dir.open_branch()
2003
except errors.NotBranchError:
2004
# No branch, don't upgrade formats
2005
target[:] = [None, True, False]
2007
target[:] = [target_branch, True, False]
2010
if (not _skip_repo and
2011
not self.repository_format.supports_external_lookups):
2012
# We need to upgrade the Repository.
2013
target_branch, _, do_upgrade = get_target_branch()
2014
if target_branch is None:
2015
# We don't have a target branch, should we upgrade anyway?
2017
# stack_on is inaccessible, JFDI.
2018
# TODO: bad monkey, hard-coded formats...
2019
if self.repository_format.rich_root_data:
2020
new_repo_format = pack_repo.RepositoryFormatKnitPack5RichRoot()
2022
new_repo_format = pack_repo.RepositoryFormatKnitPack5()
2024
# If the target already supports stacking, then we know the
2025
# project is already able to use stacking, so auto-upgrade
2027
new_repo_format = target_branch.repository._format
2028
if not new_repo_format.supports_external_lookups:
2029
# target doesn't, source doesn't, so don't auto upgrade
2031
new_repo_format = None
2032
if new_repo_format is not None:
2033
self.repository_format = new_repo_format
2034
note('Source repository format does not support stacking,'
2035
' using format:\n %s',
2036
new_repo_format.get_format_description())
2138
def require_stacking(self):
2038
2139
if not self.get_branch_format().supports_stacking():
2039
# We just checked the repo, now lets check if we need to
2040
# upgrade the branch format
2041
target_branch, _, do_upgrade = get_target_branch()
2042
if target_branch is None:
2044
# TODO: bad monkey, hard-coded formats...
2045
new_branch_format = branch.BzrBranchFormat7()
2140
# We need to make a stacked branch, but the default format for the
2141
# target doesn't support stacking. So force a branch that *can*
2143
from bzrlib.branch import BzrBranchFormat7
2144
branch_format = BzrBranchFormat7()
2145
self.set_branch_format(branch_format)
2146
mutter("using %r for stacking" % (branch_format,))
2147
from bzrlib.repofmt import pack_repo
2148
if self.repository_format.rich_root_data:
2149
bzrdir_format_name = '1.6.1-rich-root'
2150
repo_format = pack_repo.RepositoryFormatKnitPack5RichRoot()
2047
new_branch_format = target_branch._format
2048
if not new_branch_format.supports_stacking():
2049
new_branch_format = None
2050
if new_branch_format is not None:
2051
# Does support stacking, use its format.
2052
self.set_branch_format(new_branch_format)
2053
note('Source branch format does not support stacking,'
2054
' using format:\n %s',
2055
new_branch_format.get_format_description())
2152
bzrdir_format_name = '1.6'
2153
repo_format = pack_repo.RepositoryFormatKnitPack5()
2154
note('Source format does not support stacking, using format:'
2156
bzrdir_format_name, repo_format.get_format_description())
2157
self.repository_format = repo_format
2057
2159
def get_converter(self, format=None):
2058
2160
"""See BzrDirFormat.get_converter()."""
2714
2811
return local_dir_format.initialize_on_transport(transport)
2715
2812
client = _SmartClient(client_medium)
2716
2813
path = client.remote_path_from_transport(transport)
2718
response = client.call('BzrDirFormat.initialize', path)
2719
except errors.ErrorFromSmartServer, err:
2720
remote._translate_error(err, path=path)
2814
response = client.call('BzrDirFormat.initialize', path)
2721
2815
if response[0] != 'ok':
2722
2816
raise errors.SmartProtocolError('unexpected response code %s' % (response,))
2723
2817
format = RemoteBzrDirFormat()
2724
2818
self._supply_sub_formats_to(format)
2725
2819
return remote.RemoteBzrDir(transport, format)
2727
def parse_NoneTrueFalse(self, arg):
2734
raise AssertionError("invalid arg %r" % arg)
2736
def _serialize_NoneTrueFalse(self, arg):
2743
def _serialize_NoneString(self, arg):
2746
def initialize_on_transport_ex(self, transport, use_existing_dir=False,
2747
create_prefix=False, force_new_repo=False, stacked_on=None,
2748
stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
2751
# hand off the request to the smart server
2752
client_medium = transport.get_smart_medium()
2753
except errors.NoSmartMedium:
2756
# Decline to open it if the server doesn't support our required
2757
# version (3) so that the VFS-based transport will do it.
2758
if client_medium.should_probe():
2760
server_version = client_medium.protocol_version()
2761
if server_version != '2':
2765
except errors.SmartProtocolError:
2766
# Apparently there's no usable smart server there, even though
2767
# the medium supports the smart protocol.
2772
client = _SmartClient(client_medium)
2773
path = client.remote_path_from_transport(transport)
2774
if client_medium._is_remote_before((1, 16)):
2777
# TODO: lookup the local format from a server hint.
2778
local_dir_format = BzrDirMetaFormat1()
2779
self._supply_sub_formats_to(local_dir_format)
2780
return local_dir_format.initialize_on_transport_ex(transport,
2781
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
2782
force_new_repo=force_new_repo, stacked_on=stacked_on,
2783
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
2784
make_working_trees=make_working_trees, shared_repo=shared_repo,
2786
return self._initialize_on_transport_ex_rpc(client, path, transport,
2787
use_existing_dir, create_prefix, force_new_repo, stacked_on,
2788
stack_on_pwd, repo_format_name, make_working_trees, shared_repo)
2790
def _initialize_on_transport_ex_rpc(self, client, path, transport,
2791
use_existing_dir, create_prefix, force_new_repo, stacked_on,
2792
stack_on_pwd, repo_format_name, make_working_trees, shared_repo):
2794
args.append(self._serialize_NoneTrueFalse(use_existing_dir))
2795
args.append(self._serialize_NoneTrueFalse(create_prefix))
2796
args.append(self._serialize_NoneTrueFalse(force_new_repo))
2797
args.append(self._serialize_NoneString(stacked_on))
2798
# stack_on_pwd is often/usually our transport
2801
stack_on_pwd = transport.relpath(stack_on_pwd)
2802
if not stack_on_pwd:
2804
except errors.PathNotChild:
2806
args.append(self._serialize_NoneString(stack_on_pwd))
2807
args.append(self._serialize_NoneString(repo_format_name))
2808
args.append(self._serialize_NoneTrueFalse(make_working_trees))
2809
args.append(self._serialize_NoneTrueFalse(shared_repo))
2810
request_network_name = self._network_name or \
2811
BzrDirFormat.get_default_format().network_name()
2813
response = client.call('BzrDirFormat.initialize_ex_1.16',
2814
request_network_name, path, *args)
2815
except errors.UnknownSmartMethod:
2816
client._medium._remember_remote_is_before((1,16))
2817
local_dir_format = BzrDirMetaFormat1()
2818
self._supply_sub_formats_to(local_dir_format)
2819
return local_dir_format.initialize_on_transport_ex(transport,
2820
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
2821
force_new_repo=force_new_repo, stacked_on=stacked_on,
2822
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
2823
make_working_trees=make_working_trees, shared_repo=shared_repo,
2825
except errors.ErrorFromSmartServer, err:
2826
remote._translate_error(err, path=path)
2827
repo_path = response[0]
2828
bzrdir_name = response[6]
2829
require_stacking = response[7]
2830
require_stacking = self.parse_NoneTrueFalse(require_stacking)
2831
format = RemoteBzrDirFormat()
2832
format._network_name = bzrdir_name
2833
self._supply_sub_formats_to(format)
2834
bzrdir = remote.RemoteBzrDir(transport, format, _client=client)
2836
repo_format = remote.response_tuple_to_repo_format(response[1:])
2837
if repo_path == '.':
2840
repo_bzrdir_format = RemoteBzrDirFormat()
2841
repo_bzrdir_format._network_name = response[5]
2842
repo_bzr = remote.RemoteBzrDir(transport.clone(repo_path),
2846
final_stack = response[8] or None
2847
final_stack_pwd = response[9] or None
2849
final_stack_pwd = urlutils.join(
2850
transport.base, final_stack_pwd)
2851
remote_repo = remote.RemoteRepository(repo_bzr, repo_format)
2852
if len(response) > 10:
2853
# Updated server verb that locks remotely.
2854
repo_lock_token = response[10] or None
2855
remote_repo.lock_write(repo_lock_token, _skip_rpc=True)
2857
remote_repo.dont_leave_lock_in_place()
2859
remote_repo.lock_write()
2860
policy = UseExistingRepository(remote_repo, final_stack,
2861
final_stack_pwd, require_stacking)
2862
policy.acquire_repository()
2866
bzrdir._format.set_branch_format(self.get_branch_format())
2867
if require_stacking:
2868
# The repo has already been created, but we need to make sure that
2869
# we'll make a stackable branch.
2870
bzrdir._format.require_stacking(_skip_repo=True)
2871
return remote_repo, bzrdir, require_stacking, policy
2873
2821
def _open(self, transport):
2874
2822
return remote.RemoteBzrDir(transport, self)
2908
2856
BzrDirMetaFormat1._set_repository_format) #.im_func)
2911
controldir.ControlDirFormat.register_server_prober(RemoteBzrProber)
2859
BzrDirFormat.register_control_server_format(RemoteBzrDirFormat)
2862
class BzrDirFormatInfo(object):
2864
def __init__(self, native, deprecated, hidden, experimental):
2865
self.deprecated = deprecated
2866
self.native = native
2867
self.hidden = hidden
2868
self.experimental = experimental
2871
class BzrDirFormatRegistry(registry.Registry):
2872
"""Registry of user-selectable BzrDir subformats.
2874
Differs from BzrDirFormat._control_formats in that it provides sub-formats,
2875
e.g. BzrDirMeta1 with weave repository. Also, it's more user-oriented.
2879
"""Create a BzrDirFormatRegistry."""
2880
self._aliases = set()
2881
self._registration_order = list()
2882
super(BzrDirFormatRegistry, self).__init__()
2885
"""Return a set of the format names which are aliases."""
2886
return frozenset(self._aliases)
2888
def register_metadir(self, key,
2889
repository_format, help, native=True, deprecated=False,
2895
"""Register a metadir subformat.
2897
These all use a BzrDirMetaFormat1 bzrdir, but can be parameterized
2898
by the Repository/Branch/WorkingTreeformats.
2900
:param repository_format: The fully-qualified repository format class
2902
:param branch_format: Fully-qualified branch format class name as
2904
:param tree_format: Fully-qualified tree format class name as
2907
# This should be expanded to support setting WorkingTree and Branch
2908
# formats, once BzrDirMetaFormat1 supports that.
2909
def _load(full_name):
2910
mod_name, factory_name = full_name.rsplit('.', 1)
2912
mod = __import__(mod_name, globals(), locals(),
2914
except ImportError, e:
2915
raise ImportError('failed to load %s: %s' % (full_name, e))
2917
factory = getattr(mod, factory_name)
2918
except AttributeError:
2919
raise AttributeError('no factory %s in module %r'
2924
bd = BzrDirMetaFormat1()
2925
if branch_format is not None:
2926
bd.set_branch_format(_load(branch_format))
2927
if tree_format is not None:
2928
bd.workingtree_format = _load(tree_format)
2929
if repository_format is not None:
2930
bd.repository_format = _load(repository_format)
2932
self.register(key, helper, help, native, deprecated, hidden,
2933
experimental, alias)
2935
def register(self, key, factory, help, native=True, deprecated=False,
2936
hidden=False, experimental=False, alias=False):
2937
"""Register a BzrDirFormat factory.
2939
The factory must be a callable that takes one parameter: the key.
2940
It must produce an instance of the BzrDirFormat when called.
2942
This function mainly exists to prevent the info object from being
2945
registry.Registry.register(self, key, factory, help,
2946
BzrDirFormatInfo(native, deprecated, hidden, experimental))
2948
self._aliases.add(key)
2949
self._registration_order.append(key)
2951
def register_lazy(self, key, module_name, member_name, help, native=True,
2952
deprecated=False, hidden=False, experimental=False, alias=False):
2953
registry.Registry.register_lazy(self, key, module_name, member_name,
2954
help, BzrDirFormatInfo(native, deprecated, hidden, experimental))
2956
self._aliases.add(key)
2957
self._registration_order.append(key)
2959
def set_default(self, key):
2960
"""Set the 'default' key to be a clone of the supplied key.
2962
This method must be called once and only once.
2964
registry.Registry.register(self, 'default', self.get(key),
2965
self.get_help(key), info=self.get_info(key))
2966
self._aliases.add('default')
2968
def set_default_repository(self, key):
2969
"""Set the FormatRegistry default and Repository default.
2971
This is a transitional method while Repository.set_default_format
2974
if 'default' in self:
2975
self.remove('default')
2976
self.set_default(key)
2977
format = self.get('default')()
2979
def make_bzrdir(self, key):
2980
return self.get(key)()
2982
def help_topic(self, topic):
2984
default_realkey = None
2985
default_help = self.get_help('default')
2987
for key in self._registration_order:
2988
if key == 'default':
2990
help = self.get_help(key)
2991
if help == default_help:
2992
default_realkey = key
2994
help_pairs.append((key, help))
2996
def wrapped(key, help, info):
2998
help = '(native) ' + help
2999
return ':%s:\n%s\n\n' % (key,
3000
textwrap.fill(help, initial_indent=' ',
3001
subsequent_indent=' '))
3002
if default_realkey is not None:
3003
output += wrapped(default_realkey, '(default) %s' % default_help,
3004
self.get_info('default'))
3005
deprecated_pairs = []
3006
experimental_pairs = []
3007
for key, help in help_pairs:
3008
info = self.get_info(key)
3011
elif info.deprecated:
3012
deprecated_pairs.append((key, help))
3013
elif info.experimental:
3014
experimental_pairs.append((key, help))
3016
output += wrapped(key, help, info)
3017
output += "\nSee ``bzr help formats`` for more about storage formats."
3019
if len(experimental_pairs) > 0:
3020
other_output += "Experimental formats are shown below.\n\n"
3021
for key, help in experimental_pairs:
3022
info = self.get_info(key)
3023
other_output += wrapped(key, help, info)
3026
"No experimental formats are available.\n\n"
3027
if len(deprecated_pairs) > 0:
3028
other_output += "\nDeprecated formats are shown below.\n\n"
3029
for key, help in deprecated_pairs:
3030
info = self.get_info(key)
3031
other_output += wrapped(key, help, info)
3034
"\nNo deprecated formats are available.\n\n"
3036
"\nSee ``bzr help formats`` for more about storage formats."
3038
if topic == 'other-formats':
2914
3044
class RepositoryAcquisitionPolicy(object):
3068
3224
return self._repository, False
3071
def register_metadir(registry, key,
3072
repository_format, help, native=True, deprecated=False,
3078
"""Register a metadir subformat.
3080
These all use a BzrDirMetaFormat1 bzrdir, but can be parameterized
3081
by the Repository/Branch/WorkingTreeformats.
3083
:param repository_format: The fully-qualified repository format class
3085
:param branch_format: Fully-qualified branch format class name as
3087
:param tree_format: Fully-qualified tree format class name as
3090
# This should be expanded to support setting WorkingTree and Branch
3091
# formats, once BzrDirMetaFormat1 supports that.
3092
def _load(full_name):
3093
mod_name, factory_name = full_name.rsplit('.', 1)
3095
mod = __import__(mod_name, globals(), locals(),
3097
except ImportError, e:
3098
raise ImportError('failed to load %s: %s' % (full_name, e))
3100
factory = getattr(mod, factory_name)
3101
except AttributeError:
3102
raise AttributeError('no factory %s in module %r'
3107
bd = BzrDirMetaFormat1()
3108
if branch_format is not None:
3109
bd.set_branch_format(_load(branch_format))
3110
if tree_format is not None:
3111
bd.workingtree_format = _load(tree_format)
3112
if repository_format is not None:
3113
bd.repository_format = _load(repository_format)
3115
registry.register(key, helper, help, native, deprecated, hidden,
3116
experimental, alias)
3227
# Please register new formats after old formats so that formats
3228
# appear in chronological order and format descriptions can build
3230
format_registry = BzrDirFormatRegistry()
3118
3231
# The pre-0.8 formats have their repository format network name registered in
3119
3232
# repository.py. MetaDir formats have their repository format network name
3120
3233
# inferred from their disk format string.
3121
controldir.format_registry.register('weave', BzrDirFormat6,
3234
format_registry.register('weave', BzrDirFormat6,
3122
3235
'Pre-0.8 format. Slower than knit and does not'
3123
3236
' support checkouts or shared repositories.',
3125
3237
deprecated=True)
3126
register_metadir(controldir.format_registry, 'metaweave',
3238
format_registry.register_metadir('metaweave',
3127
3239
'bzrlib.repofmt.weaverepo.RepositoryFormat7',
3128
3240
'Transitional format in 0.8. Slower than knit.',
3129
3241
branch_format='bzrlib.branch.BzrBranchFormat5',
3130
3242
tree_format='bzrlib.workingtree.WorkingTreeFormat3',
3132
3243
deprecated=True)
3133
register_metadir(controldir.format_registry, 'knit',
3244
format_registry.register_metadir('knit',
3134
3245
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
3135
3246
'Format using knits. Recommended for interoperation with bzr <= 0.14.',
3136
3247
branch_format='bzrlib.branch.BzrBranchFormat5',
3137
3248
tree_format='bzrlib.workingtree.WorkingTreeFormat3',
3139
3249
deprecated=True)
3140
register_metadir(controldir.format_registry, 'dirstate',
3250
format_registry.register_metadir('dirstate',
3141
3251
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
3142
3252
help='New in 0.15: Fast local operations. Compatible with bzr 0.8 and '
3143
3253
'above when accessed over the network.',
3174
3281
experimental=True,
3177
register_metadir(controldir.format_registry, 'pack-0.92',
3284
format_registry.register_metadir('pack-0.92',
3178
3285
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack1',
3179
3286
help='New in 0.92: Pack-based format with data compatible with '
3180
3287
'dirstate-tags format repositories. Interoperates with '
3181
3288
'bzr repositories before 0.92 but cannot be read by bzr < 0.92. '
3289
'Previously called knitpack-experimental. '
3290
'For more information, see '
3291
'http://doc.bazaar-vcs.org/latest/developers/packrepo.html.',
3183
3292
branch_format='bzrlib.branch.BzrBranchFormat6',
3184
3293
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3186
register_metadir(controldir.format_registry, 'pack-0.92-subtree',
3295
format_registry.register_metadir('pack-0.92-subtree',
3187
3296
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack3',
3188
3297
help='New in 0.92: Pack-based format with data compatible with '
3189
3298
'dirstate-with-subtree format repositories. Interoperates with '
3190
3299
'bzr repositories before 0.92 but cannot be read by bzr < 0.92. '
3300
'Previously called knitpack-experimental. '
3301
'For more information, see '
3302
'http://doc.bazaar-vcs.org/latest/developers/packrepo.html.',
3192
3303
branch_format='bzrlib.branch.BzrBranchFormat6',
3193
3304
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3195
3306
experimental=True,
3197
register_metadir(controldir.format_registry, 'rich-root-pack',
3308
format_registry.register_metadir('rich-root-pack',
3198
3309
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack4',
3199
3310
help='New in 1.0: A variant of pack-0.92 that supports rich-root data '
3200
3311
'(needed for bzr-svn and bzr-git).',
3201
3312
branch_format='bzrlib.branch.BzrBranchFormat6',
3202
3313
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3205
register_metadir(controldir.format_registry, '1.6',
3315
format_registry.register_metadir('1.6',
3206
3316
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack5',
3207
3317
help='A format that allows a branch to indicate that there is another '
3208
3318
'(stacked) repository that should be used to access data that is '
3209
3319
'not present locally.',
3210
3320
branch_format='bzrlib.branch.BzrBranchFormat7',
3211
3321
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3214
register_metadir(controldir.format_registry, '1.6.1-rich-root',
3323
format_registry.register_metadir('1.6.1-rich-root',
3215
3324
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack5RichRoot',
3216
3325
help='A variant of 1.6 that supports rich-root data '
3217
3326
'(needed for bzr-svn and bzr-git).',
3218
3327
branch_format='bzrlib.branch.BzrBranchFormat7',
3219
3328
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3222
register_metadir(controldir.format_registry, '1.9',
3330
format_registry.register_metadir('1.9',
3223
3331
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6',
3224
3332
help='A repository format using B+tree indexes. These indexes '
3225
3333
'are smaller in size, have smarter caching and provide faster '
3226
3334
'performance for most operations.',
3227
3335
branch_format='bzrlib.branch.BzrBranchFormat7',
3228
3336
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3231
register_metadir(controldir.format_registry, '1.9-rich-root',
3338
format_registry.register_metadir('1.9-rich-root',
3232
3339
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6RichRoot',
3233
3340
help='A variant of 1.9 that supports rich-root data '
3234
3341
'(needed for bzr-svn and bzr-git).',
3235
3342
branch_format='bzrlib.branch.BzrBranchFormat7',
3236
3343
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3239
register_metadir(controldir.format_registry, '1.14',
3345
format_registry.register_metadir('development-wt5',
3240
3346
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6',
3241
help='A working-tree format that supports content filtering.',
3347
help='A working-tree format that supports views and content filtering.',
3242
3348
branch_format='bzrlib.branch.BzrBranchFormat7',
3243
3349
tree_format='bzrlib.workingtree.WorkingTreeFormat5',
3245
register_metadir(controldir.format_registry, '1.14-rich-root',
3352
format_registry.register_metadir('development-wt5-rich-root',
3246
3353
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6RichRoot',
3247
help='A variant of 1.14 that supports rich-root data '
3354
help='A variant of development-wt5 that supports rich-root data '
3248
3355
'(needed for bzr-svn and bzr-git).',
3249
3356
branch_format='bzrlib.branch.BzrBranchFormat7',
3250
3357
tree_format='bzrlib.workingtree.WorkingTreeFormat5',
3252
# 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 '
3360
# The following two formats should always just be aliases.
3361
format_registry.register_metadir('development',
3362
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment2',
3363
help='Current development format. Can convert data to and from pack-0.92 '
3364
'(and anything compatible with pack-0.92) format repositories. '
3365
'Repositories and branches in this format can only be read by bzr.dev. '
3367
'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3261
3369
branch_format='bzrlib.branch.BzrBranchFormat7',
3262
tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3370
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3263
3371
experimental=True,
3267
register_metadir(controldir.format_registry, 'development5-subtree',
3374
format_registry.register_metadir('development-subtree',
3268
3375
'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 '
3275
branch_format='bzrlib.branch.BzrBranchFormat7',
3276
tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3283
register_metadir(controldir.format_registry, 'development-subtree',
3284
'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2aSubtree',
3285
3376
help='Current development format, subtree variant. Can convert data to and '
3286
3377
'from pack-0.92-subtree (and anything compatible with '
3287
3378
'pack-0.92-subtree) format repositories. Repositories and branches in '
3288
3379
'this format can only be read by bzr.dev. Please read '
3289
'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
3380
'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3291
3382
branch_format='bzrlib.branch.BzrBranchFormat7',
3292
tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3383
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3293
3384
experimental=True,
3295
alias=False, # Restore to being an alias when an actual development subtree format is added
3296
# This current non-alias status is simply because we did not introduce a
3297
# chk based subtree format.
3300
3387
# 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 '
3305
'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
3307
branch_format='bzrlib.branch.BzrBranchFormat7',
3308
tree_format='bzrlib.workingtree.WorkingTreeFormat6',
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 '
3319
branch_format='bzrlib.branch.BzrBranchFormat7',
3320
tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3325
register_metadir(controldir.format_registry, '2a',
3326
'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2a',
3327
help='First format for bzr 2.0 series.\n'
3328
'Uses group-compress storage.\n'
3329
'Provides rich roots which are a one-way transition.\n',
3330
# 'storage in packs, 255-way hashed CHK inventory, bencode revision, group compress, '
3331
# 'rich roots. Supported by bzr 1.16 and later.',
3332
branch_format='bzrlib.branch.BzrBranchFormat7',
3333
tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3388
format_registry.register_metadir('development2',
3389
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment2',
3390
help='1.6.1 with B+Tree based index. '
3392
'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3394
branch_format='bzrlib.branch.BzrBranchFormat7',
3395
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3399
format_registry.register_metadir('development2-subtree',
3400
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment2Subtree',
3401
help='1.6.1-subtree with B+Tree based index. '
3403
'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3405
branch_format='bzrlib.branch.BzrBranchFormat7',
3406
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3337
3410
# The following format should be an alias for the rich root equivalent
3338
3411
# of the default format
3339
register_metadir(controldir.format_registry, 'default-rich-root',
3340
'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2a',
3341
branch_format='bzrlib.branch.BzrBranchFormat7',
3342
tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3412
format_registry.register_metadir('default-rich-root',
3413
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack4',
3414
help='Default format, rich root variant. (needed for bzr-svn and bzr-git).',
3415
branch_format='bzrlib.branch.BzrBranchFormat6',
3416
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3347
3419
# The current format that is made on 'bzr init'.
3348
controldir.format_registry.set_default('2a')
3350
# XXX 2010-08-20 JRV: There is still a lot of code relying on
3351
# bzrlib.bzrdir.format_registry existing. When BzrDir.create/BzrDir.open/etc
3352
# get changed to ControlDir.create/ControlDir.open/etc this should be removed.
3353
format_registry = controldir.format_registry
3420
format_registry.set_default('pack-0.92')