1
# Copyright (C) 2006-2010 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
"""Weave-era BzrDir formats."""
19
from bzrlib.bzrdir import (
24
from bzrlib.controldir import (
28
from bzrlib.lazy_import import lazy_import
29
lazy_import(globals(), """
39
revision as _mod_revision,
47
from bzrlib.i18n import gettext
48
from bzrlib.store.versioned import VersionedFileStore
49
from bzrlib.transactions import WriteTransaction
50
from bzrlib.transport import (
54
from bzrlib.plugins.weave_fmt import xml4
58
class BzrDirFormatAllInOne(BzrDirFormat):
59
"""Common class for formats before meta-dirs."""
61
fixed_components = True
63
def initialize_on_transport_ex(self, transport, use_existing_dir=False,
64
create_prefix=False, force_new_repo=False, stacked_on=None,
65
stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
67
"""See BzrDirFormat.initialize_on_transport_ex."""
68
require_stacking = (stacked_on is not None)
69
# Format 5 cannot stack, but we've been asked to - actually init
72
format = BzrDirMetaFormat1()
73
return format.initialize_on_transport_ex(transport,
74
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
75
force_new_repo=force_new_repo, stacked_on=stacked_on,
76
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
77
make_working_trees=make_working_trees, shared_repo=shared_repo)
78
return BzrDirFormat.initialize_on_transport_ex(self, transport,
79
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
80
force_new_repo=force_new_repo, stacked_on=stacked_on,
81
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
82
make_working_trees=make_working_trees, shared_repo=shared_repo)
85
class BzrDirFormat5(BzrDirFormatAllInOne):
86
"""Bzr control format 5.
88
This format is a combined format for working tree, branch and repository.
90
- Format 2 working trees [always]
91
- Format 4 branches [always]
92
- Format 5 repositories [always]
93
Unhashed stores in the repository.
96
_lock_class = lockable_files.TransportLock
98
def __eq__(self, other):
99
return type(self) == type(other)
101
def get_format_string(self):
102
"""See BzrDirFormat.get_format_string()."""
103
return "Bazaar-NG branch, format 5\n"
105
def get_branch_format(self):
106
from bzrlib.plugins.weave_fmt.branch import BzrBranchFormat4
107
return BzrBranchFormat4()
109
def get_format_description(self):
110
"""See BzrDirFormat.get_format_description()."""
111
return "All-in-one format 5"
113
def get_converter(self, format=None):
114
"""See BzrDirFormat.get_converter()."""
115
# there is one and only one upgrade path here.
116
return ConvertBzrDir5To6()
118
def _initialize_for_clone(self, url):
119
return self.initialize_on_transport(get_transport(url), _cloning=True)
121
def initialize_on_transport(self, transport, _cloning=False):
122
"""Format 5 dirs always have working tree, branch and repository.
124
Except when they are being cloned.
126
from bzrlib.plugins.weave_fmt.branch import BzrBranchFormat4
127
from bzrlib.plugins.weave_fmt.repository import RepositoryFormat5
128
result = (super(BzrDirFormat5, self).initialize_on_transport(transport))
129
RepositoryFormat5().initialize(result, _internal=True)
131
branch = BzrBranchFormat4().initialize(result)
132
result._init_workingtree()
135
def network_name(self):
136
return self.get_format_string()
138
def _open(self, transport):
139
"""See BzrDirFormat._open."""
140
return BzrDir5(transport, self)
142
def __return_repository_format(self):
143
"""Circular import protection."""
144
from bzrlib.plugins.weave_fmt.repository import RepositoryFormat5
145
return RepositoryFormat5()
146
repository_format = property(__return_repository_format)
149
class BzrDirFormat6(BzrDirFormatAllInOne):
150
"""Bzr control format 6.
152
This format is a combined format for working tree, branch and repository.
154
- Format 2 working trees [always]
155
- Format 4 branches [always]
156
- Format 6 repositories [always]
159
_lock_class = lockable_files.TransportLock
161
def __eq__(self, other):
162
return type(self) == type(other)
164
def get_format_string(self):
165
"""See BzrDirFormat.get_format_string()."""
166
return "Bazaar-NG branch, format 6\n"
168
def get_format_description(self):
169
"""See BzrDirFormat.get_format_description()."""
170
return "All-in-one format 6"
172
def get_branch_format(self):
173
from bzrlib.plugins.weave_fmt.branch import BzrBranchFormat4
174
return BzrBranchFormat4()
176
def get_converter(self, format=None):
177
"""See BzrDirFormat.get_converter()."""
178
# there is one and only one upgrade path here.
179
return ConvertBzrDir6ToMeta()
181
def _initialize_for_clone(self, url):
182
return self.initialize_on_transport(get_transport(url), _cloning=True)
184
def initialize_on_transport(self, transport, _cloning=False):
185
"""Format 6 dirs always have working tree, branch and repository.
187
Except when they are being cloned.
189
from bzrlib.plugins.weave_fmt.branch import BzrBranchFormat4
190
from bzrlib.plugins.weave_fmt.repository import RepositoryFormat6
191
result = super(BzrDirFormat6, self).initialize_on_transport(transport)
192
RepositoryFormat6().initialize(result, _internal=True)
194
branch = BzrBranchFormat4().initialize(result)
195
result._init_workingtree()
198
def network_name(self):
199
return self.get_format_string()
201
def _open(self, transport):
202
"""See BzrDirFormat._open."""
203
return BzrDir6(transport, self)
205
def __return_repository_format(self):
206
"""Circular import protection."""
207
from bzrlib.plugins.weave_fmt.repository import RepositoryFormat6
208
return RepositoryFormat6()
209
repository_format = property(__return_repository_format)
212
class ConvertBzrDir4To5(Converter):
213
"""Converts format 4 bzr dirs to format 5."""
216
super(ConvertBzrDir4To5, self).__init__()
217
self.converted_revs = set()
218
self.absent_revisions = set()
222
def convert(self, to_convert, pb):
223
"""See Converter.convert()."""
224
self.bzrdir = to_convert
226
warnings.warn(gettext("pb parameter to convert() is deprecated"))
227
self.pb = ui.ui_factory.nested_progress_bar()
229
ui.ui_factory.note(gettext('starting upgrade from format 4 to 5'))
230
if isinstance(self.bzrdir.transport, local.LocalTransport):
231
self.bzrdir.get_workingtree_transport(None).delete('stat-cache')
232
self._convert_to_weaves()
233
return BzrDir.open(self.bzrdir.user_url)
237
def _convert_to_weaves(self):
238
ui.ui_factory.note(gettext(
239
'note: upgrade may be faster if all store files are ungzipped first'))
242
stat = self.bzrdir.transport.stat('weaves')
243
if not S_ISDIR(stat.st_mode):
244
self.bzrdir.transport.delete('weaves')
245
self.bzrdir.transport.mkdir('weaves')
246
except errors.NoSuchFile:
247
self.bzrdir.transport.mkdir('weaves')
248
# deliberately not a WeaveFile as we want to build it up slowly.
249
self.inv_weave = weave.Weave('inventory')
250
# holds in-memory weaves for all files
251
self.text_weaves = {}
252
self.bzrdir.transport.delete('branch-format')
253
self.branch = self.bzrdir.open_branch()
254
self._convert_working_inv()
255
rev_history = self.branch.revision_history()
256
# to_read is a stack holding the revisions we still need to process;
257
# appending to it adds new highest-priority revisions
258
self.known_revisions = set(rev_history)
259
self.to_read = rev_history[-1:]
261
rev_id = self.to_read.pop()
262
if (rev_id not in self.revisions
263
and rev_id not in self.absent_revisions):
264
self._load_one_rev(rev_id)
266
to_import = self._make_order()
267
for i, rev_id in enumerate(to_import):
268
self.pb.update(gettext('converting revision'), i, len(to_import))
269
self._convert_one_rev(rev_id)
271
self._write_all_weaves()
272
self._write_all_revs()
273
ui.ui_factory.note(gettext('upgraded to weaves:'))
274
ui.ui_factory.note(' ' + gettext('%6d revisions and inventories') %
276
ui.ui_factory.note(' ' + gettext('%6d revisions not present') %
277
len(self.absent_revisions))
278
ui.ui_factory.note(' ' + gettext('%6d texts') % self.text_count)
279
self._cleanup_spare_files_after_format4()
280
self.branch._transport.put_bytes(
282
BzrDirFormat5().get_format_string(),
283
mode=self.bzrdir._get_file_mode())
285
def _cleanup_spare_files_after_format4(self):
286
# FIXME working tree upgrade foo.
287
for n in 'merged-patches', 'pending-merged-patches':
289
## assert os.path.getsize(p) == 0
290
self.bzrdir.transport.delete(n)
291
except errors.NoSuchFile:
293
self.bzrdir.transport.delete_tree('inventory-store')
294
self.bzrdir.transport.delete_tree('text-store')
296
def _convert_working_inv(self):
297
inv = xml4.serializer_v4.read_inventory(
298
self.branch._transport.get('inventory'))
299
new_inv_xml = xml5.serializer_v5.write_inventory_to_string(inv, working=True)
300
self.branch._transport.put_bytes('inventory', new_inv_xml,
301
mode=self.bzrdir._get_file_mode())
303
def _write_all_weaves(self):
304
controlweaves = VersionedFileStore(self.bzrdir.transport, prefixed=False,
305
versionedfile_class=weave.WeaveFile)
306
weave_transport = self.bzrdir.transport.clone('weaves')
307
weaves = VersionedFileStore(weave_transport, prefixed=False,
308
versionedfile_class=weave.WeaveFile)
309
transaction = WriteTransaction()
313
for file_id, file_weave in self.text_weaves.items():
314
self.pb.update(gettext('writing weave'), i,
315
len(self.text_weaves))
316
weaves._put_weave(file_id, file_weave, transaction)
318
self.pb.update(gettext('inventory'), 0, 1)
319
controlweaves._put_weave('inventory', self.inv_weave, transaction)
320
self.pb.update(gettext('inventory'), 1, 1)
324
def _write_all_revs(self):
325
"""Write all revisions out in new form."""
326
self.bzrdir.transport.delete_tree('revision-store')
327
self.bzrdir.transport.mkdir('revision-store')
328
revision_transport = self.bzrdir.transport.clone('revision-store')
330
from bzrlib.xml5 import serializer_v5
331
from bzrlib.plugins.weave_fmt.repository import RevisionTextStore
332
revision_store = RevisionTextStore(revision_transport,
333
serializer_v5, False, versionedfile.PrefixMapper(),
334
lambda:True, lambda:True)
336
for i, rev_id in enumerate(self.converted_revs):
337
self.pb.update(gettext('write revision'), i,
338
len(self.converted_revs))
339
text = serializer_v5.write_revision_to_string(
340
self.revisions[rev_id])
342
revision_store.add_lines(key, None, osutils.split_lines(text))
346
def _load_one_rev(self, rev_id):
347
"""Load a revision object into memory.
349
Any parents not either loaded or abandoned get queued to be
351
self.pb.update(gettext('loading revision'),
353
len(self.known_revisions))
354
if not self.branch.repository.has_revision(rev_id):
356
ui.ui_factory.note(gettext('revision {%s} not present in branch; '
357
'will be converted as a ghost') %
359
self.absent_revisions.add(rev_id)
361
rev = self.branch.repository.get_revision(rev_id)
362
for parent_id in rev.parent_ids:
363
self.known_revisions.add(parent_id)
364
self.to_read.append(parent_id)
365
self.revisions[rev_id] = rev
367
def _load_old_inventory(self, rev_id):
368
f = self.branch.repository.inventory_store.get(rev_id)
370
old_inv_xml = f.read()
373
inv = xml4.serializer_v4.read_inventory_from_string(old_inv_xml)
374
inv.revision_id = rev_id
375
rev = self.revisions[rev_id]
378
def _load_updated_inventory(self, rev_id):
379
inv_xml = self.inv_weave.get_text(rev_id)
380
inv = xml5.serializer_v5.read_inventory_from_string(inv_xml, rev_id)
383
def _convert_one_rev(self, rev_id):
384
"""Convert revision and all referenced objects to new format."""
385
rev = self.revisions[rev_id]
386
inv = self._load_old_inventory(rev_id)
387
present_parents = [p for p in rev.parent_ids
388
if p not in self.absent_revisions]
389
self._convert_revision_contents(rev, inv, present_parents)
390
self._store_new_inv(rev, inv, present_parents)
391
self.converted_revs.add(rev_id)
393
def _store_new_inv(self, rev, inv, present_parents):
394
new_inv_xml = xml5.serializer_v5.write_inventory_to_string(inv)
395
new_inv_sha1 = osutils.sha_string(new_inv_xml)
396
self.inv_weave.add_lines(rev.revision_id,
398
new_inv_xml.splitlines(True))
399
rev.inventory_sha1 = new_inv_sha1
401
def _convert_revision_contents(self, rev, inv, present_parents):
402
"""Convert all the files within a revision.
404
Also upgrade the inventory to refer to the text revision ids."""
405
rev_id = rev.revision_id
406
trace.mutter('converting texts of revision {%s}', rev_id)
407
parent_invs = map(self._load_updated_inventory, present_parents)
408
entries = inv.iter_entries()
410
for path, ie in entries:
411
self._convert_file_version(rev, ie, parent_invs)
413
def _convert_file_version(self, rev, ie, parent_invs):
414
"""Convert one version of one file.
416
The file needs to be added into the weave if it is a merge
417
of >=2 parents or if it's changed from its parent.
420
rev_id = rev.revision_id
421
w = self.text_weaves.get(file_id)
423
w = weave.Weave(file_id)
424
self.text_weaves[file_id] = w
426
parent_candiate_entries = ie.parent_candidates(parent_invs)
427
heads = graph.Graph(self).heads(parent_candiate_entries.keys())
428
# XXX: Note that this is unordered - and this is tolerable because
429
# the previous code was also unordered.
430
previous_entries = dict((head, parent_candiate_entries[head]) for head
432
self.snapshot_ie(previous_entries, ie, w, rev_id)
434
def get_parent_map(self, revision_ids):
435
"""See graph.StackedParentsProvider.get_parent_map"""
436
return dict((revision_id, self.revisions[revision_id])
437
for revision_id in revision_ids
438
if revision_id in self.revisions)
440
def snapshot_ie(self, previous_revisions, ie, w, rev_id):
441
# TODO: convert this logic, which is ~= snapshot to
442
# a call to:. This needs the path figured out. rather than a work_tree
443
# a v4 revision_tree can be given, or something that looks enough like
444
# one to give the file content to the entry if it needs it.
445
# and we need something that looks like a weave store for snapshot to
447
#ie.snapshot(rev, PATH, previous_revisions, REVISION_TREE, InMemoryWeaveStore(self.text_weaves))
448
if len(previous_revisions) == 1:
449
previous_ie = previous_revisions.values()[0]
450
if ie._unchanged(previous_ie):
451
ie.revision = previous_ie.revision
454
f = self.branch.repository._text_store.get(ie.text_id)
456
file_lines = f.readlines()
459
w.add_lines(rev_id, previous_revisions, file_lines)
462
w.add_lines(rev_id, previous_revisions, [])
465
def _make_order(self):
466
"""Return a suitable order for importing revisions.
468
The order must be such that an revision is imported after all
469
its (present) parents.
471
todo = set(self.revisions.keys())
472
done = self.absent_revisions.copy()
475
# scan through looking for a revision whose parents
477
for rev_id in sorted(list(todo)):
478
rev = self.revisions[rev_id]
479
parent_ids = set(rev.parent_ids)
480
if parent_ids.issubset(done):
481
# can take this one now
488
class ConvertBzrDir5To6(Converter):
489
"""Converts format 5 bzr dirs to format 6."""
491
def convert(self, to_convert, pb):
492
"""See Converter.convert()."""
493
self.bzrdir = to_convert
494
pb = ui.ui_factory.nested_progress_bar()
496
ui.ui_factory.note(gettext('starting upgrade from format 5 to 6'))
497
self._convert_to_prefixed()
498
return BzrDir.open(self.bzrdir.user_url)
502
def _convert_to_prefixed(self):
503
from bzrlib.store import TransportStore
504
self.bzrdir.transport.delete('branch-format')
505
for store_name in ["weaves", "revision-store"]:
506
ui.ui_factory.note(gettext("adding prefixes to %s") % store_name)
507
store_transport = self.bzrdir.transport.clone(store_name)
508
store = TransportStore(store_transport, prefixed=True)
509
for urlfilename in store_transport.list_dir('.'):
510
filename = urlutils.unescape(urlfilename)
511
if (filename.endswith(".weave") or
512
filename.endswith(".gz") or
513
filename.endswith(".sig")):
514
file_id, suffix = os.path.splitext(filename)
518
new_name = store._mapper.map((file_id,)) + suffix
519
# FIXME keep track of the dirs made RBC 20060121
521
store_transport.move(filename, new_name)
522
except errors.NoSuchFile: # catches missing dirs strangely enough
523
store_transport.mkdir(osutils.dirname(new_name))
524
store_transport.move(filename, new_name)
525
self.bzrdir.transport.put_bytes(
527
BzrDirFormat6().get_format_string(),
528
mode=self.bzrdir._get_file_mode())
531
class ConvertBzrDir6ToMeta(Converter):
532
"""Converts format 6 bzr dirs to metadirs."""
534
def convert(self, to_convert, pb):
535
"""See Converter.convert()."""
536
from bzrlib.plugins.weave_fmt.repository import RepositoryFormat7
537
from bzrlib.branch import BzrBranchFormat5
538
self.bzrdir = to_convert
539
self.pb = ui.ui_factory.nested_progress_bar()
541
self.total = 20 # the steps we know about
542
self.garbage_inventories = []
543
self.dir_mode = self.bzrdir._get_dir_mode()
544
self.file_mode = self.bzrdir._get_file_mode()
546
ui.ui_factory.note(gettext('starting upgrade from format 6 to metadir'))
547
self.bzrdir.transport.put_bytes(
549
"Converting to format 6",
551
# its faster to move specific files around than to open and use the apis...
552
# first off, nuke ancestry.weave, it was never used.
554
self.step(gettext('Removing ancestry.weave'))
555
self.bzrdir.transport.delete('ancestry.weave')
556
except errors.NoSuchFile:
558
# find out whats there
559
self.step(gettext('Finding branch files'))
560
last_revision = self.bzrdir.open_branch().last_revision()
561
bzrcontents = self.bzrdir.transport.list_dir('.')
562
for name in bzrcontents:
563
if name.startswith('basis-inventory.'):
564
self.garbage_inventories.append(name)
565
# create new directories for repository, working tree and branch
566
repository_names = [('inventory.weave', True),
567
('revision-store', True),
569
self.step(gettext('Upgrading repository') + ' ')
570
self.bzrdir.transport.mkdir('repository', mode=self.dir_mode)
571
self.make_lock('repository')
572
# we hard code the formats here because we are converting into
573
# the meta format. The meta format upgrader can take this to a
574
# future format within each component.
575
self.put_format('repository', RepositoryFormat7())
576
for entry in repository_names:
577
self.move_entry('repository', entry)
579
self.step(gettext('Upgrading branch') + ' ')
580
self.bzrdir.transport.mkdir('branch', mode=self.dir_mode)
581
self.make_lock('branch')
582
self.put_format('branch', BzrBranchFormat5())
583
branch_files = [('revision-history', True),
584
('branch-name', True),
586
for entry in branch_files:
587
self.move_entry('branch', entry)
589
checkout_files = [('pending-merges', True),
591
('stat-cache', False)]
592
# If a mandatory checkout file is not present, the branch does not have
593
# a functional checkout. Do not create a checkout in the converted
595
for name, mandatory in checkout_files:
596
if mandatory and name not in bzrcontents:
602
ui.ui_factory.note(gettext('No working tree.'))
603
# If some checkout files are there, we may as well get rid of them.
604
for name, mandatory in checkout_files:
605
if name in bzrcontents:
606
self.bzrdir.transport.delete(name)
608
from bzrlib.workingtree_3 import WorkingTreeFormat3
609
self.step(gettext('Upgrading working tree'))
610
self.bzrdir.transport.mkdir('checkout', mode=self.dir_mode)
611
self.make_lock('checkout')
613
'checkout', WorkingTreeFormat3())
614
self.bzrdir.transport.delete_multi(
615
self.garbage_inventories, self.pb)
616
for entry in checkout_files:
617
self.move_entry('checkout', entry)
618
if last_revision is not None:
619
self.bzrdir.transport.put_bytes(
620
'checkout/last-revision', last_revision)
621
self.bzrdir.transport.put_bytes(
623
BzrDirMetaFormat1().get_format_string(),
626
return BzrDir.open(self.bzrdir.user_url)
628
def make_lock(self, name):
629
"""Make a lock for the new control dir name."""
630
self.step(gettext('Make %s lock') % name)
631
ld = lockdir.LockDir(self.bzrdir.transport,
633
file_modebits=self.file_mode,
634
dir_modebits=self.dir_mode)
637
def move_entry(self, new_dir, entry):
638
"""Move then entry name into new_dir."""
641
self.step(gettext('Moving %s') % name)
643
self.bzrdir.transport.move(name, '%s/%s' % (new_dir, name))
644
except errors.NoSuchFile:
648
def put_format(self, dirname, format):
649
self.bzrdir.transport.put_bytes('%s/format' % dirname,
650
format.get_format_string(),
654
class BzrDirFormat4(BzrDirFormat):
657
This format is a combined format for working tree, branch and repository.
659
- Format 1 working trees [always]
660
- Format 4 branches [always]
661
- Format 4 repositories [always]
663
This format is deprecated: it indexes texts using a text it which is
664
removed in format 5; write support for this format has been removed.
667
_lock_class = lockable_files.TransportLock
669
def __eq__(self, other):
670
return type(self) == type(other)
672
def get_format_string(self):
673
"""See BzrDirFormat.get_format_string()."""
674
return "Bazaar-NG branch, format 0.0.4\n"
676
def get_format_description(self):
677
"""See BzrDirFormat.get_format_description()."""
678
return "All-in-one format 4"
680
def get_converter(self, format=None):
681
"""See BzrDirFormat.get_converter()."""
682
# there is one and only one upgrade path here.
683
return ConvertBzrDir4To5()
685
def initialize_on_transport(self, transport):
686
"""Format 4 branches cannot be created."""
687
raise errors.UninitializableFormat(self)
689
def is_supported(self):
690
"""Format 4 is not supported.
692
It is not supported because the model changed from 4 to 5 and the
693
conversion logic is expensive - so doing it on the fly was not
698
def network_name(self):
699
return self.get_format_string()
701
def _open(self, transport):
702
"""See BzrDirFormat._open."""
703
return BzrDir4(transport, self)
705
def __return_repository_format(self):
706
"""Circular import protection."""
707
from bzrlib.plugins.weave_fmt.repository import RepositoryFormat4
708
return RepositoryFormat4()
709
repository_format = property(__return_repository_format)
712
class BzrDirPreSplitOut(BzrDir):
713
"""A common class for the all-in-one formats."""
715
def __init__(self, _transport, _format):
716
"""See BzrDir.__init__."""
717
super(BzrDirPreSplitOut, self).__init__(_transport, _format)
718
self._control_files = lockable_files.LockableFiles(
719
self.get_branch_transport(None),
720
self._format._lock_file_name,
721
self._format._lock_class)
723
def break_lock(self):
724
"""Pre-splitout bzrdirs do not suffer from stale locks."""
725
raise NotImplementedError(self.break_lock)
727
def cloning_metadir(self, require_stacking=False):
728
"""Produce a metadir suitable for cloning with."""
730
return format_registry.make_bzrdir('1.6')
731
return self._format.__class__()
733
def clone(self, url, revision_id=None, force_new_repo=False,
734
preserve_stacking=False):
735
"""See BzrDir.clone().
737
force_new_repo has no effect, since this family of formats always
738
require a new repository.
739
preserve_stacking has no effect, since no source branch using this
740
family of formats can be stacked, so there is no stacking to preserve.
743
result = self._format._initialize_for_clone(url)
744
self.open_repository().clone(result, revision_id=revision_id)
745
from_branch = self.open_branch()
746
from_branch.clone(result, revision_id=revision_id)
748
tree = self.open_workingtree()
749
except errors.NotLocalUrl:
750
# make a new one, this format always has to have one.
751
result._init_workingtree()
756
def create_branch(self, name=None, repository=None,
757
append_revisions_only=None):
758
"""See BzrDir.create_branch."""
759
if repository is not None:
760
raise NotImplementedError(
761
"create_branch(repository=<not None>) on %r" % (self,))
762
return self._format.get_branch_format().initialize(self, name=name,
763
append_revisions_only=append_revisions_only)
765
def destroy_branch(self, name=None):
766
"""See BzrDir.destroy_branch."""
767
raise errors.UnsupportedOperation(self.destroy_branch, self)
769
def create_repository(self, shared=False):
770
"""See BzrDir.create_repository."""
772
raise errors.IncompatibleFormat('shared repository', self._format)
773
return self.open_repository()
775
def destroy_repository(self):
776
"""See BzrDir.destroy_repository."""
777
raise errors.UnsupportedOperation(self.destroy_repository, self)
779
def create_workingtree(self, revision_id=None, from_branch=None,
780
accelerator_tree=None, hardlink=False):
781
"""See BzrDir.create_workingtree."""
782
# The workingtree is sometimes created when the bzrdir is created,
783
# but not when cloning.
785
# this looks buggy but is not -really-
786
# because this format creates the workingtree when the bzrdir is
788
# clone and sprout will have set the revision_id
789
# and that will have set it for us, its only
790
# specific uses of create_workingtree in isolation
791
# that can do wonky stuff here, and that only
792
# happens for creating checkouts, which cannot be
793
# done on this format anyway. So - acceptable wart.
795
warning("can't support hardlinked working trees in %r"
798
result = self.open_workingtree(recommend_upgrade=False)
799
except errors.NoSuchFile:
800
result = self._init_workingtree()
801
if revision_id is not None:
802
if revision_id == _mod_revision.NULL_REVISION:
803
result.set_parent_ids([])
805
result.set_parent_ids([revision_id])
808
def _init_workingtree(self):
809
from bzrlib.plugins.weave_fmt.workingtree import WorkingTreeFormat2
811
return WorkingTreeFormat2().initialize(self)
812
except errors.NotLocalUrl:
813
# Even though we can't access the working tree, we need to
814
# create its control files.
815
return WorkingTreeFormat2()._stub_initialize_on_transport(
816
self.transport, self._control_files._file_mode)
818
def destroy_workingtree(self):
819
"""See BzrDir.destroy_workingtree."""
820
raise errors.UnsupportedOperation(self.destroy_workingtree, self)
822
def destroy_workingtree_metadata(self):
823
"""See BzrDir.destroy_workingtree_metadata."""
824
raise errors.UnsupportedOperation(self.destroy_workingtree_metadata,
827
def get_branch_transport(self, branch_format, name=None):
828
"""See BzrDir.get_branch_transport()."""
830
raise errors.NoColocatedBranchSupport(self)
831
if branch_format is None:
832
return self.transport
834
branch_format.get_format_string()
835
except NotImplementedError:
836
return self.transport
837
raise errors.IncompatibleFormat(branch_format, self._format)
839
def get_repository_transport(self, repository_format):
840
"""See BzrDir.get_repository_transport()."""
841
if repository_format is None:
842
return self.transport
844
repository_format.get_format_string()
845
except NotImplementedError:
846
return self.transport
847
raise errors.IncompatibleFormat(repository_format, self._format)
849
def get_workingtree_transport(self, workingtree_format):
850
"""See BzrDir.get_workingtree_transport()."""
851
if workingtree_format is None:
852
return self.transport
854
workingtree_format.get_format_string()
855
except NotImplementedError:
856
return self.transport
857
raise errors.IncompatibleFormat(workingtree_format, self._format)
859
def needs_format_conversion(self, format=None):
860
"""See BzrDir.needs_format_conversion()."""
861
# if the format is not the same as the system default,
862
# an upgrade is needed.
864
symbol_versioning.warn(symbol_versioning.deprecated_in((1, 13, 0))
865
% 'needs_format_conversion(format=None)')
866
format = BzrDirFormat.get_default_format()
867
return not isinstance(self._format, format.__class__)
869
def open_branch(self, name=None, unsupported=False,
870
ignore_fallbacks=False):
871
"""See BzrDir.open_branch."""
872
from bzrlib.plugins.weave_fmt.branch import BzrBranchFormat4
873
format = BzrBranchFormat4()
874
format.check_support_status(unsupported)
875
return format.open(self, name, _found=True)
877
def sprout(self, url, revision_id=None, force_new_repo=False,
878
possible_transports=None, accelerator_tree=None,
879
hardlink=False, stacked=False, create_tree_if_local=True,
881
"""See BzrDir.sprout()."""
882
if source_branch is not None:
883
my_branch = self.open_branch()
884
if source_branch.base != my_branch.base:
885
raise AssertionError(
886
"source branch %r is not within %r with branch %r" %
887
(source_branch, self, my_branch))
889
raise errors.UnstackableBranchFormat(
890
self._format, self.root_transport.base)
891
if not create_tree_if_local:
892
raise errors.MustHaveWorkingTree(
893
self._format, self.root_transport.base)
894
from bzrlib.plugins.weave_fmt.workingtree import WorkingTreeFormat2
896
result = self._format._initialize_for_clone(url)
898
self.open_repository().clone(result, revision_id=revision_id)
899
except errors.NoRepositoryPresent:
902
self.open_branch().sprout(result, revision_id=revision_id)
903
except errors.NotBranchError:
906
# we always want a working tree
907
WorkingTreeFormat2().initialize(result,
908
accelerator_tree=accelerator_tree,
913
class BzrDir4(BzrDirPreSplitOut):
914
"""A .bzr version 4 control object.
916
This is a deprecated format and may be removed after sept 2006.
919
def create_repository(self, shared=False):
920
"""See BzrDir.create_repository."""
921
return self._format.repository_format.initialize(self, shared)
923
def needs_format_conversion(self, format=None):
924
"""Format 4 dirs are always in need of conversion."""
926
symbol_versioning.warn(symbol_versioning.deprecated_in((1, 13, 0))
927
% 'needs_format_conversion(format=None)')
930
def open_repository(self):
931
"""See BzrDir.open_repository."""
932
from bzrlib.plugins.weave_fmt.repository import RepositoryFormat4
933
return RepositoryFormat4().open(self, _found=True)
936
class BzrDir5(BzrDirPreSplitOut):
937
"""A .bzr version 5 control object.
939
This is a deprecated format and may be removed after sept 2006.
942
def has_workingtree(self):
943
"""See BzrDir.has_workingtree."""
946
def open_repository(self):
947
"""See BzrDir.open_repository."""
948
from bzrlib.plugins.weave_fmt.repository import RepositoryFormat5
949
return RepositoryFormat5().open(self, _found=True)
951
def open_workingtree(self, _unsupported=False,
952
recommend_upgrade=True):
953
"""See BzrDir.create_workingtree."""
954
from bzrlib.plugins.weave_fmt.workingtree import WorkingTreeFormat2
955
wt_format = WorkingTreeFormat2()
956
# we don't warn here about upgrades; that ought to be handled for the
958
return wt_format.open(self, _found=True)
961
class BzrDir6(BzrDirPreSplitOut):
962
"""A .bzr version 6 control object.
964
This is a deprecated format and may be removed after sept 2006.
967
def has_workingtree(self):
968
"""See BzrDir.has_workingtree."""
971
def open_repository(self):
972
"""See BzrDir.open_repository."""
973
from bzrlib.plugins.weave_fmt.repository import RepositoryFormat6
974
return RepositoryFormat6().open(self, _found=True)
976
def open_workingtree(self, _unsupported=False,
977
recommend_upgrade=True):
978
"""See BzrDir.create_workingtree."""
979
# we don't warn here about upgrades; that ought to be handled for the
981
from bzrlib.plugins.weave_fmt.workingtree import WorkingTreeFormat2
982
return WorkingTreeFormat2().open(self, _found=True)