151
154
format.get_format_description(),
154
def clone(self, url, revision_id=None, force_new_repo=False,
155
preserve_stacking=False):
157
def clone(self, url, revision_id=None, force_new_repo=False):
156
158
"""Clone this bzrdir and its contents to url verbatim.
158
:param url: The url create the clone at. If url's last component does
159
not exist, it will be created.
160
:param revision_id: The tip revision-id to use for any branch or
161
working tree. If not None, then the clone operation may tune
160
If url's last component does not exist, it will be created.
162
if revision_id is not None, then the clone operation may tune
162
163
itself to download less data.
163
:param force_new_repo: Do not use a shared repository for the target
164
:param force_new_repo: Do not use a shared repository for the target
164
165
even if one is available.
165
:param preserve_stacking: When cloning a stacked branch, stack the
166
new branch on top of the other branch's stacked-on branch.
168
167
return self.clone_on_transport(get_transport(url),
169
168
revision_id=revision_id,
170
force_new_repo=force_new_repo,
171
preserve_stacking=preserve_stacking)
169
force_new_repo=force_new_repo)
173
171
def clone_on_transport(self, transport, revision_id=None,
174
force_new_repo=False, preserve_stacking=False,
172
force_new_repo=False):
176
173
"""Clone this bzrdir and its contents to transport verbatim.
178
:param transport: The transport for the location to produce the clone
179
at. If the target directory does not exist, it will be created.
180
:param revision_id: The tip revision-id to use for any branch or
181
working tree. If not None, then the clone operation may tune
175
If the target directory does not exist, it will be created.
177
if revision_id is not None, then the clone operation may tune
182
178
itself to download less data.
183
:param force_new_repo: Do not use a shared repository for the target,
179
:param force_new_repo: Do not use a shared repository for the target
184
180
even if one is available.
185
:param preserve_stacking: When cloning a stacked branch, stack the
186
new branch on top of the other branch's stacked-on branch.
188
182
transport.ensure_base()
189
require_stacking = (stacked_on is not None)
190
metadir = self.cloning_metadir(require_stacking)
191
result = metadir.initialize_on_transport(transport)
192
repository_policy = None
183
result = self._format.initialize_on_transport(transport)
194
185
local_repo = self.find_repository()
195
186
except errors.NoRepositoryPresent:
196
187
local_repo = None
198
local_branch = self.open_branch()
199
except errors.NotBranchError:
202
# enable fallbacks when branch is not a branch reference
203
if local_branch.repository.has_same_location(local_repo):
204
local_repo = local_branch.repository
205
if preserve_stacking:
207
stacked_on = local_branch.get_stacked_on_url()
208
except (errors.UnstackableBranchFormat,
209
errors.UnstackableRepositoryFormat,
214
189
# 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)
218
make_working_trees = local_repo.make_working_trees()
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)
191
result_repo = local_repo.clone(
193
revision_id=revision_id)
194
result_repo.set_make_working_trees(local_repo.make_working_trees())
197
result_repo = result.find_repository()
198
# fetch content this dir needs.
199
result_repo.fetch(local_repo, revision_id=revision_id)
200
except errors.NoRepositoryPresent:
201
# needed to make one anyway.
202
result_repo = local_repo.clone(
204
revision_id=revision_id)
205
result_repo.set_make_working_trees(local_repo.make_working_trees())
224
206
# 1 if there is a branch present
225
207
# make sure its content is available in the target repository
227
if local_branch is not None:
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)
210
self.open_branch().clone(result, revision_id=revision_id)
211
except errors.NotBranchError:
214
result_repo = result.find_repository()
215
except errors.NoRepositoryPresent:
231
217
if result_repo is None or result_repo.make_working_trees():
233
219
self.open_workingtree().clone(result)
369
356
bzrdir._find_or_create_repository(force_new_repo)
370
357
return bzrdir.create_branch()
372
def determine_repository_policy(self, force_new_repo=False, stack_on=None,
373
stack_on_pwd=None, require_stacking=False):
374
"""Return an object representing a policy to use.
376
This controls whether a new repository is created, or a shared
377
repository used instead.
379
If stack_on is supplied, will not seek a containing shared repo.
381
:param force_new_repo: If True, require a new repository to be created.
382
:param stack_on: If supplied, the location to stack on. If not
383
supplied, a default_stack_on location may be used.
384
:param stack_on_pwd: If stack_on is relative, the location it is
387
def repository_policy(found_bzrdir):
390
config = found_bzrdir.get_config()
392
if config is not None:
393
stack_on = config.get_default_stack_on()
394
if stack_on is not None:
395
stack_on_pwd = found_bzrdir.root_transport.base
397
note('Using default stacking branch %s at %s', stack_on,
399
# does it have a repository ?
401
repository = found_bzrdir.open_repository()
402
except errors.NoRepositoryPresent:
405
if ((found_bzrdir.root_transport.base !=
406
self.root_transport.base) and not repository.is_shared()):
413
return UseExistingRepository(repository, stack_on,
414
stack_on_pwd, require_stacking=require_stacking), True
416
return CreateRepository(self, stack_on, stack_on_pwd,
417
require_stacking=require_stacking), True
419
if not force_new_repo:
421
policy = self._find_containing(repository_policy)
422
if policy is not None:
426
return UseExistingRepository(self.open_repository(),
427
stack_on, stack_on_pwd,
428
require_stacking=require_stacking)
429
except errors.NoRepositoryPresent:
431
return CreateRepository(self, stack_on, stack_on_pwd,
432
require_stacking=require_stacking)
434
359
def _find_or_create_repository(self, force_new_repo):
435
360
"""Create a new repository if needed, returning the repository."""
436
policy = self.determine_repository_policy(force_new_repo)
437
return policy.acquire_repository()
362
return self.create_repository()
364
return self.find_repository()
365
except errors.NoRepositoryPresent:
366
return self.create_repository()
440
369
def create_branch_convenience(base, force_new_repo=False,
441
370
force_new_tree=None, format=None,
414
@deprecated_function(zero_ninetyone)
415
def create_repository(base, shared=False, format=None):
416
"""Create a new BzrDir and Repository at the url 'base'.
418
If no format is supplied, this will default to the current default
419
BzrDirFormat by default, and use whatever repository format that that
420
uses for bzrdirformat.create_repository.
422
:param shared: Create a shared repository rather than a standalone
424
The Repository object is returned.
426
This must be overridden as an instance method in child classes, where
427
it should take no parameters and construct whatever repository format
428
that child class desires.
430
This method is deprecated, please call create_repository on a bzrdir
433
bzrdir = BzrDir.create(base, format)
434
return bzrdir.create_repository(shared)
485
437
def create_standalone_workingtree(base, format=None):
486
438
"""Create a new BzrDir, WorkingTree, Branch and Repository at 'base'.
557
509
raise NotImplementedError(self.destroy_workingtree_metadata)
559
def _find_containing(self, evaluate):
560
"""Find something in a containing control directory.
562
This method will scan containing control dirs, until it finds what
563
it is looking for, decides that it will never find it, or runs out
564
of containing control directories to check.
566
It is used to implement find_repository and
567
determine_repository_policy.
569
:param evaluate: A function returning (value, stop). If stop is True,
570
the value will be returned.
574
result, stop = evaluate(found_bzrdir)
577
next_transport = found_bzrdir.root_transport.clone('..')
578
if (found_bzrdir.root_transport.base == next_transport.base):
579
# top of the file system
581
# find the next containing bzrdir
583
found_bzrdir = BzrDir.open_containing_from_transport(
585
except errors.NotBranchError:
588
511
def find_repository(self):
589
512
"""Find the repository that should be used.
592
515
new branches as well as to hook existing branches up to their
595
def usable_repository(found_bzrdir):
519
return self.open_repository()
520
except errors.NoRepositoryPresent:
522
next_transport = self.root_transport.clone('..')
524
# find the next containing bzrdir
526
found_bzrdir = BzrDir.open_containing_from_transport(
528
except errors.NotBranchError:
530
raise errors.NoRepositoryPresent(self)
596
531
# does it have a repository ?
598
533
repository = found_bzrdir.open_repository()
599
534
except errors.NoRepositoryPresent:
601
if found_bzrdir.root_transport.base == self.root_transport.base:
602
return repository, True
603
elif repository.is_shared():
604
return repository, True
535
next_transport = found_bzrdir.root_transport.clone('..')
536
if (found_bzrdir.root_transport.base == next_transport.base):
537
# top of the file system
541
if ((found_bzrdir.root_transport.base ==
542
self.root_transport.base) or repository.is_shared()):
608
found_repo = self._find_containing(usable_repository)
609
if found_repo is None:
610
raise errors.NoRepositoryPresent(self)
545
raise errors.NoRepositoryPresent(self)
546
raise errors.NoRepositoryPresent(self)
613
548
def get_branch_reference(self):
614
549
"""Return the referenced URL for the branch in this bzrdir.
631
566
guaranteed to point to an existing directory ready for use.
633
568
raise NotImplementedError(self.get_branch_transport)
635
def _find_creation_modes(self):
636
"""Determine the appropriate modes for files and directories.
638
They're always set to be consistent with the base directory,
639
assuming that this transport allows setting modes.
641
# TODO: Do we need or want an option (maybe a config setting) to turn
642
# this off or override it for particular locations? -- mbp 20080512
643
if self._mode_check_done:
645
self._mode_check_done = True
647
st = self.transport.stat('.')
648
except errors.TransportNotPossible:
649
self._dir_mode = None
650
self._file_mode = None
652
# Check the directory mode, but also make sure the created
653
# directories and files are read-write for this user. This is
654
# mostly a workaround for filesystems which lie about being able to
655
# write to a directory (cygwin & win32)
656
if (st.st_mode & 07777 == 00000):
657
# FTP allows stat but does not return dir/file modes
658
self._dir_mode = None
659
self._file_mode = None
661
self._dir_mode = (st.st_mode & 07777) | 00700
662
# Remove the sticky and execute bits for files
663
self._file_mode = self._dir_mode & ~07111
665
def _get_file_mode(self):
666
"""Return Unix mode for newly created files, or None.
668
if not self._mode_check_done:
669
self._find_creation_modes()
670
return self._file_mode
672
def _get_dir_mode(self):
673
"""Return Unix mode for newly created directories, or None.
675
if not self._mode_check_done:
676
self._find_creation_modes()
677
return self._dir_mode
679
570
def get_repository_transport(self, repository_format):
680
571
"""Get the transport for use by repository format in this BzrDir.
902
787
tree, branch = bzrdir._get_tree_branch()
903
788
return tree, branch, relpath
906
def open_containing_tree_branch_or_repository(klass, location):
907
"""Return the working tree, branch and repo contained by a location.
909
Returns (tree, branch, repository, relpath).
910
If there is no tree containing the location, tree will be None.
911
If there is no branch containing the location, branch will be None.
912
If there is no repository containing the location, repository will be
914
relpath is the portion of the path that is contained by the innermost
917
If no tree, branch or repository is found, a NotBranchError is raised.
919
bzrdir, relpath = klass.open_containing(location)
921
tree, branch = bzrdir._get_tree_branch()
922
except errors.NotBranchError:
924
repo = bzrdir.find_repository()
925
return None, None, repo, relpath
926
except (errors.NoRepositoryPresent):
927
raise errors.NotBranchError(location)
928
return tree, branch, branch.repository, relpath
930
790
def open_repository(self, _unsupported=False):
931
791
"""Open the repository object at this BzrDir if one is present.
1036
884
tree_format = repository._format._matchingbzrdir.workingtree_format
1037
885
format.workingtree_format = tree_format.__class__()
1038
if (require_stacking and not
1039
format.get_branch_format().supports_stacking()):
1040
# We need to make a stacked branch, but the default format for the
1041
# target doesn't support stacking. So force a branch that *can*
1043
from bzrlib.branch import BzrBranchFormat7
1044
format._branch_format = BzrBranchFormat7()
1045
mutter("using %r for stacking" % (format._branch_format,))
1046
from bzrlib.repofmt import pack_repo
1047
if format.repository_format.rich_root_data:
1048
bzrdir_format_name = '1.6.1-rich-root'
1049
repo_format = pack_repo.RepositoryFormatKnitPack5RichRoot()
1051
bzrdir_format_name = '1.6'
1052
repo_format = pack_repo.RepositoryFormatKnitPack5()
1053
note('Source format does not support stacking, using format:'
1055
bzrdir_format_name, repo_format.get_format_description())
1056
format.repository_format = repo_format
1059
888
def checkout_metadir(self):
1081
909
content is different.
1082
910
:param hardlink: If true, hard-link files from accelerator_tree,
1084
:param stacked: If true, create a stacked branch referring to the
1085
location of this control directory.
1087
913
target_transport = get_transport(url, possible_transports)
1088
914
target_transport.ensure_base()
1089
cloning_format = self.cloning_metadir(stacked)
1090
# Create/update the result branch
915
cloning_format = self.cloning_metadir()
1091
916
result = cloning_format.initialize_on_transport(target_transport)
1092
# if a stacked branch wasn't requested, we don't create one
1093
# even if the origin was stacked
1094
stacked_branch_url = None
1095
if source_branch is not None:
1097
stacked_branch_url = self.root_transport.base
918
source_branch = self.open_branch()
1098
919
source_repository = source_branch.repository
1101
source_branch = self.open_branch()
1102
source_repository = source_branch.repository
1104
stacked_branch_url = self.root_transport.base
1105
except errors.NotBranchError:
1106
source_branch = None
1108
source_repository = self.open_repository()
1109
except errors.NoRepositoryPresent:
1110
source_repository = None
1111
repository_policy = result.determine_repository_policy(
1112
force_new_repo, stacked_branch_url, require_stacking=stacked)
1113
result_repo = repository_policy.acquire_repository()
1114
if source_repository is not None:
1115
# Fetch while stacked to prevent unstacked fetch from
1117
result_repo.fetch(source_repository, revision_id=revision_id)
1119
if source_branch is None:
1120
# this is for sprouting a bzrdir without a branch; is that
1122
# Not especially, but it's part of the contract.
1123
result_branch = result.create_branch()
1125
# Force NULL revision to avoid using repository before stacking
1127
result_branch = source_branch.sprout(
1128
result, revision_id=_mod_revision.NULL_REVISION)
1129
parent_location = result_branch.get_parent()
1130
mutter("created new branch %r" % (result_branch,))
1131
repository_policy.configure_branch(result_branch)
920
except errors.NotBranchError:
923
source_repository = self.open_repository()
924
except errors.NoRepositoryPresent:
925
source_repository = None
930
result_repo = result.find_repository()
931
except errors.NoRepositoryPresent:
933
if source_repository is None and result_repo is not None:
935
elif source_repository is None and result_repo is None:
936
# no repo available, make a new one
937
result.create_repository()
938
elif source_repository is not None and result_repo is None:
939
# have source, and want to make a new target repo
940
result_repo = source_repository.sprout(result,
941
revision_id=revision_id)
943
# fetch needed content into target.
944
if source_repository is not None:
946
# source_repository.copy_content_into(result_repo,
947
# revision_id=revision_id)
948
# so we can override the copy method
949
result_repo.fetch(source_repository, revision_id=revision_id)
1132
950
if source_branch is not None:
1133
source_branch.copy_content_into(result_branch, revision_id)
1134
# Override copy_content_into
1135
result_branch.set_parent(parent_location)
1137
# Create/update the result working tree
1138
if isinstance(target_transport, local.LocalTransport) and (
951
source_branch.sprout(result, revision_id=revision_id)
953
result.create_branch()
954
if isinstance(target_transport, LocalTransport) and (
1139
955
result_repo is None or result_repo.make_working_trees()):
1140
956
wt = result.create_workingtree(accelerator_tree=accelerator_tree,
1141
957
hardlink=hardlink)
1195
1010
"""Pre-splitout bzrdirs do not suffer from stale locks."""
1196
1011
raise NotImplementedError(self.break_lock)
1198
def cloning_metadir(self, require_stacking=False):
1199
"""Produce a metadir suitable for cloning with."""
1200
if require_stacking:
1201
return format_registry.make_bzrdir('1.6')
1202
return self._format.__class__()
1204
def clone(self, url, revision_id=None, force_new_repo=False,
1205
preserve_stacking=False):
1206
"""See BzrDir.clone().
1208
force_new_repo has no effect, since this family of formats always
1209
require a new repository.
1210
preserve_stacking has no effect, since no source branch using this
1211
family of formats can be stacked, so there is no stacking to preserve.
1013
def clone(self, url, revision_id=None, force_new_repo=False):
1014
"""See BzrDir.clone()."""
1015
from bzrlib.workingtree import WorkingTreeFormat2
1213
1016
self._make_tail(url)
1214
1017
result = self._format._initialize_for_clone(url)
1215
1018
self.open_repository().clone(result, revision_id=revision_id)
1216
1019
from_branch = self.open_branch()
1217
1020
from_branch.clone(result, revision_id=revision_id)
1219
tree = self.open_workingtree()
1022
self.open_workingtree().clone(result)
1220
1023
except errors.NotLocalUrl:
1221
1024
# make a new one, this format always has to have one.
1222
result._init_workingtree()
1026
WorkingTreeFormat2().initialize(result)
1027
except errors.NotLocalUrl:
1028
# but we cannot do it for remote trees.
1029
to_branch = result.open_branch()
1030
WorkingTreeFormat2().stub_initialize_remote(to_branch.control_files)
1227
1033
def create_branch(self):
1228
1034
"""See BzrDir.create_branch."""
1229
return self._format.get_branch_format().initialize(self)
1035
return self.open_branch()
1231
1037
def destroy_branch(self):
1232
1038
"""See BzrDir.destroy_branch."""
1700
1484
# FIXME: RBC 20060121 don't peek under
1702
1486
mode=temp_control._dir_mode)
1703
if sys.platform == 'win32' and isinstance(transport, local.LocalTransport):
1487
if sys.platform == 'win32' and isinstance(transport, LocalTransport):
1704
1488
win32utils.set_file_attr_hidden(transport._abspath('.bzr'))
1705
1489
file_mode = temp_control._file_mode
1706
1490
del temp_control
1707
bzrdir_transport = transport.clone('.bzr')
1708
utf8_files = [('README',
1491
mutter('created control directory in ' + transport.base)
1492
control = transport.clone('.bzr')
1493
utf8_files = [('README',
1709
1494
"This is a Bazaar control directory.\n"
1710
1495
"Do not change any files in this directory.\n"
1711
1496
"See http://bazaar-vcs.org/ for more information about Bazaar.\n"),
1712
1497
('branch-format', self.get_format_string()),
1714
1499
# NB: no need to escape relative paths that are url safe.
1715
control_files = lockable_files.LockableFiles(bzrdir_transport,
1716
self._lock_file_name, self._lock_class)
1500
control_files = lockable_files.LockableFiles(control,
1501
self._lock_file_name, self._lock_class)
1717
1502
control_files.create_lock()
1718
1503
control_files.lock_write()
1720
for (filename, content) in utf8_files:
1721
bzrdir_transport.put_bytes(filename, content,
1505
for file, content in utf8_files:
1506
control_files.put_utf8(file, content)
1724
1508
control_files.unlock()
1725
1509
return self.open(transport, _found=True)
2208
1999
self.bzrdir.transport.mkdir('revision-store')
2209
2000
revision_transport = self.bzrdir.transport.clone('revision-store')
2210
2001
# TODO permissions
2211
from bzrlib.xml5 import serializer_v5
2212
from bzrlib.repofmt.weaverepo import RevisionTextStore
2213
revision_store = RevisionTextStore(revision_transport,
2214
serializer_v5, False, versionedfile.PrefixMapper(),
2215
lambda:True, lambda:True)
2002
_revision_store = TextRevisionStore(TextStore(revision_transport,
2006
transaction = WriteTransaction()
2217
2007
for i, rev_id in enumerate(self.converted_revs):
2218
2008
self.pb.update('write revision', i, len(self.converted_revs))
2219
text = serializer_v5.write_revision_to_string(
2220
self.revisions[rev_id])
2222
revision_store.add_lines(key, None, osutils.split_lines(text))
2009
_revision_store.add_revision(self.revisions[rev_id], transaction)
2224
2011
self.pb.clear()
2239
2026
self.absent_revisions.add(rev_id)
2241
rev = self.branch.repository.get_revision(rev_id)
2028
rev = self.branch.repository._revision_store.get_revision(rev_id,
2029
self.branch.repository.get_transaction())
2242
2030
for parent_id in rev.parent_ids:
2243
2031
self.known_revisions.add(parent_id)
2244
2032
self.to_read.append(parent_id)
2245
2033
self.revisions[rev_id] = rev
2247
2035
def _load_old_inventory(self, rev_id):
2036
assert rev_id not in self.converted_revs
2248
2037
old_inv_xml = self.branch.repository.inventory_store.get(rev_id).read()
2249
2038
inv = xml4.serializer_v4.read_inventory_from_string(old_inv_xml)
2250
2039
inv.revision_id = rev_id
2251
2040
rev = self.revisions[rev_id]
2041
if rev.inventory_sha1:
2042
assert rev.inventory_sha1 == sha_string(old_inv_xml), \
2043
'inventory sha mismatch for {%s}' % rev_id
2254
2046
def _load_updated_inventory(self, rev_id):
2047
assert rev_id in self.converted_revs
2255
2048
inv_xml = self.inv_weave.get_text(rev_id)
2256
2049
inv = xml5.serializer_v5.read_inventory_from_string(inv_xml, rev_id)
2388
2196
if (filename.endswith(".weave") or
2389
2197
filename.endswith(".gz") or
2390
2198
filename.endswith(".sig")):
2391
file_id, suffix = os.path.splitext(filename)
2199
file_id = os.path.splitext(filename)[0]
2393
2201
file_id = filename
2395
new_name = store._mapper.map((file_id,)) + suffix
2202
prefix_dir = store.hash_prefix(file_id)
2396
2203
# FIXME keep track of the dirs made RBC 20060121
2398
store_transport.move(filename, new_name)
2205
store_transport.move(filename, prefix_dir + '/' + filename)
2399
2206
except errors.NoSuchFile: # catches missing dirs strangely enough
2400
store_transport.mkdir(osutils.dirname(new_name))
2401
store_transport.move(filename, new_name)
2402
self.bzrdir.transport.put_bytes(
2404
BzrDirFormat6().get_format_string(),
2405
mode=self.bzrdir._get_file_mode())
2207
store_transport.mkdir(prefix_dir)
2208
store_transport.move(filename, prefix_dir + '/' + filename)
2209
self.bzrdir._control_files.put_utf8('branch-format', BzrDirFormat6().get_format_string())
2408
2212
class ConvertBzrDir6ToMeta(Converter):
2562
2359
# TODO: conversions of Branch and Tree should be done by
2563
# InterXFormat lookups/some sort of registry.
2360
# InterXFormat lookups
2564
2361
# Avoid circular imports
2565
2362
from bzrlib import branch as _mod_branch
2566
old = branch._format.__class__
2567
new = self.target_format.get_branch_format().__class__
2569
if (old == _mod_branch.BzrBranchFormat5 and
2570
new in (_mod_branch.BzrBranchFormat6,
2571
_mod_branch.BzrBranchFormat7)):
2572
branch_converter = _mod_branch.Converter5to6()
2573
elif (old == _mod_branch.BzrBranchFormat6 and
2574
new == _mod_branch.BzrBranchFormat7):
2575
branch_converter = _mod_branch.Converter6to7()
2577
raise errors.BadConversionTarget("No converter", new)
2363
if (branch._format.__class__ is _mod_branch.BzrBranchFormat5 and
2364
self.target_format.get_branch_format().__class__ is
2365
_mod_branch.BzrBranchFormat6):
2366
branch_converter = _mod_branch.Converter5to6()
2578
2367
branch_converter.convert(branch)
2579
branch = self.bzrdir.open_branch()
2580
old = branch._format.__class__
2582
2369
tree = self.bzrdir.open_workingtree(recommend_upgrade=False)
2583
2370
except (errors.NoWorkingTree, errors.NotLocalUrl):
2610
2397
medium = transport.get_smart_medium()
2611
2398
except (NotImplementedError, AttributeError,
2612
errors.TransportNotPossible, errors.NoSmartMedium,
2613
errors.SmartProtocolError):
2399
errors.TransportNotPossible, errors.NoSmartMedium):
2614
2400
# no smart server, so not a branch for this format type.
2615
2401
raise errors.NotBranchError(path=transport.base)
2617
2403
# Decline to open it if the server doesn't support our required
2618
# version (3) so that the VFS-based transport will do it.
2619
if medium.should_probe():
2621
server_version = medium.protocol_version()
2622
except errors.SmartProtocolError:
2623
# Apparently there's no usable smart server there, even though
2624
# the medium supports the smart protocol.
2625
raise errors.NotBranchError(path=transport.base)
2626
if server_version != '2':
2627
raise errors.NotBranchError(path=transport.base)
2404
# version (2) so that the VFS-based transport will do it.
2406
server_version = medium.protocol_version()
2407
except errors.SmartProtocolError:
2408
# Apparently there's no usable smart server there, even though
2409
# the medium supports the smart protocol.
2410
raise errors.NotBranchError(path=transport.base)
2411
if server_version != 2:
2412
raise errors.NotBranchError(path=transport.base)
2630
2415
def initialize_on_transport(self, transport):
2632
2417
# hand off the request to the smart server
2633
client_medium = transport.get_smart_medium()
2418
shared_medium = transport.get_shared_medium()
2634
2419
except errors.NoSmartMedium:
2635
2420
# TODO: lookup the local format from a server hint.
2636
2421
local_dir_format = BzrDirMetaFormat1()
2637
2422
return local_dir_format.initialize_on_transport(transport)
2638
client = _SmartClient(client_medium)
2423
client = _SmartClient(shared_medium)
2639
2424
path = client.remote_path_from_transport(transport)
2640
response = client.call('BzrDirFormat.initialize', path)
2641
if response[0] != 'ok':
2642
raise errors.SmartProtocolError('unexpected response code %s' % (response,))
2425
response = _SmartClient(shared_medium).call('BzrDirFormat.initialize',
2427
assert response[0] in ('ok', ), 'unexpected response code %s' % (response,)
2643
2428
return remote.RemoteBzrDir(transport)
2645
2430
def _open(self, transport):
2832
class RepositoryAcquisitionPolicy(object):
2833
"""Abstract base class for repository acquisition policies.
2835
A repository acquisition policy decides how a BzrDir acquires a repository
2836
for a branch that is being created. The most basic policy decision is
2837
whether to create a new repository or use an existing one.
2839
def __init__(self, stack_on, stack_on_pwd, require_stacking):
2842
:param stack_on: A location to stack on
2843
:param stack_on_pwd: If stack_on is relative, the location it is
2845
:param require_stacking: If True, it is a failure to not stack.
2847
self._stack_on = stack_on
2848
self._stack_on_pwd = stack_on_pwd
2849
self._require_stacking = require_stacking
2851
def configure_branch(self, branch):
2852
"""Apply any configuration data from this policy to the branch.
2854
Default implementation sets repository stacking.
2856
if self._stack_on is None:
2858
if self._stack_on_pwd is None:
2859
stack_on = self._stack_on
2862
stack_on = urlutils.rebase_url(self._stack_on,
2864
branch.bzrdir.root_transport.base)
2865
except errors.InvalidRebaseURLs:
2866
stack_on = self._get_full_stack_on()
2868
branch.set_stacked_on_url(stack_on)
2869
except errors.UnstackableBranchFormat:
2870
if self._require_stacking:
2873
def _get_full_stack_on(self):
2874
"""Get a fully-qualified URL for the stack_on location."""
2875
if self._stack_on is None:
2877
if self._stack_on_pwd is None:
2878
return self._stack_on
2880
return urlutils.join(self._stack_on_pwd, self._stack_on)
2882
def _add_fallback(self, repository):
2883
"""Add a fallback to the supplied repository, if stacking is set."""
2884
stack_on = self._get_full_stack_on()
2885
if stack_on is None:
2887
stacked_dir = BzrDir.open(stack_on)
2889
stacked_repo = stacked_dir.open_branch().repository
2890
except errors.NotBranchError:
2891
stacked_repo = stacked_dir.open_repository()
2893
repository.add_fallback_repository(stacked_repo)
2894
except errors.UnstackableRepositoryFormat:
2895
if self._require_stacking:
2898
def acquire_repository(self, make_working_trees=None, shared=False):
2899
"""Acquire a repository for this bzrdir.
2901
Implementations may create a new repository or use a pre-exising
2903
:param make_working_trees: If creating a repository, set
2904
make_working_trees to this value (if non-None)
2905
:param shared: If creating a repository, make it shared if True
2906
:return: A repository
2908
raise NotImplemented(RepositoryAcquisitionPolicy.acquire_repository)
2911
class CreateRepository(RepositoryAcquisitionPolicy):
2912
"""A policy of creating a new repository"""
2914
def __init__(self, bzrdir, stack_on=None, stack_on_pwd=None,
2915
require_stacking=False):
2918
:param bzrdir: The bzrdir to create the repository on.
2919
:param stack_on: A location to stack on
2920
:param stack_on_pwd: If stack_on is relative, the location it is
2923
RepositoryAcquisitionPolicy.__init__(self, stack_on, stack_on_pwd,
2925
self._bzrdir = bzrdir
2927
def acquire_repository(self, make_working_trees=None, shared=False):
2928
"""Implementation of RepositoryAcquisitionPolicy.acquire_repository
2930
Creates the desired repository in the bzrdir we already have.
2932
repository = self._bzrdir.create_repository(shared=shared)
2933
self._add_fallback(repository)
2934
if make_working_trees is not None:
2935
repository.set_make_working_trees(make_working_trees)
2939
class UseExistingRepository(RepositoryAcquisitionPolicy):
2940
"""A policy of reusing an existing repository"""
2942
def __init__(self, repository, stack_on=None, stack_on_pwd=None,
2943
require_stacking=False):
2946
:param repository: The repository to use.
2947
:param stack_on: A location to stack on
2948
:param stack_on_pwd: If stack_on is relative, the location it is
2951
RepositoryAcquisitionPolicy.__init__(self, stack_on, stack_on_pwd,
2953
self._repository = repository
2955
def acquire_repository(self, make_working_trees=None, shared=False):
2956
"""Implementation of RepositoryAcquisitionPolicy.acquire_repository
2958
Returns an existing repository to use
2960
self._add_fallback(self._repository)
2961
return self._repository
2964
2613
format_registry = BzrDirFormatRegistry()
2965
2614
format_registry.register('weave', BzrDirFormat6,
2966
2615
'Pre-0.8 format. Slower than knit and does not'
3043
2692
branch_format='bzrlib.branch.BzrBranchFormat6',
3044
2693
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3046
format_registry.register_metadir('1.6',
3047
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack5',
3048
help='A branch and pack based repository that supports stacking. ',
3049
branch_format='bzrlib.branch.BzrBranchFormat7',
3050
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3052
format_registry.register_metadir('1.6.1-rich-root',
3053
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack5RichRoot',
3054
help='A branch and pack based repository that supports stacking '
3055
'and rich root data (needed for bzr-svn). ',
3056
branch_format='bzrlib.branch.BzrBranchFormat7',
3057
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3059
format_registry.register_metadir('1.9',
3060
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6',
3061
help='A branch and pack based repository that uses btree indexes. ',
3062
branch_format='bzrlib.branch.BzrBranchFormat7',
3063
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3065
format_registry.register_metadir('1.9-rich-root',
3066
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6RichRoot',
3067
help='A branch and pack based repository that uses btree indexes '
3068
'and rich root data (needed for bzr-svn). ',
3069
branch_format='bzrlib.branch.BzrBranchFormat7',
3070
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3072
2695
# The following two formats should always just be aliases.
3073
2696
format_registry.register_metadir('development',
3074
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment2',
2697
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment0',
3075
2698
help='Current development format. Can convert data to and from pack-0.92 '
3076
2699
'(and anything compatible with pack-0.92) format repositories. '
3077
'Repositories and branches in this format can only be read by bzr.dev. '
2700
'Repositories in this format can only be read by bzr.dev. '
3079
2702
'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3081
branch_format='bzrlib.branch.BzrBranchFormat7',
2704
branch_format='bzrlib.branch.BzrBranchFormat6',
3082
2705
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3083
2706
experimental=True,
3086
2709
format_registry.register_metadir('development-subtree',
3087
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment2Subtree',
2710
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment0Subtree',
3088
2711
help='Current development format, subtree variant. Can convert data to and '
3089
'from pack-0.92-subtree (and anything compatible with '
3090
'pack-0.92-subtree) format repositories. Repositories and branches in '
3091
'this format can only be read by bzr.dev. Please read '
2712
'from pack-0.92 (and anything compatible with pack-0.92) format '
2713
'repositories. Repositories in this format can only be read by '
2714
'bzr.dev. Please read '
3092
2715
'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3094
branch_format='bzrlib.branch.BzrBranchFormat7',
2717
branch_format='bzrlib.branch.BzrBranchFormat6',
3095
2718
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3096
2719
experimental=True,
3099
# And the development formats above will have aliased one of the following:
3100
format_registry.register_metadir('development2',
3101
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment2',
3102
help='1.6.1 with B+Tree based index. '
3104
'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3106
branch_format='bzrlib.branch.BzrBranchFormat7',
3107
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3111
format_registry.register_metadir('development2-subtree',
3112
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment2Subtree',
3113
help='1.6.1-subtree with B+Tree based index. '
3115
'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3117
branch_format='bzrlib.branch.BzrBranchFormat7',
3118
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3122
# The current format that is made on 'bzr init'.
2722
# And the development formats which the will have aliased one of follow:
2723
format_registry.register_metadir('development0',
2724
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment0',
2725
help='Trivial rename of pack-0.92 to provide a development format. '
2727
'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
2729
branch_format='bzrlib.branch.BzrBranchFormat6',
2730
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2734
format_registry.register_metadir('development0-subtree',
2735
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment0Subtree',
2736
help='Trivial rename of pack-0.92-subtree to provide a development format. '
2738
'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
2740
branch_format='bzrlib.branch.BzrBranchFormat6',
2741
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3123
2745
format_registry.set_default('pack-0.92')