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 __future__ import absolute_import
21
from bzrlib.bzrdir import (
26
from bzrlib.controldir import (
31
from bzrlib.lazy_import import lazy_import
32
lazy_import(globals(), """
42
revision as _mod_revision,
50
from bzrlib.i18n import gettext
51
from bzrlib.store.versioned import VersionedFileStore
52
from bzrlib.transactions import WriteTransaction
53
from bzrlib.transport import (
57
from bzrlib.plugins.weave_fmt import xml4
61
class BzrDirFormatAllInOne(BzrDirFormat):
62
"""Common class for formats before meta-dirs."""
64
fixed_components = True
66
def initialize_on_transport_ex(self, transport, use_existing_dir=False,
67
create_prefix=False, force_new_repo=False, stacked_on=None,
68
stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
70
"""See ControlDir.initialize_on_transport_ex."""
71
require_stacking = (stacked_on is not None)
72
# Format 5 cannot stack, but we've been asked to - actually init
75
format = BzrDirMetaFormat1()
76
return format.initialize_on_transport_ex(transport,
77
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
78
force_new_repo=force_new_repo, stacked_on=stacked_on,
79
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
80
make_working_trees=make_working_trees, shared_repo=shared_repo)
81
return BzrDirFormat.initialize_on_transport_ex(self, transport,
82
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
83
force_new_repo=force_new_repo, stacked_on=stacked_on,
84
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
85
make_working_trees=make_working_trees, shared_repo=shared_repo)
88
def from_string(cls, format_string):
89
if format_string != cls.get_format_string():
90
raise AssertionError("unexpected format string %r" % format_string)
94
class BzrDirFormat5(BzrDirFormatAllInOne):
95
"""Bzr control format 5.
97
This format is a combined format for working tree, branch and repository.
99
- Format 2 working trees [always]
100
- Format 4 branches [always]
101
- Format 5 repositories [always]
102
Unhashed stores in the repository.
105
_lock_class = lockable_files.TransportLock
107
def __eq__(self, other):
108
return type(self) == type(other)
111
def get_format_string(cls):
112
"""See BzrDirFormat.get_format_string()."""
113
return "Bazaar-NG branch, format 5\n"
115
def get_branch_format(self):
116
from bzrlib.plugins.weave_fmt.branch import BzrBranchFormat4
117
return BzrBranchFormat4()
119
def get_format_description(self):
120
"""See ControlDirFormat.get_format_description()."""
121
return "All-in-one format 5"
123
def get_converter(self, format=None):
124
"""See ControlDirFormat.get_converter()."""
125
# there is one and only one upgrade path here.
126
return ConvertBzrDir5To6()
128
def _initialize_for_clone(self, url):
129
return self.initialize_on_transport(get_transport(url), _cloning=True)
131
def initialize_on_transport(self, transport, _cloning=False):
132
"""Format 5 dirs always have working tree, branch and repository.
134
Except when they are being cloned.
136
from bzrlib.plugins.weave_fmt.branch import BzrBranchFormat4
137
from bzrlib.plugins.weave_fmt.repository import RepositoryFormat5
138
result = (super(BzrDirFormat5, self).initialize_on_transport(transport))
139
RepositoryFormat5().initialize(result, _internal=True)
141
branch = BzrBranchFormat4().initialize(result)
142
result._init_workingtree()
145
def network_name(self):
146
return self.get_format_string()
148
def _open(self, transport):
149
"""See BzrDirFormat._open."""
150
return BzrDir5(transport, self)
152
def __return_repository_format(self):
153
"""Circular import protection."""
154
from bzrlib.plugins.weave_fmt.repository import RepositoryFormat5
155
return RepositoryFormat5()
156
repository_format = property(__return_repository_format)
159
class BzrDirFormat6(BzrDirFormatAllInOne):
160
"""Bzr control format 6.
162
This format is a combined format for working tree, branch and repository.
164
- Format 2 working trees [always]
165
- Format 4 branches [always]
166
- Format 6 repositories [always]
169
_lock_class = lockable_files.TransportLock
171
def __eq__(self, other):
172
return type(self) == type(other)
175
def get_format_string(cls):
176
"""See BzrDirFormat.get_format_string()."""
177
return "Bazaar-NG branch, format 6\n"
179
def get_format_description(self):
180
"""See ControlDirFormat.get_format_description()."""
181
return "All-in-one format 6"
183
def get_branch_format(self):
184
from bzrlib.plugins.weave_fmt.branch import BzrBranchFormat4
185
return BzrBranchFormat4()
187
def get_converter(self, format=None):
188
"""See ControlDirFormat.get_converter()."""
189
# there is one and only one upgrade path here.
190
return ConvertBzrDir6ToMeta()
192
def _initialize_for_clone(self, url):
193
return self.initialize_on_transport(get_transport(url), _cloning=True)
195
def initialize_on_transport(self, transport, _cloning=False):
196
"""Format 6 dirs always have working tree, branch and repository.
198
Except when they are being cloned.
200
from bzrlib.plugins.weave_fmt.branch import BzrBranchFormat4
201
from bzrlib.plugins.weave_fmt.repository import RepositoryFormat6
202
result = super(BzrDirFormat6, self).initialize_on_transport(transport)
203
RepositoryFormat6().initialize(result, _internal=True)
205
branch = BzrBranchFormat4().initialize(result)
206
result._init_workingtree()
209
def network_name(self):
210
return self.get_format_string()
212
def _open(self, transport):
213
"""See BzrDirFormat._open."""
214
return BzrDir6(transport, self)
216
def __return_repository_format(self):
217
"""Circular import protection."""
218
from bzrlib.plugins.weave_fmt.repository import RepositoryFormat6
219
return RepositoryFormat6()
220
repository_format = property(__return_repository_format)
223
class ConvertBzrDir4To5(Converter):
224
"""Converts format 4 bzr dirs to format 5."""
227
super(ConvertBzrDir4To5, self).__init__()
228
self.converted_revs = set()
229
self.absent_revisions = set()
233
def convert(self, to_convert, pb):
234
"""See Converter.convert()."""
235
self.bzrdir = to_convert
237
warnings.warn(gettext("pb parameter to convert() is deprecated"))
238
self.pb = ui.ui_factory.nested_progress_bar()
240
ui.ui_factory.note(gettext('starting upgrade from format 4 to 5'))
241
if isinstance(self.bzrdir.transport, local.LocalTransport):
242
self.bzrdir.get_workingtree_transport(None).delete('stat-cache')
243
self._convert_to_weaves()
244
return ControlDir.open(self.bzrdir.user_url)
248
def _convert_to_weaves(self):
249
ui.ui_factory.note(gettext(
250
'note: upgrade may be faster if all store files are ungzipped first'))
253
stat = self.bzrdir.transport.stat('weaves')
254
if not S_ISDIR(stat.st_mode):
255
self.bzrdir.transport.delete('weaves')
256
self.bzrdir.transport.mkdir('weaves')
257
except errors.NoSuchFile:
258
self.bzrdir.transport.mkdir('weaves')
259
# deliberately not a WeaveFile as we want to build it up slowly.
260
self.inv_weave = weave.Weave('inventory')
261
# holds in-memory weaves for all files
262
self.text_weaves = {}
263
self.bzrdir.transport.delete('branch-format')
264
self.branch = self.bzrdir.open_branch()
265
self._convert_working_inv()
266
rev_history = self.branch._revision_history()
267
# to_read is a stack holding the revisions we still need to process;
268
# appending to it adds new highest-priority revisions
269
self.known_revisions = set(rev_history)
270
self.to_read = rev_history[-1:]
272
rev_id = self.to_read.pop()
273
if (rev_id not in self.revisions
274
and rev_id not in self.absent_revisions):
275
self._load_one_rev(rev_id)
277
to_import = self._make_order()
278
for i, rev_id in enumerate(to_import):
279
self.pb.update(gettext('converting revision'), i, len(to_import))
280
self._convert_one_rev(rev_id)
282
self._write_all_weaves()
283
self._write_all_revs()
284
ui.ui_factory.note(gettext('upgraded to weaves:'))
285
ui.ui_factory.note(' ' + gettext('%6d revisions and inventories') %
287
ui.ui_factory.note(' ' + gettext('%6d revisions not present') %
288
len(self.absent_revisions))
289
ui.ui_factory.note(' ' + gettext('%6d texts') % self.text_count)
290
self._cleanup_spare_files_after_format4()
291
self.branch._transport.put_bytes(
293
BzrDirFormat5().get_format_string(),
294
mode=self.bzrdir._get_file_mode())
296
def _cleanup_spare_files_after_format4(self):
297
# FIXME working tree upgrade foo.
298
for n in 'merged-patches', 'pending-merged-patches':
300
## assert os.path.getsize(p) == 0
301
self.bzrdir.transport.delete(n)
302
except errors.NoSuchFile:
304
self.bzrdir.transport.delete_tree('inventory-store')
305
self.bzrdir.transport.delete_tree('text-store')
307
def _convert_working_inv(self):
308
inv = xml4.serializer_v4.read_inventory(
309
self.branch._transport.get('inventory'))
310
new_inv_xml = xml5.serializer_v5.write_inventory_to_string(inv, working=True)
311
self.branch._transport.put_bytes('inventory', new_inv_xml,
312
mode=self.bzrdir._get_file_mode())
314
def _write_all_weaves(self):
315
controlweaves = VersionedFileStore(self.bzrdir.transport, prefixed=False,
316
versionedfile_class=weave.WeaveFile)
317
weave_transport = self.bzrdir.transport.clone('weaves')
318
weaves = VersionedFileStore(weave_transport, prefixed=False,
319
versionedfile_class=weave.WeaveFile)
320
transaction = WriteTransaction()
324
for file_id, file_weave in self.text_weaves.items():
325
self.pb.update(gettext('writing weave'), i,
326
len(self.text_weaves))
327
weaves._put_weave(file_id, file_weave, transaction)
329
self.pb.update(gettext('inventory'), 0, 1)
330
controlweaves._put_weave('inventory', self.inv_weave, transaction)
331
self.pb.update(gettext('inventory'), 1, 1)
335
def _write_all_revs(self):
336
"""Write all revisions out in new form."""
337
self.bzrdir.transport.delete_tree('revision-store')
338
self.bzrdir.transport.mkdir('revision-store')
339
revision_transport = self.bzrdir.transport.clone('revision-store')
341
from bzrlib.xml5 import serializer_v5
342
from bzrlib.plugins.weave_fmt.repository import RevisionTextStore
343
revision_store = RevisionTextStore(revision_transport,
344
serializer_v5, False, versionedfile.PrefixMapper(),
345
lambda:True, lambda:True)
347
for i, rev_id in enumerate(self.converted_revs):
348
self.pb.update(gettext('write revision'), i,
349
len(self.converted_revs))
350
text = serializer_v5.write_revision_to_string(
351
self.revisions[rev_id])
353
revision_store.add_lines(key, None, osutils.split_lines(text))
357
def _load_one_rev(self, rev_id):
358
"""Load a revision object into memory.
360
Any parents not either loaded or abandoned get queued to be
362
self.pb.update(gettext('loading revision'),
364
len(self.known_revisions))
365
if not self.branch.repository.has_revision(rev_id):
367
ui.ui_factory.note(gettext('revision {%s} not present in branch; '
368
'will be converted as a ghost') %
370
self.absent_revisions.add(rev_id)
372
rev = self.branch.repository.get_revision(rev_id)
373
for parent_id in rev.parent_ids:
374
self.known_revisions.add(parent_id)
375
self.to_read.append(parent_id)
376
self.revisions[rev_id] = rev
378
def _load_old_inventory(self, rev_id):
379
f = self.branch.repository.inventory_store.get(rev_id)
381
old_inv_xml = f.read()
384
inv = xml4.serializer_v4.read_inventory_from_string(old_inv_xml)
385
inv.revision_id = rev_id
386
rev = self.revisions[rev_id]
389
def _load_updated_inventory(self, rev_id):
390
inv_xml = self.inv_weave.get_text(rev_id)
391
inv = xml5.serializer_v5.read_inventory_from_string(inv_xml, rev_id)
394
def _convert_one_rev(self, rev_id):
395
"""Convert revision and all referenced objects to new format."""
396
rev = self.revisions[rev_id]
397
inv = self._load_old_inventory(rev_id)
398
present_parents = [p for p in rev.parent_ids
399
if p not in self.absent_revisions]
400
self._convert_revision_contents(rev, inv, present_parents)
401
self._store_new_inv(rev, inv, present_parents)
402
self.converted_revs.add(rev_id)
404
def _store_new_inv(self, rev, inv, present_parents):
405
new_inv_xml = xml5.serializer_v5.write_inventory_to_string(inv)
406
new_inv_sha1 = osutils.sha_string(new_inv_xml)
407
self.inv_weave.add_lines(rev.revision_id,
409
new_inv_xml.splitlines(True))
410
rev.inventory_sha1 = new_inv_sha1
412
def _convert_revision_contents(self, rev, inv, present_parents):
413
"""Convert all the files within a revision.
415
Also upgrade the inventory to refer to the text revision ids."""
416
rev_id = rev.revision_id
417
trace.mutter('converting texts of revision {%s}', rev_id)
418
parent_invs = map(self._load_updated_inventory, present_parents)
419
entries = inv.iter_entries()
421
for path, ie in entries:
422
self._convert_file_version(rev, ie, parent_invs)
424
def _convert_file_version(self, rev, ie, parent_invs):
425
"""Convert one version of one file.
427
The file needs to be added into the weave if it is a merge
428
of >=2 parents or if it's changed from its parent.
431
rev_id = rev.revision_id
432
w = self.text_weaves.get(file_id)
434
w = weave.Weave(file_id)
435
self.text_weaves[file_id] = w
437
parent_candiate_entries = ie.parent_candidates(parent_invs)
438
heads = graph.Graph(self).heads(parent_candiate_entries.keys())
439
# XXX: Note that this is unordered - and this is tolerable because
440
# the previous code was also unordered.
441
previous_entries = dict((head, parent_candiate_entries[head]) for head
443
self.snapshot_ie(previous_entries, ie, w, rev_id)
445
def get_parent_map(self, revision_ids):
446
"""See graph.StackedParentsProvider.get_parent_map"""
447
return dict((revision_id, self.revisions[revision_id])
448
for revision_id in revision_ids
449
if revision_id in self.revisions)
451
def snapshot_ie(self, previous_revisions, ie, w, rev_id):
452
# TODO: convert this logic, which is ~= snapshot to
453
# a call to:. This needs the path figured out. rather than a work_tree
454
# a v4 revision_tree can be given, or something that looks enough like
455
# one to give the file content to the entry if it needs it.
456
# and we need something that looks like a weave store for snapshot to
458
#ie.snapshot(rev, PATH, previous_revisions, REVISION_TREE, InMemoryWeaveStore(self.text_weaves))
459
if len(previous_revisions) == 1:
460
previous_ie = previous_revisions.values()[0]
461
if ie._unchanged(previous_ie):
462
ie.revision = previous_ie.revision
465
f = self.branch.repository._text_store.get(ie.text_id)
467
file_lines = f.readlines()
470
w.add_lines(rev_id, previous_revisions, file_lines)
473
w.add_lines(rev_id, previous_revisions, [])
476
def _make_order(self):
477
"""Return a suitable order for importing revisions.
479
The order must be such that an revision is imported after all
480
its (present) parents.
482
todo = set(self.revisions.keys())
483
done = self.absent_revisions.copy()
486
# scan through looking for a revision whose parents
488
for rev_id in sorted(list(todo)):
489
rev = self.revisions[rev_id]
490
parent_ids = set(rev.parent_ids)
491
if parent_ids.issubset(done):
492
# can take this one now
499
class ConvertBzrDir5To6(Converter):
500
"""Converts format 5 bzr dirs to format 6."""
502
def convert(self, to_convert, pb):
503
"""See Converter.convert()."""
504
self.bzrdir = to_convert
505
pb = ui.ui_factory.nested_progress_bar()
507
ui.ui_factory.note(gettext('starting upgrade from format 5 to 6'))
508
self._convert_to_prefixed()
509
return ControlDir.open(self.bzrdir.user_url)
513
def _convert_to_prefixed(self):
514
from bzrlib.store import TransportStore
515
self.bzrdir.transport.delete('branch-format')
516
for store_name in ["weaves", "revision-store"]:
517
ui.ui_factory.note(gettext("adding prefixes to %s") % store_name)
518
store_transport = self.bzrdir.transport.clone(store_name)
519
store = TransportStore(store_transport, prefixed=True)
520
for urlfilename in store_transport.list_dir('.'):
521
filename = urlutils.unescape(urlfilename)
522
if (filename.endswith(".weave") or
523
filename.endswith(".gz") or
524
filename.endswith(".sig")):
525
file_id, suffix = os.path.splitext(filename)
529
new_name = store._mapper.map((file_id,)) + suffix
530
# FIXME keep track of the dirs made RBC 20060121
532
store_transport.move(filename, new_name)
533
except errors.NoSuchFile: # catches missing dirs strangely enough
534
store_transport.mkdir(osutils.dirname(new_name))
535
store_transport.move(filename, new_name)
536
self.bzrdir.transport.put_bytes(
538
BzrDirFormat6().get_format_string(),
539
mode=self.bzrdir._get_file_mode())
542
class ConvertBzrDir6ToMeta(Converter):
543
"""Converts format 6 bzr dirs to metadirs."""
545
def convert(self, to_convert, pb):
546
"""See Converter.convert()."""
547
from bzrlib.plugins.weave_fmt.repository import RepositoryFormat7
548
from bzrlib.branchfmt.fullhistory import BzrBranchFormat5
549
self.bzrdir = to_convert
550
self.pb = ui.ui_factory.nested_progress_bar()
552
self.total = 20 # the steps we know about
553
self.garbage_inventories = []
554
self.dir_mode = self.bzrdir._get_dir_mode()
555
self.file_mode = self.bzrdir._get_file_mode()
557
ui.ui_factory.note(gettext('starting upgrade from format 6 to metadir'))
558
self.bzrdir.transport.put_bytes(
560
"Converting to format 6",
562
# its faster to move specific files around than to open and use the apis...
563
# first off, nuke ancestry.weave, it was never used.
565
self.step(gettext('Removing ancestry.weave'))
566
self.bzrdir.transport.delete('ancestry.weave')
567
except errors.NoSuchFile:
569
# find out whats there
570
self.step(gettext('Finding branch files'))
571
last_revision = self.bzrdir.open_branch().last_revision()
572
bzrcontents = self.bzrdir.transport.list_dir('.')
573
for name in bzrcontents:
574
if name.startswith('basis-inventory.'):
575
self.garbage_inventories.append(name)
576
# create new directories for repository, working tree and branch
577
repository_names = [('inventory.weave', True),
578
('revision-store', True),
580
self.step(gettext('Upgrading repository') + ' ')
581
self.bzrdir.transport.mkdir('repository', mode=self.dir_mode)
582
self.make_lock('repository')
583
# we hard code the formats here because we are converting into
584
# the meta format. The meta format upgrader can take this to a
585
# future format within each component.
586
self.put_format('repository', RepositoryFormat7())
587
for entry in repository_names:
588
self.move_entry('repository', entry)
590
self.step(gettext('Upgrading branch') + ' ')
591
self.bzrdir.transport.mkdir('branch', mode=self.dir_mode)
592
self.make_lock('branch')
593
self.put_format('branch', BzrBranchFormat5())
594
branch_files = [('revision-history', True),
595
('branch-name', True),
597
for entry in branch_files:
598
self.move_entry('branch', entry)
600
checkout_files = [('pending-merges', True),
602
('stat-cache', False)]
603
# If a mandatory checkout file is not present, the branch does not have
604
# a functional checkout. Do not create a checkout in the converted
606
for name, mandatory in checkout_files:
607
if mandatory and name not in bzrcontents:
613
ui.ui_factory.note(gettext('No working tree.'))
614
# If some checkout files are there, we may as well get rid of them.
615
for name, mandatory in checkout_files:
616
if name in bzrcontents:
617
self.bzrdir.transport.delete(name)
619
from bzrlib.workingtree_3 import WorkingTreeFormat3
620
self.step(gettext('Upgrading working tree'))
621
self.bzrdir.transport.mkdir('checkout', mode=self.dir_mode)
622
self.make_lock('checkout')
624
'checkout', WorkingTreeFormat3())
625
self.bzrdir.transport.delete_multi(
626
self.garbage_inventories, self.pb)
627
for entry in checkout_files:
628
self.move_entry('checkout', entry)
629
if last_revision is not None:
630
self.bzrdir.transport.put_bytes(
631
'checkout/last-revision', last_revision)
632
self.bzrdir.transport.put_bytes(
634
BzrDirMetaFormat1().get_format_string(),
637
return ControlDir.open(self.bzrdir.user_url)
639
def make_lock(self, name):
640
"""Make a lock for the new control dir name."""
641
self.step(gettext('Make %s lock') % name)
642
ld = lockdir.LockDir(self.bzrdir.transport,
644
file_modebits=self.file_mode,
645
dir_modebits=self.dir_mode)
648
def move_entry(self, new_dir, entry):
649
"""Move then entry name into new_dir."""
652
self.step(gettext('Moving %s') % name)
654
self.bzrdir.transport.move(name, '%s/%s' % (new_dir, name))
655
except errors.NoSuchFile:
659
def put_format(self, dirname, format):
660
self.bzrdir.transport.put_bytes('%s/format' % dirname,
661
format.get_format_string(),
665
class BzrDirFormat4(BzrDirFormat):
668
This format is a combined format for working tree, branch and repository.
670
- Format 1 working trees [always]
671
- Format 4 branches [always]
672
- Format 4 repositories [always]
674
This format is deprecated: it indexes texts using a text it which is
675
removed in format 5; write support for this format has been removed.
678
_lock_class = lockable_files.TransportLock
680
def __eq__(self, other):
681
return type(self) == type(other)
684
def get_format_string(cls):
685
"""See BzrDirFormat.get_format_string()."""
686
return "Bazaar-NG branch, format 0.0.4\n"
688
def get_format_description(self):
689
"""See ControlDirFormat.get_format_description()."""
690
return "All-in-one format 4"
692
def get_converter(self, format=None):
693
"""See ControlDirFormat.get_converter()."""
694
# there is one and only one upgrade path here.
695
return ConvertBzrDir4To5()
697
def initialize_on_transport(self, transport):
698
"""Format 4 branches cannot be created."""
699
raise errors.UninitializableFormat(self)
701
def is_supported(self):
702
"""Format 4 is not supported.
704
It is not supported because the model changed from 4 to 5 and the
705
conversion logic is expensive - so doing it on the fly was not
710
def network_name(self):
711
return self.get_format_string()
713
def _open(self, transport):
714
"""See BzrDirFormat._open."""
715
return BzrDir4(transport, self)
717
def __return_repository_format(self):
718
"""Circular import protection."""
719
from bzrlib.plugins.weave_fmt.repository import RepositoryFormat4
720
return RepositoryFormat4()
721
repository_format = property(__return_repository_format)
724
def from_string(cls, format_string):
725
if format_string != cls.get_format_string():
726
raise AssertionError("unexpected format string %r" % format_string)
730
class BzrDirPreSplitOut(BzrDir):
731
"""A common class for the all-in-one formats."""
733
def __init__(self, _transport, _format):
734
"""See ControlDir.__init__."""
735
super(BzrDirPreSplitOut, self).__init__(_transport, _format)
736
self._control_files = lockable_files.LockableFiles(
737
self.get_branch_transport(None),
738
self._format._lock_file_name,
739
self._format._lock_class)
741
def break_lock(self):
742
"""Pre-splitout bzrdirs do not suffer from stale locks."""
743
raise NotImplementedError(self.break_lock)
745
def cloning_metadir(self, require_stacking=False):
746
"""Produce a metadir suitable for cloning with."""
748
return format_registry.make_bzrdir('1.6')
749
return self._format.__class__()
751
def clone(self, url, revision_id=None, force_new_repo=False,
752
preserve_stacking=False):
753
"""See ControlDir.clone().
755
force_new_repo has no effect, since this family of formats always
756
require a new repository.
757
preserve_stacking has no effect, since no source branch using this
758
family of formats can be stacked, so there is no stacking to preserve.
761
result = self._format._initialize_for_clone(url)
762
self.open_repository().clone(result, revision_id=revision_id)
763
from_branch = self.open_branch()
764
from_branch.clone(result, revision_id=revision_id)
766
tree = self.open_workingtree()
767
except errors.NotLocalUrl:
768
# make a new one, this format always has to have one.
769
result._init_workingtree()
774
def create_branch(self, name=None, repository=None,
775
append_revisions_only=None):
776
"""See ControlDir.create_branch."""
777
if repository is not None:
778
raise NotImplementedError(
779
"create_branch(repository=<not None>) on %r" % (self,))
780
return self._format.get_branch_format().initialize(self, name=name,
781
append_revisions_only=append_revisions_only)
783
def destroy_branch(self, name=None):
784
"""See ControlDir.destroy_branch."""
785
raise errors.UnsupportedOperation(self.destroy_branch, self)
787
def create_repository(self, shared=False):
788
"""See ControlDir.create_repository."""
790
raise errors.IncompatibleFormat('shared repository', self._format)
791
return self.open_repository()
793
def destroy_repository(self):
794
"""See ControlDir.destroy_repository."""
795
raise errors.UnsupportedOperation(self.destroy_repository, self)
797
def create_workingtree(self, revision_id=None, from_branch=None,
798
accelerator_tree=None, hardlink=False):
799
"""See ControlDir.create_workingtree."""
800
# The workingtree is sometimes created when the bzrdir is created,
801
# but not when cloning.
803
# this looks buggy but is not -really-
804
# because this format creates the workingtree when the bzrdir is
806
# clone and sprout will have set the revision_id
807
# and that will have set it for us, its only
808
# specific uses of create_workingtree in isolation
809
# that can do wonky stuff here, and that only
810
# happens for creating checkouts, which cannot be
811
# done on this format anyway. So - acceptable wart.
813
warning("can't support hardlinked working trees in %r"
816
result = self.open_workingtree(recommend_upgrade=False)
817
except errors.NoSuchFile:
818
result = self._init_workingtree()
819
if revision_id is not None:
820
if revision_id == _mod_revision.NULL_REVISION:
821
result.set_parent_ids([])
823
result.set_parent_ids([revision_id])
826
def _init_workingtree(self):
827
from bzrlib.plugins.weave_fmt.workingtree import WorkingTreeFormat2
829
return WorkingTreeFormat2().initialize(self)
830
except errors.NotLocalUrl:
831
# Even though we can't access the working tree, we need to
832
# create its control files.
833
return WorkingTreeFormat2()._stub_initialize_on_transport(
834
self.transport, self._control_files._file_mode)
836
def destroy_workingtree(self):
837
"""See ControlDir.destroy_workingtree."""
838
raise errors.UnsupportedOperation(self.destroy_workingtree, self)
840
def destroy_workingtree_metadata(self):
841
"""See ControlDir.destroy_workingtree_metadata."""
842
raise errors.UnsupportedOperation(self.destroy_workingtree_metadata,
845
def get_branch_transport(self, branch_format, name=None):
846
"""See BzrDir.get_branch_transport()."""
848
raise errors.NoColocatedBranchSupport(self)
849
if branch_format is None:
850
return self.transport
852
branch_format.get_format_string()
853
except NotImplementedError:
854
return self.transport
855
raise errors.IncompatibleFormat(branch_format, self._format)
857
def get_repository_transport(self, repository_format):
858
"""See BzrDir.get_repository_transport()."""
859
if repository_format is None:
860
return self.transport
862
repository_format.get_format_string()
863
except NotImplementedError:
864
return self.transport
865
raise errors.IncompatibleFormat(repository_format, self._format)
867
def get_workingtree_transport(self, workingtree_format):
868
"""See BzrDir.get_workingtree_transport()."""
869
if workingtree_format is None:
870
return self.transport
872
workingtree_format.get_format_string()
873
except NotImplementedError:
874
return self.transport
875
raise errors.IncompatibleFormat(workingtree_format, self._format)
877
def needs_format_conversion(self, format=None):
878
"""See ControlDir.needs_format_conversion()."""
879
# if the format is not the same as the system default,
880
# an upgrade is needed.
882
symbol_versioning.warn(symbol_versioning.deprecated_in((1, 13, 0))
883
% 'needs_format_conversion(format=None)')
884
format = BzrDirFormat.get_default_format()
885
return not isinstance(self._format, format.__class__)
887
def open_branch(self, name=None, unsupported=False,
888
ignore_fallbacks=False, possible_transports=None):
889
"""See ControlDir.open_branch."""
890
from bzrlib.plugins.weave_fmt.branch import BzrBranchFormat4
891
format = BzrBranchFormat4()
892
format.check_support_status(unsupported)
893
return format.open(self, name, _found=True,
894
possible_transports=possible_transports)
896
def sprout(self, url, revision_id=None, force_new_repo=False,
897
possible_transports=None, accelerator_tree=None,
898
hardlink=False, stacked=False, create_tree_if_local=True,
900
"""See ControlDir.sprout()."""
901
if source_branch is not None:
902
my_branch = self.open_branch()
903
if source_branch.base != my_branch.base:
904
raise AssertionError(
905
"source branch %r is not within %r with branch %r" %
906
(source_branch, self, my_branch))
908
raise errors.UnstackableBranchFormat(
909
self._format, self.root_transport.base)
910
if not create_tree_if_local:
911
raise errors.MustHaveWorkingTree(
912
self._format, self.root_transport.base)
913
from bzrlib.plugins.weave_fmt.workingtree import WorkingTreeFormat2
915
result = self._format._initialize_for_clone(url)
917
self.open_repository().clone(result, revision_id=revision_id)
918
except errors.NoRepositoryPresent:
921
self.open_branch().sprout(result, revision_id=revision_id)
922
except errors.NotBranchError:
925
# we always want a working tree
926
WorkingTreeFormat2().initialize(result,
927
accelerator_tree=accelerator_tree,
931
def set_branch_reference(self, target_branch, name=None):
932
from bzrlib.branch import BranchReferenceFormat
934
raise errors.NoColocatedBranchSupport(self)
935
raise errors.IncompatibleFormat(BranchReferenceFormat, self._format)
938
class BzrDir4(BzrDirPreSplitOut):
939
"""A .bzr version 4 control object.
941
This is a deprecated format and may be removed after sept 2006.
944
def create_repository(self, shared=False):
945
"""See ControlDir.create_repository."""
946
return self._format.repository_format.initialize(self, shared)
948
def needs_format_conversion(self, format=None):
949
"""Format 4 dirs are always in need of conversion."""
951
symbol_versioning.warn(symbol_versioning.deprecated_in((1, 13, 0))
952
% 'needs_format_conversion(format=None)')
955
def open_repository(self):
956
"""See ControlDir.open_repository."""
957
from bzrlib.plugins.weave_fmt.repository import RepositoryFormat4
958
return RepositoryFormat4().open(self, _found=True)
961
class BzrDir5(BzrDirPreSplitOut):
962
"""A .bzr version 5 control object.
964
This is a deprecated format and may be removed after sept 2006.
967
def has_workingtree(self):
968
"""See ControlDir.has_workingtree."""
971
def open_repository(self):
972
"""See ControlDir.open_repository."""
973
from bzrlib.plugins.weave_fmt.repository import RepositoryFormat5
974
return RepositoryFormat5().open(self, _found=True)
976
def open_workingtree(self, unsupported=False,
977
recommend_upgrade=True):
978
"""See ControlDir.create_workingtree."""
979
from bzrlib.plugins.weave_fmt.workingtree import WorkingTreeFormat2
980
wt_format = WorkingTreeFormat2()
981
# we don't warn here about upgrades; that ought to be handled for the
983
return wt_format.open(self, _found=True)
986
class BzrDir6(BzrDirPreSplitOut):
987
"""A .bzr version 6 control object.
989
This is a deprecated format and may be removed after sept 2006.
992
def has_workingtree(self):
993
"""See ControlDir.has_workingtree."""
996
def open_repository(self):
997
"""See ControlDir.open_repository."""
998
from bzrlib.plugins.weave_fmt.repository import RepositoryFormat6
999
return RepositoryFormat6().open(self, _found=True)
1001
def open_workingtree(self, unsupported=False, recommend_upgrade=True):
1002
"""See ControlDir.create_workingtree."""
1003
# we don't warn here about upgrades; that ought to be handled for the
1005
from bzrlib.plugins.weave_fmt.workingtree import WorkingTreeFormat2
1006
return WorkingTreeFormat2().open(self, _found=True)