215
233
errors.UnstackableRepositoryFormat,
216
234
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,
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)
224
240
make_working_trees = local_repo.make_working_trees()
225
result_repo = repository_policy.acquire_repository(
226
make_working_trees, local_repo.is_shared())
227
result_repo.fetch(local_repo, revision_id=revision_id)
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)
230
276
# 1 if there is a branch present
231
277
# make sure its content is available in the target repository
233
279
if local_branch is not None:
234
result_branch = local_branch.clone(result, revision_id=revision_id)
235
if repository_policy is not None:
236
repository_policy.configure_branch(result_branch)
237
if result_repo is None or result_repo.make_working_trees():
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():
239
287
self.open_workingtree().clone(result)
240
except (errors.NoWorkingTree, errors.NotLocalUrl):
288
except (errors.NoWorkingTree, errors.NotLocalUrl):
244
292
# TODO: This should be given a Transport, and should chdir up; otherwise
779
851
:param transport: Transport containing the bzrdir.
780
852
:param _unsupported: private.
854
for hook in BzrDir.hooks['pre_open']:
856
# Keep initial base since 'transport' may be modified while following
782
858
base = transport.base
784
859
def find_format(transport):
785
860
return transport, BzrDirFormat.find_format(
786
861
transport, _server_formats=_server_formats)
788
863
def redirected(transport, e, redirection_notice):
789
qualified_source = e.get_source_url()
790
relpath = transport.relpath(qualified_source)
791
if not e.target.endswith(relpath):
792
# Not redirected to a branch-format, not a branch
793
raise errors.NotBranchError(path=e.target)
794
target = e.target[:-len(relpath)]
864
redirected_transport = transport._redirected_to(e.source, e.target)
865
if redirected_transport is None:
866
raise errors.NotBranchError(base)
795
867
note('%s is%s redirected to %s',
796
transport.base, e.permanently, target)
797
# Let's try with a new transport
798
# FIXME: If 'transport' has a qualifier, this should
799
# be applied again to the new transport *iff* the
800
# schemes used are the same. Uncomment this code
801
# once the function (and tests) exist.
803
#target = urlutils.copy_url_qualifiers(original, target)
804
return get_transport(target)
868
transport.base, e.permanently, redirected_transport.base)
869
return redirected_transport
807
872
transport, format = do_catching_redirections(find_format,
1086
1141
where possible.
1087
1142
:param stacked: If true, create a stacked branch referring to the
1088
1143
location of this control directory.
1144
:param create_tree_if_local: If true, a working-tree will be created
1145
when working locally.
1090
1147
target_transport = get_transport(url, possible_transports)
1091
1148
target_transport.ensure_base()
1092
1149
cloning_format = self.cloning_metadir(stacked)
1093
1150
# Create/update the result branch
1094
1151
result = cloning_format.initialize_on_transport(target_transport)
1096
source_branch = self.open_branch()
1097
source_repository = source_branch.repository
1152
# if a stacked branch wasn't requested, we don't create one
1153
# even if the origin was stacked
1154
stacked_branch_url = None
1155
if source_branch is not None:
1099
1157
stacked_branch_url = self.root_transport.base
1101
# if a stacked branch wasn't requested, we don't create one
1102
# even if the origin was stacked
1103
stacked_branch_url = None
1104
except errors.NotBranchError:
1105
source_branch = None
1158
source_repository = source_branch.repository
1107
source_repository = self.open_repository()
1108
except errors.NoRepositoryPresent:
1109
source_repository = None
1110
stacked_branch_url = None
1161
source_branch = self.open_branch()
1162
source_repository = source_branch.repository
1164
stacked_branch_url = self.root_transport.base
1165
except errors.NotBranchError:
1166
source_branch = None
1168
source_repository = self.open_repository()
1169
except errors.NoRepositoryPresent:
1170
source_repository = None
1111
1171
repository_policy = result.determine_repository_policy(
1112
1172
force_new_repo, stacked_branch_url, require_stacking=stacked)
1113
result_repo = repository_policy.acquire_repository()
1173
result_repo, is_new_repo = repository_policy.acquire_repository()
1174
if is_new_repo and revision_id is not None and not stacked:
1175
fetch_spec = graph.PendingAncestryResult(
1176
[revision_id], source_repository)
1114
1179
if source_repository is not None:
1115
1180
# Fetch while stacked to prevent unstacked fetch from
1116
1181
# Branch.sprout.
1117
result_repo.fetch(source_repository, revision_id=revision_id)
1182
if fetch_spec is None:
1183
result_repo.fetch(source_repository, revision_id=revision_id)
1185
result_repo.fetch(source_repository, fetch_spec=fetch_spec)
1119
1187
if source_branch is None:
1120
1188
# this is for sprouting a bzrdir without a branch; is that
1243
def push_branch(self, source, revision_id=None, overwrite=False,
1244
remember=False, create_prefix=False):
1245
"""Push the source branch into this BzrDir."""
1247
# If we can open a branch, use its direct repository, otherwise see
1248
# if there is a repository without a branch.
1250
br_to = self.open_branch()
1251
except errors.NotBranchError:
1252
# Didn't find a branch, can we find a repository?
1253
repository_to = self.find_repository()
1255
# Found a branch, so we must have found a repository
1256
repository_to = br_to.repository
1258
push_result = PushResult()
1259
push_result.source_branch = source
1261
# We have a repository but no branch, copy the revisions, and then
1263
repository_to.fetch(source.repository, revision_id=revision_id)
1264
br_to = source.clone(self, revision_id=revision_id)
1265
if source.get_push_location() is None or remember:
1266
source.set_push_location(br_to.base)
1267
push_result.stacked_on = None
1268
push_result.branch_push_result = None
1269
push_result.old_revno = None
1270
push_result.old_revid = _mod_revision.NULL_REVISION
1271
push_result.target_branch = br_to
1272
push_result.master_branch = None
1273
push_result.workingtree_updated = False
1275
# We have successfully opened the branch, remember if necessary:
1276
if source.get_push_location() is None or remember:
1277
source.set_push_location(br_to.base)
1279
tree_to = self.open_workingtree()
1280
except errors.NotLocalUrl:
1281
push_result.branch_push_result = source.push(br_to,
1282
overwrite, stop_revision=revision_id)
1283
push_result.workingtree_updated = False
1284
except errors.NoWorkingTree:
1285
push_result.branch_push_result = source.push(br_to,
1286
overwrite, stop_revision=revision_id)
1287
push_result.workingtree_updated = None # Not applicable
1289
tree_to.lock_write()
1291
push_result.branch_push_result = source.push(
1292
tree_to.branch, overwrite, stop_revision=revision_id)
1296
push_result.workingtree_updated = True
1297
push_result.old_revno = push_result.branch_push_result.old_revno
1298
push_result.old_revid = push_result.branch_push_result.old_revid
1299
push_result.target_branch = \
1300
push_result.branch_push_result.target_branch
1304
class BzrDirHooks(hooks.Hooks):
1305
"""Hooks for BzrDir operations."""
1308
"""Create the default hooks."""
1309
hooks.Hooks.__init__(self)
1310
self.create_hook(hooks.HookPoint('pre_open',
1311
"Invoked before attempting to open a BzrDir with the transport "
1312
"that the open will use.", (1, 14), None))
1314
# install the default hooks
1315
BzrDir.hooks = BzrDirHooks()
1179
1318
class BzrDirPreSplitOut(BzrDir):
1180
1319
"""A common class for the all-in-one formats."""
1689
1856
def initialize_on_transport(self, transport):
1690
1857
"""Initialize a new bzrdir in the base directory of a Transport."""
1691
# Since we don't have a .bzr directory, inherit the
1859
# can we hand off the request to the smart server rather than using
1861
client_medium = transport.get_smart_medium()
1862
except errors.NoSmartMedium:
1863
return self._initialize_on_transport_vfs(transport)
1865
# Current RPC's only know how to create bzr metadir1 instances, so
1866
# we still delegate to vfs methods if the requested format is not a
1868
if type(self) != BzrDirMetaFormat1:
1869
return self._initialize_on_transport_vfs(transport)
1870
remote_format = RemoteBzrDirFormat()
1871
self._supply_sub_formats_to(remote_format)
1872
return remote_format.initialize_on_transport(transport)
1874
def initialize_on_transport_ex(self, transport, use_existing_dir=False,
1875
create_prefix=False, force_new_repo=False, stacked_on=None,
1876
stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
1877
shared_repo=False, vfs_only=False):
1878
"""Create this format on transport.
1880
The directory to initialize will be created.
1882
:param force_new_repo: Do not use a shared repository for the target,
1883
even if one is available.
1884
:param create_prefix: Create any missing directories leading up to
1886
:param use_existing_dir: Use an existing directory if one exists.
1887
:param stacked_on: A url to stack any created branch on, None to follow
1888
any target stacking policy.
1889
:param stack_on_pwd: If stack_on is relative, the location it is
1891
:param repo_format_name: If non-None, a repository will be
1892
made-or-found. Should none be found, or if force_new_repo is True
1893
the repo_format_name is used to select the format of repository to
1895
:param make_working_trees: Control the setting of make_working_trees
1896
for a new shared repository when one is made. None to use whatever
1897
default the format has.
1898
:param shared_repo: Control whether made repositories are shared or
1900
:param vfs_only: If True do not attempt to use a smart server
1901
:return: repo, bzrdir, require_stacking, repository_policy. repo is
1902
None if none was created or found, bzrdir is always valid.
1903
require_stacking is the result of examining the stacked_on
1904
parameter and any stacking policy found for the target.
1907
# Try to hand off to a smart server
1909
client_medium = transport.get_smart_medium()
1910
except errors.NoSmartMedium:
1913
# TODO: lookup the local format from a server hint.
1914
remote_dir_format = RemoteBzrDirFormat()
1915
remote_dir_format._network_name = self.network_name()
1916
self._supply_sub_formats_to(remote_dir_format)
1917
return remote_dir_format.initialize_on_transport_ex(transport,
1918
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
1919
force_new_repo=force_new_repo, stacked_on=stacked_on,
1920
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
1921
make_working_trees=make_working_trees, shared_repo=shared_repo)
1922
# XXX: Refactor the create_prefix/no_create_prefix code into a
1923
# common helper function
1924
# The destination may not exist - if so make it according to policy.
1925
def make_directory(transport):
1926
transport.mkdir('.')
1928
def redirected(transport, e, redirection_notice):
1929
note(redirection_notice)
1930
return transport._redirected_to(e.source, e.target)
1932
transport = do_catching_redirections(make_directory, transport,
1934
except errors.FileExists:
1935
if not use_existing_dir:
1937
except errors.NoSuchFile:
1938
if not create_prefix:
1940
transport.create_prefix()
1942
require_stacking = (stacked_on is not None)
1943
# Now the target directory exists, but doesn't have a .bzr
1944
# directory. So we need to create it, along with any work to create
1945
# all of the dependent branches, etc.
1947
result = self.initialize_on_transport(transport)
1948
if repo_format_name:
1950
# use a custom format
1951
result._format.repository_format = \
1952
repository.network_format_registry.get(repo_format_name)
1953
except AttributeError:
1954
# The format didn't permit it to be set.
1956
# A repository is desired, either in-place or shared.
1957
repository_policy = result.determine_repository_policy(
1958
force_new_repo, stacked_on, stack_on_pwd,
1959
require_stacking=require_stacking)
1960
result_repo, is_new_repo = repository_policy.acquire_repository(
1961
make_working_trees, shared_repo)
1962
if not require_stacking and repository_policy._require_stacking:
1963
require_stacking = True
1964
result._format.require_stacking()
1965
result_repo.lock_write()
1968
repository_policy = None
1969
return result_repo, result, require_stacking, repository_policy
1971
def _initialize_on_transport_vfs(self, transport):
1972
"""Initialize a new bzrdir using VFS calls.
1974
:param transport: The transport to create the .bzr directory in.
1977
# Since we are creating a .bzr directory, inherit the
1692
1978
# mode from the root directory
1693
1979
temp_control = lockable_files.LockableFiles(transport,
1694
1980
'', lockable_files.TransportLock)
1869
2185
repository_format = property(__return_repository_format)
1872
class BzrDirFormat5(BzrDirFormat):
2188
class BzrDirFormatAllInOne(BzrDirFormat):
2189
"""Common class for formats before meta-dirs."""
2191
def initialize_on_transport_ex(self, transport, use_existing_dir=False,
2192
create_prefix=False, force_new_repo=False, stacked_on=None,
2193
stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
2195
"""See BzrDirFormat.initialize_on_transport_ex."""
2196
require_stacking = (stacked_on is not None)
2197
# Format 5 cannot stack, but we've been asked to - actually init
2199
if require_stacking:
2200
format = BzrDirMetaFormat1()
2201
return format.initialize_on_transport_ex(transport,
2202
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
2203
force_new_repo=force_new_repo, stacked_on=stacked_on,
2204
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
2205
make_working_trees=make_working_trees, shared_repo=shared_repo)
2206
return BzrDirFormat.initialize_on_transport_ex(self, transport,
2207
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
2208
force_new_repo=force_new_repo, stacked_on=stacked_on,
2209
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
2210
make_working_trees=make_working_trees, shared_repo=shared_repo)
2213
class BzrDirFormat5(BzrDirFormatAllInOne):
1873
2214
"""Bzr control format 5.
1875
2216
This format is a combined format for working tree, branch and repository.
1877
- Format 2 working trees [always]
1878
- Format 4 branches [always]
2218
- Format 2 working trees [always]
2219
- Format 4 branches [always]
1879
2220
- Format 5 repositories [always]
1880
2221
Unhashed stores in the repository.
2022
2370
def set_branch_format(self, format):
2023
2371
self._branch_format = format
2373
def require_stacking(self, stack_on=None, possible_transports=None,
2375
"""We have a request to stack, try to ensure the formats support it.
2377
:param stack_on: If supplied, it is the URL to a branch that we want to
2378
stack on. Check to see if that format supports stacking before
2381
# Stacking is desired. requested by the target, but does the place it
2382
# points at support stacking? If it doesn't then we should
2383
# not implicitly upgrade. We check this here.
2384
new_repo_format = None
2385
new_branch_format = None
2387
# a bit of state for get_target_branch so that we don't try to open it
2388
# 2 times, for both repo *and* branch
2389
target = [None, False, None] # target_branch, checked, upgrade anyway
2390
def get_target_branch():
2392
# We've checked, don't check again
2394
if stack_on is None:
2395
# No target format, that means we want to force upgrading
2396
target[:] = [None, True, True]
2399
target_dir = BzrDir.open(stack_on,
2400
possible_transports=possible_transports)
2401
except errors.NotBranchError:
2402
# Nothing there, don't change formats
2403
target[:] = [None, True, False]
2405
except errors.JailBreak:
2406
# JailBreak, JFDI and upgrade anyway
2407
target[:] = [None, True, True]
2410
target_branch = target_dir.open_branch()
2411
except errors.NotBranchError:
2412
# No branch, don't upgrade formats
2413
target[:] = [None, True, False]
2415
target[:] = [target_branch, True, False]
2418
if (not _skip_repo and
2419
not self.repository_format.supports_external_lookups):
2420
# We need to upgrade the Repository.
2421
target_branch, _, do_upgrade = get_target_branch()
2422
if target_branch is None:
2423
# We don't have a target branch, should we upgrade anyway?
2425
# stack_on is inaccessible, JFDI.
2426
# TODO: bad monkey, hard-coded formats...
2427
if self.repository_format.rich_root_data:
2428
new_repo_format = pack_repo.RepositoryFormatKnitPack5RichRoot()
2430
new_repo_format = pack_repo.RepositoryFormatKnitPack5()
2432
# If the target already supports stacking, then we know the
2433
# project is already able to use stacking, so auto-upgrade
2435
new_repo_format = target_branch.repository._format
2436
if not new_repo_format.supports_external_lookups:
2437
# target doesn't, source doesn't, so don't auto upgrade
2439
new_repo_format = None
2440
if new_repo_format is not None:
2441
self.repository_format = new_repo_format
2442
note('Source repository format does not support stacking,'
2443
' using format:\n %s',
2444
new_repo_format.get_format_description())
2446
if not self.get_branch_format().supports_stacking():
2447
# We just checked the repo, now lets check if we need to
2448
# upgrade the branch format
2449
target_branch, _, do_upgrade = get_target_branch()
2450
if target_branch is None:
2452
# TODO: bad monkey, hard-coded formats...
2453
new_branch_format = branch.BzrBranchFormat7()
2455
new_branch_format = target_branch._format
2456
if not new_branch_format.supports_stacking():
2457
new_branch_format = None
2458
if new_branch_format is not None:
2459
# Does support stacking, use its format.
2460
self.set_branch_format(new_branch_format)
2461
note('Source branch format does not support stacking,'
2462
' using format:\n %s',
2463
new_branch_format.get_format_description())
2025
2465
def get_converter(self, format=None):
2026
2466
"""See BzrDirFormat.get_converter()."""
2027
2467
if format is None:
2039
2479
"""See BzrDirFormat.get_format_description()."""
2040
2480
return "Meta directory format 1"
2482
def network_name(self):
2483
return self.get_format_string()
2042
2485
def _open(self, transport):
2043
2486
"""See BzrDirFormat._open."""
2044
return BzrDirMeta1(transport, self)
2487
# Create a new format instance because otherwise initialisation of new
2488
# metadirs share the global default format object leading to alias
2490
format = BzrDirMetaFormat1()
2491
self._supply_sub_formats_to(format)
2492
return BzrDirMeta1(transport, format)
2046
2494
def __return_repository_format(self):
2047
2495
"""Circular import protection."""
2048
if getattr(self, '_repository_format', None):
2496
if self._repository_format:
2049
2497
return self._repository_format
2050
2498
from bzrlib.repository import RepositoryFormat
2051
2499
return RepositoryFormat.get_default_format()
2053
def __set_repository_format(self, value):
2501
def _set_repository_format(self, value):
2054
2502
"""Allow changing the repository format for metadir formats."""
2055
2503
self._repository_format = value
2057
repository_format = property(__return_repository_format, __set_repository_format)
2505
repository_format = property(__return_repository_format,
2506
_set_repository_format)
2508
def _supply_sub_formats_to(self, other_format):
2509
"""Give other_format the same values for sub formats as this has.
2511
This method is expected to be used when parameterising a
2512
RemoteBzrDirFormat instance with the parameters from a
2513
BzrDirMetaFormat1 instance.
2515
:param other_format: other_format is a format which should be
2516
compatible with whatever sub formats are supported by self.
2519
if getattr(self, '_repository_format', None) is not None:
2520
other_format.repository_format = self.repository_format
2521
if self._branch_format is not None:
2522
other_format._branch_format = self._branch_format
2523
if self._workingtree_format is not None:
2524
other_format.workingtree_format = self.workingtree_format
2059
2526
def __get_workingtree_format(self):
2060
2527
if self._workingtree_format is None:
2582
3059
# TODO: conversions of Branch and Tree should be done by
2583
3060
# InterXFormat lookups
2584
3061
if (isinstance(tree, workingtree.WorkingTree3) and
2585
not isinstance(tree, workingtree_4.WorkingTree4) and
3062
not isinstance(tree, workingtree_4.DirStateWorkingTree) and
2586
3063
isinstance(self.target_format.workingtree_format,
2587
workingtree_4.WorkingTreeFormat4)):
3064
workingtree_4.DirStateWorkingTreeFormat)):
2588
3065
workingtree_4.Converter3to4().convert(tree)
3066
if (isinstance(tree, workingtree_4.DirStateWorkingTree) and
3067
not isinstance(tree, workingtree_4.WorkingTree5) and
3068
isinstance(self.target_format.workingtree_format,
3069
workingtree_4.WorkingTreeFormat5)):
3070
workingtree_4.Converter4to5().convert(tree)
3071
if (isinstance(tree, workingtree_4.DirStateWorkingTree) and
3072
not isinstance(tree, workingtree_4.WorkingTree6) and
3073
isinstance(self.target_format.workingtree_format,
3074
workingtree_4.WorkingTreeFormat6)):
3075
workingtree_4.Converter4or5to6().convert(tree)
2589
3076
return to_convert
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.
3079
# This is not in remote.py because it's relatively small, and needs to be
3080
# registered. Putting it in remote.py creates a circular import problem.
2594
3081
# we can make it a lazy object if the control formats is turned into something
2595
3082
# like a registry.
2596
3083
class RemoteBzrDirFormat(BzrDirMetaFormat1):
2597
3084
"""Format representing bzrdirs accessed via a smart server"""
3087
BzrDirMetaFormat1.__init__(self)
3088
self._network_name = None
2599
3090
def get_format_description(self):
2600
3091
return 'bzr remote bzrdir'
3093
def get_format_string(self):
3094
raise NotImplementedError(self.get_format_string)
3096
def network_name(self):
3097
if self._network_name:
3098
return self._network_name
3100
raise AssertionError("No network name set.")
2603
3103
def probe_transport(klass, transport):
2604
3104
"""Return a RemoteBzrDirFormat object if it looks possible."""
2633
3133
return local_dir_format.initialize_on_transport(transport)
2634
3134
client = _SmartClient(client_medium)
2635
3135
path = client.remote_path_from_transport(transport)
2636
response = client.call('BzrDirFormat.initialize', path)
3137
response = client.call('BzrDirFormat.initialize', path)
3138
except errors.ErrorFromSmartServer, err:
3139
remote._translate_error(err, path=path)
2637
3140
if response[0] != 'ok':
2638
3141
raise errors.SmartProtocolError('unexpected response code %s' % (response,))
2639
return remote.RemoteBzrDir(transport)
3142
format = RemoteBzrDirFormat()
3143
self._supply_sub_formats_to(format)
3144
return remote.RemoteBzrDir(transport, format)
3146
def parse_NoneTrueFalse(self, arg):
3153
raise AssertionError("invalid arg %r" % arg)
3155
def _serialize_NoneTrueFalse(self, arg):
3162
def _serialize_NoneString(self, arg):
3165
def initialize_on_transport_ex(self, transport, use_existing_dir=False,
3166
create_prefix=False, force_new_repo=False, stacked_on=None,
3167
stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
3170
# hand off the request to the smart server
3171
client_medium = transport.get_smart_medium()
3172
except errors.NoSmartMedium:
3175
# Decline to open it if the server doesn't support our required
3176
# version (3) so that the VFS-based transport will do it.
3177
if client_medium.should_probe():
3179
server_version = client_medium.protocol_version()
3180
if server_version != '2':
3184
except errors.SmartProtocolError:
3185
# Apparently there's no usable smart server there, even though
3186
# the medium supports the smart protocol.
3191
client = _SmartClient(client_medium)
3192
path = client.remote_path_from_transport(transport)
3193
if client_medium._is_remote_before((1, 16)):
3196
# TODO: lookup the local format from a server hint.
3197
local_dir_format = BzrDirMetaFormat1()
3198
self._supply_sub_formats_to(local_dir_format)
3199
return local_dir_format.initialize_on_transport_ex(transport,
3200
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
3201
force_new_repo=force_new_repo, stacked_on=stacked_on,
3202
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
3203
make_working_trees=make_working_trees, shared_repo=shared_repo,
3205
return self._initialize_on_transport_ex_rpc(client, path, transport,
3206
use_existing_dir, create_prefix, force_new_repo, stacked_on,
3207
stack_on_pwd, repo_format_name, make_working_trees, shared_repo)
3209
def _initialize_on_transport_ex_rpc(self, client, path, transport,
3210
use_existing_dir, create_prefix, force_new_repo, stacked_on,
3211
stack_on_pwd, repo_format_name, make_working_trees, shared_repo):
3213
args.append(self._serialize_NoneTrueFalse(use_existing_dir))
3214
args.append(self._serialize_NoneTrueFalse(create_prefix))
3215
args.append(self._serialize_NoneTrueFalse(force_new_repo))
3216
args.append(self._serialize_NoneString(stacked_on))
3217
# stack_on_pwd is often/usually our transport
3220
stack_on_pwd = transport.relpath(stack_on_pwd)
3221
if not stack_on_pwd:
3223
except errors.PathNotChild:
3225
args.append(self._serialize_NoneString(stack_on_pwd))
3226
args.append(self._serialize_NoneString(repo_format_name))
3227
args.append(self._serialize_NoneTrueFalse(make_working_trees))
3228
args.append(self._serialize_NoneTrueFalse(shared_repo))
3229
if self._network_name is None:
3230
self._network_name = \
3231
BzrDirFormat.get_default_format().network_name()
3233
response = client.call('BzrDirFormat.initialize_ex_1.16',
3234
self.network_name(), path, *args)
3235
except errors.UnknownSmartMethod:
3236
client._medium._remember_remote_is_before((1,16))
3237
local_dir_format = BzrDirMetaFormat1()
3238
self._supply_sub_formats_to(local_dir_format)
3239
return local_dir_format.initialize_on_transport_ex(transport,
3240
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
3241
force_new_repo=force_new_repo, stacked_on=stacked_on,
3242
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
3243
make_working_trees=make_working_trees, shared_repo=shared_repo,
3245
except errors.ErrorFromSmartServer, err:
3246
remote._translate_error(err, path=path)
3247
repo_path = response[0]
3248
bzrdir_name = response[6]
3249
require_stacking = response[7]
3250
require_stacking = self.parse_NoneTrueFalse(require_stacking)
3251
format = RemoteBzrDirFormat()
3252
format._network_name = bzrdir_name
3253
self._supply_sub_formats_to(format)
3254
bzrdir = remote.RemoteBzrDir(transport, format, _client=client)
3256
repo_format = remote.response_tuple_to_repo_format(response[1:])
3257
if repo_path == '.':
3260
repo_bzrdir_format = RemoteBzrDirFormat()
3261
repo_bzrdir_format._network_name = response[5]
3262
repo_bzr = remote.RemoteBzrDir(transport.clone(repo_path),
3266
final_stack = response[8] or None
3267
final_stack_pwd = response[9] or None
3269
final_stack_pwd = urlutils.join(
3270
transport.base, final_stack_pwd)
3271
remote_repo = remote.RemoteRepository(repo_bzr, repo_format)
3272
if len(response) > 10:
3273
# Updated server verb that locks remotely.
3274
repo_lock_token = response[10] or None
3275
remote_repo.lock_write(repo_lock_token, _skip_rpc=True)
3277
remote_repo.dont_leave_lock_in_place()
3279
remote_repo.lock_write()
3280
policy = UseExistingRepository(remote_repo, final_stack,
3281
final_stack_pwd, require_stacking)
3282
policy.acquire_repository()
3286
bzrdir._format.set_branch_format(self.get_branch_format())
3287
if require_stacking:
3288
# The repo has already been created, but we need to make sure that
3289
# we'll make a stackable branch.
3290
bzrdir._format.require_stacking(_skip_repo=True)
3291
return remote_repo, bzrdir, require_stacking, policy
2641
3293
def _open(self, transport):
2642
return remote.RemoteBzrDir(transport)
3294
return remote.RemoteBzrDir(transport, self)
2644
3296
def __eq__(self, other):
2645
3297
if not isinstance(other, RemoteBzrDirFormat):
2647
3299
return self.get_format_description() == other.get_format_description()
3301
def __return_repository_format(self):
3302
# Always return a RemoteRepositoryFormat object, but if a specific bzr
3303
# repository format has been asked for, tell the RemoteRepositoryFormat
3304
# that it should use that for init() etc.
3305
result = remote.RemoteRepositoryFormat()
3306
custom_format = getattr(self, '_repository_format', None)
3308
if isinstance(custom_format, remote.RemoteRepositoryFormat):
3309
return custom_format
3311
# We will use the custom format to create repositories over the
3312
# wire; expose its details like rich_root_data for code to
3314
result._custom_format = custom_format
3317
def get_branch_format(self):
3318
result = BzrDirMetaFormat1.get_branch_format(self)
3319
if not isinstance(result, remote.RemoteBranchFormat):
3320
new_result = remote.RemoteBranchFormat()
3321
new_result._custom_format = result
3323
self.set_branch_format(new_result)
3327
repository_format = property(__return_repository_format,
3328
BzrDirMetaFormat1._set_repository_format) #.im_func)
2650
3331
BzrDirFormat.register_control_server_format(RemoteBzrDirFormat)
2946
3664
def acquire_repository(self, make_working_trees=None, shared=False):
2947
3665
"""Implementation of RepositoryAcquisitionPolicy.acquire_repository
2949
Returns an existing repository to use
3667
Returns an existing repository to use.
2951
self._add_fallback(self._repository)
2952
return self._repository
3669
self._add_fallback(self._repository,
3670
possible_transports=[self._repository.bzrdir.transport])
3671
return self._repository, False
3674
# Please register new formats after old formats so that formats
3675
# appear in chronological order and format descriptions can build
2955
3677
format_registry = BzrDirFormatRegistry()
3678
# The pre-0.8 formats have their repository format network name registered in
3679
# repository.py. MetaDir formats have their repository format network name
3680
# inferred from their disk format string.
2956
3681
format_registry.register('weave', BzrDirFormat6,
2957
3682
'Pre-0.8 format. Slower than knit and does not'
2958
3683
' support checkouts or shared repositories.',
2959
3684
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')
2965
3685
format_registry.register_metadir('metaweave',
2966
3686
'bzrlib.repofmt.weaverepo.RepositoryFormat7',
2967
3687
'Transitional format in 0.8. Slower than knit.',
2968
3688
branch_format='bzrlib.branch.BzrBranchFormat5',
2969
3689
tree_format='bzrlib.workingtree.WorkingTreeFormat3',
2970
3690
deprecated=True)
3691
format_registry.register_metadir('knit',
3692
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
3693
'Format using knits. Recommended for interoperation with bzr <= 0.14.',
3694
branch_format='bzrlib.branch.BzrBranchFormat5',
3695
tree_format='bzrlib.workingtree.WorkingTreeFormat3',
2971
3697
format_registry.register_metadir('dirstate',
2972
3698
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2973
3699
help='New in 0.15: Fast local operations. Compatible with bzr 0.8 and '
3029
3755
format_registry.register_metadir('rich-root-pack',
3030
3756
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack4',
3031
help='New in 1.0: Pack-based format with data compatible with '
3032
'rich-root format repositories. Incompatible with'
3757
help='New in 1.0: A variant of pack-0.92 that supports rich-root data '
3758
'(needed for bzr-svn and bzr-git).',
3034
3759
branch_format='bzrlib.branch.BzrBranchFormat6',
3035
3760
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3037
3762
format_registry.register_metadir('1.6',
3038
3763
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack5',
3039
help='A branch and pack based repository that supports stacking. ',
3764
help='A format that allows a branch to indicate that there is another '
3765
'(stacked) repository that should be used to access data that is '
3766
'not present locally.',
3040
3767
branch_format='bzrlib.branch.BzrBranchFormat7',
3041
3768
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3043
3770
format_registry.register_metadir('1.6.1-rich-root',
3044
3771
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack5RichRoot',
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.RepositoryFormatPackDevelopment1',
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. '
3772
help='A variant of 1.6 that supports rich-root data '
3773
'(needed for bzr-svn and bzr-git).',
3774
branch_format='bzrlib.branch.BzrBranchFormat7',
3775
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3777
format_registry.register_metadir('1.9',
3778
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6',
3779
help='A repository format using B+tree indexes. These indexes '
3780
'are smaller in size, have smarter caching and provide faster '
3781
'performance for most operations.',
3782
branch_format='bzrlib.branch.BzrBranchFormat7',
3783
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3785
format_registry.register_metadir('1.9-rich-root',
3786
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6RichRoot',
3787
help='A variant of 1.9 that supports rich-root data '
3788
'(needed for bzr-svn and bzr-git).',
3789
branch_format='bzrlib.branch.BzrBranchFormat7',
3790
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3792
format_registry.register_metadir('1.14',
3793
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6',
3794
help='A working-tree format that supports content filtering.',
3795
branch_format='bzrlib.branch.BzrBranchFormat7',
3796
tree_format='bzrlib.workingtree.WorkingTreeFormat5',
3798
format_registry.register_metadir('1.14-rich-root',
3799
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6RichRoot',
3800
help='A variant of 1.14 that supports rich-root data '
3801
'(needed for bzr-svn and bzr-git).',
3802
branch_format='bzrlib.branch.BzrBranchFormat7',
3803
tree_format='bzrlib.workingtree.WorkingTreeFormat5',
3805
# The following un-numbered 'development' formats should always just be aliases.
3806
format_registry.register_metadir('development-rich-root',
3807
'bzrlib.repofmt.groupcompress_repo.RepositoryFormatCHK1',
3808
help='Current development format. Supports rich roots. Can convert data '
3809
'to and from rich-root-pack (and anything compatible with '
3810
'rich-root-pack) format repositories. Repositories and branches in '
3811
'this format can only be read by bzr.dev. Please read '
3057
3812
'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3059
3814
branch_format='bzrlib.branch.BzrBranchFormat7',
3060
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3815
tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3061
3816
experimental=True,
3064
3819
format_registry.register_metadir('development-subtree',
3065
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment1Subtree',
3820
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment2Subtree',
3066
3821
help='Current development format, subtree variant. Can convert data to and '
3067
3822
'from pack-0.92-subtree (and anything compatible with '
3068
3823
'pack-0.92-subtree) format repositories. Repositories and branches in '
3070
3825
'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3072
3827
branch_format='bzrlib.branch.BzrBranchFormat7',
3073
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3828
tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3830
alias=False, # Restore to being an alias when an actual development subtree format is added
3831
# This current non-alias status is simply because we did not introduce a
3832
# chk based subtree format.
3835
# And the development formats above will have aliased one of the following:
3836
format_registry.register_metadir('development6-rich-root',
3837
'bzrlib.repofmt.groupcompress_repo.RepositoryFormatCHK1',
3838
help='pack-1.9 with 255-way hashed CHK inv, group compress, rich roots '
3840
'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3842
branch_format='bzrlib.branch.BzrBranchFormat7',
3843
tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3848
format_registry.register_metadir('development7-rich-root',
3849
'bzrlib.repofmt.groupcompress_repo.RepositoryFormatCHK2',
3850
help='pack-1.9 with 255-way hashed CHK inv, bencode revision, group compress, '
3851
'rich roots. Please read '
3852
'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3854
branch_format='bzrlib.branch.BzrBranchFormat7',
3855
tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3860
format_registry.register_metadir('2a',
3861
'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2a',
3862
help='First format for bzr 2.0 series.\n'
3863
'Uses group-compress storage.\n'
3864
'Provides rich roots which are a one-way transition.\n',
3865
# 'storage in packs, 255-way hashed CHK inventory, bencode revision, group compress, '
3866
# 'rich roots. Supported by bzr 1.16 and later.',
3867
branch_format='bzrlib.branch.BzrBranchFormat7',
3868
tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3872
# The following format should be an alias for the rich root equivalent
3873
# of the default format
3874
format_registry.register_metadir('default-rich-root',
3875
'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2a',
3876
branch_format='bzrlib.branch.BzrBranchFormat7',
3877
tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3077
# And the development formats which the will have aliased one of follow:
3078
format_registry.register_metadir('development1',
3079
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment1',
3080
help='A branch and pack based repository that supports stacking. '
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('development1-subtree',
3090
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment1Subtree',
3091
help='A branch and pack based repository that supports stacking. '
3093
'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3095
branch_format='bzrlib.branch.BzrBranchFormat7',
3096
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3100
3881
# The current format that is made on 'bzr init'.
3101
format_registry.set_default('pack-0.92')
3882
format_registry.set_default('2a')