233
209
errors.UnstackableRepositoryFormat,
234
210
errors.NotStacked):
236
# Bug: We create a metadir without knowing if it can support stacking,
237
# we should look up the policy needs first, or just use it as a hint,
214
# may need to copy content in
215
repository_policy = result.determine_repository_policy(
216
force_new_repo, stacked_on, self.root_transport.base,
217
require_stacking=require_stacking)
240
218
make_working_trees = local_repo.make_working_trees()
241
want_shared = local_repo.is_shared()
242
repo_format_name = format.repository_format.network_name()
244
make_working_trees = False
246
repo_format_name = None
248
result_repo, result, require_stacking, repository_policy = \
249
format.initialize_on_transport_ex(transport,
250
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
251
force_new_repo=force_new_repo, stacked_on=stacked_on,
252
stack_on_pwd=self.root_transport.base,
253
repo_format_name=repo_format_name,
254
make_working_trees=make_working_trees, shared_repo=want_shared)
257
# If the result repository is in the same place as the
258
# resulting bzr dir, it will have no content, further if the
259
# result is not stacked then we know all content should be
260
# copied, and finally if we are copying up to a specific
261
# revision_id then we can use the pending-ancestry-result which
262
# does not require traversing all of history to describe it.
263
if (result_repo.bzrdir.root_transport.base ==
264
result.root_transport.base and not require_stacking and
265
revision_id is not None):
266
fetch_spec = graph.PendingAncestryResult(
267
[revision_id], local_repo)
268
result_repo.fetch(local_repo, fetch_spec=fetch_spec)
270
result_repo.fetch(local_repo, revision_id=revision_id)
274
if result_repo is not None:
275
raise AssertionError('result_repo not None(%r)' % result_repo)
219
result_repo = repository_policy.acquire_repository(
220
make_working_trees, local_repo.is_shared())
221
result_repo.fetch(local_repo, revision_id=revision_id)
276
224
# 1 if there is a branch present
277
225
# make sure its content is available in the target repository
279
227
if local_branch is not None:
280
result_branch = local_branch.clone(result, revision_id=revision_id,
281
repository_policy=repository_policy)
283
# Cheaper to check if the target is not local, than to try making
285
result.root_transport.local_abspath('.')
286
if result_repo is None or result_repo.make_working_trees():
228
result_branch = local_branch.clone(result, revision_id=revision_id)
229
if repository_policy is not None:
230
repository_policy.configure_branch(result_branch)
231
if result_repo is None or result_repo.make_working_trees():
287
233
self.open_workingtree().clone(result)
288
except (errors.NoWorkingTree, errors.NotLocalUrl):
234
except (errors.NoWorkingTree, errors.NotLocalUrl):
292
238
# TODO: This should be given a Transport, and should chdir up; otherwise
850
773
:param transport: Transport containing the bzrdir.
851
774
:param _unsupported: private.
853
for hook in BzrDir.hooks['pre_open']:
855
# Keep initial base since 'transport' may be modified while following
857
776
base = transport.base
858
778
def find_format(transport):
859
779
return transport, BzrDirFormat.find_format(
860
780
transport, _server_formats=_server_formats)
862
782
def redirected(transport, e, redirection_notice):
863
redirected_transport = transport._redirected_to(e.source, e.target)
864
if redirected_transport is None:
865
raise errors.NotBranchError(base)
783
qualified_source = e.get_source_url()
784
relpath = transport.relpath(qualified_source)
785
if not e.target.endswith(relpath):
786
# Not redirected to a branch-format, not a branch
787
raise errors.NotBranchError(path=e.target)
788
target = e.target[:-len(relpath)]
866
789
note('%s is%s redirected to %s',
867
transport.base, e.permanently, redirected_transport.base)
868
return redirected_transport
790
transport.base, e.permanently, target)
791
# Let's try with a new transport
792
# FIXME: If 'transport' has a qualifier, this should
793
# be applied again to the new transport *iff* the
794
# schemes used are the same. Uncomment this code
795
# once the function (and tests) exist.
797
#target = urlutils.copy_url_qualifiers(original, target)
798
return get_transport(target)
871
801
transport, format = do_catching_redirections(find_format,
1140
1082
where possible.
1141
1083
:param stacked: If true, create a stacked branch referring to the
1142
1084
location of this control directory.
1143
:param create_tree_if_local: If true, a working-tree will be created
1144
when working locally.
1146
1086
target_transport = get_transport(url, possible_transports)
1147
1087
target_transport.ensure_base()
1148
1088
cloning_format = self.cloning_metadir(stacked)
1149
1089
# Create/update the result branch
1150
1090
result = cloning_format.initialize_on_transport(target_transport)
1151
# if a stacked branch wasn't requested, we don't create one
1152
# even if the origin was stacked
1153
stacked_branch_url = None
1154
if source_branch is not None:
1092
source_branch = self.open_branch()
1093
source_repository = source_branch.repository
1156
1095
stacked_branch_url = self.root_transport.base
1157
source_repository = source_branch.repository
1097
# if a stacked branch wasn't requested, we don't create one
1098
# even if the origin was stacked
1099
stacked_branch_url = None
1100
except errors.NotBranchError:
1101
source_branch = None
1160
source_branch = self.open_branch()
1161
source_repository = source_branch.repository
1163
stacked_branch_url = self.root_transport.base
1164
except errors.NotBranchError:
1165
source_branch = None
1167
source_repository = self.open_repository()
1168
except errors.NoRepositoryPresent:
1169
source_repository = None
1103
source_repository = self.open_repository()
1104
except errors.NoRepositoryPresent:
1105
source_repository = None
1106
stacked_branch_url = None
1170
1107
repository_policy = result.determine_repository_policy(
1171
1108
force_new_repo, stacked_branch_url, require_stacking=stacked)
1172
result_repo, is_new_repo = repository_policy.acquire_repository()
1173
if is_new_repo and revision_id is not None and not stacked:
1174
fetch_spec = graph.PendingAncestryResult(
1175
[revision_id], source_repository)
1109
result_repo = repository_policy.acquire_repository()
1178
1110
if source_repository is not None:
1179
1111
# Fetch while stacked to prevent unstacked fetch from
1180
1112
# Branch.sprout.
1181
if fetch_spec is None:
1182
result_repo.fetch(source_repository, revision_id=revision_id)
1184
result_repo.fetch(source_repository, fetch_spec=fetch_spec)
1113
result_repo.fetch(source_repository, revision_id=revision_id)
1186
1115
if source_branch is None:
1187
1116
# this is for sprouting a bzrdir without a branch; is that
1242
def push_branch(self, source, revision_id=None, overwrite=False,
1243
remember=False, create_prefix=False):
1244
"""Push the source branch into this BzrDir."""
1246
# If we can open a branch, use its direct repository, otherwise see
1247
# if there is a repository without a branch.
1249
br_to = self.open_branch()
1250
except errors.NotBranchError:
1251
# Didn't find a branch, can we find a repository?
1252
repository_to = self.find_repository()
1254
# Found a branch, so we must have found a repository
1255
repository_to = br_to.repository
1257
push_result = PushResult()
1258
push_result.source_branch = source
1260
# We have a repository but no branch, copy the revisions, and then
1262
repository_to.fetch(source.repository, revision_id=revision_id)
1263
br_to = source.clone(self, revision_id=revision_id)
1264
if source.get_push_location() is None or remember:
1265
source.set_push_location(br_to.base)
1266
push_result.stacked_on = None
1267
push_result.branch_push_result = None
1268
push_result.old_revno = None
1269
push_result.old_revid = _mod_revision.NULL_REVISION
1270
push_result.target_branch = br_to
1271
push_result.master_branch = None
1272
push_result.workingtree_updated = False
1274
# We have successfully opened the branch, remember if necessary:
1275
if source.get_push_location() is None or remember:
1276
source.set_push_location(br_to.base)
1278
tree_to = self.open_workingtree()
1279
except errors.NotLocalUrl:
1280
push_result.branch_push_result = source.push(br_to,
1281
overwrite, stop_revision=revision_id)
1282
push_result.workingtree_updated = False
1283
except errors.NoWorkingTree:
1284
push_result.branch_push_result = source.push(br_to,
1285
overwrite, stop_revision=revision_id)
1286
push_result.workingtree_updated = None # Not applicable
1288
tree_to.lock_write()
1290
push_result.branch_push_result = source.push(
1291
tree_to.branch, overwrite, stop_revision=revision_id)
1295
push_result.workingtree_updated = True
1296
push_result.old_revno = push_result.branch_push_result.old_revno
1297
push_result.old_revid = push_result.branch_push_result.old_revid
1298
push_result.target_branch = \
1299
push_result.branch_push_result.target_branch
1303
class BzrDirHooks(hooks.Hooks):
1304
"""Hooks for BzrDir operations."""
1307
"""Create the default hooks."""
1308
hooks.Hooks.__init__(self)
1309
self.create_hook(hooks.HookPoint('pre_open',
1310
"Invoked before attempting to open a BzrDir with the transport "
1311
"that the open will use.", (1, 14), None))
1313
# install the default hooks
1314
BzrDir.hooks = BzrDirHooks()
1317
1179
class BzrDirPreSplitOut(BzrDir):
1318
1180
"""A common class for the all-in-one formats."""
1879
1689
def initialize_on_transport(self, transport):
1880
1690
"""Initialize a new bzrdir in the base directory of a Transport."""
1882
# can we hand off the request to the smart server rather than using
1884
client_medium = transport.get_smart_medium()
1885
except errors.NoSmartMedium:
1886
return self._initialize_on_transport_vfs(transport)
1888
# Current RPC's only know how to create bzr metadir1 instances, so
1889
# we still delegate to vfs methods if the requested format is not a
1891
if type(self) != BzrDirMetaFormat1:
1892
return self._initialize_on_transport_vfs(transport)
1893
remote_format = RemoteBzrDirFormat()
1894
self._supply_sub_formats_to(remote_format)
1895
return remote_format.initialize_on_transport(transport)
1897
def initialize_on_transport_ex(self, transport, use_existing_dir=False,
1898
create_prefix=False, force_new_repo=False, stacked_on=None,
1899
stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
1900
shared_repo=False, vfs_only=False):
1901
"""Create this format on transport.
1903
The directory to initialize will be created.
1905
:param force_new_repo: Do not use a shared repository for the target,
1906
even if one is available.
1907
:param create_prefix: Create any missing directories leading up to
1909
:param use_existing_dir: Use an existing directory if one exists.
1910
:param stacked_on: A url to stack any created branch on, None to follow
1911
any target stacking policy.
1912
:param stack_on_pwd: If stack_on is relative, the location it is
1914
:param repo_format_name: If non-None, a repository will be
1915
made-or-found. Should none be found, or if force_new_repo is True
1916
the repo_format_name is used to select the format of repository to
1918
:param make_working_trees: Control the setting of make_working_trees
1919
for a new shared repository when one is made. None to use whatever
1920
default the format has.
1921
:param shared_repo: Control whether made repositories are shared or
1923
:param vfs_only: If True do not attempt to use a smart server
1924
:return: repo, bzrdir, require_stacking, repository_policy. repo is
1925
None if none was created or found, bzrdir is always valid.
1926
require_stacking is the result of examining the stacked_on
1927
parameter and any stacking policy found for the target.
1930
# Try to hand off to a smart server
1932
client_medium = transport.get_smart_medium()
1933
except errors.NoSmartMedium:
1936
# TODO: lookup the local format from a server hint.
1937
remote_dir_format = RemoteBzrDirFormat()
1938
remote_dir_format._network_name = self.network_name()
1939
self._supply_sub_formats_to(remote_dir_format)
1940
return remote_dir_format.initialize_on_transport_ex(transport,
1941
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
1942
force_new_repo=force_new_repo, stacked_on=stacked_on,
1943
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
1944
make_working_trees=make_working_trees, shared_repo=shared_repo)
1945
# XXX: Refactor the create_prefix/no_create_prefix code into a
1946
# common helper function
1947
# The destination may not exist - if so make it according to policy.
1948
def make_directory(transport):
1949
transport.mkdir('.')
1951
def redirected(transport, e, redirection_notice):
1952
note(redirection_notice)
1953
return transport._redirected_to(e.source, e.target)
1955
transport = do_catching_redirections(make_directory, transport,
1957
except errors.FileExists:
1958
if not use_existing_dir:
1960
except errors.NoSuchFile:
1961
if not create_prefix:
1963
transport.create_prefix()
1965
require_stacking = (stacked_on is not None)
1966
# Now the target directory exists, but doesn't have a .bzr
1967
# directory. So we need to create it, along with any work to create
1968
# all of the dependent branches, etc.
1970
result = self.initialize_on_transport(transport)
1971
if repo_format_name:
1973
# use a custom format
1974
result._format.repository_format = \
1975
repository.network_format_registry.get(repo_format_name)
1976
except AttributeError:
1977
# The format didn't permit it to be set.
1979
# A repository is desired, either in-place or shared.
1980
repository_policy = result.determine_repository_policy(
1981
force_new_repo, stacked_on, stack_on_pwd,
1982
require_stacking=require_stacking)
1983
result_repo, is_new_repo = repository_policy.acquire_repository(
1984
make_working_trees, shared_repo)
1985
if not require_stacking and repository_policy._require_stacking:
1986
require_stacking = True
1987
result._format.require_stacking()
1988
result_repo.lock_write()
1991
repository_policy = None
1992
return result_repo, result, require_stacking, repository_policy
1994
def _initialize_on_transport_vfs(self, transport):
1995
"""Initialize a new bzrdir using VFS calls.
1997
:param transport: The transport to create the .bzr directory in.
2000
# Since we are creating a .bzr directory, inherit the
1691
# Since we don't have a .bzr directory, inherit the
2001
1692
# mode from the root directory
2002
1693
temp_control = lockable_files.LockableFiles(transport,
2003
1694
'', lockable_files.TransportLock)
2208
1869
repository_format = property(__return_repository_format)
2211
class BzrDirFormatAllInOne(BzrDirFormat):
2212
"""Common class for formats before meta-dirs."""
2214
def initialize_on_transport_ex(self, transport, use_existing_dir=False,
2215
create_prefix=False, force_new_repo=False, stacked_on=None,
2216
stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
2218
"""See BzrDirFormat.initialize_on_transport_ex."""
2219
require_stacking = (stacked_on is not None)
2220
# Format 5 cannot stack, but we've been asked to - actually init
2222
if require_stacking:
2223
format = BzrDirMetaFormat1()
2224
return format.initialize_on_transport_ex(transport,
2225
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
2226
force_new_repo=force_new_repo, stacked_on=stacked_on,
2227
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
2228
make_working_trees=make_working_trees, shared_repo=shared_repo)
2229
return BzrDirFormat.initialize_on_transport_ex(self, transport,
2230
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
2231
force_new_repo=force_new_repo, stacked_on=stacked_on,
2232
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
2233
make_working_trees=make_working_trees, shared_repo=shared_repo)
2236
class BzrDirFormat5(BzrDirFormatAllInOne):
1872
class BzrDirFormat5(BzrDirFormat):
2237
1873
"""Bzr control format 5.
2239
1875
This format is a combined format for working tree, branch and repository.
2241
- Format 2 working trees [always]
2242
- Format 4 branches [always]
1877
- Format 2 working trees [always]
1878
- Format 4 branches [always]
2243
1879
- Format 5 repositories [always]
2244
1880
Unhashed stores in the repository.
2393
2022
def set_branch_format(self, format):
2394
2023
self._branch_format = format
2396
def require_stacking(self, stack_on=None, possible_transports=None,
2398
"""We have a request to stack, try to ensure the formats support it.
2400
:param stack_on: If supplied, it is the URL to a branch that we want to
2401
stack on. Check to see if that format supports stacking before
2404
# Stacking is desired. requested by the target, but does the place it
2405
# points at support stacking? If it doesn't then we should
2406
# not implicitly upgrade. We check this here.
2407
new_repo_format = None
2408
new_branch_format = None
2410
# a bit of state for get_target_branch so that we don't try to open it
2411
# 2 times, for both repo *and* branch
2412
target = [None, False, None] # target_branch, checked, upgrade anyway
2413
def get_target_branch():
2415
# We've checked, don't check again
2417
if stack_on is None:
2418
# No target format, that means we want to force upgrading
2419
target[:] = [None, True, True]
2422
target_dir = BzrDir.open(stack_on,
2423
possible_transports=possible_transports)
2424
except errors.NotBranchError:
2425
# Nothing there, don't change formats
2426
target[:] = [None, True, False]
2428
except errors.JailBreak:
2429
# JailBreak, JFDI and upgrade anyway
2430
target[:] = [None, True, True]
2433
target_branch = target_dir.open_branch()
2434
except errors.NotBranchError:
2435
# No branch, don't upgrade formats
2436
target[:] = [None, True, False]
2438
target[:] = [target_branch, True, False]
2441
if (not _skip_repo and
2442
not self.repository_format.supports_external_lookups):
2443
# We need to upgrade the Repository.
2444
target_branch, _, do_upgrade = get_target_branch()
2445
if target_branch is None:
2446
# We don't have a target branch, should we upgrade anyway?
2448
# stack_on is inaccessible, JFDI.
2449
# TODO: bad monkey, hard-coded formats...
2450
if self.repository_format.rich_root_data:
2451
new_repo_format = pack_repo.RepositoryFormatKnitPack5RichRoot()
2453
new_repo_format = pack_repo.RepositoryFormatKnitPack5()
2455
# If the target already supports stacking, then we know the
2456
# project is already able to use stacking, so auto-upgrade
2458
new_repo_format = target_branch.repository._format
2459
if not new_repo_format.supports_external_lookups:
2460
# target doesn't, source doesn't, so don't auto upgrade
2462
new_repo_format = None
2463
if new_repo_format is not None:
2464
self.repository_format = new_repo_format
2465
note('Source repository format does not support stacking,'
2466
' using format:\n %s',
2467
new_repo_format.get_format_description())
2469
if not self.get_branch_format().supports_stacking():
2470
# We just checked the repo, now lets check if we need to
2471
# upgrade the branch format
2472
target_branch, _, do_upgrade = get_target_branch()
2473
if target_branch is None:
2475
# TODO: bad monkey, hard-coded formats...
2476
new_branch_format = branch.BzrBranchFormat7()
2478
new_branch_format = target_branch._format
2479
if not new_branch_format.supports_stacking():
2480
new_branch_format = None
2481
if new_branch_format is not None:
2482
# Does support stacking, use its format.
2483
self.set_branch_format(new_branch_format)
2484
note('Source branch format does not support stacking,'
2485
' using format:\n %s',
2486
new_branch_format.get_format_description())
2488
2025
def get_converter(self, format=None):
2489
2026
"""See BzrDirFormat.get_converter()."""
2490
2027
if format is None:
2502
2039
"""See BzrDirFormat.get_format_description()."""
2503
2040
return "Meta directory format 1"
2505
def network_name(self):
2506
return self.get_format_string()
2508
2042
def _open(self, transport):
2509
2043
"""See BzrDirFormat._open."""
2510
# Create a new format instance because otherwise initialisation of new
2511
# metadirs share the global default format object leading to alias
2513
format = BzrDirMetaFormat1()
2514
self._supply_sub_formats_to(format)
2515
return BzrDirMeta1(transport, format)
2044
return BzrDirMeta1(transport, self)
2517
2046
def __return_repository_format(self):
2518
2047
"""Circular import protection."""
2519
if self._repository_format:
2048
if getattr(self, '_repository_format', None):
2520
2049
return self._repository_format
2521
2050
from bzrlib.repository import RepositoryFormat
2522
2051
return RepositoryFormat.get_default_format()
2524
def _set_repository_format(self, value):
2053
def __set_repository_format(self, value):
2525
2054
"""Allow changing the repository format for metadir formats."""
2526
2055
self._repository_format = value
2528
repository_format = property(__return_repository_format,
2529
_set_repository_format)
2531
def _supply_sub_formats_to(self, other_format):
2532
"""Give other_format the same values for sub formats as this has.
2534
This method is expected to be used when parameterising a
2535
RemoteBzrDirFormat instance with the parameters from a
2536
BzrDirMetaFormat1 instance.
2538
:param other_format: other_format is a format which should be
2539
compatible with whatever sub formats are supported by self.
2542
if getattr(self, '_repository_format', None) is not None:
2543
other_format.repository_format = self.repository_format
2544
if self._branch_format is not None:
2545
other_format._branch_format = self._branch_format
2546
if self._workingtree_format is not None:
2547
other_format.workingtree_format = self.workingtree_format
2057
repository_format = property(__return_repository_format, __set_repository_format)
2549
2059
def __get_workingtree_format(self):
2550
2060
if self._workingtree_format is None:
3082
2582
# TODO: conversions of Branch and Tree should be done by
3083
2583
# InterXFormat lookups
3084
2584
if (isinstance(tree, workingtree.WorkingTree3) and
3085
not isinstance(tree, workingtree_4.DirStateWorkingTree) and
2585
not isinstance(tree, workingtree_4.WorkingTree4) and
3086
2586
isinstance(self.target_format.workingtree_format,
3087
workingtree_4.DirStateWorkingTreeFormat)):
2587
workingtree_4.WorkingTreeFormat4)):
3088
2588
workingtree_4.Converter3to4().convert(tree)
3089
if (isinstance(tree, workingtree_4.DirStateWorkingTree) and
3090
not isinstance(tree, workingtree_4.WorkingTree5) and
3091
isinstance(self.target_format.workingtree_format,
3092
workingtree_4.WorkingTreeFormat5)):
3093
workingtree_4.Converter4to5().convert(tree)
3094
if (isinstance(tree, workingtree_4.DirStateWorkingTree) and
3095
not isinstance(tree, workingtree_4.WorkingTree6) and
3096
isinstance(self.target_format.workingtree_format,
3097
workingtree_4.WorkingTreeFormat6)):
3098
workingtree_4.Converter4or5to6().convert(tree)
3099
2589
return to_convert
3102
# This is not in remote.py because it's relatively small, and needs to be
3103
# registered. Putting it in remote.py creates a circular import problem.
2592
# This is not in remote.py because it's small, and needs to be registered.
2593
# Putting it in remote.py creates a circular import problem.
3104
2594
# we can make it a lazy object if the control formats is turned into something
3105
2595
# like a registry.
3106
2596
class RemoteBzrDirFormat(BzrDirMetaFormat1):
3107
2597
"""Format representing bzrdirs accessed via a smart server"""
3110
BzrDirMetaFormat1.__init__(self)
3111
# XXX: It's a bit ugly that the network name is here, because we'd
3112
# like to believe that format objects are stateless or at least
3113
# immutable, However, we do at least avoid mutating the name after
3114
# it's returned. See <https://bugs.edge.launchpad.net/bzr/+bug/504102>
3115
self._network_name = None
3118
return "%s(_network_name=%r)" % (self.__class__.__name__,
3121
2599
def get_format_description(self):
3122
if self._network_name:
3123
real_format = network_format_registry.get(self._network_name)
3124
return 'Remote: ' + real_format.get_format_description()
3125
2600
return 'bzr remote bzrdir'
3127
def get_format_string(self):
3128
raise NotImplementedError(self.get_format_string)
3130
def network_name(self):
3131
if self._network_name:
3132
return self._network_name
3134
raise AssertionError("No network name set.")
3137
2603
def probe_transport(klass, transport):
3138
2604
"""Return a RemoteBzrDirFormat object if it looks possible."""
3167
2633
return local_dir_format.initialize_on_transport(transport)
3168
2634
client = _SmartClient(client_medium)
3169
2635
path = client.remote_path_from_transport(transport)
3171
response = client.call('BzrDirFormat.initialize', path)
3172
except errors.ErrorFromSmartServer, err:
3173
remote._translate_error(err, path=path)
2636
response = client.call('BzrDirFormat.initialize', path)
3174
2637
if response[0] != 'ok':
3175
2638
raise errors.SmartProtocolError('unexpected response code %s' % (response,))
3176
format = RemoteBzrDirFormat()
3177
self._supply_sub_formats_to(format)
3178
return remote.RemoteBzrDir(transport, format)
3180
def parse_NoneTrueFalse(self, arg):
3187
raise AssertionError("invalid arg %r" % arg)
3189
def _serialize_NoneTrueFalse(self, arg):
3196
def _serialize_NoneString(self, arg):
3199
def initialize_on_transport_ex(self, transport, use_existing_dir=False,
3200
create_prefix=False, force_new_repo=False, stacked_on=None,
3201
stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
3204
# hand off the request to the smart server
3205
client_medium = transport.get_smart_medium()
3206
except errors.NoSmartMedium:
3209
# Decline to open it if the server doesn't support our required
3210
# version (3) so that the VFS-based transport will do it.
3211
if client_medium.should_probe():
3213
server_version = client_medium.protocol_version()
3214
if server_version != '2':
3218
except errors.SmartProtocolError:
3219
# Apparently there's no usable smart server there, even though
3220
# the medium supports the smart protocol.
3225
client = _SmartClient(client_medium)
3226
path = client.remote_path_from_transport(transport)
3227
if client_medium._is_remote_before((1, 16)):
3230
# TODO: lookup the local format from a server hint.
3231
local_dir_format = BzrDirMetaFormat1()
3232
self._supply_sub_formats_to(local_dir_format)
3233
return local_dir_format.initialize_on_transport_ex(transport,
3234
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
3235
force_new_repo=force_new_repo, stacked_on=stacked_on,
3236
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
3237
make_working_trees=make_working_trees, shared_repo=shared_repo,
3239
return self._initialize_on_transport_ex_rpc(client, path, transport,
3240
use_existing_dir, create_prefix, force_new_repo, stacked_on,
3241
stack_on_pwd, repo_format_name, make_working_trees, shared_repo)
3243
def _initialize_on_transport_ex_rpc(self, client, path, transport,
3244
use_existing_dir, create_prefix, force_new_repo, stacked_on,
3245
stack_on_pwd, repo_format_name, make_working_trees, shared_repo):
3247
args.append(self._serialize_NoneTrueFalse(use_existing_dir))
3248
args.append(self._serialize_NoneTrueFalse(create_prefix))
3249
args.append(self._serialize_NoneTrueFalse(force_new_repo))
3250
args.append(self._serialize_NoneString(stacked_on))
3251
# stack_on_pwd is often/usually our transport
3254
stack_on_pwd = transport.relpath(stack_on_pwd)
3255
if not stack_on_pwd:
3257
except errors.PathNotChild:
3259
args.append(self._serialize_NoneString(stack_on_pwd))
3260
args.append(self._serialize_NoneString(repo_format_name))
3261
args.append(self._serialize_NoneTrueFalse(make_working_trees))
3262
args.append(self._serialize_NoneTrueFalse(shared_repo))
3263
request_network_name = self._network_name or \
3264
BzrDirFormat.get_default_format().network_name()
3266
response = client.call('BzrDirFormat.initialize_ex_1.16',
3267
request_network_name, path, *args)
3268
except errors.UnknownSmartMethod:
3269
client._medium._remember_remote_is_before((1,16))
3270
local_dir_format = BzrDirMetaFormat1()
3271
self._supply_sub_formats_to(local_dir_format)
3272
return local_dir_format.initialize_on_transport_ex(transport,
3273
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
3274
force_new_repo=force_new_repo, stacked_on=stacked_on,
3275
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
3276
make_working_trees=make_working_trees, shared_repo=shared_repo,
3278
except errors.ErrorFromSmartServer, err:
3279
remote._translate_error(err, path=path)
3280
repo_path = response[0]
3281
bzrdir_name = response[6]
3282
require_stacking = response[7]
3283
require_stacking = self.parse_NoneTrueFalse(require_stacking)
3284
format = RemoteBzrDirFormat()
3285
format._network_name = bzrdir_name
3286
self._supply_sub_formats_to(format)
3287
bzrdir = remote.RemoteBzrDir(transport, format, _client=client)
3289
repo_format = remote.response_tuple_to_repo_format(response[1:])
3290
if repo_path == '.':
3293
repo_bzrdir_format = RemoteBzrDirFormat()
3294
repo_bzrdir_format._network_name = response[5]
3295
repo_bzr = remote.RemoteBzrDir(transport.clone(repo_path),
3299
final_stack = response[8] or None
3300
final_stack_pwd = response[9] or None
3302
final_stack_pwd = urlutils.join(
3303
transport.base, final_stack_pwd)
3304
remote_repo = remote.RemoteRepository(repo_bzr, repo_format)
3305
if len(response) > 10:
3306
# Updated server verb that locks remotely.
3307
repo_lock_token = response[10] or None
3308
remote_repo.lock_write(repo_lock_token, _skip_rpc=True)
3310
remote_repo.dont_leave_lock_in_place()
3312
remote_repo.lock_write()
3313
policy = UseExistingRepository(remote_repo, final_stack,
3314
final_stack_pwd, require_stacking)
3315
policy.acquire_repository()
3319
bzrdir._format.set_branch_format(self.get_branch_format())
3320
if require_stacking:
3321
# The repo has already been created, but we need to make sure that
3322
# we'll make a stackable branch.
3323
bzrdir._format.require_stacking(_skip_repo=True)
3324
return remote_repo, bzrdir, require_stacking, policy
2639
return remote.RemoteBzrDir(transport)
3326
2641
def _open(self, transport):
3327
return remote.RemoteBzrDir(transport, self)
2642
return remote.RemoteBzrDir(transport)
3329
2644
def __eq__(self, other):
3330
2645
if not isinstance(other, RemoteBzrDirFormat):
3332
2647
return self.get_format_description() == other.get_format_description()
3334
def __return_repository_format(self):
3335
# Always return a RemoteRepositoryFormat object, but if a specific bzr
3336
# repository format has been asked for, tell the RemoteRepositoryFormat
3337
# that it should use that for init() etc.
3338
result = remote.RemoteRepositoryFormat()
3339
custom_format = getattr(self, '_repository_format', None)
3341
if isinstance(custom_format, remote.RemoteRepositoryFormat):
3342
return custom_format
3344
# We will use the custom format to create repositories over the
3345
# wire; expose its details like rich_root_data for code to
3347
result._custom_format = custom_format
3350
def get_branch_format(self):
3351
result = BzrDirMetaFormat1.get_branch_format(self)
3352
if not isinstance(result, remote.RemoteBranchFormat):
3353
new_result = remote.RemoteBranchFormat()
3354
new_result._custom_format = result
3356
self.set_branch_format(new_result)
3360
repository_format = property(__return_repository_format,
3361
BzrDirMetaFormat1._set_repository_format) #.im_func)
3364
2650
BzrDirFormat.register_control_server_format(RemoteBzrDirFormat)
3697
2946
def acquire_repository(self, make_working_trees=None, shared=False):
3698
2947
"""Implementation of RepositoryAcquisitionPolicy.acquire_repository
3700
Returns an existing repository to use.
2949
Returns an existing repository to use
3702
self._add_fallback(self._repository,
3703
possible_transports=[self._repository.bzrdir.transport])
3704
return self._repository, False
3707
# Please register new formats after old formats so that formats
3708
# appear in chronological order and format descriptions can build
2951
self._add_fallback(self._repository)
2952
return self._repository
3710
2955
format_registry = BzrDirFormatRegistry()
3711
# The pre-0.8 formats have their repository format network name registered in
3712
# repository.py. MetaDir formats have their repository format network name
3713
# inferred from their disk format string.
3714
2956
format_registry.register('weave', BzrDirFormat6,
3715
2957
'Pre-0.8 format. Slower than knit and does not'
3716
2958
' support checkouts or shared repositories.',
3718
2959
deprecated=True)
2960
format_registry.register_metadir('knit',
2961
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2962
'Format using knits. Recommended for interoperation with bzr <= 0.14.',
2963
branch_format='bzrlib.branch.BzrBranchFormat5',
2964
tree_format='bzrlib.workingtree.WorkingTreeFormat3')
3719
2965
format_registry.register_metadir('metaweave',
3720
2966
'bzrlib.repofmt.weaverepo.RepositoryFormat7',
3721
2967
'Transitional format in 0.8. Slower than knit.',
3722
2968
branch_format='bzrlib.branch.BzrBranchFormat5',
3723
2969
tree_format='bzrlib.workingtree.WorkingTreeFormat3',
3726
format_registry.register_metadir('knit',
3727
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
3728
'Format using knits. Recommended for interoperation with bzr <= 0.14.',
3729
branch_format='bzrlib.branch.BzrBranchFormat5',
3730
tree_format='bzrlib.workingtree.WorkingTreeFormat3',
3732
2970
deprecated=True)
3733
2971
format_registry.register_metadir('dirstate',
3734
2972
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
3790
3029
format_registry.register_metadir('rich-root-pack',
3791
3030
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack4',
3792
help='New in 1.0: A variant of pack-0.92 that supports rich-root data '
3793
'(needed for bzr-svn and bzr-git).',
3031
help='New in 1.0: Pack-based format with data compatible with '
3032
'rich-root format repositories. Incompatible with'
3794
3034
branch_format='bzrlib.branch.BzrBranchFormat6',
3795
3035
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3798
3037
format_registry.register_metadir('1.6',
3799
3038
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack5',
3800
help='A format that allows a branch to indicate that there is another '
3801
'(stacked) repository that should be used to access data that is '
3802
'not present locally.',
3039
help='A branch and pack based repository that supports stacking. ',
3803
3040
branch_format='bzrlib.branch.BzrBranchFormat7',
3804
3041
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3807
3043
format_registry.register_metadir('1.6.1-rich-root',
3808
3044
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack5RichRoot',
3809
help='A variant of 1.6 that supports rich-root data '
3810
'(needed for bzr-svn and bzr-git).',
3811
branch_format='bzrlib.branch.BzrBranchFormat7',
3812
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3815
format_registry.register_metadir('1.9',
3816
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6',
3817
help='A repository format using B+tree indexes. These indexes '
3818
'are smaller in size, have smarter caching and provide faster '
3819
'performance for most operations.',
3820
branch_format='bzrlib.branch.BzrBranchFormat7',
3821
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3824
format_registry.register_metadir('1.9-rich-root',
3825
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6RichRoot',
3826
help='A variant of 1.9 that supports rich-root data '
3827
'(needed for bzr-svn and bzr-git).',
3828
branch_format='bzrlib.branch.BzrBranchFormat7',
3829
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3832
format_registry.register_metadir('1.14',
3833
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6',
3834
help='A working-tree format that supports content filtering.',
3835
branch_format='bzrlib.branch.BzrBranchFormat7',
3836
tree_format='bzrlib.workingtree.WorkingTreeFormat5',
3838
format_registry.register_metadir('1.14-rich-root',
3839
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6RichRoot',
3840
help='A variant of 1.14 that supports rich-root data '
3841
'(needed for bzr-svn and bzr-git).',
3842
branch_format='bzrlib.branch.BzrBranchFormat7',
3843
tree_format='bzrlib.workingtree.WorkingTreeFormat5',
3845
# The following un-numbered 'development' formats should always just be aliases.
3846
format_registry.register_metadir('development-rich-root',
3847
'bzrlib.repofmt.groupcompress_repo.RepositoryFormatCHK1',
3848
help='Current development format. Supports rich roots. Can convert data '
3849
'to and from rich-root-pack (and anything compatible with '
3850
'rich-root-pack) format repositories. Repositories and branches in '
3851
'this format can only be read by bzr.dev. Please read '
3852
'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
3045
help='A branch and pack based repository that supports stacking '
3046
'and rich root data (needed for bzr-svn). ',
3047
branch_format='bzrlib.branch.BzrBranchFormat7',
3048
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3050
# The following two formats should always just be aliases.
3051
format_registry.register_metadir('development',
3052
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment2',
3053
help='Current development format. Can convert data to and from pack-0.92 '
3054
'(and anything compatible with pack-0.92) format repositories. '
3055
'Repositories and branches in this format can only be read by bzr.dev. '
3057
'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3854
3059
branch_format='bzrlib.branch.BzrBranchFormat7',
3855
tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3060
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3856
3061
experimental=True,
3860
3064
format_registry.register_metadir('development-subtree',
3861
3065
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment2Subtree',
3863
3067
'from pack-0.92-subtree (and anything compatible with '
3864
3068
'pack-0.92-subtree) format repositories. Repositories and branches in '
3865
3069
'this format can only be read by bzr.dev. Please read '
3866
'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
3070
'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3868
3072
branch_format='bzrlib.branch.BzrBranchFormat7',
3869
tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3073
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3870
3074
experimental=True,
3872
alias=False, # Restore to being an alias when an actual development subtree format is added
3873
# This current non-alias status is simply because we did not introduce a
3874
# chk based subtree format.
3877
3077
# And the development formats above will have aliased one of the following:
3878
format_registry.register_metadir('development6-rich-root',
3879
'bzrlib.repofmt.groupcompress_repo.RepositoryFormatCHK1',
3880
help='pack-1.9 with 255-way hashed CHK inv, group compress, rich roots '
3882
'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
3884
branch_format='bzrlib.branch.BzrBranchFormat7',
3885
tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3890
format_registry.register_metadir('development7-rich-root',
3891
'bzrlib.repofmt.groupcompress_repo.RepositoryFormatCHK2',
3892
help='pack-1.9 with 255-way hashed CHK inv, bencode revision, group compress, '
3893
'rich roots. Please read '
3894
'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
3896
branch_format='bzrlib.branch.BzrBranchFormat7',
3897
tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3902
format_registry.register_metadir('2a',
3903
'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2a',
3904
help='First format for bzr 2.0 series.\n'
3905
'Uses group-compress storage.\n'
3906
'Provides rich roots which are a one-way transition.\n',
3907
# 'storage in packs, 255-way hashed CHK inventory, bencode revision, group compress, '
3908
# 'rich roots. Supported by bzr 1.16 and later.',
3909
branch_format='bzrlib.branch.BzrBranchFormat7',
3910
tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3914
# The following format should be an alias for the rich root equivalent
3915
# of the default format
3916
format_registry.register_metadir('default-rich-root',
3917
'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2a',
3918
branch_format='bzrlib.branch.BzrBranchFormat7',
3919
tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3078
format_registry.register_metadir('development2',
3079
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment2',
3080
help='1.6.1 with B+Tree based index. '
3082
'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3084
branch_format='bzrlib.branch.BzrBranchFormat7',
3085
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3089
format_registry.register_metadir('development2-subtree',
3090
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment2Subtree',
3091
help='1.6.1-subtree with B+Tree based index. '
3093
'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3095
branch_format='bzrlib.branch.BzrBranchFormat7',
3096
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3924
3100
# The current format that is made on 'bzr init'.
3925
format_registry.set_default('2a')
3101
format_registry.set_default('pack-0.92')